예제 #1
0
        public static Vector2 SingleLineVector2Field(Rect rect, Vector2 value, GUIContent label, float aspectRatio)
        {
            rect = EditorGUI.PrefixLabel(rect, label);
            using (new LabelWidthScope(14))
            {
                using (new IndentScope(0, false))
                {
                    rect.width = (rect.width - 4) * 0.5f;
                    using (var scope = new ChangeCheckScope(null))
                    {
                        value.x = EditorGUI.FloatField(rect, "X", value.x);
                        if (scope.changed)
                        {
                            value.y = value.x / aspectRatio;
                        }
                    }

                    rect.x = rect.xMax + 4;
                    using (var scope = new ChangeCheckScope(null))
                    {
                        value.y = EditorGUI.FloatField(rect, "Y", value.y);
                        if (scope.changed)
                        {
                            value.x = value.y * aspectRatio;
                        }
                    }
                }
            }
            return(value);
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            position = EditorGUI.PrefixLabel(position, label);

            var typeProp     = property.FindPropertyRelative("type");
            int type         = typeProp.intValue;
            var strengthProp = property.FindPropertyRelative("strength");

            var buttonRect = new Rect(position.x + 1, position.y + 2, EditorGUIKit.paneOptionsIconDark.width, EditorGUIKit.paneOptionsIconDark.height);

            using (var scope = new ChangeCheckScope(null))
            {
                EditorGUIUtility.AddCursorRect(buttonRect, MouseCursor.Arrow);

                System.Enum newType;
                if (fieldInfo.FieldType == typeof(CustomizableInterpolator))
                {
                    newType = EditorGUI.EnumPopup(buttonRect, GUIContent.none, (CustomizableInterpolator.Type)type, buttonStyle);
                }
                else
                {
                    newType = EditorGUI.EnumPopup(buttonRect, GUIContent.none, (Interpolator.Type)type, buttonStyle);
                }

                if (scope.changed)
                {
                    typeProp.intValue       = type = (int)(CustomizableInterpolator.Type)newType;
                    strengthProp.floatValue = 0.5f;
                }
            }

            if ((CustomizableInterpolator.Type)type == CustomizableInterpolator.Type.CustomCurve)
            {
                EditorGUIUtility.AddCursorRect(position, MouseCursor.Zoom);
                EditorGUI.PropertyField(position, property.FindPropertyRelative("customCurve"), GUIContent.none);
            }
            else
            {
                bool drawStrength;

                switch ((CustomizableInterpolator.Type)type)
                {
                case CustomizableInterpolator.Type.Linear:
                case CustomizableInterpolator.Type.Parabolic:
                case CustomizableInterpolator.Type.Sine:
                    drawStrength = false;
                    break;

                default:
                    strengthProp.floatValue = Mathf.Clamp01(EditorGUIKit.DragValue(position, strengthProp.floatValue, 0.01f));
                    drawStrength            = true;
                    break;
                }

                if (Event.current.type == EventType.Repaint)
                {
                    Sample(type, strengthProp.floatValue, Mathf.Min((int)position.width, 256), 0.002f);
                    DrawCurve(position, drawStrength);
                }
            }

            EditorGUI.LabelField(buttonRect, EditorGUIKit.TempContent(image: EditorGUIKit.paneOptionsIconDark), GUIStyle.none);
        }
예제 #3
0
        void OnGUI()
        {
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Start", EditorStyles.boldLabel);

            using (var scope = new ChangeCheckScope(d))
            {
                var rect = EditorGUILayout.GetControlRect();
                rect.width -= 8 + rect.height * 3;
                var startTrans = EditorGUI.ObjectField(rect, GUIContent.none, d.startTrans, typeof(Transform), true) as Transform;

                rect.x     = rect.xMax + 8;
                rect.width = rect.height * 1.5f;
                if (GUI.Button(rect, EditorGUIKit.TempContent("S", null, "Use selection"), EditorStyles.miniButtonLeft))
                {
                    startTrans = Selection.activeTransform;
                }

                rect.x = rect.xMax;
                if (GUI.Button(rect, EditorGUIKit.TempContent("C", null, "Clear reference"), EditorStyles.miniButtonRight))
                {
                    startTrans = null;
                }

                if (scope.changed)
                {
                    d.startTrans = startTrans;
                }
            }

            if (d.startTrans)
            {
                using (var scope = new ChangeCheckScope(d.startTrans))
                {
                    d.startPos = EditorGUILayout.Vector3Field(GUIContent.none, d.startTrans.position);
                    if (scope.changed)
                    {
                        d.startTrans.position = d.startPos;
                    }
                }
            }
            else
            {
                using (var scope = new ChangeCheckScope(d))
                {
                    var startPos = EditorGUILayout.Vector3Field(GUIContent.none, d.startPos);
                    if (scope.changed)
                    {
                        d.startPos = startPos;
                    }
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("End", EditorStyles.boldLabel);

            using (var scope = new ChangeCheckScope(d))
            {
                var rect = EditorGUILayout.GetControlRect();
                rect.width -= 8 + rect.height * 3;
                var endTrans = EditorGUI.ObjectField(rect, GUIContent.none, d.endTrans, typeof(Transform), true) as Transform;

                rect.x     = rect.xMax + 8;
                rect.width = rect.height * 1.5f;
                if (GUI.Button(rect, EditorGUIKit.TempContent("S", null, "Use selection"), EditorStyles.miniButtonLeft))
                {
                    endTrans = Selection.activeTransform;
                }

                rect.x = rect.xMax;
                if (GUI.Button(rect, EditorGUIKit.TempContent("C", null, "Clear reference"), EditorStyles.miniButtonRight))
                {
                    endTrans = null;
                }

                if (scope.changed)
                {
                    d.endTrans = endTrans;
                }
            }

            if (d.endTrans)
            {
                using (var scope = new ChangeCheckScope(d.endTrans))
                {
                    d.endPos = EditorGUILayout.Vector3Field(GUIContent.none, d.endTrans.position);
                    if (scope.changed)
                    {
                        d.endTrans.position = d.endPos;
                    }
                }
            }
            else
            {
                using (var scope = new ChangeCheckScope(d))
                {
                    var endPos = EditorGUILayout.Vector3Field(GUIContent.none, d.endPos);
                    if (scope.changed)
                    {
                        d.endPos = endPos;
                    }
                }
            }

            Vector3 distance = d.endPos - d.startPos;

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Distance", EditorStyles.boldLabel);
            EditorGUILayout.FloatField(GUIContent.none, distance.magnitude);

            using (new HorizontalLayoutScope(0))
            {
                using (new VerticalLayoutScope(0))
                {
                    using (new LabelWidthScope(20))
                    {
                        EditorGUILayout.FloatField("YZ", distance.yz().magnitude);
                        EditorGUILayout.FloatField("XZ", distance.xz().magnitude);
                        EditorGUILayout.FloatField("XY", distance.xy().magnitude);
                    }
                }

                EditorGUILayout.Space();

                using (new VerticalLayoutScope(0))
                {
                    using (new LabelWidthScope(14))
                    {
                        EditorGUILayout.FloatField("X", distance.x);
                        EditorGUILayout.FloatField("Y", distance.y);
                        EditorGUILayout.FloatField("Z", distance.z);
                    }
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Visualization", EditorStyles.boldLabel);
            d.showXYZ = GUILayout.Toggle(d.showXYZ, "Show XYZ 3D", EditorStyles.miniButton);
            d.showYZ  = GUILayout.Toggle(d.showYZ, "Show YZ Plane", EditorStyles.miniButton);
            d.showXZ  = GUILayout.Toggle(d.showXZ, "Show XZ Plane", EditorStyles.miniButton);
            d.showXY  = GUILayout.Toggle(d.showXY, "Show XY Plane", EditorStyles.miniButton);
            EditorGUILayout.Space();
            d.showMoveTools = GUILayout.Toggle(d.showMoveTools, "Show Move Tools", EditorStyles.miniButton);
            Tools.hidden    = !GUILayout.Toggle(!Tools.hidden, "Show Unity Tools", EditorStyles.miniButton);
        }
예제 #4
0
        void OnSceneGUI(SceneView scene)
        {
            if (d.showMoveTools)
            {
                if (d.startTrans)
                {
                    using (var scope = new ChangeCheckScope(d.startTrans))
                    {
                        d.startPos = Handles.PositionHandle(d.startTrans.position, Tools.pivotRotation == PivotRotation.Local ? d.startTrans.rotation : Quaternion.identity);
                        if (scope.changed)
                        {
                            d.startTrans.position = d.startPos;
                        }
                    }
                }
                else
                {
                    using (var scope = new ChangeCheckScope(d))
                    {
                        var startPos = Handles.PositionHandle(d.startPos, Quaternion.identity);
                        if (scope.changed)
                        {
                            d.startPos = startPos;
                            Repaint();
                        }
                    }
                }

                if (d.endTrans)
                {
                    using (var scope = new ChangeCheckScope(d.endTrans))
                    {
                        d.endPos = Handles.PositionHandle(d.endTrans.position, Tools.pivotRotation == PivotRotation.Local ? d.endTrans.rotation : Quaternion.identity);
                        if (scope.changed)
                        {
                            d.endTrans.position = d.endPos;
                        }
                    }
                }
                else
                {
                    using (var scope = new ChangeCheckScope(d))
                    {
                        var endPos = Handles.PositionHandle(d.endPos, Quaternion.identity);
                        if (scope.changed)
                        {
                            d.endPos = endPos;
                            Repaint();
                        }
                    }
                }
            }

            Vector3 distance = d.endPos - d.startPos;
            Vector3 temp;
            float   length;

            if (d.showYZ)
            {
                temp = new Vector3(d.endPos.x, d.startPos.y, d.startPos.z);

                length = Mathf.Abs(distance.x);
                if (length > Mathf.Epsilon)
                {
                    GUI.contentColor = Handles.color = new Color(1f, 0.4f, 0.4f);
                    Handles.DrawLine(d.startPos, temp);
                    Handles.Label((d.startPos + temp) * 0.5f, "X: " + length, EditorStyles.whiteBoldLabel);
                }

                length = distance.yz().magnitude;
                if (length > Mathf.Epsilon)
                {
                    GUI.contentColor = Handles.color = new Color(0.3f, 0.9f, 0.9f);
                    Handles.DrawLine(d.endPos, temp);
                    Handles.Label((d.endPos + temp) * 0.5f, "YZ: " + length, EditorStyles.whiteBoldLabel);
                }
            }

            if (d.showXZ)
            {
                temp = new Vector3(d.startPos.x, d.endPos.y, d.startPos.z);

                length = Mathf.Abs(distance.y);
                if (length > Mathf.Epsilon)
                {
                    GUI.contentColor = Handles.color = new Color(0.4f, 0.9f, 0.4f);
                    Handles.DrawLine(d.startPos, temp);
                    Handles.Label((d.startPos + temp) * 0.5f, "Y: " + length, EditorStyles.whiteBoldLabel);
                }

                length = distance.xz().magnitude;
                if (length > Mathf.Epsilon)
                {
                    GUI.contentColor = Handles.color = new Color(1f, 0.4f, 1f);
                    Handles.DrawLine(d.endPos, temp);
                    Handles.Label((d.endPos + temp) * 0.5f, "XZ: " + length, EditorStyles.whiteBoldLabel);
                }
            }

            if (d.showXY)
            {
                temp = new Vector3(d.startPos.x, d.startPos.y, d.endPos.z);

                length = Mathf.Abs(distance.z);
                if (length > Mathf.Epsilon)
                {
                    GUI.contentColor = Handles.color = new Color(0.4f, 0.7f, 1f);
                    Handles.DrawLine(d.startPos, temp);
                    Handles.Label((d.startPos + temp) * 0.5f, "Z: " + length, EditorStyles.whiteBoldLabel);
                }

                length = distance.xy().magnitude;
                if (length > Mathf.Epsilon)
                {
                    GUI.contentColor = Handles.color = new Color(0.85f, 0.85f, 0.3f);
                    Handles.DrawLine(d.endPos, temp);
                    Handles.Label((d.endPos + temp) * 0.5f, "XY: " + length, EditorStyles.whiteBoldLabel);
                }
            }

            if (d.showXYZ)
            {
                length = distance.magnitude;
                if (length > Mathf.Epsilon)
                {
                    GUI.contentColor = Handles.color = Color.white;
                    Handles.DrawLine(d.startPos, d.endPos);
                    Handles.Label((d.startPos + d.endPos) * 0.5f, "XYZ: " + length, EditorStyles.whiteBoldLabel);
                }
            }
        }