Esempio n. 1
0
        public static List <Vector3> GetPointsOnNodes(List <GraphNode> nodes, int count, float clearanceRadius = 0f)
        {
            if (nodes == null)
            {
                throw new ArgumentNullException("nodes");
            }
            if (nodes.Count == 0)
            {
                throw new ArgumentException("no nodes passed");
            }
            List <Vector3> list = ListPool <Vector3> .Claim(count);

            clearanceRadius *= clearanceRadius;
            if (clearanceRadius > 0f || nodes[0] is TriangleMeshNode || nodes[0] is GridNode)
            {
                List <float> list2 = ListPool <float> .Claim(nodes.Count);

                float num = 0f;
                for (int i = 0; i < nodes.Count; i++)
                {
                    float num2 = nodes[i].SurfaceArea();
                    num2 += 0.001f;
                    num  += num2;
                    list2.Add(num);
                }
                for (int j = 0; j < count; j++)
                {
                    int  num3 = 0;
                    int  num4 = 10;
                    bool flag = false;
                    while (!flag)
                    {
                        flag = true;
                        if (num3 >= num4)
                        {
                            clearanceRadius *= 0.809999943f;
                            num4            += 10;
                            if (num4 > 100)
                            {
                                clearanceRadius = 0f;
                            }
                        }
                        float item = UnityEngine.Random.value * num;
                        int   num5 = list2.BinarySearch(item);
                        if (num5 < 0)
                        {
                            num5 = ~num5;
                        }
                        if (num5 >= nodes.Count)
                        {
                            flag = false;
                        }
                        else
                        {
                            GraphNode graphNode = nodes[num5];
                            Vector3   vector    = graphNode.RandomPointOnSurface();
                            if (clearanceRadius > 0f)
                            {
                                for (int k = 0; k < list.Count; k++)
                                {
                                    if ((list[k] - vector).sqrMagnitude < clearanceRadius)
                                    {
                                        flag = false;
                                        break;
                                    }
                                }
                            }
                            if (flag)
                            {
                                list.Add(vector);
                                break;
                            }
                            num3++;
                        }
                    }
                }
                ListPool <float> .Release(list2);
            }
            else
            {
                for (int l = 0; l < count; l++)
                {
                    list.Add(nodes[UnityEngine.Random.Range(0, nodes.Count)].RandomPointOnSurface());
                }
            }
            return(list);
        }