1
This commit is contained in:
@@ -107,67 +107,59 @@ namespace BITKit
|
||||
{
|
||||
FillDefaultInspector(root, serializedObject, true);
|
||||
}
|
||||
public static void FillDefaultInspector(VisualElement container, SerializedObject serializedObject, bool hideScript)
|
||||
|
||||
protected static void FillDefaultInspector(VisualElement container, SerializedObject serializedObject, bool hideScript)
|
||||
{
|
||||
SerializedProperty property = serializedObject.GetIterator();
|
||||
if (property.NextVisible(true)) // Expand first child.
|
||||
var property = serializedObject.GetIterator();
|
||||
if (!property.NextVisible(true)) return; // Expand first child.
|
||||
do
|
||||
{
|
||||
do
|
||||
if (property.propertyPath == "m_Script" && hideScript)
|
||||
{
|
||||
if (property.propertyPath == "m_Script" && hideScript)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
var type = serializedObject.targetObject.GetType().GetField(property.name);
|
||||
var field = new PropertyField(property);
|
||||
|
||||
|
||||
|
||||
field.name = "PropertyField:" + property.propertyPath;
|
||||
|
||||
|
||||
if (property.propertyPath == "m_Script" && serializedObject.targetObject != null)
|
||||
{
|
||||
field.SetEnabled(false);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (type is not null)
|
||||
{
|
||||
var header = type.GetCustomAttribute<HeaderAttribute>();
|
||||
if (header is not null)
|
||||
{
|
||||
Label label = new Label(header.header);
|
||||
label.AddToClassList("subTitle");
|
||||
container.Add(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
|
||||
Debug.LogException(e);
|
||||
}
|
||||
|
||||
|
||||
container.Add(field);
|
||||
continue;
|
||||
}
|
||||
while (property.NextVisible(false));
|
||||
|
||||
foreach (var method in serializedObject.targetObject.GetType().GetMethods())
|
||||
var type = serializedObject.targetObject.GetType().GetField(property.name);
|
||||
var field = new PropertyField(property)
|
||||
{
|
||||
if (method.GetCustomAttribute<BITAttribute>() is not null)
|
||||
{
|
||||
if (method.GetParameters().Length is 0)
|
||||
{
|
||||
var button = new Button(() => method.Invoke(serializedObject.targetObject, null));
|
||||
button.text = method.Name;
|
||||
name = "PropertyField:" + property.propertyPath
|
||||
};
|
||||
|
||||
container.Add(button);
|
||||
}
|
||||
}
|
||||
|
||||
if (property.propertyPath == "m_Script" && serializedObject.targetObject != null)
|
||||
{
|
||||
field.SetEnabled(false);
|
||||
}
|
||||
|
||||
// try
|
||||
// {
|
||||
// var header = type?.GetCustomAttribute<HeaderAttribute>();
|
||||
// if (header != null)
|
||||
// {
|
||||
// var label = new Label(header.header);
|
||||
// label.AddToClassList("subTitle");
|
||||
// container.Add(label);
|
||||
// }
|
||||
// }
|
||||
// catch (System.Exception e)
|
||||
// {
|
||||
// Debug.LogException(e);
|
||||
// }
|
||||
|
||||
|
||||
container.Add(field);
|
||||
}
|
||||
while (property.NextVisible(false));
|
||||
|
||||
foreach (var method in serializedObject.targetObject.GetType().GetMethods())
|
||||
{
|
||||
if (method.GetCustomAttribute<BITAttribute>() is null) continue;
|
||||
if (method.GetParameters().Length is not 0) continue;
|
||||
var button = new Button(() => method.Invoke(serializedObject.targetObject, null))
|
||||
{
|
||||
text = method.Name
|
||||
};
|
||||
|
||||
container.Add(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -537,5 +537,34 @@ namespace BITKit
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetPosition(this VisualElement self,Vector3 worldPosition)
|
||||
{
|
||||
try
|
||||
{
|
||||
var camera = Camera.main;
|
||||
if (camera is null) return;
|
||||
var cameraTrans = camera.transform;
|
||||
var pos = RuntimePanelUtils
|
||||
.CameraTransformWorldToPanel(self.panel, worldPosition, camera);
|
||||
|
||||
pos.x = (pos.x - self.layout.width / 2);
|
||||
|
||||
self.style.left = 0;
|
||||
self.style.top = 0;
|
||||
self.style.right = new StyleLength(StyleKeyword.Auto);
|
||||
self.style.bottom = new StyleLength(StyleKeyword.Auto);
|
||||
self.style.position = Position.Absolute;
|
||||
// self.transform.position = pos;
|
||||
self.style.left = pos.x;
|
||||
self.style.top = pos.y;
|
||||
self.SetOpacity(Vector3.Dot(cameraTrans.forward, worldPosition - cameraTrans.position) > 0 ? 1 : 0);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
BIT4Log.LogException(e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,8 +1,12 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Pool;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
[System.Serializable]
|
||||
@@ -10,26 +14,43 @@ namespace BITKit
|
||||
{
|
||||
public UnityPool()
|
||||
{
|
||||
this.pool = new(Spawn, OnGet, OnReturn, OnDestroy, maxSize: 16);
|
||||
pool = new ObjectPool<T>(Spawn, OnGet, OnReturn, OnDestroy, maxSize: 16);
|
||||
}
|
||||
|
||||
[Header(Constant.Header.Prefabs)]
|
||||
public T prefab;
|
||||
[Header(Constant.Header.Gameobjects)]
|
||||
public Transform root;
|
||||
[Header(Constant.Header.InternalVariables)]
|
||||
ObjectPool<T> pool;
|
||||
public T Get(T element = null, Transform root = null)
|
||||
private ObjectPool<T> pool;
|
||||
|
||||
public T Get(T element = null, Transform _root = null)
|
||||
{
|
||||
if (element is not null)
|
||||
prefab = element;
|
||||
if (root is not null)
|
||||
this.root = root;
|
||||
if (_root is not null)
|
||||
root = _root;
|
||||
return pool.Get();
|
||||
}
|
||||
public void Return(T element) => pool.Release(element);
|
||||
T Spawn() => Transform.Instantiate(prefab, root);
|
||||
void OnGet(T element) => element.gameObject.SetActive(true);
|
||||
void OnReturn(T element) => element.gameObject.SetActive(false);
|
||||
void OnDestroy(T element) => GameObject.Destroy(element.gameObject);
|
||||
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();
|
||||
|
||||
public T GetByKey(string key)
|
||||
{
|
||||
var instance = _dictionary.GetOrAdd(key, s => Get());
|
||||
return instance;
|
||||
}
|
||||
public void RemoveByKey(string key)
|
||||
{
|
||||
_dictionary.TryRemove(key);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -3,10 +3,19 @@ using System.Collections.Generic;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.Rendering;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace BITKit
|
||||
{
|
||||
[Serializable]
|
||||
public class IProviderMonoProxy : IProvider
|
||||
{
|
||||
[SerializeField] private MonoBehaviour monoBehaviour;
|
||||
private IProvider _provider=>monoBehaviour as IProvider;
|
||||
public T Get<T>() => _provider.Get<T>();
|
||||
public void Set<T>(T t) => _provider.Set<T>(t);
|
||||
}
|
||||
public abstract class Provider : MonoBehaviour, IProvider
|
||||
{
|
||||
public virtual T Get<T>()
|
||||
@@ -35,11 +44,12 @@ namespace BITKit
|
||||
{
|
||||
VisualElement GetVisualElement();
|
||||
}
|
||||
[System.Serializable]
|
||||
[Serializable]
|
||||
public struct FrameUpdate
|
||||
{
|
||||
float prevframe;
|
||||
bool updatedThisFrame;
|
||||
public bool Allow => this;
|
||||
private float prevframe;
|
||||
private bool updatedThisFrame;
|
||||
public static implicit operator bool(FrameUpdate self)
|
||||
{
|
||||
var updatedThisFrame = BITApp.Time.DeltaTime <= self.prevframe;
|
||||
@@ -54,14 +64,14 @@ namespace BITKit
|
||||
}
|
||||
}
|
||||
}
|
||||
[System.Serializable]
|
||||
[Serializable]
|
||||
public class CompletionRate
|
||||
{
|
||||
public IntervalUpdate resetInterval = new(1);
|
||||
int requestCount;
|
||||
int successCount;
|
||||
public float rate;
|
||||
public int resetWhen = 64;
|
||||
private int requestCount;
|
||||
private int successCount;
|
||||
public static implicit operator float(CompletionRate cr)
|
||||
{
|
||||
return cr.rate;
|
||||
|
Reference in New Issue
Block a user