Example #1
0
    /// <summary>
    /// Check the adj node that walkable
    /// </summary>
    /// <param name="adjNodePos"> adj node to check </param>
    /// <param name="faceDir"> self node walkable face </param>
    /// <returns> adj node that walkable </returns>
    private List <AdjNodeInfo> CastAdjRay(WalkableAxis adjNodePos, WalkableAxis walkableFace)
    {
        Vector3 nodeCentre = transform.position;

        switch (adjNodePos)
        {
        case WalkableAxis.Up: nodeCentre += transform.up; break;

        case WalkableAxis.Down: nodeCentre -= transform.up; break;

        case WalkableAxis.Right: nodeCentre += transform.right; break;

        case WalkableAxis.Left: nodeCentre -= transform.right; break;

        case WalkableAxis.Forward: nodeCentre += transform.forward; break;

        case WalkableAxis.Back: nodeCentre -= transform.forward; break;
        }

        // get all walkable node
        Ray ray = new Ray();

        ray.direction = new Vector3(1, -1, 1);
        ray.origin    = nodeCentre - ray.direction * 100;
        List <Node> originNodes = new List <Node>();

        foreach (var hitInfo in Physics.RaycastAll(ray, 300))
        {
            Node nodeCompn = hitInfo.collider.GetComponent <Node>();
            if (nodeCompn == null)
            {
                continue;
            }
            if (HasFlag((int)nodeCompn.m_walkableAxis, (int)walkableFace) &&
                nodeCompn.ScreenSpacePosition == WorldToScreen(nodeCentre))
            {
                originNodes.Add(nodeCompn);
            }
        }

        // Get legal node
        List <AdjNodeInfo> result = new List <AdjNodeInfo>();

        // origin.y+ walkable
        if (walkableFace == WalkableAxis.Up)
        {
            foreach (var node in originNodes)
            {
                ConnecPoint adjConnec = CheckUpWalkable(node, adjNodePos);
                if (adjConnec != 0)
                {
                    result.Add(new AdjNodeInfo(adjConnec, WalkableAxis.Up, node));
                }
            }
            return(result);
        }

        return(result);
    }
Example #2
0
    // Check whether adjNode'up face wakeable.
    // If walkable, return adjNode connect point type
    // if not, return 0
    private ConnecPoint CheckUpWalkable(Node node, WalkableAxis adjNodeType)
    {
        if ((WalkableAxis.Up & node.m_walkableAxis) != WalkableAxis.Up)
        {
            return(0);  // equal to: return ConnectPoint.None
        }
        switch (adjNodeType)
        {
        case WalkableAxis.Left:
            if (node.transform.position.y >= transform.position.y ||
                HasFlag((int)node.m_nodeType, (int)NodeType.Special_Semi_Cube) ||
                HasFlag((int)m_nodeType, (int)NodeType.Special_Semi_Cube))
            {
                return(ConnecPoint.Upper_X);
            }
            break;

        case WalkableAxis.Right:
            if (node.transform.position.y <= transform.position.y ||
                HasFlag((int)node.m_nodeType, (int)NodeType.Special_Semi_Cube) ||
                HasFlag((int)m_nodeType, (int)NodeType.Special_Semi_Cube))
            {
                return(ConnecPoint.Upper_NX);
            }
            break;

        case WalkableAxis.Back:
            if (node.transform.position.y >= transform.position.y ||
                HasFlag((int)node.m_nodeType, (int)NodeType.Special_Semi_Cube) ||
                HasFlag((int)m_nodeType, (int)NodeType.Special_Semi_Cube))
            {
                return(ConnecPoint.Upper_Z);
            }
            break;

        case WalkableAxis.Forward:
            if (node.transform.position.y <= transform.position.y ||
                HasFlag((int)node.m_nodeType, (int)NodeType.Special_Semi_Cube) ||
                HasFlag((int)m_nodeType, (int)NodeType.Special_Semi_Cube))
            {
                return(ConnecPoint.Upper_NZ);
            }
            break;
        }

        return(0);
    }
Example #3
0
 public AdjNodeInfo(ConnecPoint adjConnecPoint, WalkableAxis adjWalkAxis, Node adjNode)
 {
     m_adjNodeConnecPoint = adjConnecPoint;
     m_adjWalkAxis        = adjWalkAxis;
     m_adjNode            = adjNode;
 }
Example #4
0
 public Transform GetTransByAxis(WalkableAxis axis)
 {
     return(_childTransform[axis.ToString()]);
 }