This commit is contained in:
CortexCore
2024-04-06 16:33:32 +08:00
parent 637bbef7d2
commit 37e7fcea51
42 changed files with 597 additions and 149 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

@@ -69,8 +69,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 && Attribute.IsDefined(fieldInfo, typeof(ReadOnlyAttribute),true))
{
var attribute = fieldInfo.GetCustomAttribute<ReadOnlyAttribute>();
var _container = container.Create<VisualElement>();

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();