コード例 #1
0
ファイル: Test0801.cs プロジェクト: Core-Fi/War-Clash
    private static void SearchReflectionPointFromIndex(Vector3d startPosi, int index, FixedABPath path, List <Vector3d> points)
    {
        var      graph          = AstarPath.active.graphs[0] as RecastGraph;
        bool     findStartPoint = true;
        Vector3d left           = new Vector3d();
        Vector3d right          = new Vector3d();
        int      leftIndex      = -1;
        int      rightIndex     = -1;
        int      startPosiIndex = -1;

        for (int i = index; i < path.path.Count; i++)
        {
            if (i != 0)
            {
                TriangleMeshNode prenode = path.path[i - 1] as TriangleMeshNode;
                TriangleMeshNode curnode = path.path[i] as TriangleMeshNode;
                int a, b;
                a = prenode.SharedEdge(curnode);
                b = a == 2?0:a + 1;
                Int3 l = new Int3(); Int3 r = new Int3();
                if (a != -1)
                {
                    l = prenode.GetVertex(a);
                }
                if (b != -1)
                {
                    r = prenode.GetVertex(b);
                }
                if (findStartPoint)
                {
                    left           = Int3.ToVector3D(l);
                    right          = Int3.ToVector3D(r);
                    leftIndex      = i;
                    rightIndex     = i;
                    findStartPoint = false;
                }
                else
                {
                    var tempL     = Int3.ToVector3D(l);
                    var tempR     = Int3.ToVector3D(r);
                    var relationL = GetRelation(left - startPosi, right - startPosi, tempL - startPosi);
                    var relationR = GetRelation(left - startPosi, right - startPosi, tempR - startPosi);
                    //寻找拐点
                    if (relationR == VectorRelation.Left && relationL == VectorRelation.Left)
                    {
                        bool add = AddPoint(left, points);
                        startPosi      = left;
                        startPosiIndex = leftIndex;
                        if (add)
                        {
                            SpawnGO(left, i);
                        }
                        break;
                    }
                    else if (relationR == VectorRelation.Right && relationL == VectorRelation.Right)
                    {
                        bool add = AddPoint(right, points);
                        startPosi      = right;
                        startPosiIndex = rightIndex;
                        if (add)
                        {
                            SpawnGO(right, i);
                        }
                        break;
                    }
                    else if (relationR == VectorRelation.Equal && relationL == VectorRelation.Right)
                    {
                        bool add = AddPoint(right, points);
                        startPosi      = right;
                        startPosiIndex = rightIndex;
                        if (add)
                        {
                            SpawnGO(right, i);
                        }
                        break;
                    }
                    else if (relationR == VectorRelation.Equal && relationL == VectorRelation.Left)
                    {
                        bool add = AddPoint(left, points);
                        startPosi      = left;
                        startPosiIndex = leftIndex;
                        if (add)
                        {
                            SpawnGO(left, i);
                        }
                        break;
                    }
                    //else if (relationL == VectorRelation.Equal && relationR == VectorRelation.Left)
                    //{
                    //    bool add = AddPoint(left, points);
                    //    startPosi = left;
                    //    startPosiIndex = i;
                    //    if (add)
                    //        SpawnGO(left, i);
                    //    break;
                    //}
                    //else if (relationL == VectorRelation.Equal && relationR == VectorRelation.Right)
                    //{
                    //    bool add = AddPoint(right, points);
                    //    startPosi = right;
                    //    startPosiIndex = i;
                    //    if(add)
                    //        SpawnGO(right, i);
                    //    break;
                    //}
                    //改变左右
                    if (relationR == VectorRelation.Inside && relationL == VectorRelation.Inside)
                    {
                        left       = tempL;
                        right      = tempR;
                        leftIndex  = i;
                        rightIndex = i;
                    }
                    if (relationL == VectorRelation.Inside || relationL == VectorRelation.Equal)
                    {
                        left      = tempL;
                        leftIndex = i;
                    }
                    if (relationR == VectorRelation.Inside || relationR == VectorRelation.Equal)
                    {
                        right      = tempR;
                        rightIndex = i;
                    }
                    if (i == path.path.Count - 1)
                    {
                        var relationEndPoint = GetRelation(left - startPosi, right - startPosi,
                                                           path.EndPoint - startPosi);
                        if (relationEndPoint == VectorRelation.Left)
                        {
                            AddPoint(left, points);
                            SpawnGO(left, i);
                        }
                        else if (relationEndPoint == VectorRelation.Right)
                        {
                            AddPoint(right, points);
                            SpawnGO(right, i);
                        }
                    }
                }
            }
        }
        if (startPosiIndex != -1)
        {
            startPosiIndex++;
            SearchReflectionPointFromIndex(startPosi, startPosiIndex, path, points);
        }
    }