コード例 #1
0
 public virtual EBTStatus btexec()
 {
     if (this.m_bActive)
     {
         this.UpdateVariableRegistry();
         EBTStatus status = this.btexec_();
         while (this.m_referencetree && (status == EBTStatus.BT_RUNNING))
         {
             this.m_referencetree = false;
             status = this.btexec_();
         }
         if (this.IsMasked())
         {
             this.LogVariables(false);
         }
         return(status);
     }
     SProfiler.EndSample();
     return(EBTStatus.BT_INVALID);
 }
コード例 #2
0
 private void GenerateNodes(Vector3[] vectorVertices, int[] triangles, out Vector3[] originalVertices, out VInt3[] vertices)
 {
     SProfiler.BeginSample("Init");
     if ((vectorVertices.Length == 0) || (triangles.Length == 0))
     {
         originalVertices = vectorVertices;
         vertices         = new VInt3[0];
         this.nodes       = new TriangleMeshNode[0];
     }
     else
     {
         vertices = new VInt3[vectorVertices.Length];
         int index = 0;
         for (int i = 0; i < vertices.Length; i++)
         {
             vertices[i] = (VInt3)this.matrix.MultiplyPoint3x4(vectorVertices[i]);
         }
         Dictionary <VInt3, int> dictionary = new Dictionary <VInt3, int>();
         int[] numArray = new int[vertices.Length];
         SProfiler.EndSample();
         SProfiler.BeginSample("Hashing");
         for (int j = 0; j < vertices.Length; j++)
         {
             if (!dictionary.ContainsKey(vertices[j]))
             {
                 numArray[index] = j;
                 dictionary.Add(vertices[j], index);
                 index++;
             }
         }
         for (int k = 0; k < triangles.Length; k++)
         {
             VInt3 num5 = vertices[triangles[k]];
             triangles[k] = dictionary[num5];
         }
         VInt3[] numArray2 = vertices;
         vertices         = new VInt3[index];
         originalVertices = new Vector3[index];
         for (int m = 0; m < index; m++)
         {
             vertices[m]         = numArray2[numArray[m]];
             originalVertices[m] = vectorVertices[numArray[m]];
         }
         SProfiler.EndSample();
         SProfiler.BeginSample("Constructing Nodes");
         this.nodes = new TriangleMeshNode[triangles.Length / 3];
         int graphIndex = base.active.astarData.GetGraphIndex(this);
         for (int n = 0; n < this.nodes.Length; n++)
         {
             this.nodes[n] = new TriangleMeshNode(base.active);
             TriangleMeshNode node = this.nodes[n];
             node.GraphIndex = (uint)graphIndex;
             node.Penalty    = base.initialPenalty;
             node.Walkable   = true;
             node.v0         = triangles[n * 3];
             node.v1         = triangles[(n * 3) + 1];
             node.v2         = triangles[(n * 3) + 2];
             if (!Polygon.IsClockwise(vertices[node.v0], vertices[node.v1], vertices[node.v2]))
             {
                 int num9 = node.v0;
                 node.v0 = node.v2;
                 node.v2 = num9;
             }
             if (Polygon.IsColinear(vertices[node.v0], vertices[node.v1], vertices[node.v2]))
             {
                 Debug.DrawLine((Vector3)vertices[node.v0], (Vector3)vertices[node.v1], Color.red);
                 Debug.DrawLine((Vector3)vertices[node.v1], (Vector3)vertices[node.v2], Color.red);
                 Debug.DrawLine((Vector3)vertices[node.v2], (Vector3)vertices[node.v0], Color.red);
             }
             node.UpdatePositionFromVertices();
         }
         SProfiler.EndSample();
         DictionaryView <VInt2, TriangleMeshNode> view = new DictionaryView <VInt2, TriangleMeshNode>();
         int num10 = 0;
         int num11 = 0;
         while (num10 < triangles.Length)
         {
             view[new VInt2(triangles[num10], triangles[num10 + 1])]     = this.nodes[num11];
             view[new VInt2(triangles[num10 + 1], triangles[num10 + 2])] = this.nodes[num11];
             view[new VInt2(triangles[num10 + 2], triangles[num10])]     = this.nodes[num11];
             num11++;
             num10 += 3;
         }
         SProfiler.BeginSample("Connecting Nodes");
         ListLinqView <MeshNode> view2 = new ListLinqView <MeshNode>();
         List <uint>             list  = new List <uint>();
         int num12 = 0;
         int num13 = 0;
         int num14 = 0;
         while (num13 < triangles.Length)
         {
             view2.Clear();
             list.Clear();
             TriangleMeshNode node2 = this.nodes[num14];
             for (int num15 = 0; num15 < 3; num15++)
             {
                 TriangleMeshNode node3;
                 if (view.TryGetValue(new VInt2(triangles[num13 + ((num15 + 1) % 3)], triangles[num13 + num15]), out node3))
                 {
                     view2.Add(node3);
                     VInt3 num16 = node2.position - node3.position;
                     list.Add((uint)num16.costMagnitude);
                 }
             }
             node2.connections     = view2.ToArray();
             node2.connectionCosts = list.ToArray();
             num14++;
             num13 += 3;
         }
         if (num12 > 0)
         {
             Debug.LogError("One or more triangles are identical to other triangles, this is not a good thing to have in a navmesh\nIncreasing the scale of the mesh might help\nNumber of triangles with error: " + num12 + "\n");
         }
         SProfiler.EndSample();
         SProfiler.BeginSample("Rebuilding BBTree");
         RebuildBBTree(this);
         SProfiler.EndSample();
     }
 }