This commit is contained in:
CortexCore
2024-04-16 04:15:06 +08:00
parent b673a9438d
commit 0362b2c606
183 changed files with 5695 additions and 1453 deletions

View File

@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@@ -12,6 +13,14 @@ namespace BITKit
public abstract class VisualBehaviour:MonoBehaviour
{
}
public abstract class MonoBehaviourSingleton<T> : MonoBehaviour
{
public static T Singleton { get; private set; }
protected void Awake()
{
if (this is T t) Singleton = t;
}
}
public abstract class BITBehavior : MonoBehaviour, ICustomInspector
{

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>();
@@ -69,8 +68,8 @@ namespace BITKit
}
var type = serializedObject.targetObject.GetType();
var fieldInfo = serializedObject.targetObject.GetType().GetField(property.propertyPath, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (fieldInfo is not null && Attribute.IsDefined(fieldInfo, typeof(ReadOnlyAttribute)))
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>();
@@ -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
};

View File

@@ -12,10 +12,6 @@ namespace BITKit
[System.Serializable]
public class UnityPool<T> where T : Component
{
public UnityPool()
{
pool = new ObjectPool<T>(Spawn, OnGet, OnReturn, OnDestroy, maxSize: 16);
}
[Header(Constant.Header.Settings)]
[SerializeField] private int defaultCapacity = 16;
[Header(Constant.Header.Prefabs)]
@@ -23,17 +19,32 @@ namespace BITKit
[Header(Constant.Header.Gameobjects)]
[SerializeField] private Transform root;
private ObjectPool<T> pool;
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);
private ObjectPool<T> pool=> _pool ??=
new ObjectPool<T>
(Spawn, OnGet, OnReturn, OnDestroy,defaultCapacity:DefaultCapacity, maxSize:DefaultCapacity);
private ObjectPool<T> _pool;
private readonly List<T> _list=new();
public T Prefab
{
get => prefab;
set => prefab = value;
}
public Transform Root
{
get => root;
set => root = value;
}
public int DefaultCapacity
{
get => defaultCapacity;
set => defaultCapacity = value;
}
public int InstanceCount => _list.Count;
public T Get(T element = null, Transform _root = null)
{
if (_list.Count == defaultCapacity)
@@ -64,10 +75,6 @@ namespace BITKit
_list.Remove(element);
}
private T Spawn() => Object.Instantiate(prefab, root);
private void OnGet(T element) => element.gameObject.SetActive(true);
private void OnReturn(T element) => element.gameObject.SetActive(false);
private void OnDestroy(T element) => Object.Destroy(element.gameObject);
#region
private readonly ConcurrentDictionary<string, T> _dictionary=new();

View File

@@ -146,6 +146,10 @@ namespace BITKit
{
allowUpdateTime = currentTime + Interval + interval;
}
else
{
allowUpdateTime += interval;
}
}
else
{