Beispiel #1
0
    private static Int3 InternalMove(Int3 srcLoc, Int3 delta, ref Int groundY)
    {
        Int3 num4;

        if ((delta.x == 0) && (delta.z == 0))
        {
            return(delta);
        }
        Int3         end   = srcLoc + delta;
        int          edge  = -1;
        NavMeshGraph graph = PathFindingMachine.Instance.navgationGraph as NavMeshGraph;
        NavMeshNode  node  = graph.bbTree.QueryInside(srcLoc, null);

        if (node == null)
        {
            NavMeshNode node2 = graph.bbTree.QueryInside(end, null);
            if (node2 == null)
            {
                return(Int3.zero);
            }
            else
            {
                edge = node2.EdgeIntersect(srcLoc, end);
                node = node2;
            }
        }

        MoveFromNode(node, edge, srcLoc, end, out num4);

        checkedNodes.Clear();
        groundY = num4.y;
        if (!MoveAxisY)
        {
            num4.y = srcLoc.y;
        }
        return(num4 - srcLoc);
    }
Beispiel #2
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="node"></param>
    /// <param name="startEdge"></param>
    /// <param name="srcLoc"></param>
    /// <param name="destLoc"></param>
    /// <param name="state"></param>
    /// <param name="result">实际可移动到的点</param>
    private static void MoveFromNode(NavMeshNode node, int startEdge, Int3 srcLoc, Int3 destLoc, out Int3 result)
    {
        result = srcLoc;
        while (node != null)
        {
            int num;
            int num10;
            int count = 2;
            // 当前在顶点上
            if (node.IsVertex(srcLoc, out num))
            {
                // 找到所有包含srcLoc这顶点的三角形
                Int3 vertex = node.GetVertex(num);
                List <CheckNodeInfo> nodeInfos = null;
                GetAllNodesByVert(ref nodeInfos, node, vertex);

                // 找到其中将要穿过的三角形
                NavMeshNode node2 = null;
                int         vi    = -1;
                for (int i = 0; i < nodeInfos.Count; i++)
                {
                    CheckNodeInfo info = nodeInfos[i];
                    if ((!checkedNodes.Contains(info.node) && !VectorMath.RightXZ(info.v0, info.v2, destLoc)) && VectorMath.RightOrColinearXZ(info.v0, info.v1, destLoc))
                    {
                        node2 = info.node;
                        vi    = info.vi;
                        break;
                    }
                }
                if (node2 != null)
                {
                    node = node2;
                    // 将要穿过的边
                    startEdge = (vi + 1) % 3;
                    count     = 1;
                }
                else
                {
                    int     num6    = -1;
                    VFactor factor3 = new VFactor();
                    factor3.nom = -2L;
                    factor3.den = 1L;
                    VFactor factor = factor3;
                    for (int j = 0; j < nodeInfos.Count; j++)
                    {
                        CheckNodeInfo info2 = nodeInfos[j];
                        if (!checkedNodes.Contains(info2.node))
                        {
                            int     num8;
                            VFactor factor2 = info2.GetCosineAngle(destLoc, out num8);
                            if (factor2 > factor)
                            {
                                factor = factor2;
                                num6   = num8;
                                node2  = info2.node;
                            }
                        }
                    }
                    if (node2 != null)
                    {
                        MoveAlongEdge(node2, num6, srcLoc, destLoc, out result, true);
                        break;
                    }
                }
            }

            // 将要穿过的边
            int edge = -1;
            if (startEdge == -1)
            {
                edge = node.EdgeIntersect(srcLoc, destLoc);
            }
            else
            {
                edge = node.EdgeIntersect(srcLoc, destLoc, startEdge, count);
            }

            // 不会穿越边
            if (edge == -1)
            {
                if (node.ContainsPoint(destLoc))
                {
                    // 三角形内移动
                    result = destLoc;
                    if (MoveAxisY)
                    {
                        CalculateY(ref result, node);
                    }
                }
                else
                {
                    // 沿边所在直线移动
                    edge = node.GetColinearEdge(srcLoc, destLoc);
                    if (edge != -1)
                    {
                        MoveAlongEdge(node, edge, srcLoc, destLoc, out result, true);
                    }
                }
                break;
            }

            // 会穿过边,则看相邻三角形
            NavMeshNode neighborByEdge = node.GetNeighborByEdge(edge, out num10);
            if (neighborByEdge != null)
            {
                node      = neighborByEdge;
                startEdge = num10 + 1;
                count     = 2;
            }
            else
            {
                MoveAlongEdge(node, edge, srcLoc, destLoc, out result, true);
                break;
            }
        }
    }