Пример #1
0
    void MovePath()
    {
        //如果有采集、回家图标,则关闭采集,回家图标
        CloseMineIcon();
        CloseHomeIcon();

        string root     = "/Canvas/Scroll View/Viewport/Content/map/pathList/";
        string pathline = "";

        Transform[] _ts = new Transform[0];

        //如果到达终点则打断
        if (playerPoints.Nowpoint == playerPoints.Targetpoint)
        {
            //增加路点次数信息
            PlayerInfo.AddMapInfo(playerPoints.Nowpoint);
            PlayerInfo.SetNowscene(playerPoints.Nowpoint);

            //检测触发事件
            if (eventmanager.CheckEventList(ChatEventManager.ChatEvent.EventTypeList.Arrive, true))
            {
                eventmanager.StartStory();
            }
            else
            {
                questManager.CheckQuestListWithArrive(playerPoints.Targetpoint);
                questManager.IsArriveWaitingCheckPoint(playerPoints.Targetpoint);
                eventmanager.PreCheckEventList(1);
                questManager.PreCheckQuest(1);
            }

            state = MoveState.Stay;
            AniController.Get(MovePlayer).PlayAniBySkin("down", AniController.AniType.LoopBack, 5);

            //关闭路点提示
            ClosePathPoint();
            CloseMovePathLine();
            movePathLine.Clear();

            if (playerPoints.Targetpoint != 1)
            {
                //显示采集图标
                ShowMineIcon(playerPoints.Targetpoint);
                return;
            }
            else
            {
                ShowHomeBoard(1);
                return;
            }
        }

        //找到移动的路径
        for (int i = 0; i <= Bestpaths.Count - 2; i++)
        {
            //根据方向排序
            if ((int)Bestpaths[i] == playerPoints.Nowpoint)
            {
                if ((int)Bestpaths[i + 1] > (int)Bestpaths[i])
                {
                    pathline = "pathLine_" + Bestpaths[i].ToString() + "_" + Bestpaths[i + 1].ToString();
                    Transform t = transform.Find(root + pathline);
                    if (t != null)
                    {
                        _ts = new Transform[t.childCount];
                        for (int j = 0; j < t.childCount; j++)
                        {
                            _ts[j] = t.GetChild(j);
                        }
                    }
                    else
                    {
                        Debug.Log("can't find pathline:" + root + pathline);
                    }
                }
                else
                {
                    pathline = "pathLine_" + Bestpaths[i + 1].ToString() + "_" + Bestpaths[i].ToString();
                    Transform t = transform.Find(root + pathline);
                    if (t != null)
                    {
                        _ts = new Transform[t.childCount];
                        for (int j = 0; j < t.childCount; j++)
                        {
                            _ts[j] = t.GetChild(t.childCount - 1 - j);
                        }
                    }
                    else
                    {
                        Debug.Log("can't find pathline:" + root + pathline);
                    }
                }
                playerPoints.Nextpoint = (int)Bestpaths[i + 1];
                break;
            }
        }

        //移动方法
        if (_ts.Length != 0)
        {
            playerPoints.Nowpoint = playerPoints.Nextpoint;
            Transform _map = transform.Find("/Canvas/Scroll View/Viewport/Content/map");
            Vector3[] vecs = new Vector3[_ts.Length + 2];

            for (int i = 0; i < _ts.Length; i++)
            {
                //vecs[i + 1] = _ts[i].position - _map.position;
                vecs[i + 1] = _ts[i].position;
            }
            vecs[0] = vecs[1];
            vecs[vecs.Length - 1] = vecs[vecs.Length - 2];

            state = MoveState.Moving;
            LTSpline cr   = new LTSpline(vecs);
            float    time = cr.distance / 5;
            LeanTween.move(MovePlayer.gameObject, cr, time).setOnComplete(() =>
            {
                playerPoints.Nowpoint = playerPoints.Nextpoint;
                MovePath();
            });

            SetCharacterVecter(vecs);
        }
    }