Esempio n. 1
0
        public NavMeshInstance(NavMesh mesh, TravelMode mode, int startNode, bool random, bool reverse, bool allowU, int timeOut)
        {
            m_navMesh = mesh;
            m_currentNode = new Node(startNode);

            m_overrideMode = mode;
            m_startNode = startNode;
            m_random = random;
            m_reverse = reverse;
            m_allowU = allowU;
            timeOut = Math.Max(0, timeOut);

            m_timeOut = timeOut;
        }
Esempio n. 2
0
        public Node GetNextNode()
        {
            if (m_random)
                m_currentNode = m_navMesh.GetRandomNode(m_currentNode, m_allowU);
            else
            {
                if (m_reverse == false)
                    m_currentNode = m_navMesh.GetNextNode(m_currentNode);
                else
                    m_currentNode = m_navMesh.GetPreviousNode(m_currentNode);
            }

            if (m_overrideMode != TravelMode.None)
                m_currentNode.Mode = m_overrideMode;

            return m_currentNode;
        }
Esempio n. 3
0
        // returns random node connected to the specified previous node
        public Node GetRandomNode(Node previous, bool allowU)
        {
            List<Node> nodes = new List<Node>();
            foreach (Edge edge in m_edges)
            {
                if (allowU && edge.End == previous.Index)
                {
                    Node node = new Node(edge.Start);
                    node.Mode = edge.Mode;
                    try
                    {
                        node.Position = m_nodes[edge.Start];
                    }
                    catch (System.Exception)
                    {
                        node.Position = previous.Position;
                    }

                    nodes.Add(node);
                }
                if (edge.Start == previous.Index)
                {
                    Node node = new Node(edge.End);
                    node.Mode = edge.Mode;
                    try
                    {
                        node.Position = m_nodes[edge.End];
                    }
                    catch (System.Exception)
                    {
                        node.Position = previous.Position;
                    }

                    nodes.Add(node);
                }
            }

            if (nodes.Count > 0)
            {
                int index = Util.RandomClass.Next(0, nodes.Count);
                return nodes[index];
            }
            throw new Exception("Path node number " + previous.Index.ToString() + " does not exist for path " + Name + ".");
        }
Esempio n. 4
0
        // returns previous node
        public Node GetPreviousNode(Node previous)
        {
            foreach (Edge edge in m_edges)
            {
                if (edge.End == previous.Index)
                {
                    Node node = new Node(edge.Start);
                    node.Mode = edge.Mode;
                    try
                    {
                        node.Position = m_nodes[edge.Start];
                    }
                    catch (System.Exception)
                    {
                        node.Position = previous.Position;
                    }

                    return node;
                }
            }
            throw new Exception("Path node number " + previous.Index.ToString() + " does not exist for path " + Name + ".");
        }