예제 #1
0
        // Token: 0x06000522 RID: 1314 RVA: 0x0002CBBC File Offset: 0x0002AFBC
        public static int CountChildren(Transform tr)
        {
            int         num        = 0;
            IEnumerator enumerator = tr.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object    obj = enumerator.Current;
                    Transform tr2 = (Transform)obj;
                    num++;
                    num += PointGraph.CountChildren(tr2);
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            return(num);
        }
예제 #2
0
        public static int CountChildren(Transform tr)
        {
            int num = 0;

            foreach (Transform tr2 in tr)
            {
                num++;
                num += PointGraph.CountChildren(tr2);
            }
            return(num);
        }
        // Token: 0x060025B7 RID: 9655 RVA: 0x001A1650 File Offset: 0x0019F850
        protected static int CountChildren(Transform tr)
        {
            int num = 0;

            foreach (object obj in tr)
            {
                Transform tr2 = (Transform)obj;
                num++;
                num += PointGraph.CountChildren(tr2);
            }
            return(num);
        }
예제 #4
0
 // Token: 0x06000526 RID: 1318 RVA: 0x0002CF88 File Offset: 0x0002B388
 public override void ScanInternal(OnScanStatus statusCallback)
 {
     if (this.root == null)
     {
         GameObject[] array = GameObject.FindGameObjectsWithTag(this.searchTag);
         if (array == null)
         {
             this.nodes     = new PointNode[0];
             this.nodeCount = 0;
             return;
         }
         this.nodes     = new PointNode[array.Length];
         this.nodeCount = this.nodes.Length;
         for (int i = 0; i < this.nodes.Length; i++)
         {
             this.nodes[i] = new PointNode(this.active);
         }
         for (int j = 0; j < array.Length; j++)
         {
             this.nodes[j].SetPosition((Int3)array[j].transform.position);
             this.nodes[j].Walkable   = true;
             this.nodes[j].gameObject = array[j].gameObject;
         }
     }
     else if (!this.recursive)
     {
         this.nodes     = new PointNode[this.root.childCount];
         this.nodeCount = this.nodes.Length;
         for (int k = 0; k < this.nodes.Length; k++)
         {
             this.nodes[k] = new PointNode(this.active);
         }
         int         num        = 0;
         IEnumerator enumerator = this.root.GetEnumerator();
         try
         {
             while (enumerator.MoveNext())
             {
                 object    obj       = enumerator.Current;
                 Transform transform = (Transform)obj;
                 this.nodes[num].SetPosition((Int3)transform.position);
                 this.nodes[num].Walkable   = true;
                 this.nodes[num].gameObject = transform.gameObject;
                 num++;
             }
         }
         finally
         {
             IDisposable disposable;
             if ((disposable = (enumerator as IDisposable)) != null)
             {
                 disposable.Dispose();
             }
         }
     }
     else
     {
         this.nodes     = new PointNode[PointGraph.CountChildren(this.root)];
         this.nodeCount = this.nodes.Length;
         for (int l = 0; l < this.nodes.Length; l++)
         {
             this.nodes[l] = new PointNode(this.active);
         }
         int num2 = 0;
         this.AddChildren(ref num2, this.root);
     }
     if (this.optimizeForSparseGraph)
     {
         this.RebuildNodeLookup();
     }
     if (this.maxDistance >= 0f)
     {
         List <PointNode> list  = new List <PointNode>(3);
         List <uint>      list2 = new List <uint>(3);
         for (int m = 0; m < this.nodes.Length; m++)
         {
             list.Clear();
             list2.Clear();
             PointNode pointNode = this.nodes[m];
             if (this.optimizeForSparseGraph)
             {
                 Int3 lhs  = this.WorldToLookupSpace(pointNode.position);
                 int  num3 = (this.lookupCellSize.y != 0) ? PointGraph.ThreeDNeighbours.Length : 9;
                 for (int n = 0; n < num3; n++)
                 {
                     Int3      key = lhs + PointGraph.ThreeDNeighbours[n];
                     PointNode next;
                     if (this.nodeLookup.TryGetValue(key, out next))
                     {
                         while (next != null)
                         {
                             float num4 = 0f;
                             if (this.IsValidConnection(pointNode, next, out num4))
                             {
                                 list.Add(next);
                                 list2.Add((uint)Mathf.RoundToInt(num4 * 1000f));
                             }
                             next = next.next;
                         }
                     }
                 }
             }
             else
             {
                 for (int num5 = 0; num5 < this.nodes.Length; num5++)
                 {
                     if (m != num5)
                     {
                         PointNode pointNode2 = this.nodes[num5];
                         float     num6       = 0f;
                         if (this.IsValidConnection(pointNode, pointNode2, out num6))
                         {
                             list.Add(pointNode2);
                             list2.Add((uint)Mathf.RoundToInt(num6 * 1000f));
                         }
                     }
                 }
             }
             pointNode.connections     = list.ToArray();
             pointNode.connectionCosts = list2.ToArray();
         }
     }
 }
예제 #5
0
        public override IEnumerable <Progress> ScanInternal()
        {
            yield return(new Progress(0f, "Searching for GameObjects"));

            if (this.root == null)
            {
                GameObject[] gos = (this.searchTag == null) ? null : GameObject.FindGameObjectsWithTag(this.searchTag);
                if (gos == null)
                {
                    this.nodes     = new PointNode[0];
                    this.nodeCount = 0;
                    yield break;
                }
                yield return(new Progress(0.1f, "Creating nodes"));

                this.nodes     = new PointNode[gos.Length];
                this.nodeCount = this.nodes.Length;
                for (int j = 0; j < this.nodes.Length; j++)
                {
                    this.nodes[j] = new PointNode(this.active);
                }
                for (int k = 0; k < gos.Length; k++)
                {
                    this.nodes[k].SetPosition((Int3)gos[k].transform.position);
                    this.nodes[k].Walkable   = true;
                    this.nodes[k].gameObject = gos[k].gameObject;
                }
            }
            else if (!this.recursive)
            {
                this.nodes     = new PointNode[this.root.childCount];
                this.nodeCount = this.nodes.Length;
                for (int l = 0; l < this.nodes.Length; l++)
                {
                    this.nodes[l] = new PointNode(this.active);
                }
                int         num        = 0;
                IEnumerator enumerator = this.root.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        object    obj       = enumerator.Current;
                        Transform transform = (Transform)obj;
                        this.nodes[num].SetPosition((Int3)transform.position);
                        this.nodes[num].Walkable   = true;
                        this.nodes[num].gameObject = transform.gameObject;
                        num++;
                    }
                }
                finally
                {
                    IDisposable disposable;
                    if ((disposable = (enumerator as IDisposable)) != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            else
            {
                this.nodes     = new PointNode[PointGraph.CountChildren(this.root)];
                this.nodeCount = this.nodes.Length;
                for (int m = 0; m < this.nodes.Length; m++)
                {
                    this.nodes[m] = new PointNode(this.active);
                }
                int num2 = 0;
                this.AddChildren(ref num2, this.root);
            }
            if (this.optimizeForSparseGraph)
            {
                yield return(new Progress(0.15f, "Building node lookup"));

                this.RebuildNodeLookup();
            }
            if (this.maxDistance >= 0f)
            {
                List <PointNode> connections          = new List <PointNode>();
                List <uint>      costs                = new List <uint>();
                List <GraphNode> candidateConnections = new List <GraphNode>();
                long             maxPossibleSqrRange;
                if (this.maxDistance == 0f && (this.limits.x == 0f || this.limits.y == 0f || this.limits.z == 0f))
                {
                    maxPossibleSqrRange = long.MaxValue;
                }
                else
                {
                    maxPossibleSqrRange  = (long)(Mathf.Max(this.limits.x, Mathf.Max(this.limits.y, Mathf.Max(this.limits.z, this.maxDistance))) * 1000f) + 1L;
                    maxPossibleSqrRange *= maxPossibleSqrRange;
                }
                for (int i = 0; i < this.nodes.Length; i++)
                {
                    if (i % 512 == 0)
                    {
                        yield return(new Progress(Mathf.Lerp(0.15f, 1f, (float)i / (float)this.nodes.Length), "Connecting nodes"));
                    }
                    connections.Clear();
                    costs.Clear();
                    PointNode node = this.nodes[i];
                    if (this.optimizeForSparseGraph)
                    {
                        candidateConnections.Clear();
                        this.lookupTree.GetInRange(node.position, maxPossibleSqrRange, candidateConnections);
                        Console.WriteLine(i + " " + candidateConnections.Count);
                        for (int n = 0; n < candidateConnections.Count; n++)
                        {
                            PointNode pointNode = candidateConnections[n] as PointNode;
                            float     num3;
                            if (pointNode != node && this.IsValidConnection(node, pointNode, out num3))
                            {
                                connections.Add(pointNode);
                                costs.Add((uint)Mathf.RoundToInt(num3 * 1000f));
                            }
                        }
                    }
                    else
                    {
                        for (int num4 = 0; num4 < this.nodes.Length; num4++)
                        {
                            if (i != num4)
                            {
                                PointNode pointNode2 = this.nodes[num4];
                                float     num5;
                                if (this.IsValidConnection(node, pointNode2, out num5))
                                {
                                    connections.Add(pointNode2);
                                    costs.Add((uint)Mathf.RoundToInt(num5 * 1000f));
                                }
                            }
                        }
                    }
                    node.connections     = connections.ToArray();
                    node.connectionCosts = costs.ToArray();
                }
            }
            yield break;
        }
        // Token: 0x060025BC RID: 9660 RVA: 0x001A17D0 File Offset: 0x0019F9D0
        protected override IEnumerable <Progress> ScanInternal()
        {
            yield return(new Progress(0f, "Searching for GameObjects"));

            if (this.root == null)
            {
                GameObject[] gos = (this.searchTag != null) ? GameObject.FindGameObjectsWithTag(this.searchTag) : null;
                if (gos == null)
                {
                    this.nodes     = new PointNode[0];
                    this.nodeCount = 0;
                    yield break;
                }
                yield return(new Progress(0.1f, "Creating nodes"));

                this.nodeCount = gos.Length;
                this.nodes     = this.CreateNodes(this.nodeCount);
                for (int i = 0; i < gos.Length; i++)
                {
                    this.nodes[i].position   = (Int3)gos[i].transform.position;
                    this.nodes[i].Walkable   = true;
                    this.nodes[i].gameObject = gos[i].gameObject;
                }
                gos = null;
            }
            else
            {
                if (!this.recursive)
                {
                    this.nodeCount = this.root.childCount;
                    this.nodes     = this.CreateNodes(this.nodeCount);
                    int num = 0;
                    using (IEnumerator enumerator = this.root.GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            object    obj       = enumerator.Current;
                            Transform transform = (Transform)obj;
                            this.nodes[num].position   = (Int3)transform.position;
                            this.nodes[num].Walkable   = true;
                            this.nodes[num].gameObject = transform.gameObject;
                            num++;
                        }
                        goto IL_24A;
                    }
                }
                this.nodeCount = PointGraph.CountChildren(this.root);
                this.nodes     = this.CreateNodes(this.nodeCount);
                int num2 = 0;
                this.AddChildren(ref num2, this.root);
            }
IL_24A:
            if (this.optimizeForSparseGraph)
            {
                yield return(new Progress(0.15f, "Building node lookup"));

                this.RebuildNodeLookup();
            }
            foreach (Progress progress in this.ConnectNodesAsync())
            {
                yield return(progress.MapTo(0.16f, 1f, null));
            }
            IEnumerator <Progress> enumerator2 = null;

            yield break;
            yield break;
        }