This commit is contained in:
CortexCore
2023-10-24 23:38:22 +08:00
parent 2c4710bc5d
commit bd40165ade
152 changed files with 3681 additions and 1531 deletions

View File

@@ -9,8 +9,6 @@ using System;
using UnityEditor;
using Editor = UnityEditor.Editor;
using UnityEditor.UIElements;
#else
using Editor=BITKit.Constant.EmetyClass;
#endif
namespace BITKit
{
@@ -18,13 +16,13 @@ namespace BITKit
{
}
#if UNITY_EDITOR
[CustomEditor(typeof(MonoBehaviour),true)]
public class MonoBehaviorInspector : BITInspector<MonoBehaviour>
{
}
#endif
public class BITEditorUtils
{
public const string InspectorPath = "Assets/BITKit/Unity/UX/BITInspector.uss";
@@ -52,7 +50,7 @@ namespace BITKit
}
public class BITInspector<T> : Editor
{
const string ussName = "BITInspector";
private const string ussName = "BITInspector";
public class VisualElementCreator
{
public static implicit operator VisualElement(VisualElementCreator self)
@@ -78,7 +76,16 @@ namespace BITKit
}
else
{
FillDefaultInspector();
try
{
FillDefaultInspector();
}
catch (Exception e)
{
Debug.LogException(e);
return base.CreateInspectorGUI();
}
return root;
}
}
@@ -120,12 +127,14 @@ namespace BITKit
}
protected void FillDefaultInspector()
{
root.root.Clear();
FillDefaultInspector(root, serializedObject, true);
}
protected static void FillDefaultInspector(VisualElement container, SerializedObject serializedObject, bool hideScript)
{
var property = serializedObject.GetIterator();
container.Clear();
var property = serializedObject.GetIterator();
if (!property.NextVisible(true)) return; // Expand first child.
do
{
@@ -133,8 +142,9 @@ namespace BITKit
{
continue;
}
var type = serializedObject.targetObject.GetType().GetField(property.name);
if ( type is not null && Attribute.IsDefined(type.FieldType, typeof(ReadOnlyAttribute)))
if (type is not null && Attribute.IsDefined(type.FieldType, typeof(ReadOnlyAttribute)))
{
container.Create<Label>().bindingPath = property.propertyPath;
}
@@ -148,6 +158,7 @@ namespace BITKit
{
field.SetEnabled(false);
}
container.Add(field);
}
// try
@@ -164,11 +175,7 @@ namespace BITKit
// {
// Debug.LogException(e);
// }
}
while (property.NextVisible(false));
} while (property.NextVisible(false));
foreach (var method in serializedObject.targetObject.GetType().GetMethods())
{