using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UIElements; using System.Reflection; using System; #if UNITY_EDITOR using MackySoft.SerializeReferenceExtensions.Editor; using UnityEditor; using Editor = UnityEditor.Editor; using UnityEditor.UIElements; #endif namespace BITKit { public class BITAttribute : System.Attribute { } #if UNITY_EDITOR [CanEditMultipleObjects] [CustomEditor(typeof(MonoBehaviour),true)] public class MonoBehaviorInspector : BITInspector { } [CanEditMultipleObjects] [CustomEditor(typeof(ScriptableObject),true)] public class ScriptableObjectInspector : BITInspector { } [CustomPropertyDrawer(typeof(ReadOnlyAttribute),true)] public class ReadOnlyDrawer : PropertyDrawer { public override VisualElement CreatePropertyGUI(SerializedProperty property) { var field = new PropertyField(property) { name = "PropertyField:" + property.propertyPath }; Debug.Log("ReadOnlyAttribute"); field.pickingMode = PickingMode.Ignore; field.SetEnabled(false); field.style.opacity = 1; var x = field.Q("unity-text-input"); var clearColor = new Color(0, 0, 0, 0); x.style.backgroundColor = clearColor; x.style.borderTopColor = clearColor; x.style.borderBottomColor = clearColor; x.style.borderLeftColor = clearColor; x.style.borderRightColor = clearColor; foreach (var visualElement in field.Children()) { visualElement.pickingMode = PickingMode.Ignore; } field.Bind(property.serializedObject); return field; } } #endif public class BITEditorUtils { public const string InspectorPath = "Assets/BITKit/Unity/UX/BITInspector.uss"; public const string StylePath = "Assets/BITKit/Unity/UX/Common/Common.uss"; #if UNITY_EDITOR public static StyleSheet Style => AssetDatabase.LoadAssetAtPath(StylePath); public static StyleSheet InspectorStyleSheet => AssetDatabase.LoadAssetAtPath(InspectorPath); #endif } #if UNITY_EDITOR public static class BITInspectorExtensions { public static T Get(this SerializedProperty self) { var obj = self.serializedObject.targetObject; var type = obj.GetType(); var field = type.GetField(self.propertyPath, ReflectionHelper.Flags); if (field is null) { throw new NullReferenceException($"Field {self.propertyPath} is null"); } return (T)field.GetValue(obj); } public static void FillDefaultInspector(VisualElement container, SerializedObject serializedObject, bool hideScript) { container.Clear(); if (serializedObject.targetObject is null) { var label = container.Create