0.2.0: Moved into inspector drawer from module.toolbox to module.inspector
This commit is contained in:
parent
5671c2c754
commit
ffec2abdf4
227 changed files with 5306 additions and 29 deletions
33
Editor/Drawers/DrawerEnumFlag.cs
Normal file
33
Editor/Drawers/DrawerEnumFlag.cs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
using System;
|
||||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(EnumFlag))]
|
||||
internal sealed class DrawerEnumFlag : DrawerPropertyDrawer
|
||||
{
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.Enum)
|
||||
return false;
|
||||
|
||||
Type type = property.GetValueType();
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
var e = (Enum)Enum.ToObject(type, property.intValue);
|
||||
e = EditorGUI.EnumFlagsField(position, label, e);
|
||||
property.intValue = Convert.ToInt32(e);
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports enum";
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerEnumFlag.cs.meta
Normal file
11
Editor/Drawers/DrawerEnumFlag.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 87df0640e8498c44fb2dde2702ef30fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
50
Editor/Drawers/DrawerFilePath.cs
Normal file
50
Editor/Drawers/DrawerFilePath.cs
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(FilePath))]
|
||||
internal sealed class DrawerFilePath : DrawerPropertyDrawer
|
||||
{
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.String)
|
||||
return false;
|
||||
|
||||
var att = (FilePath)attribute;
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
const float WIDTH = 80;
|
||||
|
||||
var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height);
|
||||
var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height);
|
||||
|
||||
EditorGUI.PropertyField(rect0, property, label);
|
||||
|
||||
if (GUI.Button(rect1, "Find"))
|
||||
{
|
||||
string path = EditorUtility.OpenFilePanel("File", "Assets/", att.extension);
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
if (!att.useAbsolute && path.StartsWith(Application.dataPath))
|
||||
path = path.Remove(0, Application.dataPath.Length - 6);
|
||||
|
||||
property.stringValue = path;
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports strings";
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerFilePath.cs.meta
Normal file
11
Editor/Drawers/DrawerFilePath.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bc4ff235b2ee1fa409b5d2e2de824159
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
49
Editor/Drawers/DrawerFolderPath.cs
Normal file
49
Editor/Drawers/DrawerFolderPath.cs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(FolderPath))]
|
||||
internal sealed class DrawerFolderPath : DrawerPropertyDrawer
|
||||
{
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.String)
|
||||
return false;
|
||||
|
||||
var att = (FolderPath)attribute;
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
const float WIDTH = 80;
|
||||
|
||||
var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height);
|
||||
var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height);
|
||||
|
||||
EditorGUI.PropertyField(rect0, property, label);
|
||||
|
||||
if (GUI.Button(rect1, "Find"))
|
||||
{
|
||||
string path = EditorUtility.OpenFolderPanel("Folder", "Assets/", string.Empty);
|
||||
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
if (!att.useAbsolute && path.StartsWith(Application.dataPath))
|
||||
path = path.Remove(0, Application.dataPath.Length - 6);
|
||||
|
||||
property.stringValue = path;
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports strings";
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerFolderPath.cs.meta
Normal file
11
Editor/Drawers/DrawerFolderPath.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d7135fc5f0bd8a54cb9378694247551d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
64
Editor/Drawers/DrawerIntToEnum.cs
Normal file
64
Editor/Drawers/DrawerIntToEnum.cs
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
using System;
|
||||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(IntToEnum))]
|
||||
internal sealed class DrawerIntToEnum : DrawerPropertyDrawer
|
||||
{
|
||||
private GUIContent[] names;
|
||||
private int[] values;
|
||||
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.Integer)
|
||||
return false;
|
||||
|
||||
var att = (IntToEnum)attribute;
|
||||
FetchLayerNames(att);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
int index = Array.IndexOf(values, property.intValue);
|
||||
int newIndex = EditorGUI.Popup(position, label, index, names);
|
||||
|
||||
if (newIndex != -1 && index != newIndex)
|
||||
property.intValue = values[newIndex];
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
bool changed = EditorGUI.EndChangeCheck();
|
||||
|
||||
if (changed)
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports integers";
|
||||
}
|
||||
|
||||
private void FetchLayerNames(IntToEnum attribute)
|
||||
{
|
||||
if (names != null)
|
||||
return;
|
||||
|
||||
Type type = attribute.GetValidType();
|
||||
string[] arrNames = Enum.GetNames(type);
|
||||
Array arrValues = Enum.GetValues(type);
|
||||
|
||||
names = new GUIContent[arrNames.Length];
|
||||
values = new int[arrValues.Length];
|
||||
|
||||
for (var i = 0; i < names.Length; i++)
|
||||
{
|
||||
names[i] = new GUIContent(arrNames[i]);
|
||||
values[i] = Convert.ToInt32(arrValues.GetValue(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerIntToEnum.cs.meta
Normal file
11
Editor/Drawers/DrawerIntToEnum.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: b3b20e9cb8fa0894f9a41a0fff58cb8b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
68
Editor/Drawers/DrawerIntToLayer.cs
Normal file
68
Editor/Drawers/DrawerIntToLayer.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(IntToLayer))]
|
||||
internal sealed class DrawerIntToLayer : DrawerPropertyDrawer
|
||||
{
|
||||
private static GUIContent[] NAMES;
|
||||
private static int[] INDICES;
|
||||
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.Integer)
|
||||
return false;
|
||||
|
||||
FetchLayerNames();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
int index = Array.IndexOf(INDICES, property.intValue);
|
||||
int newIndex = EditorGUI.Popup(position, label, index, NAMES);
|
||||
|
||||
if (newIndex != -1 && index != newIndex)
|
||||
property.intValue = INDICES[newIndex];
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
bool changed = EditorGUI.EndChangeCheck();
|
||||
|
||||
if (changed)
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports integers";
|
||||
}
|
||||
|
||||
private static void FetchLayerNames()
|
||||
{
|
||||
if (NAMES != null)
|
||||
return;
|
||||
|
||||
var listNames = new List<GUIContent>(32);
|
||||
var listIndices = new List<int>(32);
|
||||
|
||||
for (var i = 0; i < 32; i++)
|
||||
{
|
||||
string name = LayerMask.LayerToName(i);
|
||||
|
||||
if (string.IsNullOrEmpty(name))
|
||||
continue;
|
||||
|
||||
listNames.Add(new GUIContent(name));
|
||||
listIndices.Add(i);
|
||||
}
|
||||
|
||||
NAMES = listNames.ToArray();
|
||||
INDICES = listIndices.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerIntToLayer.cs.meta
Normal file
11
Editor/Drawers/DrawerIntToLayer.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: d256c1ba203028245a0d8bffc2f1558b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
25
Editor/Drawers/DrawerMethodButton.cs
Normal file
25
Editor/Drawers/DrawerMethodButton.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomMethodDrawer(typeof(MethodButton))]
|
||||
internal sealed class DrawerMethodButton : DrawerMethodDrawer
|
||||
{
|
||||
public override bool Draw(Rect position, DrawerMethodAttribute attribute, Object target, MethodInfo methodInfo)
|
||||
{
|
||||
var att = (MethodButton)attribute;
|
||||
string name = string.IsNullOrEmpty(att.name) ? methodInfo.Name : att.name;
|
||||
|
||||
if (GUI.Button(position, name))
|
||||
methodInfo.Invoke(methodInfo.IsStatic ? null : target, null);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage()
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerMethodButton.cs.meta
Normal file
11
Editor/Drawers/DrawerMethodButton.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: ed6fa023ff3f3434aadacc9aa3594459
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
42
Editor/Drawers/DrawerNaming.cs
Normal file
42
Editor/Drawers/DrawerNaming.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Naming))]
|
||||
internal sealed class DrawerNaming : DrawerPropertyDrawer
|
||||
{
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.String)
|
||||
return false;
|
||||
|
||||
var att = (Naming)attribute;
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
const float WIDTH = 80;
|
||||
|
||||
var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height);
|
||||
var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height);
|
||||
|
||||
EditorGUI.PropertyField(rect0, property);
|
||||
|
||||
if (GUI.Button(rect1, "Go"))
|
||||
{
|
||||
string str = EditorNamingUtility.ConvertTo(att.type, property.stringValue);
|
||||
property.stringValue = str;
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports strings";
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerNaming.cs.meta
Normal file
11
Editor/Drawers/DrawerNaming.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8cecc94b8bbefe64d824ba528b4e99a1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
42
Editor/Drawers/DrawerPercentage.cs
Normal file
42
Editor/Drawers/DrawerPercentage.cs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Percentage))]
|
||||
internal sealed class DrawerPercentage : DrawerPropertyDrawer
|
||||
{
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.Float)
|
||||
return false;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
float v = property.floatValue * 100.0f;
|
||||
string str = EditorGUI.TextField(position, label, v.ToString("0.0") + "%");
|
||||
str = str.Replace('%', ' ').Trim();
|
||||
|
||||
if (float.TryParse(str, out float temp))
|
||||
v = temp;
|
||||
|
||||
v *= 0.01f;
|
||||
property.floatValue = v;
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
bool changed = EditorGUI.EndChangeCheck();
|
||||
|
||||
if (changed)
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports float";
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerPercentage.cs.meta
Normal file
11
Editor/Drawers/DrawerPercentage.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5fccdfb1ef2fe074aa547033c1433c06
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
72
Editor/Drawers/DrawerPopupFromConst.cs
Normal file
72
Editor/Drawers/DrawerPopupFromConst.cs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(PopupFromConst))]
|
||||
internal sealed class DrawerPopupFromConst : DrawerPropertyDrawer
|
||||
{
|
||||
private GUIContent[] names;
|
||||
private string[] values;
|
||||
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.String)
|
||||
return false;
|
||||
|
||||
var att = (PopupFromConst)attribute;
|
||||
FetchConstArray(att);
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
int index = Array.IndexOf(values, property.stringValue);
|
||||
int newIndex = EditorGUI.Popup(position, label, index, names);
|
||||
|
||||
if (newIndex != -1 && index != newIndex)
|
||||
property.stringValue = values[newIndex];
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
bool changed = EditorGUI.EndChangeCheck();
|
||||
|
||||
if (changed)
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports integers";
|
||||
}
|
||||
|
||||
private void FetchConstArray(PopupFromConst attribute)
|
||||
{
|
||||
if (names != null)
|
||||
return;
|
||||
|
||||
FieldInfo[] fields = attribute.type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
|
||||
.Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType == typeof(string))
|
||||
.ToArray();
|
||||
|
||||
names = new GUIContent[fields.Length + 1];
|
||||
values = new string[fields.Length + 1];
|
||||
|
||||
names[0] = new GUIContent("-- Empty --");
|
||||
values[0] = string.Empty;
|
||||
|
||||
for (var i = 0; i < fields.Length; i++)
|
||||
{
|
||||
FieldInfo fi = fields[i];
|
||||
var value = (string)fi.GetValue(null);
|
||||
|
||||
names[i + 1] = new GUIContent(value);
|
||||
values[i + 1] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerPopupFromConst.cs.meta
Normal file
11
Editor/Drawers/DrawerPopupFromConst.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8a5a9feab54affb45bde1a4eda91d439
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
Editor/Drawers/DrawerQuaternionToEuler.cs
Normal file
36
Editor/Drawers/DrawerQuaternionToEuler.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(QuaternionToEuler))]
|
||||
internal sealed class DrawerQuaternionToEuler : DrawerPropertyDrawer
|
||||
{
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.Quaternion)
|
||||
return false;
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
Vector3 euler = property.quaternionValue.eulerAngles;
|
||||
Vector3 temp = EditorGUI.Vector3Field(position, label, euler);
|
||||
property.quaternionValue = Quaternion.Euler(temp);
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
bool changed = EditorGUI.EndChangeCheck();
|
||||
|
||||
if (changed)
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports quaternions";
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerQuaternionToEuler.cs.meta
Normal file
11
Editor/Drawers/DrawerQuaternionToEuler.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8954c2ee521537a49a53bf4de92575e7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
74
Editor/Drawers/DrawerSceneDropdown.cs
Normal file
74
Editor/Drawers/DrawerSceneDropdown.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(SceneDropdown))]
|
||||
internal sealed class DrawerSceneDropdown : DrawerPropertyDrawer
|
||||
{
|
||||
private static GUIContent[] NAMES;
|
||||
private static string[] PATHS;
|
||||
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.String)
|
||||
return false;
|
||||
|
||||
FetchScenes();
|
||||
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
int index = Array.IndexOf(PATHS, property.stringValue);
|
||||
int newIndex = EditorGUI.Popup(position, label, index, NAMES);
|
||||
|
||||
if (newIndex != -1 && index != newIndex)
|
||||
property.stringValue = PATHS[newIndex];
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
bool changed = EditorGUI.EndChangeCheck();
|
||||
|
||||
if (changed)
|
||||
property.serializedObject.ApplyModifiedProperties();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports strings";
|
||||
}
|
||||
|
||||
private static string ToSceneName(string path)
|
||||
{
|
||||
return !string.IsNullOrEmpty(path) ? path.Substring(7, path.Length - 13).Replace('/', '\\') : string.Empty;
|
||||
}
|
||||
|
||||
private static void FetchScenes()
|
||||
{
|
||||
if (NAMES != null)
|
||||
return;
|
||||
|
||||
EditorBuildSettingsScene[] scenes = EditorBuildSettings.scenes;
|
||||
var listNames = new List<GUIContent>(scenes.Length);
|
||||
var listPaths = new List<string>(scenes.Length);
|
||||
|
||||
for (var i = 0; i < scenes.Length; i++)
|
||||
{
|
||||
string path = scenes[i].path;
|
||||
|
||||
if (string.IsNullOrEmpty(path))
|
||||
continue;
|
||||
|
||||
listNames.Add(new GUIContent(ToSceneName(path)));
|
||||
listPaths.Add(path);
|
||||
}
|
||||
|
||||
NAMES = listNames.ToArray();
|
||||
PATHS = listPaths.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerSceneDropdown.cs.meta
Normal file
11
Editor/Drawers/DrawerSceneDropdown.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: dff7a960f4e593145a913cd65ed37da1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
134
Editor/Drawers/DrawerSlider.cs
Normal file
134
Editor/Drawers/DrawerSlider.cs
Normal file
|
|
@ -0,0 +1,134 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(Slider))]
|
||||
internal sealed class DrawerSlider : DrawerPropertyDrawer
|
||||
{
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
var min = result.GetValueModifier<MinValue>();
|
||||
var max = result.GetValueModifier<MaxValue>();
|
||||
|
||||
if (min == null || max == null)
|
||||
return false;
|
||||
|
||||
switch (property.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
case SerializedPropertyType.Float:
|
||||
DrawRange(position, property, label, min, max);
|
||||
break;
|
||||
case SerializedPropertyType.Vector2:
|
||||
case SerializedPropertyType.Vector2Int:
|
||||
DrawerMinMax(position, property, label, min, max);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
switch (property.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
case SerializedPropertyType.Float:
|
||||
case SerializedPropertyType.Vector2:
|
||||
case SerializedPropertyType.Vector2Int:
|
||||
return "Requires MinValue and MaxValue";
|
||||
}
|
||||
|
||||
return "Only supports integer, float, vector2 and vector2int";
|
||||
}
|
||||
|
||||
private void DrawRange(Rect position, SerializedProperty property, GUIContent label, MinValue minValue, MaxValue maxValue)
|
||||
{
|
||||
int indentLevel = EditorGUI.indentLevel;
|
||||
float indentSpacing = indentLevel * 15.0f;
|
||||
EditorGUI.indentLevel = 0;
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
float xMin = position.x + indentSpacing;
|
||||
var r0 = new Rect(xMin, position.y, EditorGUIUtility.labelWidth - indentSpacing + 2.0f, position.height);
|
||||
var r1 = new Rect(r0.xMax, r0.y, position.width - r0.width - indentSpacing, r0.height);
|
||||
|
||||
EditorGUI.LabelField(r0, label);
|
||||
|
||||
switch (property.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Integer:
|
||||
property.intValue = EditorGUI.IntSlider(r1, property.intValue, minValue.intValue, maxValue.intValue);
|
||||
break;
|
||||
case SerializedPropertyType.Float:
|
||||
property.floatValue = EditorGUI.Slider(r1, property.floatValue, minValue.floatValue, maxValue.floatValue);
|
||||
break;
|
||||
}
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
EditorGUI.indentLevel = indentLevel;
|
||||
}
|
||||
|
||||
private void DrawerMinMax(Rect position, SerializedProperty property, GUIContent label, MinValue min, MaxValue max)
|
||||
{
|
||||
const float FLOAT_WIDTH = 50.0f;
|
||||
const float FLOAT_SPACING = 8.0f;
|
||||
|
||||
int indentLevel = EditorGUI.indentLevel;
|
||||
float indentSpacing = indentLevel * 15.0f;
|
||||
EditorGUI.indentLevel = 0;
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
float xMin = position.x + indentSpacing;
|
||||
float width = position.width - indentSpacing;
|
||||
|
||||
var r0 = new Rect(xMin, position.y, EditorGUIUtility.labelWidth - indentSpacing + 2.0f, position.height);
|
||||
var r1 = new Rect(r0.xMax, r0.y, FLOAT_WIDTH, r0.height);
|
||||
var r2 = new Rect(r1.xMax + FLOAT_SPACING, r1.y, width - r0.width - (FLOAT_WIDTH + FLOAT_SPACING) * 2, r1.height);
|
||||
var r3 = new Rect(r2.xMax + FLOAT_SPACING, r2.y, FLOAT_WIDTH, r2.height);
|
||||
|
||||
EditorGUI.LabelField(r0, label);
|
||||
|
||||
switch (property.propertyType)
|
||||
{
|
||||
case SerializedPropertyType.Vector2:
|
||||
Vector2 v = property.vector2Value;
|
||||
float minValue = v.x;
|
||||
float maxValue = v.y;
|
||||
|
||||
minValue = EditorGUI.FloatField(r1, minValue);
|
||||
maxValue = EditorGUI.FloatField(r3, maxValue);
|
||||
EditorGUI.MinMaxSlider(r2, ref minValue, ref maxValue, min.floatValue, max.floatValue);
|
||||
|
||||
v.x = minValue;
|
||||
v.y = maxValue;
|
||||
|
||||
property.vector2Value = v;
|
||||
break;
|
||||
case SerializedPropertyType.Vector2Int:
|
||||
Vector2Int v2Int = property.vector2IntValue;
|
||||
float minIntValue = v2Int.x;
|
||||
float maxIntValue = v2Int.y;
|
||||
|
||||
minIntValue = EditorGUI.IntField(r1, Mathf.RoundToInt(minIntValue));
|
||||
maxIntValue = EditorGUI.IntField(r3, Mathf.RoundToInt(maxIntValue));
|
||||
EditorGUI.MinMaxSlider(r2, ref minIntValue, ref maxIntValue, min.floatValue, max.floatValue);
|
||||
|
||||
v2Int.x = Mathf.RoundToInt(minIntValue);
|
||||
v2Int.y = Mathf.RoundToInt(maxIntValue);
|
||||
|
||||
property.vector2IntValue = v2Int;
|
||||
break;
|
||||
}
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
EditorGUI.indentLevel = indentLevel;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerSlider.cs.meta
Normal file
11
Editor/Drawers/DrawerSlider.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 485f79e819f053d41b57536ca476ec1f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
38
Editor/Drawers/DrawerStringToField.cs
Normal file
38
Editor/Drawers/DrawerStringToField.cs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(StringToField))]
|
||||
internal sealed class DrawerStringToField : DrawerPropertyDrawer
|
||||
{
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.String)
|
||||
return false;
|
||||
|
||||
var att = (StringToField)attribute;
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
const float WIDTH = 80;
|
||||
|
||||
var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height);
|
||||
var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height);
|
||||
|
||||
EditorGUI.PropertyField(rect0, property, label);
|
||||
|
||||
if (GUI.Button(rect1, "Find"))
|
||||
EditorWindowStringToField.Open(att.type, property);
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports strings";
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerStringToField.cs.meta
Normal file
11
Editor/Drawers/DrawerStringToField.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fef0de5c591508a43ad30e46920f7e08
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
39
Editor/Drawers/DrawerStringToType.cs
Normal file
39
Editor/Drawers/DrawerStringToType.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(StringToType))]
|
||||
internal sealed class DrawerStringToType : DrawerPropertyDrawer
|
||||
{
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.String)
|
||||
return false;
|
||||
|
||||
var att = (StringToType)attribute;
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
const float WIDTH = 80;
|
||||
|
||||
var rect0 = new Rect(position.x, position.y, position.width - WIDTH, position.height);
|
||||
var rect1 = new Rect(rect0.xMax, position.y, WIDTH, position.height);
|
||||
|
||||
EditorGUI.PropertyField(rect0, property, label);
|
||||
|
||||
if (GUI.Button(rect1, "Find"))
|
||||
EditorWindowStringToType.Open(att.assignableFrom, property);
|
||||
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports strings";
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerStringToType.cs.meta
Normal file
11
Editor/Drawers/DrawerStringToType.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5bd5ab3cdc645674d84151133c5b5b78
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
36
Editor/Drawers/DrawerUrlGoTo.cs
Normal file
36
Editor/Drawers/DrawerUrlGoTo.cs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
using Module.Inspector.Editor.Utilities;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Module.Inspector.Editor
|
||||
{
|
||||
[CustomPropertyDrawer(typeof(UrlGoTo))]
|
||||
internal sealed class DrawerUrlGoTo : DrawerPropertyDrawer
|
||||
{
|
||||
public override bool Draw(Rect position, DrawerPropertyAttribute attribute, SerializedProperty property, GUIContent label, EditorPropertyUtility.Result result)
|
||||
{
|
||||
if (property.propertyType != SerializedPropertyType.String)
|
||||
return false;
|
||||
|
||||
EditorGUI.BeginProperty(position, label, property);
|
||||
{
|
||||
const float WIDTH = 80;
|
||||
|
||||
var r0 = new Rect(position.x, position.y, position.width - WIDTH, position.height);
|
||||
var r1 = new Rect(r0.xMax, r0.y, WIDTH, r0.height);
|
||||
|
||||
EditorGUI.PropertyField(r0, property, label);
|
||||
|
||||
if (GUI.Button(r1, "Go"))
|
||||
Application.OpenURL(property.stringValue);
|
||||
}
|
||||
EditorGUI.EndProperty();
|
||||
return true;
|
||||
}
|
||||
|
||||
public override string GetErrorMessage(SerializedProperty property)
|
||||
{
|
||||
return "Only supports strings";
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Editor/Drawers/DrawerUrlGoTo.cs.meta
Normal file
11
Editor/Drawers/DrawerUrlGoTo.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c78fde2b0fd08fa42ae7a1c8ee72a0e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue