1
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
@@ -4,17 +4,12 @@ using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using UnityEngine.Networking;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Text;
|
||||
using System.IO.Compression;
|
||||
using System.Data;
|
||||
using UnityEngine.UIElements;
|
||||
namespace BITKit
|
||||
{
|
||||
@@ -402,18 +397,6 @@ namespace BITKit
|
||||
text = text.Remove(0, text.Split('\n')[0].Length + 1);
|
||||
return text;
|
||||
}
|
||||
public static TaskAwaiter GetAwaiter(this AsyncOperation asyncOp)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<object>();
|
||||
asyncOp.completed += obj => { tcs.SetResult(null); };
|
||||
return ((Task)tcs.Task).GetAwaiter();
|
||||
}
|
||||
public static TaskAwaiter GetAwaiter(this System.Action action)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<object>();
|
||||
action += () => { tcs.SetResult(null); };
|
||||
return ((Task)tcs.Task).GetAwaiter();
|
||||
}
|
||||
public static float GetDifference(this IEnumerable<float> self)
|
||||
{
|
||||
return self.Max() - self.Min();
|
||||
@@ -665,13 +648,32 @@ namespace BITKit
|
||||
|
||||
public static Vector2 GetScreenPosition(this VisualElement self, Vector3 worldPosition)
|
||||
{
|
||||
var pos = RuntimePanelUtils
|
||||
.CameraTransformWorldToPanel(self.panel, worldPosition, Camera.main);
|
||||
try
|
||||
{
|
||||
var panel = self.panel;
|
||||
if (panel is null)
|
||||
{
|
||||
panel = self.parent.panel;
|
||||
}
|
||||
|
||||
pos.x -= self.layout.width / 2;
|
||||
pos.y -= self.layout.height / 2;
|
||||
if (panel is null)
|
||||
{
|
||||
panel = self.parent.parent.panel;
|
||||
}
|
||||
|
||||
return pos;
|
||||
var pos = RuntimePanelUtils
|
||||
.CameraTransformWorldToPanel(panel, worldPosition, Camera.main);
|
||||
|
||||
pos.x -= self.layout.width / 2;
|
||||
pos.y -= self.layout.height / 2;
|
||||
|
||||
return pos;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogException(e);
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
public static Vector2 GetPosition(this VisualElement self)
|
||||
|
@@ -22,6 +22,7 @@ namespace BITKit
|
||||
public Action<T> OnGet { get; set; } = x=>x.gameObject.SetActive(true);
|
||||
public Action<T> OnReturn { get; set; } = x=>x.gameObject.SetActive(false);
|
||||
public Action<T> OnDestroy { get; set; } = x=>Object.Destroy(x.gameObject);
|
||||
public Action<T> OnSpawn { get; set; }
|
||||
private ObjectPool<T> pool=> _pool ??=
|
||||
new ObjectPool<T>
|
||||
(Spawn, OnGet, OnReturn, OnDestroy,defaultCapacity:DefaultCapacity, maxSize:DefaultCapacity);
|
||||
@@ -71,10 +72,21 @@ namespace BITKit
|
||||
|
||||
public void Return(T element)
|
||||
{
|
||||
pool.Release(element);
|
||||
_list.Remove(element);
|
||||
try
|
||||
{
|
||||
pool.Release(element);
|
||||
}
|
||||
catch (InvalidOperationException){}
|
||||
|
||||
_list.TryRemove(element);
|
||||
}
|
||||
private T Spawn() => Object.Instantiate(prefab, root);
|
||||
private T Spawn()
|
||||
{
|
||||
var newObject = Object.Instantiate(prefab, root);
|
||||
OnSpawn?.Invoke(newObject);
|
||||
return newObject;
|
||||
}
|
||||
|
||||
#region 拓展
|
||||
|
||||
private readonly ConcurrentDictionary<string, T> _dictionary=new();
|
||||
|
Reference in New Issue
Block a user