editor namespace

This commit is contained in:
max 2022-12-28 14:06:42 +01:00
parent 0d04c50612
commit acec8003c1
6 changed files with 248 additions and 230 deletions

View File

@ -4,9 +4,11 @@ using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
[CustomPropertyDrawer(typeof(SerializeReferenceButtonAttribute))] namespace Textus.SerializeReferenceUI.Editor
public class SerializeReferenceButtonAttributeDrawer : PropertyDrawer
{ {
[CustomPropertyDrawer(typeof(SerializeReferenceButtonAttribute))]
public class SerializeReferenceButtonAttributeDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{ {
return EditorGUI.GetPropertyHeight(property, true); return EditorGUI.GetPropertyHeight(property, true);
@ -26,5 +28,6 @@ public class SerializeReferenceButtonAttributeDrawer : PropertyDrawer
EditorGUI.EndProperty(); EditorGUI.EndProperty();
} }
}
} }
#endif #endif

View File

@ -4,9 +4,11 @@ using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
[CustomPropertyDrawer(typeof(SerializeReferenceMenuAttribute))] namespace Textus.SerializeReferenceUI.Editor
public class SerializeReferenceMenuAttributeDrawer : PropertyDrawer
{ {
[CustomPropertyDrawer(typeof(SerializeReferenceMenuAttribute))]
public class SerializeReferenceMenuAttributeDrawer : PropertyDrawer
{
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{ {
return EditorGUI.GetPropertyHeight(property, true); return EditorGUI.GetPropertyHeight(property, true);
@ -22,5 +24,6 @@ public class SerializeReferenceMenuAttributeDrawer : PropertyDrawer
EditorGUI.PropertyField(position, property, true); EditorGUI.PropertyField(position, property, true);
EditorGUI.EndProperty(); EditorGUI.EndProperty();
} }
}
} }
#endif #endif

View File

@ -6,8 +6,10 @@ using UnityEditor;
using UnityEngine; using UnityEngine;
using Object = UnityEngine.Object; using Object = UnityEngine.Object;
public static class ManagedReferenceUtility namespace Textus.SerializeReferenceUI.Editor
{ {
public static class ManagedReferenceUtility
{
/// Creates instance of passed type and assigns it to managed reference /// Creates instance of passed type and assigns it to managed reference
public static object AssignNewInstanceOfTypeToManagedReference(this SerializedProperty serializedProperty, Type type) public static object AssignNewInstanceOfTypeToManagedReference(this SerializedProperty serializedProperty, Type type)
{ {
@ -103,7 +105,7 @@ public static class ManagedReferenceUtility
{ {
if (string.IsNullOrEmpty(typename)) if (string.IsNullOrEmpty(typename))
{ {
return ("",""); return ("", "");
} }
string[] typeSplitString = typename.Split(char.Parse(" ")); string[] typeSplitString = typename.Split(char.Parse(" "));
@ -112,5 +114,6 @@ public static class ManagedReferenceUtility
return (typeAssemblyName, typeClassName); return (typeAssemblyName, typeClassName);
} }
}
} }
#endif #endif

View File

@ -5,8 +5,10 @@ using System.Linq;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
public static class SerializeReferenceGenericSelectionMenu namespace Textus.SerializeReferenceUI.Editor
{ {
public static class SerializeReferenceGenericSelectionMenu
{
/// Purpose. /// Purpose.
/// This is generic selection menu (will appear at position). /// This is generic selection menu (will appear at position).
/// Filtering. /// Filtering.
@ -14,7 +16,7 @@ public static class SerializeReferenceGenericSelectionMenu
/// As well ass type or interface restrictions. /// As well ass type or interface restrictions.
/// As well as any custom restriction that is based on input type. /// As well as any custom restriction that is based on input type.
/// And it will be performed on each Appropriate type found by TypeCache. /// And it will be performed on each Appropriate type found by TypeCache.
public static void ShowContextMenuForManagedReference(this SerializedProperty property, Rect position, IEnumerable<Func<Type,bool>> filters = null) public static void ShowContextMenuForManagedReference(this SerializedProperty property, Rect position, IEnumerable<Func<Type, bool>> filters = null)
{ {
GenericMenu context = new GenericMenu(); GenericMenu context = new GenericMenu();
FillContextMenu(filters, context, property); FillContextMenu(filters, context, property);
@ -59,9 +61,9 @@ public static class SerializeReferenceGenericSelectionMenu
genericMenuContext.AddItem(new GUIContent(entryName), false, AssignNewInstanceCommand, new GenericMenuParameterForAssignInstanceCommand(type, property)); genericMenuContext.AddItem(new GUIContent(entryName), false, AssignNewInstanceCommand, new GenericMenuParameterForAssignInstanceCommand(type, property));
} }
private static void AssignNewInstanceCommand(object objectGenericMenuParameter ) private static void AssignNewInstanceCommand(object objectGenericMenuParameter)
{ {
GenericMenuParameterForAssignInstanceCommand parameter = (GenericMenuParameterForAssignInstanceCommand) objectGenericMenuParameter; GenericMenuParameterForAssignInstanceCommand parameter = (GenericMenuParameterForAssignInstanceCommand)objectGenericMenuParameter;
Type type = parameter.Type; Type type = parameter.Type;
SerializedProperty property = parameter.Property; SerializedProperty property = parameter.Property;
property.AssignNewInstanceOfTypeToManagedReference(type); property.AssignNewInstanceOfTypeToManagedReference(type);
@ -78,5 +80,6 @@ public static class SerializeReferenceGenericSelectionMenu
public readonly SerializedProperty Property; public readonly SerializedProperty Property;
public readonly Type Type; public readonly Type Type;
} }
}
} }
#endif #endif

View File

@ -4,8 +4,10 @@ using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
public static class SerializeReferenceInspectorButton namespace Textus.SerializeReferenceUI.Editor
{ {
public static class SerializeReferenceInspectorButton
{
/// Must be drawn before DefaultProperty in order to receive input /// Must be drawn before DefaultProperty in order to receive input
public static void DrawSelectionButtonForManagedReference(this SerializedProperty property, Rect position, IEnumerable<Func<Type, bool>> filters = null) public static void DrawSelectionButtonForManagedReference(this SerializedProperty property, Rect position, IEnumerable<Func<Type, bool>> filters = null)
{ {
@ -26,7 +28,7 @@ public static class SerializeReferenceInspectorButton
string className = isNull ? "Null (Assign)" : ClassName; string className = isNull ? "Null (Assign)" : ClassName;
string assemblyName = AssemblyName; string assemblyName = AssemblyName;
if (GUI.Button(buttonPosition, new GUIContent(className, className + " ( "+ assemblyName +" )"))) if (GUI.Button(buttonPosition, new GUIContent(className, className + " ( " + assemblyName + " )")))
{ {
property.ShowContextMenuForManagedReference(buttonPosition, filters); property.ShowContextMenuForManagedReference(buttonPosition, filters);
} }
@ -34,5 +36,6 @@ public static class SerializeReferenceInspectorButton
GUI.backgroundColor = storedColor; GUI.backgroundColor = storedColor;
EditorGUI.indentLevel = storedIndent; EditorGUI.indentLevel = storedIndent;
} }
}
} }
#endif #endif

View File

@ -4,8 +4,10 @@ using System.Collections.Generic;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
public static class SerializeReferenceInspectorMiddleMouseMenu namespace Textus.SerializeReferenceUI.Editor
{ {
public static class SerializeReferenceInspectorMiddleMouseMenu
{
public static void ShowContextMenuForManagedReferenceOnMouseMiddleButton(this SerializedProperty property, Rect position, IEnumerable<Func<Type, bool>> filters = null) public static void ShowContextMenuForManagedReferenceOnMouseMiddleButton(this SerializedProperty property, Rect position, IEnumerable<Func<Type, bool>> filters = null)
{ {
Event e = Event.current; Event e = Event.current;
@ -16,5 +18,6 @@ public static class SerializeReferenceInspectorMiddleMouseMenu
property.ShowContextMenuForManagedReference(filters); property.ShowContextMenuForManagedReference(filters);
} }
}
} }
#endif #endif