少年修仙传客户端代码仓库
client_Hale
2019-03-25 4534825e23c2dac117e8de04d3bb1eae64dffd33
Fight/Stage/MapEditor/Game/ClientSceneManager.cs
@@ -251,6 +251,7 @@
    }
    private List<MapTrasfer> m_ChkedList = new List<MapTrasfer>();
    private List<MapTrasfer> m_ChkedList1 = new List<MapTrasfer>();
    public Vector3 GetTransPoint(Vector3 start, Vector3 next)
    {
@@ -259,6 +260,176 @@
        return GetNext(start, next);
    }
    public Vector3 GetNext1(Vector3 start, Vector3 dest)
    {
        m_ChkedList1.Clear();
        if (PathFinder.WalkAble(start, dest))
        {
            float _dis = PathFinder.CalculateDistance(start, dest);
            Debug.Log("得出的距离平方为: " + _dis);
            int _chkTransID = -1;
            int _chkIndex = -1;
            float _compareDis = float.MaxValue;
            float _chkDis1;
            float _chkDis2;
            float _totalDis = 0;
            foreach (var _t in m_MapData.transfers)
            {
                if (_t.transferPoints.Length >= 2)
                {
                    if (!PathFinder.WalkAble(_t.transferPoints[0].position, dest)
                     && !PathFinder.WalkAble(_t.transferPoints[_t.transferPoints.Length - 1].position, dest))
                    {
                        continue;
                    }
                    _chkDis1 = Vector3.Distance(_t.transferPoints[0].position, dest);
                    _chkDis2 = Vector3.Distance(_t.transferPoints[_t.transferPoints.Length - 1].position, dest);
                    if (_chkDis1 > _compareDis && _chkDis2 > _compareDis)
                    {
                        continue;
                    }
                    if (_chkDis1 < _chkDis2)
                    {
                        _compareDis = _chkDis1;
                        _chkIndex = 0;
                    }
                    else
                    {
                        _compareDis = _chkDis2;
                        _chkIndex = _t.transferPoints.Length - 1;
                    }
                    m_ChkedList1.Add(_t);
                }
            }
            Debug.LogFormat("离终点最近的点为飞跃组: {0} 的第 {1} 个点", _chkTransID, _chkIndex);
            if (m_ChkedList1.Count == 0)
            {
                return Vector3.zero;
            }
            var _t1 = m_ChkedList1[m_ChkedList1.Count - 1];
            for (int i = 0; i < _t1.transferPoints.Length - 1; ++i)
            {
                var _p1 = _t1.transferPoints[i].position;
                _p1.y = 0;
                var _p2 = _t1.transferPoints[i + 1].position;
                _p2.y = 0;
                _totalDis += Vector3.Distance(_p1, _p2);
                // Debug.LogFormat(" ### 2个点的距离: {0}, {1}", Vector3.Distance(_p1, _p2), _totalDis);
            }
            var _p = _t1.transferPoints[_chkIndex].position;
            _p.y = 0;
            _totalDis += Vector3.Distance(_p, dest);
            //Debug.LogFormat(" ### 终点和跳跃点的距离: {0}, {1}", Vector3.Distance(_p, dest), _totalDis);
            var _nextIdx = _chkIndex == 0 ? _t1.transferPoints.Length - 1 : 0;
            _p = _t1.transferPoints[_nextIdx].position;
            var _startDis = PathFinder.CalculateDistance(start, _p);
            _totalDis += _startDis;
            //Debug.LogFormat(" ### 起点和跳跃点的距离: {0}, {1}", _startDis, _totalDis);
            if (_totalDis < _dis)
            {
                return _p;
            }
            var _next = GetNext11(start, _p, ref _totalDis, _dis);
            if (_totalDis < _dis)
            {
                return _next;
            }
            else
            {
                return Vector3.zero;
            }
        }
        else
        {
            return GetNext(start, dest);
        }
    }
    private Vector3 GetNext11(Vector3 start, Vector3 dest, ref float dis, float totalDis)
    {
        float _chkDis1;
        float _chkDis2;
        float _compareDis = float.MaxValue;
        int _chkTransID = -1;
        int _chkIndex = -1;
        foreach (var _t in m_MapData.transfers)
        {
            if (m_ChkedList1.Contains(_t))
            {
                continue;
            }
            if (_t.transferPoints.Length >= 2)
            {
                if (!PathFinder.WalkAble(_t.transferPoints[0].position, dest)
                 && !PathFinder.WalkAble(_t.transferPoints[_t.transferPoints.Length - 1].position, dest))
                {
                    continue;
                }
                _chkDis1 = Vector3.Distance(_t.transferPoints[0].position, dest);
                _chkDis2 = Vector3.Distance(_t.transferPoints[_t.transferPoints.Length - 1].position, dest);
                if (_chkDis1 > _compareDis && _chkDis2 > _compareDis)
                {
                    continue;
                }
                if (_chkDis1 < _chkDis2)
                {
                    _compareDis = _chkDis1;
                    _chkIndex = 0;
                }
                else
                {
                    _compareDis = _chkDis2;
                    _chkIndex = _t.transferPoints.Length - 1;
                }
                m_ChkedList1.Add(_t);
                _chkTransID = _t.id;
            }
        }
        if (m_ChkedList1.Count == 0)
        {
            return Vector3.zero;
        }
        var _t1 = m_ChkedList1[m_ChkedList1.Count - 1];
        if (_chkTransID != -1)
        {
            for (int i = 0; i < _t1.transferPoints.Length - 1; ++i)
            {
                var _p1 = _t1.transferPoints[i].position;
                _p1.y = 0;
                var _p2 = _t1.transferPoints[i + 1].position;
                _p2.y = 0;
                dis += Vector3.Distance(_p1, _p2);
                // Debug.LogFormat(" ### 2个点的距离: {0}", Vector3.Distance(_p1, _p2));
            }
            var _p = _t1.transferPoints[_chkIndex].position;
            _p.y = 0;
            dis += Vector3.Distance(_p, dest);
            _p = _t1.transferPoints[_chkIndex].position;
            _p.y = 0;
            //Debug.LogFormat(" ### 终点和跳跃点的距离: {0}", Vector3.Distance(_p, dest));
            int _nextIdx = _chkIndex == 0 ? _t1.transferPoints.Length - 1 : 0;
            return GetNext11(start, _t1.transferPoints[_nextIdx].position, ref dis, totalDis);
        }
        else
        {
            int _nextIdx = _chkIndex == 0 ? _t1.transferPoints.Length - 1 : 0;
            return _t1.transferPoints[_nextIdx].position;
        }
    }
    private Vector3 GetNext(Vector3 start, Vector3 next)
    {
        Vector3 _targetPos = Vector3.zero;