[TASK] Content fixes
This commit is contained in:
20
Assets/EasyButtons/Editor/ButtonEditor.cs
Normal file
20
Assets/EasyButtons/Editor/ButtonEditor.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace EasyButtons
|
||||
{
|
||||
/// <summary>
|
||||
/// Custom inspector for Object including derived classes.
|
||||
/// </summary>
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(UnityEngine.Object), true)]
|
||||
public class ObjectEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
this.DrawEasyButtons();
|
||||
|
||||
// Draw the rest of the inspector as usual
|
||||
DrawDefaultInspector();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/EasyButtons/Editor/ButtonEditor.cs.meta
Normal file
11
Assets/EasyButtons/Editor/ButtonEditor.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7a3384be8a368e4c8e870e5feedb31d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace EasyButtons
|
||||
{
|
||||
[CustomEditor(typeof(CustomEditorButtonsExample))]
|
||||
public class CustomEditorButtonsExampleEditor : Editor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
this.DrawEasyButtons();
|
||||
base.OnInspectorGUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f42477c48fa930844bbbf0ba8cf55828
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
49
Assets/EasyButtons/Editor/EasyButtonsEditorExtensions.cs
Normal file
49
Assets/EasyButtons/Editor/EasyButtonsEditorExtensions.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EasyButtons
|
||||
{
|
||||
public static class EasyButtonsEditorExtensions
|
||||
{
|
||||
public static void DrawEasyButtons(this Editor editor)
|
||||
{
|
||||
// Loop through all methods with no parameters
|
||||
var methods = editor.target.GetType()
|
||||
.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
|
||||
.Where(m => m.GetParameters().Length == 0);
|
||||
foreach (var method in methods)
|
||||
{
|
||||
// Get the ButtonAttribute on the method (if any)
|
||||
var ba = (ButtonAttribute)Attribute.GetCustomAttribute(method, typeof(ButtonAttribute));
|
||||
|
||||
if (ba != null)
|
||||
{
|
||||
// Determine whether the button should be enabled based on its mode
|
||||
var wasEnabled = GUI.enabled;
|
||||
GUI.enabled = ba.Mode == ButtonMode.AlwaysEnabled
|
||||
|| (EditorApplication.isPlaying ? ba.Mode == ButtonMode.EnabledInPlayMode : ba.Mode == ButtonMode.DisabledInPlayMode);
|
||||
|
||||
|
||||
if (((int)ba.Spacing & (int)ButtonSpacing.Before) != 0) GUILayout.Space(10);
|
||||
|
||||
// Draw a button which invokes the method
|
||||
var buttonName = String.IsNullOrEmpty(ba.Name) ? ObjectNames.NicifyVariableName(method.Name) : ba.Name;
|
||||
if (GUILayout.Button(buttonName))
|
||||
{
|
||||
foreach (var t in editor.targets)
|
||||
{
|
||||
method.Invoke(t, null);
|
||||
}
|
||||
}
|
||||
|
||||
if (((int)ba.Spacing & (int)ButtonSpacing.After) != 0) GUILayout.Space(10);
|
||||
|
||||
GUI.enabled = wasEnabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f80fb24d5fa6b441bd6c9d7b25f04cb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user