Пример #1
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            if (!property.isExpanded)
            {
                return(EditorGUIUtility.singleLineHeight);
            }
            Animatable.Clip clip  = property.GetInternalStructValue() as Animatable.Clip;
            int             lines = 5;

            lines += (clip.animate.HasFlag(Animatable.TransformOptions.position) ? 1 : 0)
                     + (clip.animate.HasFlag(Animatable.TransformOptions.rotation) ? 1 : 0)
                     + (clip.animate.HasFlag(Animatable.TransformOptions.scale) ? 1 : 0);
            return(EditorGUIUtility.singleLineHeight * lines
                   + EditorGUI.GetPropertyHeight(property.FindPropertyRelative(nameof(Animatable.Clip.events)))
                   + (clip.animate.HasFlag(Animatable.TransformOptions.color) ? EditorGUI.GetPropertyHeight(property.FindPropertyRelative(nameof(Animatable.Clip.colorData))) : 0)
                   + (clip.animate.HasFlag(Animatable.TransformOptions.single) ? EditorGUI.GetPropertyHeight(property.FindPropertyRelative(nameof(Animatable.Clip.floatData))) : 0)
                   + 16);
        }
Пример #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var numberString = Regex.Match(label.text, @"\d+").Value;

            label.text = "Animation State " + numberString + " ( ";
            var animate = (Animatable.TransformOptions)property.FindPropertyRelative(nameof(Animatable.Clip.animate)).intValue;

            if (animate.HasFlag(Animatable.TransformOptions.position))
            {
                label.text += "Position ";
            }
            if (animate.HasFlag(Animatable.TransformOptions.rotation))
            {
                label.text += "Rotation ";
            }
            if (animate.HasFlag(Animatable.TransformOptions.scale))
            {
                label.text += "Scale ";
            }
            if (animate.HasFlag(Animatable.TransformOptions.color))
            {
                label.text += "Color ";
            }
            if (animate.HasFlag(Animatable.TransformOptions.single))
            {
                label.text += "Float ";
            }
            label.text += ")";
            EditorGUI.BeginProperty(position, label, property);
            var rect = position;

            position.height     = EditorGUIUtility.singleLineHeight;
            property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);
            if (property.isExpanded)
            {
                EditorGUI.BeginChangeCheck();
                Animatable.Clip clip = property.GetInternalStructValue() as Animatable.Clip;
                rect        = position;
                rect.y     += EditorGUIUtility.singleLineHeight;
                rect.height = EditorGUIUtility.singleLineHeight * 2;
                property.FindPropertyRelative(nameof(Animatable.Clip.curve)).animationCurveValue =
                    EditorGUI.CurveField(rect, clip.curve);
                rect.y     += rect.height;
                rect.height = EditorGUIUtility.singleLineHeight;

                rect.width = position.width / 2f - 6;
                property.FindPropertyRelative(nameof(Animatable.Clip.time)).floatValue =
                    EditorGUI.FloatField(rect, clip.time);
                rect.x += rect.width + 3;
                property.FindPropertyRelative(nameof(Animatable.Clip.animate)).intValue =
                    Convert.ToInt32(EditorGUI.EnumFlagsField(rect, clip.animate));

                rect.y    += rect.height;
                rect.x     = position.x;
                rect.width = 22;
                property.FindPropertyRelative(nameof(Animatable.Clip.loop)).boolValue =
                    EditorGUI.Toggle(rect, clip.loop);
                rect.x    += rect.width + 3;
                rect.width = position.width / 4f - 6;
                EditorGUI.LabelField(rect, "Loop");
                rect.x    += rect.width + 3;
                rect.width = 22;
                property.FindPropertyRelative(nameof(Animatable.Clip.useInitialMatrix)).boolValue =
                    EditorGUI.Toggle(rect, clip.useInitialMatrix);

                rect.x    += rect.width + 3;
                rect.width = position.width / 4f - 6;
                EditorGUI.LabelField(rect, "Initial Matrix");

                rect.y    += rect.height + 8;
                rect.width = position.width;
                rect.x     = position.x;

                if (clip.animate.HasFlag(Animatable.TransformOptions.position))
                {
                    EditorGUI.PropertyField(rect,
                                            property.FindPropertyRelative(nameof(clip.data) + "." + nameof(clip.data.localPos)));
                    rect.y += rect.height;
                }

                if (clip.animate.HasFlag(Animatable.TransformOptions.rotation))
                {
                    EditorGUI.PropertyField(rect,
                                            property.FindPropertyRelative(nameof(clip.data) + "." + nameof(clip.data.localRotation)));
                    rect.y += rect.height;
                }

                if (clip.animate.HasFlag(Animatable.TransformOptions.scale))
                {
                    EditorGUI.PropertyField(rect,
                                            property.FindPropertyRelative(nameof(clip.data) + "." + nameof(clip.data.localScale)));
                    rect.y += rect.height;
                }

                if (clip.animate.HasFlag(Animatable.TransformOptions.color))
                {
                    var customListProperty = property.FindPropertyRelative(nameof(Animatable.Clip.colorData));
                    if (customListProperty != null)
                    {
                        rect.height = EditorGUI.GetPropertyHeight(customListProperty);
                        EditorGUI.PropertyField(rect, customListProperty);
                        rect.y     += rect.height;
                        rect.height = EditorGUIUtility.singleLineHeight;
                    }
                }

                if (clip.animate.HasFlag(Animatable.TransformOptions.single))
                {
                    var customListProperty = property.FindPropertyRelative(nameof(Animatable.Clip.floatData));
                    if (customListProperty != null)
                    {
                        rect.height = EditorGUI.GetPropertyHeight(customListProperty);
                        EditorGUI.PropertyField(rect, customListProperty);
                        rect.y     += rect.height;
                        rect.height = EditorGUIUtility.singleLineHeight;
                    }
                }

                var eventsProperty = property.FindPropertyRelative(nameof(clip.events));
                // rect.height = EditorGUI.GetPropertyHeight(eventsProperty);
                rect.height = EditorGUIUtility.singleLineHeight + 8;
                //EditorGUI.PropertyField(rect, eventsProperty);
                string eventsLabel         = "Events";
                int    onStartedEventCount = clip.events.OnStarted.GetPersistentEventCount();
                int    onExitedEventCount  = clip.events.OnEnded.GetPersistentEventCount();
                eventsLabel += onStartedEventCount > 0 ? $" | Started ({onStartedEventCount})" : "";
                eventsLabel += onExitedEventCount > 0 ? $" | Ended ({onExitedEventCount})" : "";
                eventsProperty.isExpanded = EditorGUI.Foldout(rect, eventsProperty.isExpanded, eventsLabel);
                if (eventsProperty.isExpanded)
                {
                    rect.y += rect.height;
                    var enterEventProperty = property.FindPropertyRelative(nameof(clip.events) + "." + nameof(clip.events.OnStarted));
                    rect.height = EditorGUI.GetPropertyHeight(enterEventProperty);
                    EditorGUI.PropertyField(rect, enterEventProperty);
                    rect.y += rect.height;
                    var exitEventProperty = property.FindPropertyRelative(nameof(clip.events) + "." + nameof(clip.events.OnEnded));
                    EditorGUI.PropertyField(rect, exitEventProperty);
                    rect.y += EditorGUI.GetPropertyHeight(exitEventProperty);
                }

                if (EditorGUI.EndChangeCheck())
                {
                    property.serializedObject.ApplyModifiedProperties();
                }
            }

            EditorGUI.EndProperty();
        }