This commit is contained in:
CortexCore
2024-05-31 01:23:15 +08:00
parent c798b224be
commit 299082fe27
164 changed files with 3604 additions and 2018 deletions

View File

@@ -23,6 +23,34 @@ namespace BITKit
{
}
[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
{
@@ -69,38 +97,53 @@ namespace BITKit
var type = serializedObject.targetObject.GetType();
var fieldInfo = serializedObject.targetObject.GetType().GetField(property.propertyPath, ReflectionHelper.Flags);
if (fieldInfo is not null && type == typeof(string) && Attribute.IsDefined(fieldInfo, typeof(ReadOnlyAttribute),true))
{
var attribute = fieldInfo.GetCustomAttribute<ReadOnlyAttribute>();
var _container = container.Create<VisualElement>();
_container.style.flexDirection = FlexDirection.Row;
if (attribute.HideLabel is false)
{
_container.Create<Label>().text = $"{property.displayName}:";
_container.Create<VisualElement>().style.flexGrow = 1;
}
_container.Create<Label>().bindingPath = property.propertyPath;
}
else if (PropertyDrawerCache.TryGetPropertyDrawer(type, out var drawer))
{
var ve = drawer.CreatePropertyGUI(property);
container.Add(ve);
}
else
// if (fieldInfo is not null && type == typeof(string) && Attribute.IsDefined(fieldInfo, typeof(ReadOnlyAttribute),true))
// {
// var attribute = fieldInfo.GetCustomAttribute<ReadOnlyAttribute>();
// var _container = container.Create<VisualElement>();
// _container.style.flexDirection = FlexDirection.Row;
//
// if (attribute.HideLabel is false)
// {
// _container.Create<Label>().text = $"{property.displayName}:";
// _container.Create<VisualElement>().style.flexGrow = 1;
// }
// _container.Create<Label>().bindingPath = property.propertyPath;
// }
// else
// if (PropertyDrawerCache.TryGetPropertyDrawer(type, out var drawer))
// {
// var ve = drawer.CreatePropertyGUI(property);
// container.Add(ve);
// }
// else
{
//var label = container.Create<Label>();
//label.text =$"propertyPath:{property.propertyPath} fieldInfo:{fieldInfo} type:{type} fieldInfo:{fieldInfo}";
var _container = container;
var field = new PropertyField(property)
{
name = "PropertyField:" + property.propertyPath
};
if (fieldInfo is not null && Attribute.IsDefined(fieldInfo, typeof(ReadOnlyAttribute), true))
{
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);
if (x is not null)
{
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;
}
}
}
@@ -144,7 +187,7 @@ namespace BITKit
// });
// }
_container.Add(field);
container.Add(field);
}
// try
// {
@@ -215,7 +258,6 @@ namespace BITKit
Debug.LogException(e);
return base.CreateInspectorGUI();
}
return root;
}
}