This commit is contained in:
CortexCore
2023-11-06 01:17:23 +08:00
parent bd40165ade
commit 5446067f91
114 changed files with 2023 additions and 414 deletions

View File

@@ -134,6 +134,13 @@ namespace BITKit
protected static void FillDefaultInspector(VisualElement container, SerializedObject serializedObject, bool hideScript)
{
container.Clear();
if (serializedObject.targetObject is null)
{
var label = container.Create<Label>();
label.text = "Null";
return;
}
var property = serializedObject.GetIterator();
if (!property.NextVisible(true)) return; // Expand first child.
do

View File

@@ -24,9 +24,38 @@ namespace BITKit
{
return float.IsNaN(self.x) || float.IsNaN(self.y) || float.IsNaN(self.z) || float.IsNaN(self.w);
}
public static Quaternion AlignRotation(Quaternion rotation, float angleIncrement)
{
var eulerAngles = rotation.eulerAngles;
eulerAngles.x = Mathf.Round(eulerAngles.x / angleIncrement) * angleIncrement;
eulerAngles.y = Mathf.Round(eulerAngles.y / angleIncrement) * angleIncrement;
eulerAngles.z = Mathf.Round(eulerAngles.z / angleIncrement) * angleIncrement;
return Quaternion.Euler(eulerAngles);
}
}
public static partial class MathV
{
// 对于 Vector3
public static Vector3 AlignRotation(Vector3 eulerAngles, float angleIncrement)
{
eulerAngles.x = Mathf.Round(eulerAngles.x / angleIncrement) * angleIncrement;
eulerAngles.y = Mathf.Round(eulerAngles.y / angleIncrement) * angleIncrement;
eulerAngles.z = Mathf.Round(eulerAngles.z / angleIncrement) * angleIncrement;
return eulerAngles;
}
public static Vector3 AlignToGrid(Vector3 position, float gridSize)
{
var x = Mathf.Round(position.x / gridSize) * gridSize;
var y = Mathf.Round(position.y / gridSize) * gridSize;
var z = Mathf.Round(position.z / gridSize) * gridSize;
return new Vector3(x, y, z);
}
private static float CalculateMaxSpeed(this Vector2 direction)
{
var angle = Vector2.Angle(Vector2.right, direction);

View File

@@ -16,22 +16,47 @@ namespace BITKit
{
pool = new ObjectPool<T>(Spawn, OnGet, OnReturn, OnDestroy, maxSize: 16);
}
[Header(Constant.Header.Settings)]
[SerializeField] private int defaultCapacity = 16;
[Header(Constant.Header.Prefabs)]
public T prefab;
[SerializeField] private T prefab;
[Header(Constant.Header.Gameobjects)]
public Transform root;
[SerializeField] private Transform root;
private ObjectPool<T> pool;
private readonly List<T> _list=new();
public T Get(T element = null, Transform _root = null)
{
if (_list.Count == defaultCapacity)
{
var next = _list[0];
next.gameObject.SetActive(false);
_list.RemoveAt(0);
_list.Add(next);
next.gameObject.SetActive(true);
return next;
}
if (element is not null)
prefab = element;
if (_root is not null)
root = _root;
return pool.Get();
var instance = pool.Get();
_list.Add(instance);
return instance;
}
public void Return(T element)
{
pool.Release(element);
_list.Remove(element);
}
public void Return(T element) => pool.Release(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);

View File

@@ -179,6 +179,14 @@ namespace BITKit
public Vector3 position;
public Vector3 forward;
public Quaternion rotation;
public Location(Vector3 position, Quaternion rotation)
{
this.position = position;
this.rotation = rotation;
this.forward = rotation * Vector3.forward;
}
public Location Set(Vector3 value)
{
position = value;