示例#1
0
        public static void Cylinder(Vector3 start, Vector3 end, Color color, float radius = 1, float duration = 0, bool depthTest = true)
        {
            Vector3 up      = (end - start).normalized * radius;
            Vector3 forward = Vector3.Slerp(up, -up, 0.5f);
            Vector3 right   = Vector3.Cross(up, forward).normalized *radius;

            //Radial circles
            AdvancedDebug.Circle(start, up, color, radius, duration, depthTest);
            AdvancedDebug.Circle(end, -up, color, radius, duration, depthTest);
            AdvancedDebug.Circle((start + end) * 0.5f, up, color, radius, duration, depthTest);

            //Side lines
            Debug.DrawLine(start + right, end + right, color, duration, depthTest);
            Debug.DrawLine(start - right, end - right, color, duration, depthTest);

            Debug.DrawLine(start + forward, end + forward, color, duration, depthTest);
            Debug.DrawLine(start - forward, end - forward, color, duration, depthTest);

            //Start endcap
            Debug.DrawLine(start - right, start + right, color, duration, depthTest);
            Debug.DrawLine(start - forward, start + forward, color, duration, depthTest);

            //End endcap
            Debug.DrawLine(end - right, end + right, color, duration, depthTest);
            Debug.DrawLine(end - forward, end + forward, color, duration, depthTest);
        }
示例#2
0
        public static void Capsule(Vector3 start, Vector3 end, Color color, float radius = 1, float duration = 0, bool depthTest = true)
        {
            Vector3 up      = (end - start).normalized * radius;
            Vector3 forward = Vector3.Slerp(up, -up, 0.5f);
            Vector3 right   = Vector3.Cross(up, forward).normalized *radius;

            float   height     = (start - end).magnitude;
            float   sideLength = Mathf.Max(0, (height * 0.5f) - radius);
            Vector3 middle     = (end + start) * 0.5f;

            start = middle + ((start - middle).normalized * sideLength);
            end   = middle + ((end - middle).normalized * sideLength);

            //Radial circles
            AdvancedDebug.Circle(start, up, color, radius, duration, depthTest);
            AdvancedDebug.Circle(end, -up, color, radius, duration, depthTest);

            //Side lines
            Debug.DrawLine(start + right, end + right, color, duration, depthTest);
            Debug.DrawLine(start - right, end - right, color, duration, depthTest);

            Debug.DrawLine(start + forward, end + forward, color, duration, depthTest);
            Debug.DrawLine(start - forward, end - forward, color, duration, depthTest);

            for (int i = 1; i < 26; i++)
            {
                //Start endcap
                Debug.DrawLine(Vector3.Slerp(right, -up, i / 25) + start, Vector3.Slerp(right, -up, (i - 1) / 25) + start, color, duration, depthTest);
                Debug.DrawLine(Vector3.Slerp(-right, -up, i / 25) + start, Vector3.Slerp(-right, -up, (i - 1) / 25) + start, color, duration, depthTest);
                Debug.DrawLine(Vector3.Slerp(forward, -up, i / 25) + start, Vector3.Slerp(forward, -up, (i - 1) / 25) + start, color, duration, depthTest);
                Debug.DrawLine(Vector3.Slerp(-forward, -up, i / 25) + start, Vector3.Slerp(-forward, -up, (i - 1) / 25) + start, color, duration, depthTest);

                //End endcap
                Debug.DrawLine(Vector3.Slerp(right, up, i / 25) + end, Vector3.Slerp(right, up, (i - 1) / 25) + end, color, duration, depthTest);
                Debug.DrawLine(Vector3.Slerp(-right, up, i / 25) + end, Vector3.Slerp(-right, up, (i - 1) / 25) + end, color, duration, depthTest);
                Debug.DrawLine(Vector3.Slerp(forward, up, i / 25) + end, Vector3.Slerp(forward, up, (i - 1) / 25) + end, color, duration, depthTest);
                Debug.DrawLine(Vector3.Slerp(-forward, up, i / 25) + end, Vector3.Slerp(-forward, up, (i - 1) / 25) + end, color, duration, depthTest);
            }
        }