Insanely huge initial commit

This commit is contained in:
2026-02-21 17:04:05 -08:00
parent 9cdd36191a
commit 613d75914a
22525 changed files with 4035207 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MoreMountains.Tools
{
[CustomPropertyDrawer(typeof(MMBackgroundColorAttribute))]
public class MMBackgroundColorAttributeDrawer : PropertyDrawer
{
#if UNITY_EDITOR
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
var backgroundColorAttribute = attribute as MMBackgroundColorAttribute;
bool doHighlight = true;
if (doHighlight)
{
var color = GetColor(backgroundColorAttribute.Color);
var padding = EditorGUIUtility.standardVerticalSpacing;
var highlightRect = new Rect(position.x - padding, position.y - padding,
position.width + (padding * 2), position.height + (padding * 2));
EditorGUI.DrawRect(highlightRect, color);
var cc = GUI.contentColor;
GUI.contentColor = Color.black;
EditorGUI.PropertyField(position, property, label);
GUI.contentColor = cc;
}
else
{
EditorGUI.PropertyField(position, property, label);
}
}
#endif
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, label, true);
}
private Color GetColor(MMBackgroundAttributeColor color)
{
switch (color)
{
case MMBackgroundAttributeColor.Red:
return new Color32(255, 0, 63, 255);
case MMBackgroundAttributeColor.Pink:
return new Color32(255, 66, 160, 255);
case MMBackgroundAttributeColor.Orange:
return new Color32(255, 128, 0, 255);
case MMBackgroundAttributeColor.Yellow:
return new Color32(255, 211, 0, 255);
case MMBackgroundAttributeColor.Green:
return new Color32(102, 255, 0, 255);
case MMBackgroundAttributeColor.Blue:
return new Color32(0, 135, 189, 255);
case MMBackgroundAttributeColor.Violet:
return new Color32(127, 0, 255, 255);
default:
return Color.white;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: eab424a6e91496d4c9cc45c31adc7cc6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MoreMountains.Tools
{
[CustomPropertyDrawer(typeof(MMColorAttribute))]
public class MMColorAttributeDrawer : PropertyDrawer
{
#if UNITY_EDITOR
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
Color color = (attribute as MMColorAttribute).color;
Color prev = GUI.color;
GUI.color = color;
EditorGUI.PropertyField(position, property, label, true);
GUI.color = prev;
}
#endif
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6cf9893ce00472244950a7d0b0c4430e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,64 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MoreMountains.Tools
{
// original implementation by http://www.brechtos.com/hiding-or-disabling-inspector-properties-using-propertydrawers-within-unity-5/
[CustomPropertyDrawer(typeof(MMConditionAttribute))]
public class MMConditionAttributeDrawer : PropertyDrawer
{
#if UNITY_EDITOR
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
MMConditionAttribute conditionAttribute = (MMConditionAttribute)attribute;
bool enabled = GetConditionAttributeResult(conditionAttribute, property);
bool previouslyEnabled = GUI.enabled;
GUI.enabled = enabled;
if (!conditionAttribute.Hidden || enabled)
{
EditorGUI.PropertyField(position, property, label, true);
}
GUI.enabled = previouslyEnabled;
}
#endif
private bool GetConditionAttributeResult(MMConditionAttribute condHAtt, SerializedProperty property)
{
bool enabled = true;
string propertyPath = property.propertyPath;
string conditionPath = propertyPath.Replace(property.name, condHAtt.ConditionBoolean);
SerializedProperty sourcePropertyValue = property.serializedObject.FindProperty(conditionPath);
if (sourcePropertyValue != null)
{
enabled = sourcePropertyValue.boolValue;
}
else
{
Debug.LogWarning("No matching boolean found for ConditionAttribute in object: " + condHAtt.ConditionBoolean);
}
return enabled;
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
MMConditionAttribute conditionAttribute = (MMConditionAttribute)attribute;
bool enabled = GetConditionAttributeResult(conditionAttribute, property);
if (!conditionAttribute.Hidden || enabled)
{
return EditorGUI.GetPropertyHeight(property, label);
}
else
{
return -EditorGUIUtility.standardVerticalSpacing;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a7418ffb631904a47b36fa84af828aa9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System;
namespace MoreMountains.Tools
{
[CustomPropertyDrawer(typeof(MMDropdownAttribute))]
public class MMDropdownAttributeDrawer : PropertyDrawer
{
protected MMDropdownAttribute _dropdownAttribute;
protected string[] _dropdownValues;
protected int _selectedDropdownValueIndex = -1;
protected Type _propertyType;
#if UNITY_EDITOR
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (_dropdownAttribute == null)
{
_dropdownAttribute = (MMDropdownAttribute)attribute;
if (_dropdownAttribute.DropdownValues == null || _dropdownAttribute.DropdownValues.Length == 0)
{
return;
}
_propertyType = _dropdownAttribute.DropdownValues[0].GetType();
_dropdownValues = new string[_dropdownAttribute.DropdownValues.Length];
for (int i = 0; i < _dropdownAttribute.DropdownValues.Length; i++)
{
_dropdownValues[i] = _dropdownAttribute.DropdownValues[i].ToString();
}
bool found = false;
for (var i = 0; i < _dropdownValues.Length; i++)
{
if ((_propertyType == typeof(string)) && property.stringValue == _dropdownValues[i])
{
_selectedDropdownValueIndex = i;
found = true;
break;
}
if ((_propertyType == typeof(int)) && property.intValue == Convert.ToInt32(_dropdownValues[i]))
{
_selectedDropdownValueIndex = i;
found = true;
break;
}
if ((_propertyType == typeof(float)) && Mathf.Approximately(property.floatValue, Convert.ToSingle(_dropdownValues[i])))
{
_selectedDropdownValueIndex = i;
found = true;
break;
}
}
if (!found)
{
_selectedDropdownValueIndex = 0;
}
}
if ((_dropdownValues == null) || (_dropdownValues.Length == 0) || (_selectedDropdownValueIndex < 0))
{
EditorGUI.PropertyField(position, property, label);
return;
}
EditorGUI.BeginChangeCheck();
_selectedDropdownValueIndex = EditorGUI.Popup(position, label.text, _selectedDropdownValueIndex, _dropdownValues);
if (EditorGUI.EndChangeCheck())
{
if (_propertyType == typeof(string))
{
property.stringValue = _dropdownValues[_selectedDropdownValueIndex];
}
else if (_propertyType == typeof(int))
{
property.intValue = Convert.ToInt32(_dropdownValues[_selectedDropdownValueIndex]);
}
else if (_propertyType == typeof(float))
{
property.floatValue = Convert.ToSingle(_dropdownValues[_selectedDropdownValueIndex]);
}
property.serializedObject.ApplyModifiedProperties();
}
}
#endif
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f211a3800cfd6094db6caf6e9d4571fd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,74 @@
using UnityEngine;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MoreMountains.Tools
{
// original implementation by http://www.brechtos.com/hiding-or-disabling-inspector-properties-using-propertydrawers-within-unity-5/
[CustomPropertyDrawer(typeof(MMEnumConditionAttribute))]
public class MMEnumConditionAttributeDrawer : PropertyDrawer
{
#if UNITY_EDITOR
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
MMEnumConditionAttribute enumConditionAttribute = (MMEnumConditionAttribute)attribute;
bool enabled = GetConditionAttributeResult(enumConditionAttribute, property);
bool previouslyEnabled = GUI.enabled;
GUI.enabled = enabled;
if (!enumConditionAttribute.Hidden || enabled)
{
EditorGUI.PropertyField(position, property, label, true);
}
GUI.enabled = previouslyEnabled;
}
#endif
private static Dictionary<string, string> cachedPaths = new Dictionary<string, string>();
private bool GetConditionAttributeResult(MMEnumConditionAttribute enumConditionAttribute, SerializedProperty property)
{
bool enabled = true;
SerializedProperty enumProp;
string enumPropPath = string.Empty;
string propertyPath = property.propertyPath;
if (!cachedPaths.TryGetValue(propertyPath, out enumPropPath))
{
enumPropPath = propertyPath.Replace(property.name, enumConditionAttribute.ConditionEnum);
cachedPaths.Add(propertyPath, enumPropPath);
}
enumProp = property.serializedObject.FindProperty(enumPropPath);
if (enumProp != null)
{
int currentEnum = enumProp.enumValueIndex;
enabled = enumConditionAttribute.ContainsBitFlag(currentEnum);
}
else
{
Debug.LogWarning("No matching boolean found for ConditionAttribute in object: " + enumConditionAttribute.ConditionEnum);
}
return enabled;
}
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
MMEnumConditionAttribute enumConditionAttribute = (MMEnumConditionAttribute)attribute;
bool enabled = GetConditionAttributeResult(enumConditionAttribute, property);
if (!enumConditionAttribute.Hidden || enabled)
{
return EditorGUI.GetPropertyHeight(property, label);
}
else
{
return -EditorGUIUtility.standardVerticalSpacing;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0e88eb20b861cbc49b096ad2baac77cb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,26 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using UnityEditor;
namespace MoreMountains.Tools
{
[CustomPropertyDrawer(typeof(MMHiddenAttribute))]
public class MMHiddenAttributeDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return 0f;
}
#if UNITY_EDITOR
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
}
#endif
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: ac53bf83e8327014bbc73944dfec5ff8
timeCreated: 1456270265
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,118 @@
#if UNITY_EDITOR
using System;
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
using System.Reflection;
namespace MoreMountains.Tools
{
[CustomPropertyDrawer (typeof(MMInformationAttribute))]
/// <summary>
/// This class allows the display of a message box (warning, info, error...) next to a property (before or after)
/// </summary>
public class MMInformationAttributeDrawer : PropertyDrawer
{
// determines the space after the help box, the space before the text box, and the width of the help box icon
const int spaceBeforeTheTextBox = 5;
const int spaceAfterTheTextBox = 10;
const int iconWidth = 55;
MMInformationAttribute informationAttribute { get { return ((MMInformationAttribute)attribute); } }
#if UNITY_EDITOR
/// <summary>
/// OnGUI, displays the property and the textbox in the specified order
/// </summary>
/// <param name="rect">Rect.</param>
/// <param name="prop">Property.</param>
/// <param name="label">Label.</param>
public override void OnGUI (Rect rect, SerializedProperty prop, GUIContent label)
{
if (HelpEnabled())
{
EditorStyles.helpBox.richText=true ;
if (!informationAttribute.MessageAfterProperty)
{
// we position the message before the property
rect.height = DetermineTextboxHeight(informationAttribute.Message);
EditorGUI.HelpBox (rect, informationAttribute.Message, informationAttribute.Type);
rect.y += rect.height + spaceBeforeTheTextBox;
EditorGUI.PropertyField(rect, prop, label, true);
}
else
{
// we position the property first, then the message
rect.height = GetPropertyHeight(prop,label);
EditorGUI.PropertyField(rect, prop, label, true);
rect.height = DetermineTextboxHeight(informationAttribute.Message);
// we add the complete property height (property + helpbox, as overridden in this very script), and substract both to get just the property
rect.y += GetPropertyHeight(prop,label) - DetermineTextboxHeight(informationAttribute.Message) - spaceAfterTheTextBox;
EditorGUI.HelpBox (rect, informationAttribute.Message, informationAttribute.Type);
}
}
else
{
EditorGUI.PropertyField(rect, prop, label, true);
}
}
#endif
/// <summary>
/// Returns the complete height of the whole block (property + help text)
/// </summary>
/// <returns>The block height.</returns>
/// <param name="property">Property.</param>
/// <param name="label">Label.</param>
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (HelpEnabled())
{
return EditorGUI.GetPropertyHeight(property) + DetermineTextboxHeight(informationAttribute.Message) + spaceAfterTheTextBox + spaceBeforeTheTextBox;
}
else
{
return EditorGUI.GetPropertyHeight(property);
}
}
/// <summary>
/// Checks the editor prefs to see if help is enabled or not
/// </summary>
/// <returns><c>true</c>, if enabled was helped, <c>false</c> otherwise.</returns>
protected virtual bool HelpEnabled()
{
bool helpEnabled = false;
if (EditorPrefs.HasKey("MMShowHelpInInspectors"))
{
if (EditorPrefs.GetBool("MMShowHelpInInspectors"))
{
helpEnabled = true;
}
}
return helpEnabled;
}
/// <summary>
/// Determines the height of the textbox.
/// </summary>
/// <returns>The textbox height.</returns>
/// <param name="message">Message.</param>
protected virtual float DetermineTextboxHeight(string message)
{
GUIStyle style = new GUIStyle(EditorStyles.helpBox);
style.richText=true;
float newHeight = style.CalcHeight(new GUIContent(message),EditorGUIUtility.currentViewWidth - iconWidth);
return newHeight;
}
}
}
#endif

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 45b7f6ca773ad4e81ad2ed6d93158953
timeCreated: 1459517598
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
using UnityEngine;
using System.Collections;
using MoreMountains.Tools;
using UnityEditor;
namespace MoreMountains.Tools
{
/// <summary>
/// This class adds a MoreMountains entry in Unity's top menu, allowing to enable/disable the help texts from the engine's inspectors
/// </summary>
public static class MMMenuHelp
{
[MenuItem("Tools/More Mountains/Enable Help in Inspectors", false,0)]
/// <summary>
/// Adds a menu item to enable help
/// </summary>
private static void EnableHelpInInspectors()
{
SetHelpEnabled(true);
}
[MenuItem("Tools/More Mountains/Enable Help in Inspectors", true)]
/// <summary>
/// Conditional method to determine if the "enable help" entry should be greyed or not
/// </summary>
private static bool EnableHelpInInspectorsValidation()
{
return !HelpEnabled();
}
[MenuItem("Tools/More Mountains/Disable Help in Inspectors", false,1)]
/// <summary>
/// Adds a menu item to disable help
/// </summary>
private static void DisableHelpInInspectors()
{
SetHelpEnabled(false);
}
[MenuItem("Tools/More Mountains/Disable Help in Inspectors", true)]
/// <summary>
/// Conditional method to determine if the "disable help" entry should be greyed or not
/// </summary>
private static bool DisableHelpInInspectorsValidation()
{
return HelpEnabled();
}
/// <summary>
/// Checks editor prefs to see if help is enabled or not
/// </summary>
/// <returns><c>true</c>, if enabled was helped, <c>false</c> otherwise.</returns>
private static bool HelpEnabled()
{
if (EditorPrefs.HasKey("MMShowHelpInInspectors"))
{
return EditorPrefs.GetBool("MMShowHelpInInspectors");
}
else
{
EditorPrefs.SetBool("MMShowHelpInInspectors",true);
return true;
}
}
/// <summary>
/// Sets the help enabled editor pref.
/// </summary>
/// <param name="status">If set to <c>true</c> status.</param>
private static void SetHelpEnabled(bool status)
{
EditorPrefs.SetBool("MMShowHelpInInspectors",status);
SceneView.RepaintAll();
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 28fbd4d56656345f4ba40f7e4d786fb1
timeCreated: 1477393124
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,268 @@
using UnityEngine;
using UnityEditor;
using System;
using System.Reflection;
using System.Linq;
using System.Collections.Generic;
namespace MoreMountains.Tools
{
public class MMInspectorGroupData
{
public bool GroupIsOpen;
public MMInspectorGroupAttribute GroupAttribute;
public List<SerializedProperty> PropertiesList = new List<SerializedProperty>();
public HashSet<string> GroupHashSet = new HashSet<string>();
public Color GroupColor;
public void ClearGroup()
{
GroupAttribute = null;
GroupHashSet.Clear();
PropertiesList.Clear();
}
}
/// <summary>
/// A generic drawer for all MMMonoBehaviour, handles both the Group and RequiresConstantRepaint attributes
/// </summary>
[CanEditMultipleObjects]
[CustomEditor(typeof(MMMonoBehaviour), true, isFallback = true)]
public class MMMonoBehaviourDrawer : UnityEditor.Editor
{
public bool DrawerInitialized;
public List<SerializedProperty> PropertiesList = new List<SerializedProperty>();
public Dictionary<string, MMInspectorGroupData> GroupData = new Dictionary<string, MMInspectorGroupData>();
private string[] _mmHiddenPropertiesToHide;
private bool _hasMMHiddenProperties = false;
private bool _requiresConstantRepaint;
protected bool _shouldDrawBase = true;
public override bool RequiresConstantRepaint()
{
return _requiresConstantRepaint;
}
protected virtual void OnEnable()
{
DrawerInitialized = false;
if (!target || !serializedObject.targetObject)
{
return;
}
_requiresConstantRepaint = serializedObject.targetObject.GetType().GetCustomAttribute<MMRequiresConstantRepaintAttribute>() != null;
MMHiddenPropertiesAttribute[] hiddenProperties = (MMHiddenPropertiesAttribute[])target.GetType().GetCustomAttributes(typeof(MMHiddenPropertiesAttribute), false);
if (hiddenProperties != null && hiddenProperties.Length > 0 && hiddenProperties[0].PropertiesNames != null)
{
_mmHiddenPropertiesToHide = hiddenProperties[0].PropertiesNames;
_hasMMHiddenProperties = true;
}
}
protected virtual void OnDisable()
{
if (target == null)
{
return;
}
foreach (KeyValuePair<string, MMInspectorGroupData> groupData in GroupData)
{
EditorPrefs.SetBool(string.Format($"{groupData.Value.GroupAttribute.GroupName}{groupData.Value.PropertiesList[0].name}{target.GetInstanceID()}"), groupData.Value.GroupIsOpen);
groupData.Value.ClearGroup();
}
}
public override void OnInspectorGUI()
{
serializedObject.Update();
Initialization();
DrawBase();
DrawScriptBox();
DrawContainer();
DrawContents();
serializedObject.ApplyModifiedProperties();
}
protected virtual void Initialization()
{
if (DrawerInitialized)
{
return;
}
List<FieldInfo> fieldInfoList;
MMInspectorGroupAttribute previousGroupAttribute = default;
int fieldInfoLength = MMMonoBehaviourFieldInfo.GetFieldInfo(target, out fieldInfoList);
for (int i = 0; i < fieldInfoLength; i++)
{
MMInspectorGroupAttribute group = Attribute.GetCustomAttribute(fieldInfoList[i], typeof(MMInspectorGroupAttribute)) as MMInspectorGroupAttribute;
MMInspectorGroupData groupData;
if (group == null)
{
if (previousGroupAttribute != null && previousGroupAttribute.GroupAllFieldsUntilNextGroupAttribute)
{
_shouldDrawBase = false;
if (!GroupData.TryGetValue(previousGroupAttribute.GroupName, out groupData))
{
GroupData.Add(previousGroupAttribute.GroupName, new MMInspectorGroupData
{
GroupAttribute = previousGroupAttribute,
GroupHashSet = new HashSet<string> { fieldInfoList[i].Name },
GroupColor = MMColors.GetColorAt(previousGroupAttribute.GroupColorIndex)
});
}
else
{
groupData.GroupColor = MMColors.GetColorAt(previousGroupAttribute.GroupColorIndex);
groupData.GroupHashSet.Add(fieldInfoList[i].Name);
}
}
continue;
}
previousGroupAttribute = group;
if (!GroupData.TryGetValue(group.GroupName, out groupData))
{
bool groupIsOpen = EditorPrefs.GetBool(string.Format($"{group.GroupName}{fieldInfoList[i].Name}{target.GetInstanceID()}"), false);
GroupData.Add(group.GroupName, new MMInspectorGroupData
{
GroupAttribute = group,
GroupColor = MMColors.GetColorAt(previousGroupAttribute.GroupColorIndex),
GroupHashSet = new HashSet<string> { fieldInfoList[i].Name }, GroupIsOpen = groupIsOpen });
}
else
{
groupData.GroupHashSet.Add(fieldInfoList[i].Name);
groupData.GroupColor = MMColors.GetColorAt(previousGroupAttribute.GroupColorIndex);
}
}
SerializedProperty iterator = serializedObject.GetIterator();
if (iterator.NextVisible(true))
{
do
{
FillPropertiesList(iterator);
} while (iterator.NextVisible(false));
}
DrawerInitialized = true;
}
protected virtual void DrawBase()
{
if (_shouldDrawBase)
{
DrawDefaultInspector();
return;
}
}
protected virtual void DrawScriptBox()
{
if (PropertiesList.Count == 0)
{
return;
}
using (new EditorGUI.DisabledScope("m_Script" == PropertiesList[0].propertyPath))
{
EditorGUILayout.PropertyField(PropertiesList[0], true);
}
}
protected virtual void DrawContainer()
{
if (PropertiesList.Count == 0)
{
return;
}
foreach (KeyValuePair<string, MMInspectorGroupData> pair in GroupData)
{
this.DrawVerticalLayout(() => DrawGroup(pair.Value), MMMonoBehaviourDrawerStyle.ContainerStyle);
EditorGUI.indentLevel = 0;
}
}
protected virtual void DrawContents()
{
if (PropertiesList.Count == 0)
{
return;
}
EditorGUILayout.Space();
for (int i = 1; i < PropertiesList.Count; i++)
{
if (_hasMMHiddenProperties && (!_mmHiddenPropertiesToHide.Contains(PropertiesList[i].name)))
{
EditorGUILayout.PropertyField(PropertiesList[i], true);
}
}
}
protected virtual void DrawGroup(MMInspectorGroupData groupData)
{
Rect verticalGroup = EditorGUILayout.BeginVertical();
var leftBorderRect = new Rect(verticalGroup.xMin + 5, verticalGroup.yMin - 10, 3f, verticalGroup.height + 20);
leftBorderRect.xMin = 15f;
leftBorderRect.xMax = 18f;
EditorGUI.DrawRect(leftBorderRect, groupData.GroupColor);
groupData.GroupIsOpen = EditorGUILayout.Foldout(groupData.GroupIsOpen, groupData.GroupAttribute.GroupName, true, MMMonoBehaviourDrawerStyle.GroupStyle);
if (groupData.GroupIsOpen)
{
EditorGUI.indentLevel = 0;
for (int i = 0; i < groupData.PropertiesList.Count; i++)
{
this.DrawVerticalLayout(() => DrawChild(i), MMMonoBehaviourDrawerStyle.BoxChildStyle);
}
}
EditorGUILayout.EndVertical();
void DrawChild(int i)
{
if ((_hasMMHiddenProperties) && (_mmHiddenPropertiesToHide.Contains(groupData.PropertiesList[i].name)))
{
return;
}
EditorGUILayout.PropertyField(groupData.PropertiesList[i], new GUIContent(ObjectNames.NicifyVariableName(groupData.PropertiesList[i].name), tooltip:groupData.PropertiesList[i].tooltip), true);
}
}
public void FillPropertiesList(SerializedProperty serializedProperty)
{
bool shouldClose = false;
foreach (KeyValuePair<string, MMInspectorGroupData> pair in GroupData)
{
if (pair.Value.GroupHashSet.Contains(serializedProperty.name))
{
SerializedProperty property = serializedProperty.Copy();
shouldClose = true;
pair.Value.PropertiesList.Add(property);
break;
}
}
if (!shouldClose)
{
SerializedProperty property = serializedProperty.Copy();
PropertiesList.Add(property);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 57340accc3653b34da87f607fbb6cb05
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEngine;
namespace MoreMountains.Tools
{
[InitializeOnLoad]
public static class MMMonoBehaviourDrawerHelper
{
public static void DrawButton(this Editor editor, MethodInfo methodInfo)
{
if (GUILayout.Button(methodInfo.Name))
{
methodInfo.Invoke(editor.target, null);
}
}
public static void DrawVerticalLayout(this Editor editor, Action action, GUIStyle style)
{
EditorGUILayout.BeginVertical(style);
action();
EditorGUILayout.EndVertical();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4593a46207e8ba843828a1929c41a13d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,93 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace MoreMountains.Tools
{
static class MMMonoBehaviourDrawerStyle
{
public static GUIStyle ContainerStyle;
public static GUIStyle BoxChildStyle;
public static GUIStyle GroupStyle;
public static GUIStyle TextStyle;
public static bool IsProSkin = EditorGUIUtility.isProSkin;
public static Texture2D GroupClosedTriangle = Resources.Load<Texture2D>("IN foldout focus-6510");
public static Texture2D GroupOpenTriangle = Resources.Load<Texture2D>("IN foldout focus on-5718");
public static Texture2D NoTexture = new Texture2D(0, 0);
static MMMonoBehaviourDrawerStyle()
{
// TEXT STYLE --------------------------------------------------------------------------------------------------------------
TextStyle = new GUIStyle(EditorStyles.largeLabel);
TextStyle.richText = true;
TextStyle.contentOffset = new Vector2(0, 5);
//TextStyle.font = Font.CreateDynamicFontFromOSFont(new[] { "Terminus (TTF) for Windows", "Calibri" }, 14);
// GROUP STYLE --------------------------------------------------------------------------------------------------------------
GroupStyle = new GUIStyle(EditorStyles.foldout);
GroupStyle.active.background = GroupClosedTriangle;
GroupStyle.focused.background = GroupClosedTriangle;
GroupStyle.hover.background = GroupClosedTriangle;
GroupStyle.onActive.background = GroupOpenTriangle;
GroupStyle.onFocused.background = GroupOpenTriangle;
GroupStyle.onHover.background = GroupOpenTriangle;
GroupStyle.fontStyle = FontStyle.Bold;
GroupStyle.overflow = new RectOffset(100, 0, 0, 0);
GroupStyle.padding = new RectOffset(20, 0, 0, 0);
// CONTAINER STYLE --------------------------------------------------------------------------------------------------------------
ContainerStyle = new GUIStyle(GUI.skin.box);
ContainerStyle.padding = new RectOffset(20, 0, 10, 10);
// BOX CHILD STYLE --------------------------------------------------------------------------------------------------------------
BoxChildStyle = new GUIStyle(GUI.skin.box);
/*BoxChildStyle.active.background = GroupClosedTriangle;
BoxChildStyle.focused.background = GroupClosedTriangle;
BoxChildStyle.onActive.background = GroupOpenTriangle;
BoxChildStyle.onFocused.background = GroupOpenTriangle;*/
BoxChildStyle.padding = new RectOffset(0, 0, 0, 0);
BoxChildStyle.margin = new RectOffset(0, 0, 0, 0);
BoxChildStyle.normal.background = NoTexture;
// FOLDOUT STYLE --------------------------------------------------------------------------------------------------------------
/*EditorStyles.foldout.active.background = GroupClosedTriangle;
EditorStyles.foldout.focused.background = GroupClosedTriangle;
EditorStyles.foldout.hover.background = GroupClosedTriangle;
EditorStyles.foldout.onActive.background = GroupOpenTriangle;
EditorStyles.foldout.onFocused.background = GroupOpenTriangle;
EditorStyles.foldout.onHover.background = GroupOpenTriangle;
//EditorStyles.foldout.overflow = new RectOffset(100, 0, 0, 0);
EditorStyles.foldout.padding = new RectOffset(0, 0, 0, 0);
EditorStyles.foldout.overflow = new RectOffset(0, 0, 0, 0);
EditorStyles.foldout.*/
}
static Texture2D MakeTex(int width, int height, Color col)
{
Color[] pix = new Color[width * height];
for (int i = 0; i < pix.Length; ++i)
{
pix[i] = col;
}
Texture2D result = new Texture2D(width, height);
result.SetPixels(pix);
result.Apply();
return result;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 940535a309e9c95418b91f406df57b43
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
namespace MoreMountains.Tools
{
static class MMMonoBehaviourFieldInfo
{
public static Dictionary<int, List<FieldInfo>> FieldInfoList = new Dictionary<int, List<FieldInfo>>();
public static int GetFieldInfo(Object target, out List<FieldInfo> fieldInfoList)
{
Type targetType = target.GetType();
int targetTypeHashCode = targetType.GetHashCode();
if (!FieldInfoList.TryGetValue(targetTypeHashCode, out fieldInfoList))
{
IList<Type> typeTree = targetType.GetBaseTypes();
fieldInfoList = target.GetType().GetFields(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.NonPublic)
.OrderByDescending(x => typeTree.IndexOf(x.DeclaringType))
.ToList();
FieldInfoList.Add(targetTypeHashCode, fieldInfoList);
}
return fieldInfoList.Count;
}
public static IList<Type> GetBaseTypes(this Type t)
{
var types = new List<Type>();
while (t.BaseType != null)
{
types.Add(t);
t = t.BaseType;
}
return types;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e65295240cbc68641b5b47a57a4296a9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,30 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
using UnityEditor;
namespace MoreMountains.Tools
{
[CustomPropertyDrawer(typeof(MMReadOnlyAttribute))]
public class MMReadOnlyAttributeDrawer : PropertyDrawer
{
// Necessary since some properties tend to collapse smaller than their content
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
return EditorGUI.GetPropertyHeight(property, label, true);
}
#if UNITY_EDITOR
// Draw a disabled property field
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
GUI.enabled = false; // Disable fields
EditorGUI.PropertyField(position, property, label, true);
GUI.enabled = true; // Enable fields
}
#endif
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8bc90960c2aea754a8ff74069babfa0b
timeCreated: 1456269803
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,102 @@
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace MoreMountains.Tools
{
[CustomPropertyDrawer(typeof(MMVectorAttribute))]
public class MMVectorLabelsAttributeDrawer : PropertyDrawer
{
protected static readonly GUIContent[] originalLabels = new GUIContent[] { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z"), new GUIContent("W") };
protected const int padding = 375;
public override float GetPropertyHeight(SerializedProperty property, GUIContent guiContent)
{
int ratio = (padding > Screen.width) ? 2 : 1;
return ratio * base.GetPropertyHeight(property, guiContent);
}
#if UNITY_EDITOR
public override void OnGUI(Rect rect, SerializedProperty property, GUIContent guiContent)
{
MMVectorAttribute vector = (MMVectorAttribute)attribute;
if (property.propertyType == SerializedPropertyType.Vector2)
{
float[] fieldArray = new float[] { property.vector2Value.x, property.vector2Value.y };
fieldArray = DrawFields(rect, fieldArray, ObjectNames.NicifyVariableName(property.name), EditorGUI.FloatField, vector);
property.vector2Value = new Vector2(fieldArray[0], fieldArray[1]);
}
else if (property.propertyType == SerializedPropertyType.Vector3)
{
float[] fieldArray = new float[] { property.vector3Value.x, property.vector3Value.y, property.vector3Value.z };
fieldArray = DrawFields(rect, fieldArray, ObjectNames.NicifyVariableName(property.name), EditorGUI.FloatField, vector);
property.vector3Value = new Vector3(fieldArray[0], fieldArray[1], fieldArray[2]);
}
else if (property.propertyType == SerializedPropertyType.Vector4)
{
float[] fieldArray = new float[] { property.vector4Value.x, property.vector4Value.y, property.vector4Value.z, property.vector4Value.w };
fieldArray = DrawFields(rect, fieldArray, ObjectNames.NicifyVariableName(property.name), EditorGUI.FloatField, vector);
property.vector4Value = new Vector4(fieldArray[0], fieldArray[1], fieldArray[2]);
}
else if (property.propertyType == SerializedPropertyType.Vector2Int)
{
int[] fieldArray = new int[] { property.vector2IntValue.x, property.vector2IntValue.y };
fieldArray = DrawFields(rect, fieldArray, ObjectNames.NicifyVariableName(property.name), EditorGUI.IntField, vector);
property.vector2IntValue = new Vector2Int(fieldArray[0], fieldArray[1]);
}
else if (property.propertyType == SerializedPropertyType.Vector3Int)
{
int[] array = new int[] { property.vector3IntValue.x, property.vector3IntValue.y, property.vector3IntValue.z };
array = DrawFields(rect, array, ObjectNames.NicifyVariableName(property.name), EditorGUI.IntField, vector);
property.vector3IntValue = new Vector3Int(array[0], array[1], array[2]);
}
}
#endif
protected T[] DrawFields<T>(Rect rect, T[] vector, string mainLabel, System.Func<Rect, GUIContent, T, T> fieldDrawer, MMVectorAttribute vectors)
{
T[] result = vector;
bool shortSpace = (Screen.width < padding);
Rect mainLabelRect = rect;
mainLabelRect.width = EditorGUIUtility.labelWidth;
if (shortSpace)
{
mainLabelRect.height *= 0.5f;
}
Rect fieldRect = rect;
if (shortSpace)
{
fieldRect.height *= 0.5f;
fieldRect.y += fieldRect.height;
fieldRect.width = rect.width / vector.Length;
}
else
{
fieldRect.x += mainLabelRect.width;
fieldRect.width = (rect.width - mainLabelRect.width) / vector.Length;
}
EditorGUI.LabelField(mainLabelRect, mainLabel);
for (int i = 0; i < vector.Length; i++)
{
GUIContent label = vectors.Labels.Length > i ? new GUIContent(vectors.Labels[i]) : originalLabels[i];
Vector2 labelSize = EditorStyles.label.CalcSize(label);
EditorGUIUtility.labelWidth = Mathf.Max(labelSize.x + 5, 0.3f * fieldRect.width);
result[i] = fieldDrawer(fieldRect, label, vector[i]);
fieldRect.x += fieldRect.width;
}
EditorGUIUtility.labelWidth = 0;
return result;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d2ed4e1d780d3c341b45a60fd3358cf5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: