示例#1
0
        public static Vector3 RandomPoint(this CapsuleCollider that)
        {
            float   radius = that.radius;
            float   height = that.height;
            float   num    = 3.14159274f * radius * radius * height;
            float   num2   = 4.18879032f * radius * radius * radius;
            float   num3   = UnityEngine.Random.Range(0f, num + num2);
            Vector3 result;

            if (num3 < num)
            {
                result   = ColliderExtensions.RandomPointInCircle(radius);
                result.z = result.y;
                result.y = UnityEngine.Random.Range(-height * 0.5f, height * 0.5f);
            }
            else
            {
                result = ColliderExtensions.RandomPointInSphere(radius);
                if (result.y < 0f)
                {
                    result.y -= height * 0.5f;
                }
                else
                {
                    result.y += height * 0.5f;
                }
            }
            int direction = that.direction;

            if (direction != 0)
            {
                if (direction == 2)
                {
                    float y = result.y;
                    result.y = result.z;
                    result.z = y;
                }
            }
            else
            {
                float y2 = result.y;
                result.y = result.x;
                result.x = y2;
            }
            return(result);
        }
示例#2
0
 public static Vector3 RandomPoint(this SphereCollider that)
 {
     return(ColliderExtensions.RandomPointInSphere(that.radius));
 }