This commit is contained in:
CortexCore
2024-04-16 04:06:46 +08:00
parent 37e7fcea51
commit c798b224be
67 changed files with 1305 additions and 425 deletions

View File

@@ -41,7 +41,7 @@ namespace BITKit
{
var obj = self.serializedObject.targetObject;
var type = obj.GetType();
var field = type.GetField(self.propertyPath, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
var field = type.GetField(self.propertyPath, ReflectionHelper.Flags);
if (field is null)
{
throw new NullReferenceException($"Field {self.propertyPath} is null");
@@ -51,7 +51,6 @@ namespace BITKit
public static void FillDefaultInspector(VisualElement container, SerializedObject serializedObject, bool hideScript)
{
container.Clear();
if (serializedObject.targetObject is null)
{
var label = container.Create<Label>();
@@ -70,7 +69,7 @@ namespace BITKit
var type = serializedObject.targetObject.GetType();
var fieldInfo = serializedObject.targetObject.GetType().GetField(property.propertyPath, ReflectionHelper.Flags);
if (fieldInfo is not null && Attribute.IsDefined(fieldInfo, typeof(ReadOnlyAttribute),true))
if (fieldInfo is not null && type == typeof(string) && Attribute.IsDefined(fieldInfo, typeof(ReadOnlyAttribute),true))
{
var attribute = fieldInfo.GetCustomAttribute<ReadOnlyAttribute>();
var _container = container.Create<VisualElement>();
@@ -92,16 +91,60 @@ namespace BITKit
{
//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.SetEnabled(false);
field.style.opacity = 1;
}
if (property.propertyPath == "m_Script" && serializedObject.targetObject != null)
{
field.SetEnabled(false);
}
// if (fieldInfo?.FieldType == typeof(Texture2D) && fieldInfo.GetValue(serializedObject) is Texture2D texture && texture)
// {
// _container = container.Create<VisualElement>();
//
// var foldout = _container.Create<Foldout>();
// foldout.text = property.displayName;
//
// var icon = foldout.Create<VisualElement>();
// var slider = foldout.Create<Slider>();
//
// var width = 128;
// var m = texture.height /width;
//
// icon.style.width = width;
// icon.style.height = width*m;
// icon.style.backgroundImage = texture;
//
// field.style.flexGrow = 1;
//
// _container.style.backgroundColor =new StyleColor(new Color32(31,31,31,255)) ;
// _container.style.borderBottomLeftRadius = 5;
// _container.style.borderBottomRightRadius = 5;
// _container.style.borderTopLeftRadius = 5;
// _container.style.borderTopRightRadius = 5;
//
// slider.label = "Scale";
// slider.lowValue = 1;
// slider.highValue = 2;
// slider.RegisterValueChangedCallback(x =>
// {
// icon.style.width = width * x.newValue;
// icon.style.height = width*m * x.newValue;
// });
// }
container.Add(field);
_container.Add(field);
}
// try
// {
@@ -123,7 +166,10 @@ namespace BITKit
{
if (method.GetCustomAttribute<BITAttribute>() is null) continue;
if (method.GetParameters().Length is not 0) continue;
var button = new Button(() => method.Invoke(serializedObject.targetObject, null))
var button = new Button(() =>
{
method.Invoke(serializedObject.targetObject, null);
})
{
text = method.Name
};