Exemplo n.º 1
0
    protected override PointNode[] CreateNodes(int count)
    {
        var nodes = new PlateformerPointNode[count];

        for (int i = 0; i < nodeCount; i++)
        {
            nodes[i] = new PlateformerPointNode(active);
        }
        return(nodes);
    }
Exemplo n.º 2
0
    public override ProcessResult process()
    {
        if (m_currentPath != null)
        {
            Vector3 currentPosition   = m_tree.getModel().transform.position;
            bool    hasReachEndOfPath = false;
            computeBehaviour();

            if (m_running)
            {
                m_nextNode = m_previousNodes.Peek();
                Vector3 currentWayPointPosition = (Vector3)m_nextNode.position;
                bool    inside = isInside(currentPosition, currentWayPointPosition);
                if (inside)
                {
                    m_previousNode = m_previousNodes.Pop();
                    if (m_previousNodes.Count > 0)
                    {
                        m_nextNode = m_previousNodes.Peek();
                    }
                }
            }
            else
            {
                float distanceToCurrentWayPoint = Vector3.Distance(currentPosition, m_currentPath.vectorPath[m_currentWaypoint]);
                //find if we have reach a wayPoint
                for (int i = 0; i < m_currentPath.vectorPath.Count; i++)
                {
                    float distanceToWaypoint = Vector3.Distance(currentPosition, m_currentPath.vectorPath[i]);
                    bool  inside             = isInside(currentPosition, m_currentPath.vectorPath[i]);
                    if (inside)
                    {
                        if (i < m_currentPath.path.Count)
                        {
                            var currentPlateformerNode = (PlateformerPointNode)m_currentPath.path[i];
                            distanceToCurrentWayPoint = distanceToWaypoint;
                            m_currentWaypoint         = i == (m_currentPath.path.Count - 1) ? i : i + 1;
                            m_previousNode            = (PlateformerPointNode)m_currentPath.path[i];
                            m_previousNodes.Push(m_previousNode);
                        }
                    }
                }

                m_nextNode        = (PlateformerPointNode)m_currentPath.path[m_currentWaypoint];
                hasReachEndOfPath = (m_currentWaypoint == m_currentPath.vectorPath.Count - 1) && (distanceToCurrentWayPoint < 0.5f);
            }

            Move();
            return(ProcessResult.Running);
        }
        return(ProcessResult.Failed);
    }
Exemplo n.º 3
0
    private void Move()
    {
        Vector3 currentPosition = m_tree.getModel().transform.position;;
        Vector2 dir             = (Vector3)m_nextNode.position - currentPosition;
        bool    shouldJump      = false;

        if (m_previousNode != null && m_nextNode != null)
        {
            shouldJump = PlateformerPointNode.shouldJump(m_previousNode, m_nextNode);
        }
        m_tree.getController().setCurrentDirection(dir);
        m_tree.getController().setShouldJump(shouldJump);
    }
Exemplo n.º 4
0
    public static bool shouldJump(PlateformerPointNode current, PlateformerPointNode next)
    {
        bool result        = false;
        var  jumpableNodes = current.data.jumpableNode;

        foreach (var node in jumpableNodes)
        {
            if (node.GetComponent <NodeData>().m_id == next.data.m_id)
            {
                result = true;
            }
        }
        return(result);
    }
Exemplo n.º 5
0
    protected override IEnumerable <Progress> ScanInternal()
    {
        //Creating the nodes
        nodeCount = root.childCount;
        nodes     = CreateNodes(nodeCount);
        m_nodes   = new Dictionary <int, PlateformerPointNode>(nodeCount);

        int c = 0;

        foreach (Transform child in root)
        {
            PlateformerPointNode pNode = (PlateformerPointNode)(nodes[c]);
            nodes[c].position   = (Int3)child.position;
            nodes[c].Walkable   = true;
            nodes[c].gameObject = child.gameObject;
            pNode.setData(child.gameObject.GetComponent <NodeData>());
            var data = child.gameObject.GetComponent <NodeData>();
            m_nodes[pNode.data.getId()] = pNode;
            c++;
        }

        //Creating the connections
        foreach (KeyValuePair <int, PlateformerPointNode> nodeIt in m_nodes)
        {
            PlateformerPointNode node     = nodeIt.Value;
            NodeData             nodeData = node.data;
            var neighbours = nodeData.neighbours;

            var connections = new Connection[neighbours.Length];
            c = 0;
            foreach (GameObject obj in neighbours)
            {
                NodeData n = obj.GetComponent <NodeData>();
                connections[c].node = m_nodes[n.getId()];
                connections[c].cost = (uint)(node.position - connections[c].node.position).costMagnitude; //could add if jumpable
                c++;
            }
            node.connections = connections;
        }

        yield break;
    }
Exemplo n.º 6
0
    public void setCurrentPath(Path p)
    {
        m_currentPath = p;
        var  nodes             = p.path;
        bool previousNodeFound = false;

        for (int i = 0; i < nodes.Count; i++)
        {
            if (nodes[i] == nextNode)
            {
                previousNodeFound = true;
                m_currentWaypoint = i;
                break;
            }
        }
        if (!previousNodeFound)
        {
            m_currentWaypoint = 0;
            nextNode          = null;
        }
    }