private void DrawArc(ArcHandle minHandle, ArcHandle maxHandle, Color color, ArcType arcType)
        {
            float   angle   = maxHandle.angle - minHandle.angle;
            Vector3 forward = Quaternion.AngleAxis(minHandle.angle, Vector3.up) * Vector3.forward;

            using (new Handles.DrawingScope(Handles.color * color))
            {
                if (arcType == ArcType.Solid)
                {
                    for (int i = 0, revolutions = (int)Mathf.Abs(angle) / 360; i < revolutions; ++i)
                    {
                        Handles.DrawSolidArc(Vector3.zero, Vector3.up, Vector3.forward, 360f, radius);
                    }
                    Handles.DrawSolidArc(Vector3.zero, Vector3.up, forward, angle % 360f, radius);
                }
                else
                {
                    for (int i = 0, revolutions = (int)Mathf.Abs(angle) / 360; i < revolutions; ++i)
                    {
                        Handles.DrawWireArc(Vector3.zero, Vector3.up, Vector3.forward, 360f, radius);
                    }
                    Handles.DrawWireArc(Vector3.zero, Vector3.up, forward, angle % 360f, radius);
                }
            }
        }
Example #2
0
        private void DrawArc(ArcHandle minHandle, ArcHandle maxHandle, Color color, JointAngularLimitHandle.ArcType arcType)
        {
            float   num  = maxHandle.angle - minHandle.angle;
            Vector3 from = Quaternion.AngleAxis(minHandle.angle, Vector3.up) * Vector3.forward;

            using (new Handles.DrawingScope(Handles.color * color))
            {
                if (arcType == JointAngularLimitHandle.ArcType.Solid)
                {
                    int i    = 0;
                    int num2 = (int)Mathf.Abs(num) / 360;
                    while (i < num2)
                    {
                        Handles.DrawSolidArc(Vector3.zero, Vector3.up, Vector3.forward, 360f, this.radius);
                        i++;
                    }
                    Handles.DrawSolidArc(Vector3.zero, Vector3.up, from, num % 360f, this.radius);
                }
                else
                {
                    int j    = 0;
                    int num3 = (int)Mathf.Abs(num) / 360;
                    while (j < num3)
                    {
                        Handles.DrawWireArc(Vector3.zero, Vector3.up, Vector3.forward, 360f, this.radius);
                        j++;
                    }
                    Handles.DrawWireArc(Vector3.zero, Vector3.up, from, num % 360f, this.radius);
                }
            }
        }
Example #3
0
        private static float GetSortingDistance(ArcHandle handle)
        {
            Vector3 a   = Handles.matrix.MultiplyPoint3x4(Quaternion.AngleAxis(handle.angle, Vector3.up) * Vector3.forward * handle.radius);
            Vector3 rhs = a - Camera.current.transform.position;

            if (Camera.current.orthographic)
            {
                Vector3 forward = Camera.current.transform.forward;
                rhs = forward * Vector3.Dot(forward, rhs);
            }
            return(rhs.sqrMagnitude);
        }
 public JointAngularLimitHandle()
 {
     m_XMinHandle   = new ArcHandle();
     m_XMaxHandle   = new ArcHandle();
     m_YMinHandle   = new ArcHandle();
     m_YMaxHandle   = new ArcHandle();
     m_ZMinHandle   = new ArcHandle();
     m_ZMaxHandle   = new ArcHandle();
     xMotion        = yMotion = zMotion = ConfigurableJointMotion.Limited;
     radius         = 1f;
     fillAlpha      = 0.1f;
     wireframeAlpha = 1f;
     xRange         = yRange = zRange = new Vector2(-180f, 180f);
 }
Example #5
0
        // handle functions need to be manually sorted
        private static float GetSortingDistance(ArcHandle handle)
        {
            Vector3 worldPosition = Handles.matrix.MultiplyPoint3x4(
                Quaternion.AngleAxis(handle.angle, Vector3.up) * Vector3.forward * handle.radius
                );
            Vector3 toHandle = worldPosition - Camera.current.transform.position;

            if (Camera.current.orthographic)
            {
                Vector3 lookVector = Camera.current.transform.forward;
                toHandle = lookVector * Vector3.Dot(lookVector, toHandle);
            }
            return(toHandle.sqrMagnitude);
        }
Example #6
0
        public JointAngularLimitHandle()
        {
            this.m_XMinHandle = new ArcHandle();
            this.m_XMaxHandle = new ArcHandle();
            this.m_YMinHandle = new ArcHandle();
            this.m_YMaxHandle = new ArcHandle();
            this.m_ZMinHandle = new ArcHandle();
            this.m_ZMaxHandle = new ArcHandle();
            ConfigurableJointMotion configurableJointMotion = ConfigurableJointMotion.Limited;

            this.zMotion            = configurableJointMotion;
            configurableJointMotion = configurableJointMotion;
            this.yMotion            = configurableJointMotion;
            this.xMotion            = configurableJointMotion;
            this.radius             = 1f;
            this.fillAlpha          = 0.1f;
            this.wireframeAlpha     = 1f;
            Vector2 vector = new Vector2(-180f, 180f);

            this.zRange = vector;
            vector      = vector;
            this.yRange = vector;
            this.xRange = vector;
        }
Example #7
0
        public void DrawHandle()
        {
            this.m_SecondaryAxesMatrix = Handles.matrix;
            this.xHandleColor          = this.xHandleColor;
            this.yHandleColor          = this.yHandleColor;
            this.zHandleColor          = this.zHandleColor;
            ArcHandle arg_49_0 = this.m_XMinHandle;
            Color     clear    = Color.clear;

            this.m_XMinHandle.wireframeColor = clear;
            arg_49_0.fillColor = clear;
            ArcHandle arg_67_0 = this.m_XMaxHandle;

            clear = Color.clear;
            this.m_XMaxHandle.wireframeColor = clear;
            arg_67_0.fillColor = clear;
            ArcHandle arg_85_0 = this.m_YMinHandle;

            clear = Color.clear;
            this.m_YMinHandle.wireframeColor = clear;
            arg_85_0.fillColor = clear;
            ArcHandle arg_A3_0 = this.m_YMaxHandle;

            clear = Color.clear;
            this.m_YMaxHandle.wireframeColor = clear;
            arg_A3_0.fillColor = clear;
            ArcHandle arg_C1_0 = this.m_ZMinHandle;

            clear = Color.clear;
            this.m_ZMinHandle.wireframeColor = clear;
            arg_C1_0.fillColor = clear;
            ArcHandle arg_DF_0 = this.m_ZMaxHandle;

            clear = Color.clear;
            this.m_ZMaxHandle.wireframeColor = clear;
            arg_DF_0.fillColor = clear;
            Color b     = new Color(1f, 1f, 1f, this.fillAlpha);
            bool  flag  = false;
            bool  flag2 = false;
            bool  flag3 = false;
            ConfigurableJointMotion xMotion = this.xMotion;

            if (xMotion != ConfigurableJointMotion.Free)
            {
                if (xMotion != ConfigurableJointMotion.Limited)
                {
                    if (xMotion == ConfigurableJointMotion.Locked)
                    {
                        using (new Handles.DrawingScope(Handles.color * Color.Lerp(this.xHandleColor, JointAngularLimitHandle.s_LockedColor, JointAngularLimitHandle.s_LockedColorAmount)))
                        {
                            Handles.DrawWireDisc(Vector3.zero, Vector3.right, this.radius);
                        }
                    }
                }
                else
                {
                    flag = true;
                    this.m_SecondaryAxesMatrix *= Matrix4x4.TRS(Vector3.zero, Quaternion.AngleAxis((this.xMin + this.xMax) * 0.5f, Vector3.left), Vector3.one);
                    if (this.yMotion == ConfigurableJointMotion.Limited)
                    {
                        this.DrawMultiaxialFillShape();
                    }
                    else
                    {
                        using (new Handles.DrawingScope(Handles.matrix * JointAngularLimitHandle.s_XHandleOffset))
                        {
                            this.DrawArc(this.m_XMinHandle, this.m_XMaxHandle, this.xHandleColor * b, JointAngularLimitHandle.ArcType.Solid);
                        }
                    }
                }
            }
            else
            {
                using (new Handles.DrawingScope(Handles.color * this.xHandleColor))
                {
                    Handles.DrawWireDisc(Vector3.zero, Vector3.right, this.radius);
                    Handles.color *= b;
                    Handles.DrawSolidDisc(Vector3.zero, Vector3.right, this.radius);
                }
            }
            using (new Handles.DrawingScope(this.m_SecondaryAxesMatrix))
            {
                ConfigurableJointMotion yMotion = this.yMotion;
                if (yMotion != ConfigurableJointMotion.Free)
                {
                    if (yMotion != ConfigurableJointMotion.Limited)
                    {
                        if (yMotion == ConfigurableJointMotion.Locked)
                        {
                            using (new Handles.DrawingScope(Handles.color * Color.Lerp(this.yHandleColor, JointAngularLimitHandle.s_LockedColor, JointAngularLimitHandle.s_LockedColorAmount)))
                            {
                                Handles.DrawWireDisc(Vector3.zero, Vector3.up, this.radius);
                            }
                        }
                    }
                    else
                    {
                        flag2 = true;
                        if (this.xMotion != ConfigurableJointMotion.Limited)
                        {
                            this.DrawArc(this.m_YMinHandle, this.m_YMaxHandle, this.yHandleColor * b, JointAngularLimitHandle.ArcType.Solid);
                        }
                    }
                }
                else
                {
                    using (new Handles.DrawingScope(Handles.color * this.yHandleColor))
                    {
                        Handles.DrawWireDisc(Vector3.zero, Vector3.up, this.radius);
                        Handles.color *= b;
                        Handles.DrawSolidDisc(Vector3.zero, Vector3.up, this.radius);
                    }
                }
                ConfigurableJointMotion zMotion = this.zMotion;
                if (zMotion != ConfigurableJointMotion.Free)
                {
                    if (zMotion != ConfigurableJointMotion.Limited)
                    {
                        if (zMotion == ConfigurableJointMotion.Locked)
                        {
                            using (new Handles.DrawingScope(Handles.color * Color.Lerp(this.zHandleColor, JointAngularLimitHandle.s_LockedColor, JointAngularLimitHandle.s_LockedColorAmount)))
                            {
                                Handles.DrawWireDisc(Vector3.zero, Vector3.forward, this.radius);
                            }
                        }
                    }
                    else
                    {
                        using (new Handles.DrawingScope(Handles.matrix * JointAngularLimitHandle.s_ZHandleOffset))
                        {
                            this.DrawArc(this.m_ZMinHandle, this.m_ZMaxHandle, this.zHandleColor * b, JointAngularLimitHandle.ArcType.Solid);
                        }
                        flag3 = true;
                    }
                }
                else
                {
                    using (new Handles.DrawingScope(Handles.color * this.zHandleColor))
                    {
                        Handles.DrawWireDisc(Vector3.zero, Vector3.forward, this.radius);
                        Handles.color *= b;
                        Handles.DrawSolidDisc(Vector3.zero, Vector3.forward, this.radius);
                    }
                }
            }
            this.m_HandleFunctionDistances.Clear();
            this.m_XMinHandle.GetControlIDs();
            this.m_XMaxHandle.GetControlIDs();
            this.m_YMinHandle.GetControlIDs();
            this.m_YMaxHandle.GetControlIDs();
            this.m_ZMinHandle.GetControlIDs();
            this.m_ZMaxHandle.GetControlIDs();
            if (flag)
            {
                using (new Handles.DrawingScope(Handles.matrix * JointAngularLimitHandle.s_XHandleOffset))
                {
                    this.DrawArc(this.m_XMinHandle, this.m_XMaxHandle, this.xHandleColor, JointAngularLimitHandle.ArcType.Wire);
                    this.m_HandleFunctionDistances.Add(new KeyValuePair <Action, float>(new Action(this.DrawXMinHandle), JointAngularLimitHandle.GetSortingDistance(this.m_XMinHandle)));
                    this.m_HandleFunctionDistances.Add(new KeyValuePair <Action, float>(new Action(this.DrawXMaxHandle), JointAngularLimitHandle.GetSortingDistance(this.m_XMaxHandle)));
                }
            }
            using (new Handles.DrawingScope(this.m_SecondaryAxesMatrix))
            {
                if (flag2)
                {
                    this.DrawArc(this.m_YMinHandle, this.m_YMaxHandle, this.yHandleColor, JointAngularLimitHandle.ArcType.Wire);
                    this.m_HandleFunctionDistances.Add(new KeyValuePair <Action, float>(new Action(this.DrawYMinHandle), JointAngularLimitHandle.GetSortingDistance(this.m_YMinHandle)));
                    this.m_HandleFunctionDistances.Add(new KeyValuePair <Action, float>(new Action(this.DrawYMaxHandle), JointAngularLimitHandle.GetSortingDistance(this.m_YMaxHandle)));
                }
                if (flag3)
                {
                    using (new Handles.DrawingScope(Handles.matrix * JointAngularLimitHandle.s_ZHandleOffset))
                    {
                        this.DrawArc(this.m_ZMinHandle, this.m_ZMaxHandle, this.zHandleColor, JointAngularLimitHandle.ArcType.Wire);
                        this.m_HandleFunctionDistances.Add(new KeyValuePair <Action, float>(new Action(this.DrawZMinHandle), JointAngularLimitHandle.GetSortingDistance(this.m_ZMinHandle)));
                        this.m_HandleFunctionDistances.Add(new KeyValuePair <Action, float>(new Action(this.DrawZMaxHandle), JointAngularLimitHandle.GetSortingDistance(this.m_ZMaxHandle)));
                    }
                }
            }
            List <KeyValuePair <Action, float> > arg_72E_0 = this.m_HandleFunctionDistances;

            if (JointAngularLimitHandle.< > f__mg$cache0 == null)
            {
                JointAngularLimitHandle.< > f__mg$cache0 = new Comparison <KeyValuePair <Action, float> >(JointAngularLimitHandle.CompareHandleFunctionsByDistance);
            }
            arg_72E_0.Sort(JointAngularLimitHandle.< > f__mg$cache0);
            foreach (KeyValuePair <Action, float> current in this.m_HandleFunctionDistances)
            {
                current.Key();
            }
        }
Example #8
0
 public void DrawHandle()
 {
     if (!this.m_ControlIDsReserved)
     {
         this.GetControlIDs();
     }
     this.m_ControlIDsReserved = false;
     if (Handles.color.a != 0f)
     {
         Vector3 vector = Handles.matrix.MultiplyPoint3x4(Vector3.one) - Handles.matrix.MultiplyPoint3x4(Vector3.zero);
         if (vector.x != 0f || vector.z != 0f)
         {
             Vector3 vector2 = Quaternion.AngleAxis(this.angle, Vector3.up) * Vector3.forward * this.radius;
             float   num     = Mathf.Abs(this.angle);
             float   num2    = this.angle % 360f;
             using (new Handles.DrawingScope(Handles.color * this.fillColor))
             {
                 if (Handles.color.a > 0f)
                 {
                     int i    = 0;
                     int num3 = (int)num / 360;
                     while (i < num3)
                     {
                         Handles.DrawSolidArc(Vector3.zero, Vector3.up, Vector3.forward, 360f, this.radius);
                         i++;
                     }
                     Handles.DrawSolidArc(Vector3.zero, Vector3.up, Vector3.forward, num2, this.radius);
                 }
             }
             using (new Handles.DrawingScope(Handles.color * this.wireframeColor))
             {
                 if (Handles.color.a > 0f)
                 {
                     Handles.DrawWireArc(Vector3.zero, Vector3.up, Vector3.forward, (num < 360f) ? num2 : 360f, this.radius);
                 }
             }
             if (Event.current.alt)
             {
                 bool  flag = true;
                 int[] radiusHandleControlIDs = this.m_RadiusHandleControlIDs;
                 for (int j = 0; j < radiusHandleControlIDs.Length; j++)
                 {
                     int num4 = radiusHandleControlIDs[j];
                     if (num4 == GUIUtility.hotControl)
                     {
                         flag = false;
                         break;
                     }
                 }
                 if (flag && GUIUtility.hotControl != this.m_AngleHandleControlID)
                 {
                     return;
                 }
             }
             using (new Handles.DrawingScope(Handles.color * this.radiusHandleColor))
             {
                 if (Handles.color.a > 0f)
                 {
                     float num5 = Mathf.Sign(this.angle);
                     int   num6 = Mathf.Min(1 + (int)(Mathf.Min(360f, num) * 0.0111111114f), 4);
                     for (int k = 0; k < num6; k++)
                     {
                         Quaternion q = Quaternion.AngleAxis((float)k * 90f * num5, Vector3.up);
                         using (new Handles.DrawingScope(Handles.matrix * Matrix4x4.TRS(Vector3.zero, q, Vector3.one)))
                         {
                             Vector3 vector3 = Vector3.forward * this.radius;
                             EditorGUI.BeginChangeCheck();
                             float               num7      = (this.radiusHandleSizeFunction != null) ? this.radiusHandleSizeFunction(vector3) : ArcHandle.DefaultRadiusHandleSizeFunction(vector3);
                             int                 arg_37A_0 = this.m_RadiusHandleControlIDs[k];
                             Vector3             arg_37A_1 = vector3;
                             Vector3             arg_37A_2 = Vector3.forward;
                             float               arg_37A_3 = num7;
                             Handles.CapFunction arg_37A_4;
                             if ((arg_37A_4 = this.radiusHandleDrawFunction) == null)
                             {
                                 if (ArcHandle.< > f__mg$cache0 == null)
                                 {
                                     ArcHandle.< > f__mg$cache0 = new Handles.CapFunction(ArcHandle.DefaultRadiusHandleDrawFunction);
                                 }
                                 arg_37A_4 = ArcHandle.< > f__mg$cache0;
                             }
                             Vector3 a = Handles.Slider(arg_37A_0, arg_37A_1, arg_37A_2, arg_37A_3, arg_37A_4, SnapSettings.move.z);
                             if (EditorGUI.EndChangeCheck())
                             {
                                 this.radius += (a - vector3).z;
                             }
                         }
                     }
                 }
             }
             using (new Handles.DrawingScope(Handles.color * this.angleHandleColor))
             {
                 if (Handles.color.a > 0f)
                 {
                     EditorGUI.BeginChangeCheck();
                     float handleSize = (this.angleHandleSizeFunction != null) ? this.angleHandleSizeFunction(vector2) : ArcHandle.DefaultAngleHandleSizeFunction(vector2);
                     vector2 = Handles.Slider2D(this.m_AngleHandleControlID, vector2, Vector3.up, Vector3.forward, Vector3.right, handleSize, this.angleHandleDrawFunction ?? new Handles.CapFunction(this.DefaultAngleHandleDrawFunction), Vector2.zero);
                     if (EditorGUI.EndChangeCheck())
                     {
                         float target = Vector3.Angle(Vector3.forward, vector2) * Mathf.Sign(Vector3.Dot(Vector3.right, vector2));
                         this.angle += Mathf.DeltaAngle(this.angle, target);
                         this.angle  = Handles.SnapValue(this.angle, SnapSettings.rotation);
                     }
                 }
             }
         }
     }
 }