mirror of
https://github.com/maxartz15/UnitySerializedReferenceUI.git
synced 2024-11-22 15:45:35 +01:00
Button colors
- Use default Unity color for button - Make button red when un assigned
This commit is contained in:
parent
51aff60626
commit
b9472d59b4
@ -1,5 +1,4 @@
|
|||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
@ -7,39 +6,33 @@ using UnityEngine;
|
|||||||
|
|
||||||
public static class SerializeReferenceInspectorButton
|
public static class SerializeReferenceInspectorButton
|
||||||
{
|
{
|
||||||
public static readonly Color SerializedReferenceMenuBackgroundColor = new Color(0.1f, 0.55f, 0.9f, 1f);
|
|
||||||
|
|
||||||
/// 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)
|
||||||
property.DrawSelectionButtonForManagedReference(position, SerializedReferenceMenuBackgroundColor, filters);
|
|
||||||
|
|
||||||
/// Must be drawn before DefaultProperty in order to receive input
|
|
||||||
public static void DrawSelectionButtonForManagedReference(this SerializedProperty property,
|
|
||||||
Rect position, Color color, IEnumerable<Func<Type, bool>> filters = null)
|
|
||||||
{
|
{
|
||||||
|
Rect buttonPosition = position;
|
||||||
var backgroundColor = color;
|
|
||||||
|
|
||||||
var buttonPosition = position;
|
|
||||||
buttonPosition.x += EditorGUIUtility.labelWidth + 1 * EditorGUIUtility.standardVerticalSpacing;
|
buttonPosition.x += EditorGUIUtility.labelWidth + 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||||
buttonPosition.width = position.width - EditorGUIUtility.labelWidth - 1 * EditorGUIUtility.standardVerticalSpacing;
|
buttonPosition.width = position.width - EditorGUIUtility.labelWidth - 1 * EditorGUIUtility.standardVerticalSpacing;
|
||||||
buttonPosition.height = EditorGUIUtility.singleLineHeight;
|
buttonPosition.height = EditorGUIUtility.singleLineHeight;
|
||||||
|
|
||||||
var storedIndent = EditorGUI.indentLevel;
|
Color storedColor = GUI.backgroundColor;
|
||||||
|
int storedIndent = EditorGUI.indentLevel;
|
||||||
EditorGUI.indentLevel = 0;
|
EditorGUI.indentLevel = 0;
|
||||||
var storedColor = GUI.backgroundColor;
|
|
||||||
GUI.backgroundColor = backgroundColor;
|
|
||||||
|
|
||||||
|
(string AssemblyName, string ClassName) = ManagedReferenceUtility.GetSplitNamesFromTypename(property.managedReferenceFullTypename);
|
||||||
|
|
||||||
|
bool isNull = string.IsNullOrEmpty(ClassName);
|
||||||
|
GUI.backgroundColor = isNull ? Color.red : storedColor;
|
||||||
|
|
||||||
|
string className = isNull ? "Null (Assign)" : ClassName;
|
||||||
|
string assemblyName = AssemblyName;
|
||||||
|
|
||||||
var names = ManagedReferenceUtility.GetSplitNamesFromTypename(property.managedReferenceFullTypename);
|
|
||||||
var className = string.IsNullOrEmpty(names.ClassName) ? "Null (Assign)" : names.ClassName;
|
|
||||||
var assemblyName = names.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);
|
||||||
|
}
|
||||||
|
|
||||||
GUI.backgroundColor = storedColor;
|
GUI.backgroundColor = storedColor;
|
||||||
EditorGUI.indentLevel = storedIndent;
|
EditorGUI.indentLevel = storedIndent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue
Block a user