chore: initial commit
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
public enum MMBackgroundAttributeColor
|
||||
{
|
||||
Red,
|
||||
Pink,
|
||||
Orange,
|
||||
Yellow,
|
||||
Green,
|
||||
Blue,
|
||||
Violet,
|
||||
White
|
||||
}
|
||||
|
||||
public class MMBackgroundColorAttribute : PropertyAttribute
|
||||
{
|
||||
public MMBackgroundAttributeColor Color;
|
||||
|
||||
public MMBackgroundColorAttribute(MMBackgroundAttributeColor color = MMBackgroundAttributeColor.Yellow)
|
||||
{
|
||||
this.Color = color;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d940d484781c4040921ce29789b1943
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Feel/MMTools/Core/MMAttributes/MMColorAttribute.cs
Normal file
14
Assets/Feel/MMTools/Core/MMAttributes/MMColorAttribute.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
public class MMColorAttribute : PropertyAttribute
|
||||
{
|
||||
public Color color;
|
||||
|
||||
public MMColorAttribute(float red = 1, float green = 0, float blue = 0)
|
||||
{
|
||||
this.color = new Color(red, green, blue, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 44a39707cf7142b45a78bb9d0e5ebfa5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class | AttributeTargets.Struct, Inherited = true)]
|
||||
public class MMConditionAttribute : PropertyAttribute
|
||||
{
|
||||
public string ConditionBoolean = "";
|
||||
public bool Hidden = false;
|
||||
public bool Negative = false;
|
||||
|
||||
public MMConditionAttribute(string conditionBoolean)
|
||||
{
|
||||
this.ConditionBoolean = conditionBoolean;
|
||||
this.Hidden = false;
|
||||
}
|
||||
|
||||
public MMConditionAttribute(string conditionBoolean, bool hideInInspector)
|
||||
{
|
||||
this.ConditionBoolean = conditionBoolean;
|
||||
this.Hidden = hideInInspector;
|
||||
this.Negative = false;
|
||||
}
|
||||
|
||||
public MMConditionAttribute(string conditionBoolean, bool hideInInspector, bool negative)
|
||||
{
|
||||
this.ConditionBoolean = conditionBoolean;
|
||||
this.Hidden = hideInInspector;
|
||||
this.Negative = negative;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d99b1ef0840200a4ca8c98ee8b49e114
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// An attribute to add to static methods to they can be called via the MMDebugMenu's command line
|
||||
/// </summary>
|
||||
[AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)]
|
||||
public class MMDebugLogCommandArgumentCountAttribute : System.Attribute
|
||||
{
|
||||
public readonly int ArgumentCount;
|
||||
|
||||
public MMDebugLogCommandArgumentCountAttribute(int argumentCount)
|
||||
{
|
||||
this.ArgumentCount = argumentCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cdec9bf9a59856c48a9bd8fe7caaedc7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// An attribute to add to static methods to they can be called via the MMDebugMenu's command line
|
||||
/// </summary>
|
||||
[AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false)]
|
||||
public class MMDebugLogCommandAttribute : System.Attribute { }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4de406fa905b7cd4586793dec9e9d93d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
16
Assets/Feel/MMTools/Core/MMAttributes/MMDropdownAttribute.cs
Normal file
16
Assets/Feel/MMTools/Core/MMAttributes/MMDropdownAttribute.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
public class MMDropdownAttribute : PropertyAttribute
|
||||
{
|
||||
public readonly object[] DropdownValues;
|
||||
|
||||
public MMDropdownAttribute(params object[] dropdownValues)
|
||||
{
|
||||
DropdownValues = dropdownValues;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42dea95f190fc574eb0ce3f815cb2200
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,37 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using System;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// An attribute to conditionnally hide fields based on the current selection in an enum.
|
||||
/// Usage : [MMEnumCondition("rotationMode", (int)RotationMode.LookAtTarget, (int)RotationMode.RotateToAngles)]
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class | AttributeTargets.Struct, Inherited = true)]
|
||||
public class MMEnumConditionAttribute : PropertyAttribute
|
||||
{
|
||||
public string ConditionEnum = "";
|
||||
public bool Hidden = false;
|
||||
|
||||
BitArray bitArray = new BitArray(32);
|
||||
public bool ContainsBitFlag(int enumValue)
|
||||
{
|
||||
return bitArray.Get(enumValue);
|
||||
}
|
||||
|
||||
public MMEnumConditionAttribute(string conditionBoolean, params int[] enumValues)
|
||||
{
|
||||
this.ConditionEnum = conditionBoolean;
|
||||
this.Hidden = true;
|
||||
|
||||
for (int i = 0; i < enumValues.Length; i++)
|
||||
{
|
||||
bitArray.Set(enumValues[i], true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c44d260255c89244812b064b6bbb5ca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,157 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// Add this attribute to a class and its Execution Order will be changed to the value specified in parameters
|
||||
/// Usage : [ExecutionOrder(66)]
|
||||
/// </summary>
|
||||
public class MMExecutionOrderAttribute : Attribute
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
/// the execution order you want for the class this attribute is applied to
|
||||
public int ExecutionOrder = 0;
|
||||
|
||||
protected static Dictionary<MonoScript, MMExecutionOrderAttribute> _monoScripts;
|
||||
protected static Type _executionOrderAttributeType;
|
||||
protected static Assembly _typeAssembly;
|
||||
protected static Type[] _assemblyTypes;
|
||||
|
||||
/// <summary>
|
||||
/// Attribute method
|
||||
/// </summary>
|
||||
/// <param name="newExecutionOrder"></param>
|
||||
public MMExecutionOrderAttribute(int newExecutionOrder)
|
||||
{
|
||||
ExecutionOrder = newExecutionOrder;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// When Unity loads, modifies the execution orders of monos with an ExecutionOrder attribute, if needed
|
||||
/// </summary>
|
||||
[InitializeOnLoadMethod]
|
||||
protected static void ModifyExecutionOrder()
|
||||
{
|
||||
Initialization();
|
||||
|
||||
FindExecutionOrderAttributes();
|
||||
|
||||
if (ExecutionOrderHasChanged())
|
||||
{
|
||||
UpdateExecutionOrders();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialization method
|
||||
/// </summary>
|
||||
protected static void Initialization()
|
||||
{
|
||||
_monoScripts = new Dictionary<MonoScript, MMExecutionOrderAttribute>();
|
||||
_executionOrderAttributeType = typeof(MMExecutionOrderAttribute);
|
||||
_typeAssembly = _executionOrderAttributeType.Assembly;
|
||||
_assemblyTypes = _typeAssembly.GetTypes();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Goes through all assembly types and stores execution order attributes when found
|
||||
/// </summary>
|
||||
protected static void FindExecutionOrderAttributes()
|
||||
{
|
||||
foreach (Type assemblyType in _assemblyTypes)
|
||||
{
|
||||
if (!HasExecutionOrderAttribute(assemblyType))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
object[] attributes = assemblyType.GetCustomAttributes(_executionOrderAttributeType, false);
|
||||
MMExecutionOrderAttribute attribute = attributes[0] as MMExecutionOrderAttribute;
|
||||
|
||||
string asset = "";
|
||||
string[] guids = AssetDatabase.FindAssets(assemblyType.Name + " t:script");
|
||||
|
||||
if (guids.Length != 0)
|
||||
{
|
||||
foreach (string guid in guids)
|
||||
{
|
||||
string assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||
string filename = Path.GetFileNameWithoutExtension(assetPath);
|
||||
if (filename == assemblyType.Name)
|
||||
{
|
||||
asset = guid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("MMTools' ExecutionOrderAttribute : Can't change "+ assemblyType.Name + "'s execution order");
|
||||
return;
|
||||
}
|
||||
|
||||
MonoScript monoScript = AssetDatabase.LoadAssetAtPath<MonoScript>(AssetDatabase.GUIDToAssetPath(asset));
|
||||
_monoScripts.Add(monoScript, attribute);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the class in parameters has the ExecutionOrder attribute, false otherwise
|
||||
/// </summary>
|
||||
/// <param name="assemblyType"></param>
|
||||
/// <returns></returns>
|
||||
protected static bool HasExecutionOrderAttribute(Type assemblyType)
|
||||
{
|
||||
object[] attributes = assemblyType.GetCustomAttributes(_executionOrderAttributeType, false);
|
||||
return (attributes.Length == 1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the execution order has changed since last time
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected static bool ExecutionOrderHasChanged()
|
||||
{
|
||||
bool executionOrderHasChanged = false;
|
||||
foreach (KeyValuePair<MonoScript, MMExecutionOrderAttribute> monoScript in _monoScripts)
|
||||
{
|
||||
if (monoScript.Key != null)
|
||||
{
|
||||
if (MonoImporter.GetExecutionOrder(monoScript.Key) != monoScript.Value.ExecutionOrder)
|
||||
{
|
||||
executionOrderHasChanged = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return executionOrderHasChanged;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Updates the execution orders for all pairs found by FindExecutionOrderAttributes()
|
||||
/// </summary>
|
||||
protected static void UpdateExecutionOrders()
|
||||
{
|
||||
foreach (KeyValuePair<MonoScript, MMExecutionOrderAttribute> monoScript in _monoScripts)
|
||||
{
|
||||
if (monoScript.Key != null)
|
||||
{
|
||||
if (MonoImporter.GetExecutionOrder(monoScript.Key) != monoScript.Value.ExecutionOrder)
|
||||
{
|
||||
MonoImporter.SetExecutionOrder(monoScript.Key, monoScript.Value.ExecutionOrder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b9d2829e14d10b4ca64457e40710bf2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
public class MMHiddenAttribute : PropertyAttribute { }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 171bddfe1b8d24a049ab93c4b4d2323d
|
||||
timeCreated: 1456675987
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
|
||||
public class MMHiddenPropertiesAttribute : Attribute
|
||||
{
|
||||
public string[] PropertiesNames;
|
||||
|
||||
public MMHiddenPropertiesAttribute(params string[] propertiesNames)
|
||||
{
|
||||
PropertiesNames = propertiesNames;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e10dd6620d1eaec43a30fad8fa6249bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,34 @@
|
||||
using UnityEngine;
|
||||
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
public class MMInformationAttribute : PropertyAttribute
|
||||
{
|
||||
public enum InformationType { Error, Info, None, Warning }
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public string Message;
|
||||
public MessageType Type;
|
||||
public bool MessageAfterProperty;
|
||||
|
||||
public MMInformationAttribute(string message, InformationType type, bool messageAfterProperty)
|
||||
{
|
||||
this.Message = message;
|
||||
if (type==InformationType.Error) { this.Type = UnityEditor.MessageType.Error;}
|
||||
if (type==InformationType.Info) { this.Type = UnityEditor.MessageType.Info;}
|
||||
if (type==InformationType.Warning) { this.Type = UnityEditor.MessageType.Warning;}
|
||||
if (type==InformationType.None) { this.Type = UnityEditor.MessageType.None;}
|
||||
this.MessageAfterProperty = messageAfterProperty;
|
||||
}
|
||||
#else
|
||||
public MMInformationAttribute(string message, InformationType type, bool messageAfterProperty)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a083e52b3b6964a0d88af5b74900af5e
|
||||
timeCreated: 1459528299
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,56 @@
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using System.Reflection;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
[System.AttributeUsage(System.AttributeTargets.Field)]
|
||||
public class MMInspectorButtonAttribute : PropertyAttribute
|
||||
{
|
||||
public readonly string MethodName;
|
||||
|
||||
public MMInspectorButtonAttribute(string MethodName)
|
||||
{
|
||||
this.MethodName = MethodName;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomPropertyDrawer(typeof(MMInspectorButtonAttribute))]
|
||||
public class InspectorButtonPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
private MethodInfo _eventMethodInfo = null;
|
||||
|
||||
public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
|
||||
{
|
||||
MMInspectorButtonAttribute inspectorButtonAttribute = (MMInspectorButtonAttribute)attribute;
|
||||
|
||||
float buttonLength = position.width;
|
||||
Rect buttonRect = new Rect(position.x, position.y, buttonLength, position.height);
|
||||
GUI.skin.button.alignment = TextAnchor.MiddleLeft;
|
||||
|
||||
if (GUI.Button(buttonRect, inspectorButtonAttribute.MethodName))
|
||||
{
|
||||
System.Type eventOwnerType = prop.serializedObject.targetObject.GetType();
|
||||
string eventName = inspectorButtonAttribute.MethodName;
|
||||
|
||||
if (_eventMethodInfo == null)
|
||||
{
|
||||
_eventMethodInfo = eventOwnerType.GetMethod(eventName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
}
|
||||
|
||||
if (_eventMethodInfo != null)
|
||||
{
|
||||
_eventMethodInfo.Invoke(prop.serializedObject.targetObject, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning(string.Format("InspectorButton: Unable to find method {0} in {1}", eventName, eventOwnerType));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 325b5ef7494cead4fbd33a7e9c22c44d
|
||||
timeCreated: 1490625668
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,112 @@
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using System.Reflection;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
[System.AttributeUsage(System.AttributeTargets.Field)]
|
||||
public class MMInspectorButtonBarAttribute : PropertyAttribute
|
||||
{
|
||||
public string[] Labels { get; set; }
|
||||
public string[] Methods{ get; set; }
|
||||
public bool[] OnlyWhenPlaying{ get; set; }
|
||||
public string[] UssClass{ get; set; }
|
||||
|
||||
|
||||
public MMInspectorButtonBarAttribute(string[] labels, string[] methods, bool[] onlyWhenPlaying, string[] ussClass)
|
||||
{
|
||||
this.Labels = labels;
|
||||
this.Methods = methods;
|
||||
this.OnlyWhenPlaying = onlyWhenPlaying;
|
||||
this.UssClass = ussClass;
|
||||
}
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomPropertyDrawer(typeof(MMInspectorButtonBarAttribute))]
|
||||
public class MMInspectorButtonBarPropertyDrawer : PropertyDrawer
|
||||
{
|
||||
private MethodInfo[] _eventMethodInfos = null;
|
||||
|
||||
public override VisualElement CreatePropertyGUI(SerializedProperty property)
|
||||
{
|
||||
MMInspectorButtonBarAttribute inspectorButtonBarAttribute = (MMInspectorButtonBarAttribute)attribute;
|
||||
System.Type eventOwnerType = property.serializedObject.targetObject.GetType();
|
||||
|
||||
// add our root
|
||||
var root = new VisualElement();
|
||||
|
||||
// add toolbar
|
||||
Toolbar moveToControls = new Toolbar();
|
||||
moveToControls.AddToClassList("mm-toolbar");
|
||||
|
||||
if (_eventMethodInfos == null)
|
||||
{
|
||||
_eventMethodInfos = new MethodInfo[inspectorButtonBarAttribute.Methods.Length];
|
||||
}
|
||||
|
||||
// add each button
|
||||
for (var i = 0; i < inspectorButtonBarAttribute.Labels.Length; i++)
|
||||
{
|
||||
var newButton = new ToolbarButton();
|
||||
newButton.text = inspectorButtonBarAttribute.Labels[i];
|
||||
newButton.style.flexGrow = 1;
|
||||
|
||||
if (inspectorButtonBarAttribute.UssClass[i] != "")
|
||||
{
|
||||
newButton.AddToClassList(inspectorButtonBarAttribute.UssClass[i]);
|
||||
}
|
||||
|
||||
if (_eventMethodInfos[i] == null)
|
||||
{
|
||||
_eventMethodInfos[i] = eventOwnerType.GetMethod(inspectorButtonBarAttribute.Methods[i], BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
}
|
||||
if (_eventMethodInfos[i] != null)
|
||||
{
|
||||
var i1 = i;
|
||||
newButton.clicked += () => _eventMethodInfos[i1].Invoke(property.serializedObject.targetObject, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning(string.Format("InspectorButton: Unable to find method {0} in {1}", inspectorButtonBarAttribute.Methods[i], eventOwnerType));
|
||||
}
|
||||
|
||||
if (inspectorButtonBarAttribute.OnlyWhenPlaying[i] && !Application.isPlaying)
|
||||
{
|
||||
newButton.SetEnabled(false);
|
||||
}
|
||||
|
||||
moveToControls.Add(newButton);
|
||||
}
|
||||
root.Add(moveToControls);
|
||||
|
||||
return root;
|
||||
/*
|
||||
|
||||
if (GUI.Button(buttonRect, inspectorButtonBarAttribute.MethodName))
|
||||
{
|
||||
System.Type eventOwnerType = prop.serializedObject.targetObject.GetType();
|
||||
string eventName = inspectorButtonBarAttribute.MethodName;
|
||||
|
||||
if (_eventMethodInfo == null)
|
||||
{
|
||||
_eventMethodInfo = eventOwnerType.GetMethod(eventName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
|
||||
}
|
||||
|
||||
if (_eventMethodInfo != null)
|
||||
{
|
||||
_eventMethodInfo.Invoke(prop.serializedObject.targetObject, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning(string.Format("InspectorButton: Unable to find method {0} in {1}", eventName, eventOwnerType));
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba5bf5d06e4a7ef4a8002f4444c4dab6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
/// <summary>
|
||||
/// An attribute used to group inspector fields under common dropdowns
|
||||
/// Implementation inspired by Rodrigo Prinheiro's work, available at https://github.com/RodrigoPrinheiro/unityFoldoutAttribute
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Class | AttributeTargets.Struct, Inherited = true)]
|
||||
public class MMInspectorGroupAttribute : PropertyAttribute
|
||||
{
|
||||
public string GroupName;
|
||||
public bool GroupAllFieldsUntilNextGroupAttribute;
|
||||
public int GroupColorIndex;
|
||||
public bool ClosedByDefault;
|
||||
|
||||
public MMInspectorGroupAttribute(string groupName, bool groupAllFieldsUntilNextGroupAttribute = false, int groupColorIndex = 24, bool closedByDefault = false)
|
||||
{
|
||||
if (groupColorIndex > 139) { groupColorIndex = 139; }
|
||||
|
||||
this.GroupName = groupName;
|
||||
this.GroupAllFieldsUntilNextGroupAttribute = groupAllFieldsUntilNextGroupAttribute;
|
||||
this.GroupColorIndex = groupColorIndex;
|
||||
this.ClosedByDefault = closedByDefault;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 59a1dca0105634a4db09372297afadbf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Assets/Feel/MMTools/Core/MMAttributes/MMMonoBehaviour.cs
Normal file
11
Assets/Feel/MMTools/Core/MMAttributes/MMMonoBehaviour.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
public class MMMonoBehaviour : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 743d5178809b16b47a7cb50d29677882
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,6 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
public class MMNavMeshAreaMaskAttribute : PropertyAttribute { }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: feb8bb2f278c6b047ab36f275dcaa126
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,9 @@
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
public class MMReadOnlyAttribute : PropertyAttribute { }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f54d7ad2fa8f4411e8cceb8d27f6e1ae
|
||||
timeCreated: 1456675993
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,28 @@
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
public class MMReadOnlyWhenPlayingAttribute : PropertyAttribute { }
|
||||
|
||||
|
||||
#if UNITY_EDITOR
|
||||
[CustomPropertyDrawer(typeof(MMReadOnlyWhenPlayingAttribute))]
|
||||
public class ReadOnlyWhenPlayingAttributeDrawer : PropertyDrawer
|
||||
{
|
||||
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
|
||||
{
|
||||
GUI.enabled = !Application.isPlaying;
|
||||
EditorGUI.PropertyField(position, property, label, true);
|
||||
GUI.enabled = true;
|
||||
}
|
||||
|
||||
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
|
||||
{
|
||||
return EditorGUI.GetPropertyHeight(property, label, true);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e1e841ae422aba49bcc65672025dfa4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class MMRequiresConstantRepaintAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca6eb3d6d3c09444ca79e5047b01e58c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class MMRequiresConstantRepaintOnlyWhenPlayingAttribute : Attribute
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c690b0b68e66a04d83df51f41d80650
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
17
Assets/Feel/MMTools/Core/MMAttributes/MMVectorAttribute.cs
Normal file
17
Assets/Feel/MMTools/Core/MMAttributes/MMVectorAttribute.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using UnityEngine;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
|
||||
namespace MoreMountains.Tools
|
||||
{
|
||||
public class MMVectorAttribute : PropertyAttribute
|
||||
{
|
||||
public readonly string[] Labels;
|
||||
|
||||
public MMVectorAttribute(params string[] labels)
|
||||
{
|
||||
Labels = labels;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e0c0838d8791ea4e8b901003c8639a8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user