Przeglądaj źródła

Feature: Quaternion now has its own inspector field renderer

BearishSun 7 lat temu
rodzic
commit
37e78df597

+ 1 - 0
Source/Scripting/MBansheeEditor/MBansheeEditor.csproj

@@ -100,6 +100,7 @@
     <Compile Include="Windows\Inspector\InspectableCurve.cs" />
     <Compile Include="Windows\Inspector\InspectableCurve.cs" />
     <Compile Include="Windows\Inspector\InspectableFloatDistribution.cs" />
     <Compile Include="Windows\Inspector\InspectableFloatDistribution.cs" />
     <Compile Include="Windows\Inspector\InspectableLayerMask.cs" />
     <Compile Include="Windows\Inspector\InspectableLayerMask.cs" />
+    <Compile Include="Windows\Inspector\InspectableQuaternion.cs" />
     <Compile Include="Windows\Inspector\InspectableRRef.cs" />
     <Compile Include="Windows\Inspector\InspectableRRef.cs" />
     <Compile Include="Windows\Inspector\Style\InspectableFieldRangeStyle.cs" />
     <Compile Include="Windows\Inspector\Style\InspectableFieldRangeStyle.cs" />
     <Compile Include="Windows\Inspector\Style\InspectableFieldStepStyle.cs" />
     <Compile Include="Windows\Inspector\Style\InspectableFieldStepStyle.cs" />

+ 7 - 29
Source/Scripting/MBansheeEditor/Windows/AnimationWindow.cs

@@ -1422,20 +1422,10 @@ namespace BansheeEditor
                     break;
                     break;
                 case SerializableProperty.FieldType.Vector4:
                 case SerializableProperty.FieldType.Vector4:
                     {
                     {
-                        if (property.InternalType == typeof(Vector4))
-                        {
-                            Vector4 value = property.GetValue<Vector4>();
-
-                            for (int i = 0; i < 4; i++)
-                                action(value[i], i);
-                        }
-                        else if (property.InternalType == typeof(Quaternion))
-                        {
-                            Quaternion value = property.GetValue<Quaternion>();
+                        Vector4 value = property.GetValue<Vector4>();
 
 
-                            for (int i = 0; i < 4; i++)
-                                action(value[i], i);
-                        }
+                        for (int i = 0; i < 4; i++)
+                            action(value[i], i);
                     }
                     }
                     break;
                     break;
                 case SerializableProperty.FieldType.Color:
                 case SerializableProperty.FieldType.Color:
@@ -1504,24 +1494,12 @@ namespace BansheeEditor
                     break;
                     break;
                 case SerializableProperty.FieldType.Vector4:
                 case SerializableProperty.FieldType.Vector4:
                     {
                     {
-                        if (property.InternalType == typeof(Vector4))
-                        {
-                            Vector4 value = new Vector4();
+                        Vector4 value = new Vector4();
 
 
-                            for (int i = 0; i < 4; i++)
-                                value[i] = action(i);
-
-                            property.SetValue(value);
-                        }
-                        else if (property.InternalType == typeof(Quaternion))
-                        {
-                            Quaternion value = new Quaternion();
-
-                            for (int i = 0; i < 4; i++)
-                                value[i] = action(i);
+                        for (int i = 0; i < 4; i++)
+                            value[i] = action(i);
 
 
-                            property.SetValue(value);
-                        }
+                        property.SetValue(value);
                     }
                     }
                     break;
                     break;
                 case SerializableProperty.FieldType.Color:
                 case SerializableProperty.FieldType.Color:

+ 3 - 0
Source/Scripting/MBansheeEditor/Windows/Inspector/InspectableField.cs

@@ -198,6 +198,9 @@ namespace BansheeEditor
                     case SerializableProperty.FieldType.Vector4:
                     case SerializableProperty.FieldType.Vector4:
                         field = new InspectableVector4(parent, title, path, depth, layout, property);
                         field = new InspectableVector4(parent, title, path, depth, layout, property);
                         break;
                         break;
+                    case SerializableProperty.FieldType.Quaternion:
+                        field = new InspectableQuaternion(parent, title, path, depth, layout, property);
+                        break;
                     case SerializableProperty.FieldType.Resource:
                     case SerializableProperty.FieldType.Resource:
                         field = new InspectableResource(parent, title, path, depth, layout, property);
                         field = new InspectableResource(parent, title, path, depth, layout, property);
                         break;
                         break;

+ 89 - 0
Source/Scripting/MBansheeEditor/Windows/Inspector/InspectableQuaternion.cs

@@ -0,0 +1,89 @@
+//********************************** Banshee Engine (www.banshee3d.com) **************************************************//
+//**************** Copyright (c) 2018 Marko Pintera ([email protected]). All rights reserved. **********************//
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    /** @addtogroup Inspector
+     *  @{
+     */
+
+    /// <summary>
+    /// Displays GUI for a serializable property containing a quaternion.
+    /// </summary>
+    public class InspectableQuaternion : InspectableField
+    {
+        private GUIVector4Field guiField;
+        private InspectableState state;
+
+        /// <summary>
+        /// Creates a new inspectable quaternion GUI for the specified property.
+        /// </summary>
+        /// <param name="parent">Parent Inspector this field belongs to.</param>
+        /// <param name="title">Name of the property, or some other value to set as the title.</param>
+        /// <param name="path">Full path to this property (includes name of this property and all parent properties).</param>
+        /// <param name="depth">Determines how deep within the inspector nesting hierarchy is this field. Some fields may
+        ///                     contain other fields, in which case you should increase this value by one.</param>
+        /// <param name="layout">Parent layout that all the field elements will be added to.</param>
+        /// <param name="property">Serializable property referencing the field whose contents to display.</param>
+        public InspectableQuaternion(Inspector parent, string title, string path, int depth, InspectableFieldLayout layout,
+            SerializableProperty property)
+            : base(parent, title, path, SerializableProperty.FieldType.Quaternion, depth, layout, property)
+        {
+
+        }
+
+        /// <inheritoc/>
+        protected internal override void Initialize(int layoutIndex)
+        {
+            if (property.Type == SerializableProperty.FieldType.Quaternion)
+            {
+                guiField = new GUIVector4Field(new GUIContent(title));
+                guiField.OnChanged += OnFieldValueChanged;
+                guiField.OnConfirmed += OnFieldValueConfirm;
+                guiField.OnFocusLost += OnFieldValueConfirm;
+
+                layout.AddElement(layoutIndex, guiField);
+            }
+        }
+
+        /// <inheritdoc/>
+        public override InspectableState Refresh(int layoutIndex)
+        {
+            if (guiField != null && !guiField.HasInputFocus)
+            {
+                Quaternion quaternion = property.GetValue<Quaternion>();
+                guiField.Value = new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
+            }
+
+            InspectableState oldState = state;
+            if (state.HasFlag(InspectableState.Modified))
+                state = InspectableState.NotModified;
+
+            return oldState;
+        }
+
+        /// <summary>
+        /// Triggered when the user changes the field value.
+        /// </summary>
+        /// <param name="newValue">New value of the 3D vector field.</param>
+        private void OnFieldValueChanged(Vector4 newValue)
+        {
+            Quaternion quaternion = new Quaternion(newValue.x, newValue.y, newValue.y, newValue.w);
+
+            property.SetValue(quaternion);
+            state |= InspectableState.ModifyInProgress;
+        }
+
+        /// <summary>
+        /// Triggered when the user confirms input in the 3D vector field.
+        /// </summary>
+        private void OnFieldValueConfirm()
+        {
+            if (state.HasFlag(InspectableState.ModifyInProgress))
+                state |= InspectableState.Modified;
+        }
+    }
+
+    /** @} */
+}

+ 5 - 17
Source/Scripting/MBansheeEngine/Animation/Animation.cs

@@ -321,24 +321,12 @@ namespace BansheeEngine
                         }
                         }
                         break;
                         break;
                     case SerializableProperty.FieldType.Vector4:
                     case SerializableProperty.FieldType.Vector4:
-                        if (internalType == typeof(Vector4))
-                        {
-                            setter = f =>
-                            {
-                                Vector4 value = property.GetValue<Vector4>();
-                                value[elementIdx] = f;
-                                property.SetValue(value);
-                            };
-                        }
-                        else if (internalType == typeof(Quaternion))
+                        setter = f =>
                         {
                         {
-                            setter = f =>
-                            {
-                                Quaternion value = property.GetValue<Quaternion>();
-                                value[elementIdx] = f;
-                                property.SetValue(value);
-                            };
-                        }
+                            Vector4 value = property.GetValue<Vector4>();
+                            value[elementIdx] = f;
+                            property.SetValue(value);
+                        };
                         break;
                         break;
                     case SerializableProperty.FieldType.Color:
                     case SerializableProperty.FieldType.Color:
                         if (internalType == typeof(Color))
                         if (internalType == typeof(Color))

+ 3 - 2
Source/Scripting/MBansheeEngine/Serialization/SerializableProperty.cs

@@ -40,7 +40,8 @@ namespace BansheeEngine
             ColorGradient,
             ColorGradient,
             Curve,
             Curve,
             FloatDistribution,
             FloatDistribution,
-            ColorDistribution
+            ColorDistribution,
+            Quaternion
         }
         }
 
 
         public delegate object Getter();
         public delegate object Getter();
@@ -373,7 +374,7 @@ namespace BansheeEngine
                 else if (internalType == typeof (Vector4))
                 else if (internalType == typeof (Vector4))
                     return FieldType.Vector4;
                     return FieldType.Vector4;
                 else if (internalType == typeof(Quaternion))
                 else if (internalType == typeof(Quaternion))
-                    return FieldType.Vector4;
+                    return FieldType.Quaternion;
                 else if (internalType == typeof (Color))
                 else if (internalType == typeof (Color))
                     return FieldType.Color;
                     return FieldType.Color;
                 else if (internalType == typeof(ColorGradient))
                 else if (internalType == typeof(ColorGradient))