Exemplo n.º 1
0
    //到达目的地
    void ReachTarget(NodeItem _node)
    {
        //清除路径
        ClearPath();

        //停止移动动画
        Hero hero = TravelManager.currentHero;

        hero.SetMovingStatus(0);

        hero.transform.position = _node.transform.position;

        GameManager.gameState = GameState.playerControl;

        if (targetNodeObject != null)
        {
            NodeObject_Travel obj = (NodeObject_Travel)targetNodeObject;
            targetNodeObject = null;

            obj.advantureObject.OnInteracted(hero);

            Destroy(obj.gameObject);
        }

        //镜头停止跟随
        TravelCamMgr.instance.StopFocus();
    }
Exemplo n.º 2
0
    public static void CreateAdvantureObject(AdvantureObject _advantureObject, NodeItem_Travel _node)
    {
        AdvantureObject advantureObject = ScriptableObject.Instantiate(_advantureObject, _node.transform);

        NodeObject_Travel nodeObject = _node.CreateNodeObject();

        nodeObject.advantureObject = advantureObject;
        nodeObject.Init();
    }
Exemplo n.º 3
0
    //点击节点
    public override void OnNodePressed(NodeItem _node)
    {
        NodeItem_Travel   node = (NodeItem_Travel)_node;
        NodeObject_Travel obj  = (NodeObject_Travel)node.nodeObject;

        Hero hero = TravelManager.currentHero;

        if (hero == null)
        {
            Debug.LogError("当前英雄为空");
        }

        //有路径,而且点击的是终点,则开始移动。否则寻路
        if (path != null && node.pathType == TravelPathType.goal)
        {
            //是空地直接移动
            //否则移动到目标点,然后开始交互
            if (obj == null)
            {
                MoveObjectAlongPath(hero.gameObject, path);
            }
            else
            {
                targetNodeObject = obj;

                if (obj.objectType == TravelNodeType.empty)
                {
                    MoveObjectAlongPath(hero.gameObject, path);
                }
                //是英雄,或者单位,或者物品,只要移动到相邻处,就能开始交互
                else if (obj.objectType == TravelNodeType.hero ||
                         obj.objectType == TravelNodeType.unit ||
                         obj.objectType == TravelNodeType.item)
                {
                    List <NodeItem> shortPath = new List <NodeItem>(path);
                    shortPath.RemoveAt(shortPath.Count - 1);
                    MoveObjectAlongPath(hero.gameObject, shortPath);
                }
                else
                {
                    //城镇或者地点类物体,进入后交互
                    MoveObjectAlongPath(hero.gameObject, path);
                }
            }
        }
        else
        {
            //清除之前的路径显示
            ClearPath();

            path = AStarManager.FindPath(this, hero.nodeItem, _node);

            int movementRate = hero.movementRate;
            if (path != null)
            {
                NodeItem lastNode;
                for (int i = 1; i < path.Count; i++)
                {
                    lastNode = path[i - 1];

                    if (movementRate >= 0)
                    {
                        movementRate -= GetNodeDistance(lastNode, path[i]);
                    }

                    NodeItem_Travel currentNode = (NodeItem_Travel)path[i];

                    if (i == path.Count - 1)
                    {
                        //是终点
                        currentNode.UpdateStatus(TravelPathType.goal);
                    }
                    else
                    {
                        currentNode.UpdateStatus(TravelPathType.path);
                    }

                    if (movementRate >= 0)
                    {
                        currentNode.ChangeColor(color_reachable);
                    }
                    else
                    {
                        currentNode.ChangeColor(color_outOfReach);
                    }

                    lastNode.GetComponent <NodeItem_Travel>().ArrowFaceTarget(path[i].gameObject);
                }
            }
        }
    }