initial upload
This commit is contained in:
@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
namespace RootMotion {
|
||||
|
||||
/*
|
||||
* Custom inspector for BipedReferences
|
||||
* */
|
||||
public class BipedReferencesInspector: Inspector {
|
||||
|
||||
/*
|
||||
* Draws the default property, returns true if modified
|
||||
* */
|
||||
public static bool AddModifiedInspector(SerializedProperty prop) {
|
||||
EditorGUILayout.PropertyField(prop, true);
|
||||
|
||||
if (prop.isExpanded) EditorGUILayout.Space();
|
||||
|
||||
// If references have changed reinitiate the bipedIK.
|
||||
if (prop.serializedObject.ApplyModifiedProperties()) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5880965ffd5754534ac6d4c1fce8bb73
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,41 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using UnityEditor;
|
||||
|
||||
namespace RootMotion {
|
||||
|
||||
[CustomEditor(typeof(Comments))]
|
||||
public class CommentsInspector : Editor {
|
||||
|
||||
private Comments script { get { return target as Comments; }}
|
||||
private GUIStyle style = new GUIStyle();
|
||||
|
||||
// Black and white
|
||||
//private static Color pro = new Color(0.7f, 0.7f, 0.7f, 1f);
|
||||
//private static Color free = new Color(0, 0, 0, 1);
|
||||
|
||||
// Colors
|
||||
private static Color pro = new Color(0.5f, 0.7f, 0.3f, 1f);
|
||||
private static Color free = new Color(0.2f, 0.3f, 0.1f, 1f);
|
||||
|
||||
public override void OnInspectorGUI() {
|
||||
if (serializedObject == null) return;
|
||||
|
||||
style.wordWrap = true;
|
||||
style.normal.textColor = EditorGUIUtility.isProSkin? pro: free;
|
||||
|
||||
serializedObject.Update();
|
||||
EditorGUILayout.Space();
|
||||
|
||||
string text = EditorGUILayout.TextArea(script.text, style);
|
||||
if (text != script.text) {
|
||||
Undo.RecordObject(script, "Edit Comments");
|
||||
script.text = text;
|
||||
}
|
||||
|
||||
EditorGUILayout.Space();
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c93e61235cb3cad45aec1688c1990eff
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,323 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
namespace RootMotion {
|
||||
|
||||
/*
|
||||
* Inspector contains helper methods for creating undoable custom inspectors with enforced layout, tooltips and styling
|
||||
* */
|
||||
public class Inspector {
|
||||
|
||||
#region InspectorGUI tools
|
||||
|
||||
public const int indent = 16;
|
||||
|
||||
public delegate void DrawArrayElement(SerializedProperty prop, bool editHierarchy);
|
||||
public delegate void DrawArrayElementLabel(SerializedProperty prop, bool editHierarchy);
|
||||
public delegate void OnAddToArray(SerializedProperty prop);
|
||||
|
||||
private static string arrayName;
|
||||
private static SerializedProperty property;
|
||||
private static SerializedProperty element;
|
||||
|
||||
public static string GetArrayName(SerializedProperty array, string emptyName, string propertyName = "") {
|
||||
if (array.arraySize < 1) return emptyName;
|
||||
property = propertyName == ""? array.GetArrayElementAtIndex(0): array.GetArrayElementAtIndex(0).FindPropertyRelative(propertyName);
|
||||
return GetObjectReferenceName(property, emptyName);
|
||||
}
|
||||
|
||||
public static string GetObjectReferenceName(SerializedProperty prop, string emptyName) {
|
||||
if (prop.objectReferenceValue == null) return emptyName;
|
||||
return prop.objectReferenceValue.name;
|
||||
}
|
||||
|
||||
public static void AddArray(SerializedProperty prop, GUIContent guiContent, bool editHierarchy, bool changeOrder, DrawArrayElement drawArrayElement = null, OnAddToArray onAddToArray = null, DrawArrayElementLabel drawArrayElementLabel = null, bool showHeading = true) {
|
||||
int resetIndent = EditorGUI.indentLevel;
|
||||
|
||||
// Array heading
|
||||
if (showHeading) {
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space(EditorGUI.indentLevel * indent);
|
||||
|
||||
if (drawArrayElement == null) {
|
||||
GUILayout.Label(guiContent.text + " (" + prop.arraySize.ToString() + ")", GUILayout.Width(150));
|
||||
} else {
|
||||
EditorGUILayout.PropertyField(prop, new GUIContent(guiContent.text + " (" + prop.arraySize.ToString() + ")", string.Empty), false, GUILayout.Width(150));
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
int deleteIndex = -1;
|
||||
|
||||
if (drawArrayElement == null || !showHeading) prop.isExpanded = true;
|
||||
|
||||
// Draw Array elements
|
||||
if (prop.isExpanded) {
|
||||
for(int i = 0; i < prop.arraySize; i++) {
|
||||
GUILayout.BeginHorizontal(); // Main
|
||||
GUILayout.Space(((EditorGUI.indentLevel + 1) * indent));
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
element = prop.GetArrayElementAtIndex(i);
|
||||
|
||||
// Label
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (editHierarchy && GUILayout.Button(new GUIContent("-", "Remove"), changeOrder? EditorStyles.miniButtonLeft: EditorStyles.miniButton, GUILayout.Width(20))){
|
||||
deleteIndex = i;
|
||||
}
|
||||
|
||||
if (changeOrder) {
|
||||
if (GUILayout.Button(new GUIContent("<", "Move up"), editHierarchy? EditorStyles.miniButtonMid: EditorStyles.miniButtonLeft, GUILayout.Width(20))) {
|
||||
int moveTo = i == 0? prop.arraySize - 1: i - 1;
|
||||
prop.MoveArrayElement(i, moveTo);
|
||||
prop.isExpanded = true;
|
||||
}
|
||||
|
||||
if (GUILayout.Button(new GUIContent(">", "Move down"), EditorStyles.miniButtonRight, GUILayout.Width(20))) {
|
||||
int moveTo = i == prop.arraySize - 1? 0: i + 1;
|
||||
prop.MoveArrayElement(i, moveTo);
|
||||
prop.isExpanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Calling the DrawArrayElementLabel delegate
|
||||
if (drawArrayElementLabel != null) {
|
||||
drawArrayElementLabel(element, editHierarchy);
|
||||
}
|
||||
|
||||
GUILayout.EndHorizontal(); // End Label
|
||||
|
||||
// Array Element
|
||||
GUILayout.BeginVertical();
|
||||
if (element.isExpanded && drawArrayElement != null) {
|
||||
drawArrayElement(element, editHierarchy);
|
||||
}
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.Space(5);
|
||||
|
||||
GUILayout.EndVertical(); // End Style
|
||||
GUILayout.EndHorizontal(); // End Main
|
||||
}
|
||||
|
||||
// Deleting array elements
|
||||
if (deleteIndex != -1) prop.DeleteArrayElementAtIndex(deleteIndex);
|
||||
|
||||
// Adding array elements
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space(((EditorGUI.indentLevel + 1) * indent) + 4);
|
||||
GUILayout.BeginVertical();
|
||||
|
||||
if (editHierarchy && GUILayout.Button(new GUIContent("+", "Add"), EditorStyles.miniButton, GUILayout.Width(20))) {
|
||||
prop.arraySize ++;
|
||||
|
||||
if (onAddToArray != null) onAddToArray(prop.GetArrayElementAtIndex(prop.arraySize - 1));
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
EditorGUI.indentLevel = resetIndent;
|
||||
}
|
||||
|
||||
public static void AddContent(SerializedContent content, bool addChildren = false, params GUILayoutOption[] options) {
|
||||
EditorGUILayout.PropertyField(content.prop, content.guiContent, addChildren, options);
|
||||
}
|
||||
|
||||
public static void AddClampedFloat(SerializedContent content, float min = 0f, float max = 1f, params GUILayoutOption[] options) {
|
||||
AddClampedFloat(content.prop, content.guiContent, min, max, options);
|
||||
}
|
||||
|
||||
public static void AddClampedInt(SerializedContent content, int min = int.MinValue, int max = int.MaxValue, params GUILayoutOption[] options) {
|
||||
AddClampedInt(content.prop, content.guiContent, min, max, options);
|
||||
}
|
||||
|
||||
public static void AddClampedFloat(SerializedProperty prop, GUIContent guiContent, float min = 0f, float max = 1f, params GUILayoutOption[] options) {
|
||||
EditorGUILayout.PropertyField(prop, guiContent, options);
|
||||
prop.floatValue = Mathf.Clamp(prop.floatValue, min, max);
|
||||
}
|
||||
|
||||
public static void AddClampedInt(SerializedProperty prop, GUIContent guiContent, int min = int.MinValue, int max = int.MaxValue, params GUILayoutOption[] options) {
|
||||
EditorGUILayout.PropertyField(prop, guiContent, options);
|
||||
prop.intValue = Mathf.Clamp(prop.intValue, min, max);
|
||||
}
|
||||
|
||||
public static void AddObjectReference(SerializedProperty prop, GUIContent guiContent, bool editHierarchy, int labelWidth, bool alignToEdge = true) {
|
||||
if (alignToEdge) GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(guiContent, GUILayout.MinWidth(labelWidth));
|
||||
if (editHierarchy) {
|
||||
EditorGUILayout.PropertyField(prop, GUIContent.none);
|
||||
} else {
|
||||
UnityEngine.Object obj = prop.objectReferenceValue;
|
||||
EditorGUILayout.LabelField(new GUIContent(obj != null? obj.name: "None"));
|
||||
}
|
||||
if (alignToEdge) GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public static void AddObjectReference(SerializedProperty prop, GUIContent guiContent, bool editHierarchy, int labelWidth, int propWidth, bool alignToEdge = true) {
|
||||
//if (alignToEdge) GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(guiContent, GUILayout.Width(labelWidth));
|
||||
if (editHierarchy) {
|
||||
EditorGUILayout.PropertyField(prop, GUIContent.none, GUILayout.Width(propWidth));
|
||||
} else {
|
||||
UnityEngine.Object obj = prop.objectReferenceValue;
|
||||
EditorGUILayout.LabelField(new GUIContent(obj != null? obj.name: "None"), GUILayout.Width(propWidth));
|
||||
}
|
||||
//if (alignToEdge) GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
#endregion InspectorGUI tools
|
||||
|
||||
#region SceneGUI tools
|
||||
|
||||
public static bool Button(string name, string toolTip, Object undoObject, params GUILayoutOption[] options) {
|
||||
bool button = GUILayout.Button(new GUIContent(name, toolTip), options);
|
||||
if (button && !Application.isPlaying) Undo.RecordObject(undoObject, name);
|
||||
return button;
|
||||
}
|
||||
|
||||
public static Object AddObject(Object input, string name, string toolTip, System.Type type, bool allowSceneObjects, Object undoObject, params GUILayoutOption[] options) {
|
||||
Object newValue = EditorGUILayout.ObjectField(new GUIContent(name, toolTip), input, type, allowSceneObjects, options);
|
||||
|
||||
return RecordObject(input, newValue, name, undoObject);
|
||||
}
|
||||
|
||||
public static System.Enum AddEnum(System.Enum input, string name, string toolTip, Object undoObject, params GUILayoutOption[] options) {
|
||||
System.Enum newValue = EditorGUILayout.EnumPopup(new GUIContent(name, toolTip), input, options);
|
||||
|
||||
if (newValue.ToString() != input.ToString() && !Application.isPlaying) Undo.RecordObject(undoObject, name);
|
||||
return newValue;
|
||||
}
|
||||
|
||||
public static void AddHorizontalSlider(ref float input, float leftValue, float rightValue, string name, string toolTip, Object undoObject, int labelWidth, int minWidth) {
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
GUILayout.Label(new GUIContent(name, toolTip), GUILayout.Width(labelWidth));
|
||||
|
||||
input = RecordObjectFloat(input, GUILayout.HorizontalSlider(input, leftValue, rightValue, GUILayout.MinWidth(minWidth)), name, undoObject);
|
||||
input = Mathf.Clamp(RecordObjectFloat(input, EditorGUILayout.FloatField(string.Empty, input, GUILayout.Width(75)), name, undoObject), leftValue, rightValue);
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
public static void AddFloat(ref float input, string name, string toolTip, Object undoObject, float min = -Mathf.Infinity, float max = Mathf.Infinity, params GUILayoutOption[] options) {
|
||||
input = Mathf.Clamp(RecordObjectFloat(input, EditorGUILayout.FloatField(new GUIContent(name, toolTip), input, options), name, undoObject), min, max);
|
||||
}
|
||||
|
||||
public static void AddInt(ref int input, string name, string toolTip, Object undoObject, int min = -int.MaxValue, int max = int.MaxValue, params GUILayoutOption[] options) {
|
||||
input = Mathf.Clamp((int)RecordObjectFloat((float)input, (float)EditorGUILayout.IntField(new GUIContent(name, toolTip), input, options), name, undoObject), min, max);
|
||||
}
|
||||
|
||||
public static void AddBool(ref bool input, string name, string toolTip, Object undoObject) {
|
||||
bool newValue = EditorGUILayout.Toggle(new GUIContent(name, toolTip), input);
|
||||
|
||||
if (newValue != input && !Application.isPlaying) {
|
||||
Undo.RecordObject(undoObject, name);
|
||||
}
|
||||
|
||||
input = newValue;
|
||||
}
|
||||
|
||||
public static void AddVector3(ref Vector3 input, string name, Object undoObject, params GUILayoutOption[] options) {
|
||||
Vector3 newValue = EditorGUILayout.Vector3Field(name, input, options);
|
||||
|
||||
if (newValue != input && !Application.isPlaying) {
|
||||
Undo.RecordObject(undoObject, name);
|
||||
}
|
||||
|
||||
input = newValue;
|
||||
}
|
||||
|
||||
private static float RecordObjectFloat(float input, float newValue, string name, Object undoObject) {
|
||||
if (newValue != input && !Application.isPlaying) Undo.RecordObject(undoObject, name);
|
||||
return newValue;
|
||||
}
|
||||
|
||||
private static Object RecordObject(Object input, Object newValue, string name, Object undoObject) {
|
||||
if (newValue != input && !Application.isPlaying) Undo.RecordObject(undoObject, name);
|
||||
return newValue;
|
||||
}
|
||||
|
||||
#endregion SceneGUI tools
|
||||
|
||||
#region Platform dependent
|
||||
|
||||
public static void SphereCap(int controlID, Vector3 position, Quaternion rotation, float size) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.SphereHandleCap(controlID, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.SphereCap(controlID, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void CubeCap(int controlID, Vector3 position, Quaternion rotation, float size) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.CubeHandleCap(controlID, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.CubeCap(controlID, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void ConeCap(int controlID, Vector3 position, Quaternion rotation, float size) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.ConeHandleCap(controlID, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.ConeCap(controlID, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void ArrowCap(int controlID, Vector3 position, Quaternion rotation, float size) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.ArrowHandleCap(controlID, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.ArrowCap(controlID, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void CircleCap(int controlID, Vector3 position, Quaternion rotation, float size) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.CircleHandleCap(controlID, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.CircleCap(controlID, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static void DotCap(int controlID, Vector3 position, Quaternion rotation, float size) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
Handles.DotHandleCap(controlID, position, rotation, size, EventType.Repaint);
|
||||
#else
|
||||
Handles.DotCap(controlID, position, rotation, size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool DotButton(Vector3 position, Quaternion direction, float size, float pickSize) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
return Handles.Button(position, direction, size, pickSize, Handles.DotHandleCap);
|
||||
#else
|
||||
return Handles.Button(position, direction, size, pickSize, Handles.DotCap);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static bool SphereButton(Vector3 position, Quaternion direction, float size, float pickSize) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
return Handles.Button(position, direction, size, pickSize, Handles.SphereHandleCap);
|
||||
#else
|
||||
return Handles.Button(position, direction, size, pickSize, Handles.SphereCap);
|
||||
#endif
|
||||
}
|
||||
|
||||
public static float ScaleValueHandleSphere(float value, Vector3 position, Quaternion rotation, float size, float snap) {
|
||||
#if UNITY_5_6_OR_NEWER
|
||||
return Handles.ScaleValueHandle(value, position, rotation, size, Handles.SphereHandleCap, snap);
|
||||
#else
|
||||
return Handles.ScaleValueHandle(value, position, rotation, size, Handles.SphereCap, snap);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion Platform dependent
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c18519ac3faf848ca878cd0509c4ce8c
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,65 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
|
||||
// Custom drawer for the LargeHeader attribute
|
||||
[CustomPropertyDrawer(typeof(InspectorComment))]
|
||||
public class InspectorCommentDrawer : DecoratorDrawer
|
||||
{
|
||||
// Used to calculate the height of the box
|
||||
public static Texture2D lineTex = null;
|
||||
private GUIStyle style;
|
||||
|
||||
InspectorComment comment { get { return ((InspectorComment)attribute); } }
|
||||
|
||||
// Get the height of the element
|
||||
public override float GetHeight()
|
||||
{
|
||||
style = GetStyle();
|
||||
return style.CalcHeight(new GUIContent(comment.name), EditorGUIUtility.currentViewWidth) + 10f;
|
||||
|
||||
//return base.GetHeight() * 1.5f;
|
||||
}
|
||||
|
||||
// Override the GUI drawing for this attribute
|
||||
public override void OnGUI(Rect pos)
|
||||
{
|
||||
// Get the color the line should be
|
||||
Color color = Color.white;
|
||||
switch (comment.color.ToString().ToLower())
|
||||
{
|
||||
case "white": color = Color.white; break;
|
||||
case "red": color = Color.red; break;
|
||||
case "blue": color = Color.blue; break;
|
||||
case "green": color = Color.green; break;
|
||||
case "gray": color = Color.gray; break;
|
||||
case "grey": color = Color.grey; break;
|
||||
case "black": color = Color.black; break;
|
||||
}
|
||||
|
||||
color *= 0.5f;
|
||||
|
||||
style = GetStyle();
|
||||
|
||||
GUI.color = color;
|
||||
|
||||
Rect labelRect = pos;
|
||||
//labelRect.y += 10;
|
||||
EditorGUI.LabelField(labelRect, new GUIContent(comment.name), style);
|
||||
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
|
||||
private GUIStyle GetStyle()
|
||||
{
|
||||
var style = new GUIStyle(GUI.skin.label);
|
||||
style.fontSize = 10;
|
||||
style.fontStyle = FontStyle.Normal;
|
||||
style.wordWrap = true;
|
||||
style.alignment = TextAnchor.LowerLeft;
|
||||
return style;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c87de0c0b96012c43b2684edd36e3289
|
||||
timeCreated: 1533045048
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,171 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace RootMotion
|
||||
{
|
||||
|
||||
[CustomPropertyDrawer(typeof(ShowIfAttribute))]
|
||||
public class ShowIfPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
protected ShowIfAttribute showIfAttribute;
|
||||
protected SerializedProperty prop;
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
if (!Show(property) && showIfAttribute.mode == ShowIfMode.Hidden) return -EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
return EditorGUI.GetPropertyHeight(property, label);
|
||||
}
|
||||
|
||||
protected bool Show(SerializedProperty property)
|
||||
{
|
||||
showIfAttribute = attribute as ShowIfAttribute;
|
||||
|
||||
var path = property.propertyPath.Contains(".") ? System.IO.Path.ChangeExtension(property.propertyPath, showIfAttribute.propName) : showIfAttribute.propName;
|
||||
|
||||
prop = property.serializedObject.FindProperty(path);
|
||||
if (prop == null) return true;
|
||||
|
||||
switch(prop.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Enum:
|
||||
return prop.enumValueIndex.Equals((int)showIfAttribute.propValue);
|
||||
case SerializedPropertyType.Boolean:
|
||||
return prop.boolValue.Equals(showIfAttribute.propValue);
|
||||
case SerializedPropertyType.Float:
|
||||
return prop.floatValue > (float)showIfAttribute.propValue && prop.floatValue < (float)showIfAttribute.otherPropValue;
|
||||
case SerializedPropertyType.LayerMask:
|
||||
return prop.intValue != 0;
|
||||
case SerializedPropertyType.String:
|
||||
return prop.stringValue != string.Empty && prop.stringValue != "";
|
||||
case SerializedPropertyType.Vector2:
|
||||
float sqrMag2 = prop.vector2Value.sqrMagnitude;
|
||||
return sqrMag2 > (float)showIfAttribute.propValue && sqrMag2 < (float)showIfAttribute.otherPropValue;
|
||||
case SerializedPropertyType.Vector3:
|
||||
float sqrMag3 = prop.vector3Value.sqrMagnitude;
|
||||
return sqrMag3 > (float)showIfAttribute.propValue && sqrMag3 < (float)showIfAttribute.otherPropValue;
|
||||
case SerializedPropertyType.Vector4:
|
||||
float sqrMag4 = prop.vector4Value.sqrMagnitude;
|
||||
return sqrMag4 > (float)showIfAttribute.propValue && sqrMag4 < (float)showIfAttribute.otherPropValue;
|
||||
case SerializedPropertyType.ObjectReference:
|
||||
return prop.objectReferenceValue != null;
|
||||
default:
|
||||
Debug.LogError("Unsupported ShowIf property type: " + prop.propertyType);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
showIfAttribute = attribute as ShowIfAttribute;
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
|
||||
if (Show(property))
|
||||
{
|
||||
if (showIfAttribute.indent) EditorGUI.indentLevel++;
|
||||
Draw(position, property, attribute, label);
|
||||
if (showIfAttribute.indent) EditorGUI.indentLevel--;
|
||||
}
|
||||
else if (showIfAttribute.mode == ShowIfMode.Disabled)
|
||||
{
|
||||
if (showIfAttribute.indent) EditorGUI.indentLevel++;
|
||||
GUI.enabled = false;
|
||||
Draw(position, property, attribute, label);
|
||||
GUI.enabled = true;
|
||||
if (showIfAttribute.indent) EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
EditorGUI.EndProperty();
|
||||
}
|
||||
|
||||
protected virtual void Draw(Rect position, SerializedProperty property, PropertyAttribute attribute, GUIContent label)
|
||||
{
|
||||
|
||||
EditorGUI.PropertyField(position, property, label, true);
|
||||
}
|
||||
}
|
||||
|
||||
[CustomPropertyDrawer(typeof(ShowRangeIfAttribute))]
|
||||
public class ShowRangeIfPropertyDrawer : ShowIfPropertyDrawer
|
||||
{
|
||||
protected override void Draw(Rect position, SerializedProperty property, PropertyAttribute attribute, GUIContent label)
|
||||
{
|
||||
ShowRangeIfAttribute range = attribute as ShowRangeIfAttribute;
|
||||
|
||||
if (property.propertyType == SerializedPropertyType.Float)
|
||||
EditorGUI.Slider(position, property, range.min, range.max, label);
|
||||
else if (property.propertyType == SerializedPropertyType.Integer)
|
||||
EditorGUI.IntSlider(position, property, Convert.ToInt32(range.min), Convert.ToInt32(range.max), label);
|
||||
else
|
||||
EditorGUI.LabelField(position, label.text, "Use Range with float or int.");
|
||||
}
|
||||
}
|
||||
|
||||
// Custom drawer for the LargeHeader attribute
|
||||
[CustomPropertyDrawer(typeof(ShowLargeHeaderIf))]
|
||||
public class ShowLargeHeaderIfDrawer : ShowIfPropertyDrawer
|
||||
{
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
if (!Show(property) && showIfAttribute.mode == ShowIfMode.Hidden) return -EditorGUIUtility.standardVerticalSpacing;
|
||||
|
||||
return base.GetPropertyHeight(property, label) * 2f;
|
||||
}
|
||||
|
||||
// Override the GUI drawing for this attribute
|
||||
protected override void Draw(Rect position, SerializedProperty property, PropertyAttribute attribute, GUIContent label)
|
||||
{
|
||||
var largeHeader = (ShowLargeHeaderIf)attribute;
|
||||
LargeHeaderDrawer.Draw(position, largeHeader.name, largeHeader.color);
|
||||
}
|
||||
}
|
||||
|
||||
// Custom drawer for the LargeHeader attribute
|
||||
[CustomPropertyDrawer(typeof(LargeHeader))]
|
||||
public class LargeHeaderDrawer : DecoratorDrawer
|
||||
{
|
||||
// Get the height of the element
|
||||
public override float GetHeight()
|
||||
{
|
||||
return base.GetHeight() * 2f;
|
||||
}
|
||||
|
||||
// Override the GUI drawing for this attribute
|
||||
public override void OnGUI(Rect position)
|
||||
{
|
||||
var largeHeader = (LargeHeader)attribute;
|
||||
Draw(position, largeHeader.name, largeHeader.color);
|
||||
}
|
||||
|
||||
public static void Draw(Rect position, string name, string color)
|
||||
{
|
||||
// Get the color the line should be
|
||||
Color c = Color.white;
|
||||
switch (color.ToString().ToLower())
|
||||
{
|
||||
case "white": c = Color.white; break;
|
||||
case "red": c = Color.red; break;
|
||||
case "blue": c = Color.blue; break;
|
||||
case "green": c = Color.green; break;
|
||||
case "gray": c = Color.gray; break;
|
||||
case "grey": c = Color.grey; break;
|
||||
case "black": c = Color.black; break;
|
||||
}
|
||||
|
||||
c *= 0.7f;
|
||||
|
||||
var style = new GUIStyle(GUI.skin.label);
|
||||
style.fontSize = 16;
|
||||
style.fontStyle = FontStyle.Normal;
|
||||
style.alignment = TextAnchor.LowerLeft;
|
||||
GUI.color = c;
|
||||
|
||||
Rect labelRect = position;
|
||||
EditorGUI.LabelField(labelRect, name, style);
|
||||
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ac9eb818e19f0442850412e6c19c51d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,19 @@
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using System.Collections;
|
||||
|
||||
namespace RootMotion {
|
||||
|
||||
/*
|
||||
* Serialized content is used for caching serialized properties and their respective GUIContent and enforcing unified GUI layout.
|
||||
* */
|
||||
public struct SerializedContent {
|
||||
public SerializedProperty prop;
|
||||
public GUIContent guiContent;
|
||||
|
||||
public SerializedContent(SerializedProperty prop, GUIContent guiContent) {
|
||||
this.prop = prop;
|
||||
this.guiContent = guiContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa9bdb02a53b1450c8f474d42de57950
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user