コード例 #1
0
 /// <summary>
 /// Create a tree node.
 /// </summary>
 public PathTreeNode(Node node, Node.WalkableAxis axis, PathTreeNode father)
 {
     m_node   = node;
     m_axis   = axis;
     m_father = father;
     _nodes   = new List <PathTreeNode>();
 }
コード例 #2
0
ファイル: PathTree.cs プロジェクト: hdmmY/HDM-MonumentValley
    /// <summary>
    /// Get a tree node from the tree.
    /// </summary>
    /// <returns> return null if there is no such tree node </returns>
    public PathTreeNode FindTreeNode(Node nodeToFind, Node.WalkableAxis axisToFind)
    {
        if (m_head == null)
        {
            return(null);
        }

        Queue <PathTreeNode> queue = new Queue <PathTreeNode>();

        queue.Enqueue(m_head);

        while (queue.Count > 0)
        {
            PathTreeNode treeNode = queue.Dequeue();
            if (treeNode == null)
            {
                continue;
            }

            foreach (var childTreeNode in treeNode.GetChilds())
            {
                if (childTreeNode == null)
                {
                    continue;
                }

                if ((childTreeNode.m_node == nodeToFind) &&
                    (childTreeNode.m_axis == axisToFind))
                {
                    return(childTreeNode);
                }
                else
                {
                    queue.Enqueue(childTreeNode);
                }
            }
        }

        return(null);
    }
コード例 #3
0
    private List <Transform> GetPath(Transform startTrans, Transform endTrans)
    {
        Node startNode = startTrans.parent.GetComponent <Node>();

        Node.WalkableAxis startAxis = StandingAxis;

        Node endNode = endTrans.parent.GetComponent <Node>();

        Node.WalkableAxis endAxis = Node.GetWalkAxisByName(endTrans.name);

        PathTree pathTree = new PathTree(new PathTreeNode(startNode, startAxis, null));

        pathTree.Init();
        List <Transform> pathTrans = pathTree.FindPathFromStartToEnd(endNode, endAxis);

        if (pathTrans == null)
        {
            return(null);
        }

        return(pathTrans);
    }
コード例 #4
0
ファイル: PathTree.cs プロジェクト: hdmmY/HDM-MonumentValley
    /// <summary>
    /// Get a path, from head to endNode
    /// </summary>
    public List <Transform> FindPathFromStartToEnd(Node endNode, Node.WalkableAxis endAxis)
    {
        PathTreeNode curTreeNode = FindTreeNode(endNode, endAxis);

        if (curTreeNode == null)
        {
            return(null);
        }

        List <Transform> path = new List <Transform>();

        // Add first node
        path.Add(curTreeNode.m_node.GetTransByAxis(curTreeNode.m_axis));

        // Add other nodes
        while (curTreeNode != m_head)
        {
            Node curNode = curTreeNode.m_node;
            Node.WalkableAxis curAxis = curTreeNode.m_axis;

            Node fatherNode = curTreeNode.m_father.m_node;
            Node.WalkableAxis fatherAxis = curTreeNode.m_father.m_axis;

            Transform curConnect = curNode.FindConnectTrans(fatherNode);
            Transform adjConnect = fatherNode.FindConnectTrans(curNode);

            path.Add(curConnect);
            path.Add(adjConnect);
            path.Add(fatherNode.GetTransByAxis(fatherAxis));

            curTreeNode = curTreeNode.m_father;
        }

        path.Reverse();
        return(path);
    }
コード例 #5
0
ファイル: Node.cs プロジェクト: hdmmY/HDM-MonumentValley
    /// <summary>
    /// Get the connect point in specific walk axis
    /// </summary>
    public static ConnecPoint[] GetConnectTypeOnFace(Node.WalkableAxis face)
    {
        if (face == Node.WalkableAxis.Up)
        {
            return(new Node.ConnecPoint[]
            {
                Node.ConnecPoint.Upper_X,
                Node.ConnecPoint.Upper_Z,
                Node.ConnecPoint.Upper_NX,
                Node.ConnecPoint.Upper_NZ
            });
        }

        if (face == Node.WalkableAxis.Down)
        {
            return(new Node.ConnecPoint[]
            {
                Node.ConnecPoint.Down_X,
                Node.ConnecPoint.Down_Z,
                Node.ConnecPoint.Down_NX,
                Node.ConnecPoint.Down_NZ
            });
        }

        if (face == Node.WalkableAxis.Left)
        {
            return(new Node.ConnecPoint[]
            {
                Node.ConnecPoint.Upper_NX,
                Node.ConnecPoint.Down_NX,
                Node.ConnecPoint.Middle_NXNZ,
                Node.ConnecPoint.Middle_NXZ
            });
        }

        if (face == Node.WalkableAxis.Right)
        {
            return(new Node.ConnecPoint[]
            {
                Node.ConnecPoint.Upper_X,
                Node.ConnecPoint.Down_X,
                Node.ConnecPoint.Middle_XNZ,
                Node.ConnecPoint.Middle_XZ
            });
        }

        if (face == Node.WalkableAxis.Forward)
        {
            return(new Node.ConnecPoint[]
            {
                Node.ConnecPoint.Upper_Z,
                Node.ConnecPoint.Down_Z,
                Node.ConnecPoint.Middle_NXZ,
                Node.ConnecPoint.Middle_XZ
            });
        }

        if (face == Node.WalkableAxis.Back)
        {
            return(new Node.ConnecPoint[]
            {
                Node.ConnecPoint.Upper_NZ,
                Node.ConnecPoint.Down_NZ,
                Node.ConnecPoint.Middle_NXNZ,
                Node.ConnecPoint.Middle_XNZ
            });
        }

        return(null);
    }