Пример #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);
            Vector2 orgIconSize = EditorGUIUtility.GetIconSize();

            EditorGUIUtility.SetIconSize(Vector2.one * 32f);

            Rect line = position.Clone(height: lineH + 16f);

            property.isExpanded = EditorGUI.Foldout(line, property.isExpanded, ZoomSectionLabel, true);
            EditorGUIUtility.SetIconSize(orgIconSize);

            if (property.isExpanded)
            {
                float forward  = property.FindPropertyRelative("m_ForwardLimit").floatValue;
                float backward = property.FindPropertyRelative("m_BackwardLimit").floatValue;
                line = line.GetRectBottom(height: lineH * 2f).Modify(y: lineS);
                if (property.FindPropertyRelative("m_Distance").floatValue < 0.1f)
                {
                    EditorGUI.HelpBox(line, "To enable zoom method, input vaild [Distance]", MessageType.Warning);
                }
                else if (forward < 0.1f && backward < 0.1f)
                {
                    EditorGUI.HelpBox(line, "Drag slider bar or input [Forward] & [Backward] to config zoom range.", MessageType.Warning);
                }
                else
                {
                    EditorGUI.HelpBox(line, "You may adjust [Speed] to override the camera zoom speed.", MessageType.Info);
                }

                // Distance
                line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                SerializedProperty distanceProp = property.FindPropertyRelative("m_Distance");
                EditorGUI.BeginChangeCheck();
                EditorGUI.PropertyField(line, distanceProp, ZoomDistanceLabel);
                if (EditorGUI.EndChangeCheck())
                {
                    distanceProp.floatValue = Mathf.Abs(distanceProp.floatValue);
                }

                // Speed
                line = line.GetRectBottom().Modify(y: lineS);
                SerializedProperty speedProp = property.FindPropertyRelative("m_Speed");
                EditorGUI.BeginChangeCheck();
                EditorGUI.PropertyField(line, speedProp, ZoomSpeedLabel);
                if (EditorGUI.EndChangeCheck() && speedProp.floatValue <= 0f)
                {
                    speedProp.floatValue = 1f;
                }

                line = line.GetRectBottom().Modify(y: lineS);
                SerializedProperty
                    forwardLimitProp  = property.FindPropertyRelative("m_ForwardLimit"),
                    backwardLimitProp = property.FindPropertyRelative("m_BackwardLimit");
                float max             = distanceProp.floatValue;
                float min             = -max;
                EditorGUI.BeginChangeCheck();
                EditorGUI.MinMaxSlider(line, ref forward, ref backward, min, max);
                if (EditorGUI.EndChangeCheck() && forward <= 0 && backward >= 0)
                {
                    forwardLimitProp.floatValue  = Mathf.Clamp(forward, min, 0f);;
                    backwardLimitProp.floatValue = Mathf.Clamp(backward, 0f, max);
                }

                line = line.GetRectBottom().Modify(y: lineS);
                Rect cell = line.Clone(width: line.width / 4f);
                EditorGUI.BeginChangeCheck();
                EditorGUI.PrefixLabel(cell, ZoomForwardLabel);
                cell = cell.GetRectRight();
                float forward2 = EditorGUI.FloatField(cell, GUIContent.none, forwardLimitProp.floatValue);
                cell = cell.GetRectRight();
                EditorGUI.PrefixLabel(cell, ZoomBackwardLabel);
                cell = cell.GetRectRight();
                float backward2 = EditorGUI.FloatField(cell, GUIContent.none, backwardLimitProp.floatValue);
                if (EditorGUI.EndChangeCheck())
                {
                    if (forward2 <= 0 && forward2 >= min)
                    {
                        forwardLimitProp.floatValue = Mathf.Clamp(forward2, min, 0f);
                    }
                    if (backward2 >= 0)
                    {
                        backwardLimitProp.floatValue = Mathf.Clamp(backward2, 0f, max);
                    }
                }

                SerializedProperty reboundProp = property.FindPropertyRelative("m_Rebound");
                if (reboundProp.boolValue)
                {
                    line = line.GetRectBottom(height: lineH * 2f).Modify(y: lineS + 10f);
                    EditorGUI.HelpBox(line,
                                      string.Format("Enable \"Rebound\" method, the camera will trying to reset its position to the initial direction."),
                                      MessageType.Info);
                }

                line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                EditorGUI.PropertyField(line, reboundProp, ReboundLabel);
                if (reboundProp.boolValue)
                {
                    line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                    EditorGUI.PropertyField(line, property.FindPropertyRelative("m_ReboundDelay"), ReboundDelayLabel);
                    line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                    EditorGUI.PropertyField(line, property.FindPropertyRelative("m_ReboundPeriod"), ReboundPeriodLabel);
                    line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                    AnimationCurve curve = EditorGUI.CurveField(line, ReboundCurveLabel, property.FindPropertyRelative("m_ReboundCurve").animationCurveValue);
                    curve.Clamp(0f, -1f, 1f, 1f);
                    property.FindPropertyRelative("m_ReboundCurve").animationCurveValue = curve;
                    if (!curve.MatchStartEndKeysValues(0f, 1f))
                    {
                        line = line.GetRectBottom(height: 40f).Modify(y: lineS);
                        if (GUI.Button(line, "Fix curve values into 0f..1f"))
                        {
                            property.FindPropertyRelative("m_ReboundCurve").animationCurveValue = curve.FixStartEndKeysValues(0f, 1f);
                        }
                    }
                    line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                    EditorGUI.PropertyField(line, property.FindPropertyRelative("m_WaitForClampAngle"), ReboundWaitClampAngleLabel);
                }
            }
            EditorGUI.EndProperty();
        }
Пример #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            Vector2 orgIconSize = EditorGUIUtility.GetIconSize();

            EditorGUI.BeginProperty(position, label, property);

            Rect line = position.Clone(height: lineH + 16f);

            EditorGUIUtility.SetIconSize(Vector2.one * 32f);
            property.isExpanded = EditorGUI.Foldout(line, property.isExpanded, ClampAngleLabel, true);
            EditorGUIUtility.SetIconSize(orgIconSize);

            if (property.isExpanded)
            {
                SerializedProperty prop;
                line = line.GetRectBottom(height: lineH * 2f).Modify(y: lineS);
                EditorGUI.HelpBox(line, "use [ForwardReference] to override [Target Forward], ignore this setting if using global setting.", MessageType.Info);

                line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                EditorGUI.PropertyField(line, property.FindPropertyRelative("m_ForwardReference"), ForwardReferenceLabel);

                string help;
                prop = property.FindPropertyRelative("m_UpwardReferenceMethod");
                switch ((UpwardReferenceMethod)prop.enumValueIndex)
                {
                default:
                case UpwardReferenceMethod.World:
                    help = "World : fastest, alway point to sky, but have flip camera issue when pass though 'Gimbal Lock'";
                    break;

                case UpwardReferenceMethod.Local:
                    help = "Local : simulate rotate orbit child object";
                    break;

                case UpwardReferenceMethod.RealLocal:
                    help = "RealLocal : simulate rotate orbit child object, real local have angle!";
                    break;

                case UpwardReferenceMethod.Custom:
                    help = "Custom : assign transform's upward as a reference, you may also roll the camera by this method";
                    break;
                }
                line = line.GetRectBottom(height: lineH * 2f).Modify(y: lineS);
                EditorGUI.HelpBox(line, help, MessageType.Info);

                line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                EditorGUI.PropertyField(line, prop, RotationUpwardMethodLabel);
                if (prop.enumValueIndex == (int)UpwardReferenceMethod.Custom)
                {
                    line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                    EditorGUI.PropertyField(line, property.FindPropertyRelative("m_UpReference"), CustomTransformLabel);
                }

                line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                EditorGUI.PrefixLabel(line, LeftRightLabel);
                line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                EditorGUI.PropertyField(line, property.FindPropertyRelative("m_PolarLeftRange"));
                line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                EditorGUI.PropertyField(line, property.FindPropertyRelative("m_PolarRightRange"));

                line = line.GetRectBottom(height: lineH).Modify(y: lineS * 2f);
                EditorGUI.PrefixLabel(line, UpDownLabel);

                line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                EditorGUI.PropertyField(line, property.FindPropertyRelative("m_ElevationUpRange"));

                line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                EditorGUI.PropertyField(line, property.FindPropertyRelative("m_ElevationDownRange"));

                prop = property.FindPropertyRelative("m_Rebound");
                if (prop.boolValue)
                {
                    line = line.GetRectBottom(height: lineH * 2f).Modify(y: lineS * 2f);
                    EditorGUI.HelpBox(line,
                                      string.Format("Enable \"Rebound\" method, after changed camera direction, the camera will trying to reset its position to the initial direction."),
                                      MessageType.Info);
                }

                line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                EditorGUI.PropertyField(line, prop, ReboundLabel);
                if (prop.boolValue)
                {
                    line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                    EditorGUI.PropertyField(line, property.FindPropertyRelative("m_ReboundDelay"), ReboundDelayLabel);
                    line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                    EditorGUI.PropertyField(line, property.FindPropertyRelative("m_ReboundPeriod"), ReboundPeriodLabel);
                    line = line.GetRectBottom(height: lineH).Modify(y: lineS);
                    AnimationCurve curve = EditorGUI.CurveField(line, ReboundCurveLabel, property.FindPropertyRelative("m_ReboundCurve").animationCurveValue);
                    curve.Clamp(0f, -1f, 1f, 1f);
                    property.FindPropertyRelative("m_ReboundCurve").animationCurveValue = curve;
                    if (!curve.MatchStartEndKeysValues(0f, 1f))
                    {
                        line = line.GetRectBottom(height: 40f).Modify(y: lineS);
                        if (GUI.Button(line, "Fix curve values into 0f..1f"))
                        {
                            property.FindPropertyRelative("m_ReboundCurve").animationCurveValue = curve.FixStartEndKeysValues(0f, 1f);
                        }
                    }
                }
            }
            EditorGUI.EndProperty();
        }