diff --git a/Code/Common/Editor/QuaternionValueReferenceDrawer.cs b/Code/Common/Editor/QuaternionValueReferenceDrawer.cs
new file mode 100644
index 0000000..35617bd
--- /dev/null
+++ b/Code/Common/Editor/QuaternionValueReferenceDrawer.cs
@@ -0,0 +1,26 @@
+using UnityEngine;
+using UnityEditor;
+
+
+
+namespace Signals.Common
+{
+ [CustomPropertyDrawer(typeof(QuaternionValueReference))]
+ public class QuaternionValueReferenceDrawer : ValueReferenceDrawer
+ {
+ static Vector4 QuaternionToVector4(Quaternion quaternion)
+ {
+ return new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
+ }
+
+ static Quaternion Vector4ToQuaternion(Vector4 vector)
+ {
+ return new Quaternion(vector.x, vector.y, vector.z, vector.w);
+ }
+
+ protected override void LocalValueField(Rect position, SerializedProperty localValue)
+ {
+ localValue.quaternionValue = Vector4ToQuaternion(EditorGUI.Vector4Field(position, GUIContent.none, QuaternionToVector4(localValue.quaternionValue)));
+ }
+ }
+}
diff --git a/Code/Common/Editor/QuaternionValueReferenceDrawer.cs.meta b/Code/Common/Editor/QuaternionValueReferenceDrawer.cs.meta
new file mode 100644
index 0000000..23b1c7e
--- /dev/null
+++ b/Code/Common/Editor/QuaternionValueReferenceDrawer.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: cb0a7b1726292ca46b5fbcd2babc29cc
+timeCreated: 1518773061
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Code/Common/Editor/Vector2IntValueReferenceDrawer.cs b/Code/Common/Editor/Vector2IntValueReferenceDrawer.cs
new file mode 100644
index 0000000..d14b6b8
--- /dev/null
+++ b/Code/Common/Editor/Vector2IntValueReferenceDrawer.cs
@@ -0,0 +1,9 @@
+using UnityEditor;
+
+
+
+namespace Signals.Common
+{
+ [CustomPropertyDrawer(typeof(Vector2IntValueReference))]
+ public class Vector2IntValueReferenceDrawer : ValueReferenceDrawer { }
+}
diff --git a/Code/Common/Editor/Vector2IntValueReferenceDrawer.cs.meta b/Code/Common/Editor/Vector2IntValueReferenceDrawer.cs.meta
new file mode 100644
index 0000000..dab43e5
--- /dev/null
+++ b/Code/Common/Editor/Vector2IntValueReferenceDrawer.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: e63cd0adcfe38dd4d8992d14c4382bab
+timeCreated: 1518773061
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Code/Common/Editor/Vector2ValueReferenceDrawer.cs b/Code/Common/Editor/Vector2ValueReferenceDrawer.cs
new file mode 100644
index 0000000..8279df2
--- /dev/null
+++ b/Code/Common/Editor/Vector2ValueReferenceDrawer.cs
@@ -0,0 +1,9 @@
+using UnityEditor;
+
+
+
+namespace Signals.Common
+{
+ [CustomPropertyDrawer(typeof(Vector2ValueReference))]
+ public class Vector2ValueReferenceDrawer : ValueReferenceDrawer { }
+}
diff --git a/Code/Common/Editor/Vector2ValueReferenceDrawer.cs.meta b/Code/Common/Editor/Vector2ValueReferenceDrawer.cs.meta
new file mode 100644
index 0000000..72c1865
--- /dev/null
+++ b/Code/Common/Editor/Vector2ValueReferenceDrawer.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: 8dca5ce9e4eb07e4ca3d0ffbebb3644a
+timeCreated: 1518773061
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Code/Common/Editor/Vector3IntValueReferenceDrawer.cs b/Code/Common/Editor/Vector3IntValueReferenceDrawer.cs
new file mode 100644
index 0000000..5a1b6d6
--- /dev/null
+++ b/Code/Common/Editor/Vector3IntValueReferenceDrawer.cs
@@ -0,0 +1,9 @@
+using UnityEditor;
+
+
+
+namespace Signals.Common
+{
+ [CustomPropertyDrawer(typeof(Vector3IntValueReference))]
+ public class Vector3IntValueReferenceDrawer : ValueReferenceDrawer { }
+}
diff --git a/Code/Common/Editor/Vector3IntValueReferenceDrawer.cs.meta b/Code/Common/Editor/Vector3IntValueReferenceDrawer.cs.meta
new file mode 100644
index 0000000..b0a6291
--- /dev/null
+++ b/Code/Common/Editor/Vector3IntValueReferenceDrawer.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: 9ec4b3d6533797e40a1fc6b734078338
+timeCreated: 1518773061
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Code/Common/Editor/Vector3ValueReferenceDrawer.cs b/Code/Common/Editor/Vector3ValueReferenceDrawer.cs
new file mode 100644
index 0000000..338ed27
--- /dev/null
+++ b/Code/Common/Editor/Vector3ValueReferenceDrawer.cs
@@ -0,0 +1,9 @@
+using UnityEditor;
+
+
+
+namespace Signals.Common
+{
+ [CustomPropertyDrawer(typeof(Vector3ValueReference))]
+ public class Vector3ValueReferenceDrawer : ValueReferenceDrawer { }
+}
\ No newline at end of file
diff --git a/Code/Common/Editor/Vector3ValueReferenceDrawer.cs.meta b/Code/Common/Editor/Vector3ValueReferenceDrawer.cs.meta
new file mode 100644
index 0000000..3df341d
--- /dev/null
+++ b/Code/Common/Editor/Vector3ValueReferenceDrawer.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: c3c7be82d698bd6448343fe0a3d1b9e9
+timeCreated: 1518771897
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Code/Common/Editor/Vector4ValueReferenceDrawer.cs b/Code/Common/Editor/Vector4ValueReferenceDrawer.cs
new file mode 100644
index 0000000..4cc5635
--- /dev/null
+++ b/Code/Common/Editor/Vector4ValueReferenceDrawer.cs
@@ -0,0 +1,16 @@
+using UnityEngine;
+using UnityEditor;
+
+
+
+namespace Signals.Common
+{
+ [CustomPropertyDrawer(typeof(Vector4ValueReference))]
+ public class Vector4ValueReferenceDrawer : ValueReferenceDrawer
+ {
+ protected override void LocalValueField(Rect position, SerializedProperty localValue)
+ {
+ localValue.vector4Value = EditorGUI.Vector4Field(position, GUIContent.none, localValue.vector4Value);
+ }
+ }
+}
diff --git a/Code/Common/Editor/Vector4ValueReferenceDrawer.cs.meta b/Code/Common/Editor/Vector4ValueReferenceDrawer.cs.meta
new file mode 100644
index 0000000..5ab1bd3
--- /dev/null
+++ b/Code/Common/Editor/Vector4ValueReferenceDrawer.cs.meta
@@ -0,0 +1,13 @@
+fileFormatVersion: 2
+guid: d174ad068742ae84095072f229184333
+timeCreated: 1518773061
+licenseType: Free
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Code/Editor/ValueReferenceDrawer.cs b/Code/Editor/ValueReferenceDrawer.cs
index d622fb2..2b5134c 100644
--- a/Code/Editor/ValueReferenceDrawer.cs
+++ b/Code/Editor/ValueReferenceDrawer.cs
@@ -10,42 +10,55 @@ namespace Signals
///
public abstract class ValueReferenceDrawer : PropertyDrawer
{
- readonly static string[] popupOptions = { "Use Signal Value", "Use Local Value" };
- static GUIStyle popupStyle;
+ readonly static string[] _popupOptions = { "Use Signal Value", "Use Local Value" };
- public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
+ readonly static GUIStyle _popupStyle = new GUIStyle(GUI.skin.GetStyle("PaneOptions"))
{
- if (popupStyle == null)
- {
- popupStyle = new GUIStyle(GUI.skin.GetStyle("PaneOptions"));
- popupStyle.imagePosition = ImagePosition.ImageOnly;
- }
+ imagePosition = ImagePosition.ImageOnly
+ };
+ public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
+ {
label = EditorGUI.BeginProperty(position, label, property);
position = EditorGUI.PrefixLabel(position, label);
EditorGUI.BeginChangeCheck();
+ var popupPosition = new Rect(position.x, position.y + _popupStyle.margin.top, _popupStyle.fixedWidth + _popupStyle.margin.right, position.height);
var useLocalValue = property.FindPropertyRelative("_useLocalValue");
- var signal = property.FindPropertyRelative("_signal");
- var localValue = property.FindPropertyRelative("_localValue");
+ useLocalValue.boolValue = EditorGUI.Popup(popupPosition, useLocalValue.boolValue ? 1 : 0, _popupOptions, _popupStyle) == 1;
- var buttonRect = new Rect(position);
- buttonRect.yMin += popupStyle.margin.top;
- buttonRect.width = popupStyle.fixedWidth + popupStyle.margin.right;
- position.xMin = buttonRect.xMax;
+ position.xMin = popupPosition.xMax;
+ if (useLocalValue.boolValue) LocalValueField(position, property.FindPropertyRelative("_localValue"));
+ else EditorGUI.PropertyField(position, property.FindPropertyRelative("_signal"), GUIContent.none);
- var indent = EditorGUI.indentLevel;
- EditorGUI.indentLevel = 0;
+ if (EditorGUI.EndChangeCheck()) property.serializedObject.ApplyModifiedProperties();
- useLocalValue.boolValue = EditorGUI.Popup(buttonRect, useLocalValue.boolValue ? 1 : 0, popupOptions, popupStyle) == 1;
+ EditorGUI.EndProperty();
+ }
- EditorGUI.PropertyField(position, useLocalValue.boolValue ? localValue : signal, GUIContent.none);
+ ///
+ /// Override this method to implement a custom inspector for the .
+ ///
+ /// The field's position.
+ /// The SerializedProperty containing the value.
+ protected virtual void LocalValueField(Rect position, SerializedProperty localValue)
+ {
+ EditorGUI.PropertyField(position, localValue, GUIContent.none, true);
+ }
- if (EditorGUI.EndChangeCheck()) property.serializedObject.ApplyModifiedProperties();
+ public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
+ {
+ return property.FindPropertyRelative("_useLocalValue").boolValue ? GetLocalValueFieldHeight() : EditorGUIUtility.singleLineHeight;
+ }
- EditorGUI.indentLevel = indent;
- EditorGUI.EndProperty();
+ ///
+ /// Override this if your is higher than one line.
+ ///
+ /// The 's height.
+ protected virtual float GetLocalValueFieldHeight()
+ {
+ return EditorGUIUtility.singleLineHeight;
}
}
}
\ No newline at end of file