split runtime and editor

This commit is contained in:
max
2022-12-28 13:55:36 +01:00
parent b9472d59b4
commit a0fa2c9b36
36 changed files with 43 additions and 7 deletions

View File

@ -0,0 +1,38 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public static class SerializeReferenceInspectorButton
{
/// 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)
{
Rect buttonPosition = position;
buttonPosition.x += EditorGUIUtility.labelWidth + 1 * EditorGUIUtility.standardVerticalSpacing;
buttonPosition.width = position.width - EditorGUIUtility.labelWidth - 1 * EditorGUIUtility.standardVerticalSpacing;
buttonPosition.height = EditorGUIUtility.singleLineHeight;
Color storedColor = GUI.backgroundColor;
int storedIndent = EditorGUI.indentLevel;
EditorGUI.indentLevel = 0;
(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;
if (GUI.Button(buttonPosition, new GUIContent(className, className + " ( "+ assemblyName +" )")))
{
property.ShowContextMenuForManagedReference(buttonPosition, filters);
}
GUI.backgroundColor = storedColor;
EditorGUI.indentLevel = storedIndent;
}
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 50b013bc3b4409b438f8781dee4dbbf1
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,21 @@
#if UNITY_EDITOR
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
public static class SerializeReferenceInspectorMiddleMouseMenu
{
public static void ShowContextMenuForManagedReferenceOnMouseMiddleButton(this SerializedProperty property,
Rect position, IEnumerable<Func<Type, bool>> filters = null)
{
var e = Event.current;
if (e.type != EventType.MouseDown || !position.Contains(e.mousePosition) || e.button != 2)
return;
property.ShowContextMenuForManagedReference(filters);
}
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ba51bcbc90077924abfcf504152b4a51
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: