初始化

This commit is contained in:
come
2025-07-26 16:56:42 +08:00
parent 8291dbb91c
commit fa81439a8c
2574 changed files with 328492 additions and 2170 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 770a1d2479464fb9ae487db64a02bb18
timeCreated: 1681720506

View File

@@ -0,0 +1,114 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace YIUIFramework
{
/// <summary>
/// 可以自动回收的池
/// 适合用于临时的函数返对象
/// </summary>
public static class AutoListPool<T>
{
private static ListPool g_pool = new ListPool();
static AutoListPool()
{
AutoListPool.g_recyclers.Add(g_pool);
}
public static List<T> Get()
{
return g_pool.Get();
}
private class ListPool : Recycler
{
private List<List<T>> m_pool = new List<List<T>>(5);
private int m_index;
public List<T> Get()
{
List<T> item;
if (m_index == m_pool.Count)
{
item = new List<T>();
m_pool.Add(item);
}
else
{
item = m_pool[m_index];
}
m_index++;
Dirty = true;
AutoListPool.g_dirty = true;
//虽然回收时已经清了,但这样双保险,不香么?
item.Clear();
return item;
}
public override void Recycle()
{
if (m_index == 0)
{
return;
}
for (int i = 0; i < m_pool.Count; i++)
{
m_pool[i].Clear();
}
m_index = 0;
Dirty = false;
}
}
}
internal abstract class Recycler
{
public bool Dirty;
public abstract void Recycle();
}
[DefaultExecutionOrder(int.MaxValue)]
internal class AutoListPool : MonoBehaviour
{
internal static readonly List<Recycler> g_recyclers = new List<Recycler>();
internal static bool g_dirty;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
public static void OnLoad()
{
SceneManager.sceneLoaded -= OnSceneLoadedHandler;
SceneManager.sceneLoaded += OnSceneLoadedHandler;
}
private static void OnSceneLoadedHandler(UnityEngine.SceneManagement.Scene arg0, LoadSceneMode arg1)
{
var autoListPoolGo = new GameObject("AutoListPool");
autoListPoolGo.hideFlags = HideFlags.HideInHierarchy;
autoListPoolGo.AddComponent<AutoListPool>();
}
private void LateUpdate()
{
if (!g_dirty)
{
return;
}
g_dirty = false;
for (int i = 0; i < g_recyclers.Count; i++)
{
var item = g_recyclers[i];
if (item.Dirty)
{
item.Recycle();
}
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 90978b12434d48669352366cfb8b2744
timeCreated: 1681720507

View File

@@ -0,0 +1,90 @@
using System;
using System.Collections.Generic;
namespace YIUIFramework
{
/// <summary>
/// 可以自动回收的对象池
/// </summary>
/// <typeparam name="T"></typeparam>
public class AutoRecycleObjPool<T>
{
private Action<T> m_clearCallback;
private Func<T> m_newCallback;
private ITimeProvider m_timer;
private int m_lastUpdateTime;
private List<PoolVo> m_uses;
private List<PoolVo> m_frees;
public AutoRecycleObjPool(ITimeProvider timer,
Func<T> newCallback,
Action<T> clearCallback)
{
m_timer = timer;
m_newCallback = newCallback;
m_clearCallback = clearCallback;
m_uses = new List<PoolVo>();
m_frees = new List<PoolVo>();
}
public T Get()
{
Update();
PoolVo result;
if (m_frees.Count > 0)
{
result = m_frees.Pop();
}
else
{
result = new PoolVo();
result.Value = m_newCallback();
}
result.Timeout = m_timer.Time + 1;
m_uses.Add(result);
return result.Value;
}
public void Update()
{
var count = m_uses.Count;
if (count < 1)
{
return;
}
var curTime = m_timer.Time;
if (m_lastUpdateTime == curTime)
{
return;
}
m_lastUpdateTime = curTime;
//找出过时的对象
for (var i = 0; i < count; i++)
{
var poolVo = m_uses[i];
if (curTime >= poolVo.Timeout)
{
m_uses.FastRemoveAt(i);
m_clearCallback(poolVo.Value);
m_frees.Add(poolVo);
count--;
i--;
}
}
}
private class PoolVo
{
public int Timeout;
public T Value;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1d63555742804916844a9d8873b1e924
timeCreated: 1681720507

View File

@@ -0,0 +1,31 @@
using System.Collections.Generic;
namespace YIUIFramework
{
/// <summary>
/// 字典的池
/// </summary>
public class DictionaryPool<TKey, TValue>
{
private static Stack<Dictionary<TKey, TValue>> g_pool = new Stack<Dictionary<TKey, TValue>>();
public static Dictionary<TKey, TValue> Get()
{
lock (g_pool)
{
return g_pool.Count == 0
? new Dictionary<TKey, TValue>()
: g_pool.Pop();
}
}
public static void Put(Dictionary<TKey, TValue> map)
{
map.Clear();
lock (g_pool)
{
g_pool.Push(map);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e3cb60974c6e4598822a56e8640ec898
timeCreated: 1681720507

View File

@@ -0,0 +1,63 @@
using System.Collections.Generic;
namespace YIUIFramework
{
/// <summary>
/// HashSet的池
/// </summary>
public class HashSetPool<T>
{
private static Stack<HashSet<T>> g_pool = new Stack<HashSet<T>>(5);
public static HashSet<T> Get()
{
lock (g_pool)
{
return g_pool.Count == 0
? new HashSet<T>()
: g_pool.Pop();
}
}
/// <summary>
/// 得到一个hashSet, 并帮你填充了data
/// </summary>
/// <param name="initData"></param>
/// <returns></returns>
public static HashSet<T> Get(T[] initData)
{
var map = Get();
for (int i = 0; i < initData.Length; i++)
{
map.Add(initData[i]);
}
return map;
}
/// <summary>
/// 得到一个hashSet, 并帮你填充了data
/// </summary>
/// <param name="initData"></param>
/// <returns></returns>
public static HashSet<T> Get(IList<T> initData)
{
var map = Get();
for (int i = 0; i < initData.Count; i++)
{
map.Add(initData[i]);
}
return map;
}
public static void Put(HashSet<T> list)
{
list.Clear();
lock (g_pool)
{
g_pool.Push(list);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7ae235583b5340aab9dccbc51499513c
timeCreated: 1681720507

View File

@@ -0,0 +1,35 @@
using System.Collections.Generic;
namespace YIUIFramework
{
/*public static class ListPool<T>
{
private static readonly ObjectPool<List<T>> s_ListPool = new ObjectPool<List<T>>(null, l => l.Clear());
public static List<T> Get()
{
return s_ListPool.Get();
}
public static void Release(List<T> toRelease)
{
s_ListPool.Release(toRelease);
}
}*/
public static class LinkedListPool<T>
{
private static readonly ObjectPool<LinkedList<T>> s_ListPool =
new ObjectPool<LinkedList<T>>(null, l => l.Clear());
public static LinkedList<T> Get()
{
return s_ListPool.Get();
}
public static void Release(LinkedList<T> toRelease)
{
s_ListPool.Release(toRelease);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 212be9f6f4814d0e87332d23561af12c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
using System.Collections.Generic;
namespace YIUIFramework
{
/// <summary>
/// 各种列表的池
/// </summary>
/// <typeparam name="T"></typeparam>
public static class ListPool<T>
{
private static Stack<List<T>> g_pool = new Stack<List<T>>(5);
public static List<T> Get()
{
lock (g_pool)
{
return g_pool.Count == 0
? new List<T>()
: g_pool.Pop();
}
}
public static void Put(List<T> list)
{
list.Clear();
lock (g_pool)
{
g_pool.Push(list);
}
}
public static T[] PutAndToArray(List<T> list)
{
var t = list.ToArray();
Put(list);
return t;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 801d2ad7c6c444e9961eb176e0ea8691
timeCreated: 1681720506

View File

@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using Cysharp.Threading.Tasks;
namespace YIUIFramework
{
/// <summary>
/// 异步对象缓存池
/// </summary>
public class ObjAsyncCache<T>
{
private Stack<T> m_pool;
protected Func<UniTask<T>> m_createCallback;
public ObjAsyncCache(Func<UniTask<T>> createCallback, int capacity = 0)
{
m_pool = capacity > 0
? new Stack<T>(capacity)
: new Stack<T>();
m_createCallback = createCallback;
}
public async UniTask<T> Get()
{
return m_pool.Count > 0 ? m_pool.Pop() : await m_createCallback();
}
public void Put(T value)
{
m_pool.Push(value);
}
public void Clear(bool disposeItem = false)
{
if (disposeItem)
{
foreach (var item in m_pool)
{
if (item is IDisposer disposer)
{
disposer.Dispose();
}
else if (item is IDisposable disposer2)
{
disposer2.Dispose();
}
}
}
m_pool.Clear();
}
public void Clear(Action<T> disposeAction)
{
while (m_pool.Count >= 1)
{
disposeAction?.Invoke(m_pool.Pop());
}
m_pool.Clear();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 100e412be3594bb2b6a08fd501297d1f
timeCreated: 1684290887

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
namespace YIUIFramework
{
/// <summary>
/// 对象缓存池
/// </summary>
public class ObjCache<T>
{
private Stack<T> m_pool;
protected Func<T> m_createCallback;
public ObjCache(Func<T> createCallback, int capacity = 0)
{
m_pool = capacity > 0
? new Stack<T>(capacity)
: new Stack<T>();
m_createCallback = createCallback;
}
public T Get()
{
return m_pool.Count > 0 ? m_pool.Pop() : m_createCallback();
}
public void Put(T value)
{
m_pool.Push(value);
}
public void Clear(bool disposeItem = false)
{
if (disposeItem)
{
foreach (var item in m_pool)
{
if (item is IDisposer disposer)
{
disposer.Dispose();
}
else if (item is IDisposable disposer2)
{
disposer2.Dispose();
}
}
}
m_pool.Clear();
}
public void Clear(Action<T> disposeAction)
{
while (m_pool.Count >= 1)
{
disposeAction?.Invoke(m_pool.Pop());
}
m_pool.Clear();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ec17f07373554d608d685f879c6a9957
timeCreated: 1681720506

View File

@@ -0,0 +1,86 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace YIUIFramework
{
public class ObjectPool<T> where T : new()
{
#if UNITY_EDITOR
public static bool isRunning = false;
private readonly HashSet<T> Trace = new HashSet<T>();
#endif
private readonly Stack<T> m_Stack = new Stack<T>();
private readonly UnityAction<T> m_ActionOnGet;
private readonly UnityAction<T> m_ActionOnRelease;
public int countAll { get; private set; }
public int countActive
{
get { return countAll - countInactive; }
}
public int countInactive
{
get { return m_Stack.Count; }
}
public ObjectPool(UnityAction<T> actionOnGet, UnityAction<T> actionOnRelease)
{
m_ActionOnGet = actionOnGet;
m_ActionOnRelease = actionOnRelease;
}
public T Get()
{
T element;
if (m_Stack.Count == 0)
{
element = new T();
countAll++;
#if UNITY_EDITOR
Trace.Add(element);
#endif
}
else
{
element = m_Stack.Pop();
}
if (m_ActionOnGet != null)
m_ActionOnGet(element);
return element;
}
public void Release(T element)
{
#if UNITY_EDITOR
if (m_Stack.Count > 0 && ReferenceEquals(m_Stack.Peek(), element))
Debug.LogError("Internal error. Trying to destroy object that is already released to pool.");
if (element == null)
{
Debug.LogError("Internal error. Release element is null.");
return;
}
if (ObjectPool<bool>.isRunning == false)
{
if (m_ActionOnRelease != null)
m_ActionOnRelease(element);
return;
}
if (Trace.Contains(element) == false)
{
Debug.LogError("Internal error. Release element is not from pool ");
}
#endif
if (m_ActionOnRelease != null)
m_ActionOnRelease(element);
m_Stack.Push(element);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6703f8ed118d4f56b759711a066e235c
timeCreated: 1679041134

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8104da227f5d4b31913d534031f9e44f
timeCreated: 1688349310

View File

@@ -0,0 +1,13 @@
namespace YIUIFramework
{
/// <summary>
/// 引用接口
/// </summary>
public interface IRefPool
{
/// <summary>
/// 被回收时 重置所有数据
/// </summary>
void Recycle();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: b4faaba43e964a7ca00f6a686626e180
timeCreated: 1688349310

View File

@@ -0,0 +1,122 @@
using System;
using System.Collections.Generic;
namespace YIUIFramework
{
public static partial class RefPool
{
private sealed class RefCollection
{
private readonly Queue<IRefPool> m_Refs;
private readonly Type m_RefType;
public RefCollection(Type refType)
{
m_Refs = new Queue<IRefPool>();
m_RefType = refType;
}
public Type RefType
{
get { return m_RefType; }
}
public T Get<T>() where T : class, IRefPool, new()
{
if (typeof(T) != m_RefType)
{
throw new Exception("类型无效");
}
lock (m_Refs)
{
if (m_Refs.Count > 0)
{
return (T)m_Refs.Dequeue();
}
}
return new T();
}
public IRefPool Get()
{
lock (m_Refs)
{
if (m_Refs.Count > 0)
{
return m_Refs.Dequeue();
}
}
return (IRefPool)Activator.CreateInstance(m_RefType);
}
public bool Put(IRefPool iRef)
{
iRef.Recycle();
lock (m_Refs)
{
if (!m_Refs.Contains(iRef))
{
m_Refs.Enqueue(iRef);
return true;
}
}
return false;
}
public void Add<T>(int count) where T : class, IRefPool, new()
{
if (typeof(T) != m_RefType)
{
throw new Exception("类型无效。");
}
lock (m_Refs)
{
while (count-- > 0)
{
m_Refs.Enqueue(new T());
}
}
}
public void Add(int count)
{
lock (m_Refs)
{
while (count-- > 0)
{
m_Refs.Enqueue((IRefPool)Activator.CreateInstance(m_RefType));
}
}
}
public void Remove(int count)
{
lock (m_Refs)
{
if (count > m_Refs.Count)
{
count = m_Refs.Count;
}
while (count-- > 0)
{
m_Refs.Dequeue();
}
}
}
public void RemoveAll()
{
lock (m_Refs)
{
m_Refs.Clear();
}
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d41524c232e54efeb690d109acfea6a3
timeCreated: 1688349310

View File

@@ -0,0 +1,190 @@
using System.Collections.Generic;
using System;
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// 引用池
/// </summary>
public static partial class RefPool
{
private static readonly Dictionary<Type, RefCollection>
s_RefCollections = new Dictionary<Type, RefCollection>();
public static int Count
{
get
{
lock (s_RefCollections)
{
return s_RefCollections.Count;
}
}
}
/// <summary>
/// 清除所有引用池
/// </summary>
public static void ClearAll()
{
lock (s_RefCollections)
{
foreach (KeyValuePair<Type, RefCollection> refCollection in s_RefCollections)
{
refCollection.Value.RemoveAll();
}
s_RefCollections.Clear();
}
}
/// <summary>
/// 从引用池获取引用
/// </summary>
/// <typeparam name="T">引用类型</typeparam>
/// <returns>引用</returns>
public static T Get<T>() where T : class, IRefPool, new()
{
return GetRefCollection(typeof(T))?.Get<T>();
}
/// <summary>
/// 从引用池获取引用
/// </summary>
/// <param name="refreceType">引用类型</param>
/// <returns>引用</returns>
public static IRefPool Get(Type refreceType)
{
return GetRefCollection(refreceType)?.Get();
}
/// <summary>
/// 回收引用
/// </summary>
public static bool Put(IRefPool iRef)
{
if (iRef == null)
{
Debug.LogError("refType == null 无效 请检查");
return false;
}
var collection = GetRefCollection(iRef.GetType());
return collection != null && collection.Put(iRef);
}
/// <summary>
/// 向引用池中追加指定数量的引用
/// </summary>
/// <typeparam name="T">引用类型</typeparam>
/// <param name="count">追加数量</param>
public static void Add<T>(int count) where T : class, IRefPool, new()
{
GetRefCollection(typeof(T))?.Add<T>(count);
}
/// <summary>
/// 向引用池中追加指定数量的引用
/// </summary>
/// <param name="refType">引用类型</param>
/// <param name="count">追加数量</param>
public static void Add(Type refType, int count)
{
GetRefCollection(refType)?.Add(count);
}
/// <summary>
/// 从引用池中移除指定数量的引用
/// </summary>
/// <typeparam name="T">引用类型</typeparam>
/// <param name="count">移除数量</param>
public static void Remove<T>(int count) where T : class, IRefPool, new()
{
GetRefCollection(typeof(T),true)?.Remove(count);
}
/// <summary>
/// 从引用池中移除指定数量的引用
/// </summary>
/// <param name="refType">引用类型</param>
/// <param name="count">移除数量</param>
public static void Remove(Type refType, int count)
{
GetRefCollection(refType,true)?.Remove(count);
}
/// <summary>
/// 从引用池中移除所有的引用
/// </summary>
/// <typeparam name="T">引用类型</typeparam>
public static void RemoveAll<T>() where T : class, IRefPool, new()
{
GetRefCollection(typeof(T),true)?.RemoveAll();
}
/// <summary>
/// 从引用池中移除所有的引用
/// </summary>
/// <param name="refType">引用类型</param>
public static void RemoveAll(Type refType)
{
GetRefCollection(refType,true)?.RemoveAll();
}
private static bool InternalCheckRefType(Type refType)
{
if (refType == null)
{
Debug.LogError("refType == null 无效 请检查");
return false;
}
if (!refType.IsClass || refType.IsAbstract)
{
Debug.LogError("引用类型不是非抽象类类型");
return false;
}
if (!typeof(IRefPool).IsAssignableFrom(refType))
{
Debug.LogError($"引用类型'{refType.FullName}'无效。");
return false;
}
return true;
}
private static RefCollection GetRefCollection(Type refType, bool allowNull = false)
{
if (refType == null)
{
Debug.LogError("refType == null 无效 请检查");
return null;
}
RefCollection refCollection = null;
lock (s_RefCollections)
{
if (!s_RefCollections.TryGetValue(refType, out refCollection))
{
if (allowNull)
{
return null;
}
if (!InternalCheckRefType(refType))
{
return null;
}
refCollection = new RefCollection(refType);
s_RefCollections.Add(refType, refCollection);
}
}
return refCollection;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: baa8034445504494a567cf5a6dcf12b5
timeCreated: 1688349310

View File

@@ -0,0 +1,39 @@
using System.Collections.Generic;
using System.Text;
namespace YIUIFramework
{
/// <summary>
/// StringBuilder池
/// </summary>
public static class SbPool
{
private static Stack<StringBuilder> g_pool = new Stack<StringBuilder>(5);
public static StringBuilder Get()
{
lock (g_pool)
{
return g_pool.Count == 0
? new StringBuilder()
: g_pool.Pop();
}
}
public static void Put(StringBuilder sb)
{
sb.Clear();
lock (g_pool)
{
g_pool.Push(sb);
}
}
public static string PutAndToStr(StringBuilder sb)
{
var str = sb.ToString();
Put(sb);
return str;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2c28dc904d6441da8cbd9d1db473a283
timeCreated: 1681720506

View File

@@ -0,0 +1,15 @@
namespace YIUIFramework
{
public class SimplePool<T> : ObjCache<T> where T : new()
{
public SimplePool(int capacity = 0) : base(null, capacity)
{
m_createCallback = Create;
}
private T Create()
{
return new T();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ef154f446c7247d18c3b07df39be75cd
timeCreated: 1681720506

View File

@@ -0,0 +1,38 @@
using System.Collections.Generic;
namespace YIUIFramework
{
/// <summary>
/// 堆栈池
/// </summary>
public class StackPool<T>
{
private static Stack<Stack<T>> g_pool = new Stack<Stack<T>>(5);
public static Stack<T> Get()
{
lock (g_pool)
{
return g_pool.Count == 0
? new Stack<T>()
: g_pool.Pop();
}
}
public static void Put(Stack<T> list)
{
list.Clear();
lock (g_pool)
{
g_pool.Push(list);
}
}
public static T[] PutAndToArray(Stack<T> list)
{
var t = list.ToArray();
Put(list);
return t;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 404ba99bdbef49aa9cc9e1a75b4bc12e
timeCreated: 1681720506

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4a9db0e8966d41ddad196099b949d7db
timeCreated: 1688982061

View File

@@ -0,0 +1,34 @@
namespace YIUIFramework
{
/// <summary>
/// IDisposer的实现
/// 可以继承使用
/// 如果只是用接口,可以直接复制使用
/// </summary>
public abstract class Disposer : IDisposer
{
public bool Disposed
{
get { return m_disposed; }
}
public bool Dispose()
{
if (m_disposed)
{
return false;
}
m_disposed = true;
OnDispose();
return true;
}
/// <summary>
/// 处理释放相关事情
/// </summary>
protected abstract void OnDispose();
private bool m_disposed;
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5182d43dff414185b0367f9cb16945ed
timeCreated: 1688978764

View File

@@ -0,0 +1,19 @@
namespace YIUIFramework
{
/// <summary>
/// 释放者接口
/// </summary>
public interface IDisposer
{
/// <summary>
/// 表示是否已经释放过了
/// </summary>
bool Disposed { get; }
/// <summary>
/// 释放资源,如果执行了这个方法,就不能再使用这个对象了
/// </summary>
/// <returns>true表示执行成功false表示因为某些原因执行失败最常见的就是已经执行过这个方法</returns>
bool Dispose();
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3e437d9920734dfd87db67fed593e4a3
timeCreated: 1681720464

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0b4dfae83a474907bc80cbf56b940b71
timeCreated: 1679041183

View File

@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using Random = UnityEngine.Random;
namespace YIUIFramework
{
/// <summary>
/// <see cref="Array"/>.
/// </summary>
public static class ArrayExtensions
{
/// <summary>
/// 洗牌
/// </summary>
public static void Shuffle<T>(this T[] array)
{
for (int i = 0; i < array.Length; ++i)
{
var randIdx = Random.Range(0, array.Length);
(array[randIdx], array[i]) = (array[i], array[randIdx]);
}
}
/// <summary>
/// 删除重复
/// </summary>
public static T[] RemoveDuplicate<T>(this T[] array)
{
var lookup = new HashSet<T>();
foreach (var i in array)
{
if (!lookup.Contains(i))
{
lookup.Add(i);
}
}
var newArray = new T[lookup.Count];
int index = 0;
foreach (var i in lookup)
{
newArray[index++] = i;
}
return newArray;
}
/// <summary>
/// 将数组强制转换为子类
/// </summary>
public static U[] Cast<T, U>(this T[] array)
where U : class, T
where T : class
{
return Array.ConvertAll<T, U>(array, input => input as U);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0cd2498236654c55b05babc0c6f337cb
timeCreated: 1679041183

View File

@@ -0,0 +1,76 @@
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// <see cref="UnityEngine.Color"/>.
/// </summary>
public static class ColorExtensions
{
/// <summary>
/// 设置颜色的alpha值。
/// </summary>
public static Color[] SetAlpha(this Color[] colors, float alpha)
{
for (int i = 0; i < colors.Length; ++i)
{
colors[i].a = alpha;
}
return colors;
}
/// <summary>
/// 设置颜色的alpha值。
/// </summary>
public static Color SetAlpha(this Color color, float alpha)
{
color.a = alpha;
return color;
}
/// <summary>
/// 将颜色值固定为[0,1]
/// </summary>
public static Color Clamp(this Color c)
{
for (int i = 0; i < 4; ++i)
{
if (float.IsNaN(c[i]) || float.IsNegativeInfinity(c[i]))
{
c[i] = 0.0f;
}
else if (float.IsPositiveInfinity(c[i]))
{
c[i] = 1.0f;
}
else
{
c[i] = Mathf.Clamp(c[i], 0.0f, 1.0f);
}
}
return c;
}
/// <summary>
/// 计算颜色的亮度。
/// </summary>
public static float Luminance(this Color c)
{
return (0.3f * c.r) + (0.59f * c.g) + (0.11f * c.b);
}
/// <summary>
/// 只使用颜色中的RGB组件
/// </summary>
public static Color LerpRGB(Color a, Color b, float t)
{
return new Color(
Mathf.Lerp(a.r, b.r, t),
Mathf.Lerp(a.g, b.g, t),
Mathf.Lerp(a.b, b.b, t),
a.a);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 90c0b72094f94cd2ae0f33236da8a9d0
timeCreated: 1679041183

View File

@@ -0,0 +1,98 @@
using UnityEngine;
using UnityEngine.Assertions;
namespace YIUIFramework
{
/// <summary>
/// <see cref="UnityEngine.Component"/>.
/// </summary>
public static class ComponentExtensions
{
/// <summary>
/// 从目标组件中获取一个组件,如果是组件类型不存在,则添加
/// </summary>
public static Component GetOrAddComponent(
this Component obj, System.Type type)
{
var component = obj.GetComponent(type);
if (component == null)
{
component = obj.gameObject.AddComponent(type);
}
return component;
}
/// <summary>
/// 从目标组件中获取一个组件,如果是组件类型不存在,则添加
/// </summary>
public static T GetOrAddComponent<T>(
this Component obj) where T : Component
{
var component = obj.GetComponent<T>();
if (component == null)
{
component = obj.gameObject.AddComponent<T>();
}
return component;
}
/// <summary>
/// 从目标组件中获取一个组件,如果是组件类型不存在,则添加
/// 标记不保存
/// </summary>
public static T GetOrAddComponentDontSave<T>(
this Component obj) where T : Component
{
var component = obj.GetComponent<T>();
if (component == null)
{
component = obj.gameObject.AddComponent<T>();
component.hideFlags = HideFlags.DontSave;
}
return component;
}
/// <summary>
/// 检查目标组件的GameObject上是否有一个或多个指定类型的组件
/// </summary>
public static bool HasComponent(
this Component obj, System.Type type)
{
return obj.GetComponent(type) != null;
}
/// <summary>
/// 检查目标组件的GameObject上是否有一个或多个指定类型的组件
/// </summary>
public static bool HasComponent<T>(
this Component obj) where T : Component
{
return obj.GetComponent<T>() != null;
}
/// <summary>
/// 在parent中查找组件即使该组件处于非活动状态或已禁用 都能查询
/// </summary>
public static T GetComponentInParentHard<T>(
this Component obj) where T : Component
{
Assert.IsNotNull(obj);
var transform = obj.transform;
while (transform != null)
{
var component = transform.GetComponent<T>();
if (component != null)
{
return component;
}
transform = transform.parent;
}
return null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 54e3cb3cb3a346ca8844971eff47f7a2
timeCreated: 1679041183

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
namespace YIUIFramework
{
/// <summary>
/// <see cref="Dictionary"/>.
/// </summary>
public static class DictionaryExtensions
{
/// <summary>
/// 删除过滤器检查的所有值
/// </summary>
public static void RemoveAll<K, V>(
this Dictionary<K, V> dic, Func<K, V, bool> filter)
{
var sweep = RemoveList<K>.SweepList;
var itr = dic.GetEnumerator();
while (itr.MoveNext())
{
var kv = itr.Current;
if (filter(kv.Key, kv.Value))
{
sweep.Add(kv.Key);
}
}
for (int i = 0; i < sweep.Count; ++i)
{
dic.Remove(sweep[i]);
}
sweep.Clear();
}
private static class RemoveList<T>
{
private static List<T> sweepList = new List<T>();
public static List<T> SweepList
{
get { return sweepList; }
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a22ea6f1b8894437ba02170d16dc731e
timeCreated: 1679041183

View File

@@ -0,0 +1,93 @@
using UnityEngine;
using UnityEngine.Assertions;
namespace YIUIFramework
{
/// <summary>
/// <see cref="GameObject"/>.
/// </summary>
public static class GameObjectExtensions
{
/// <summary>
/// 从目标组件中获取一个组件,如果是组件类型不存在,则添加
/// </summary>
public static Component GetOrAddComponent(
this GameObject obj, System.Type type)
{
var component = obj.GetComponent(type);
if (component == null)
{
component = obj.gameObject.AddComponent(type);
}
return component;
}
/// <summary>
/// 从目标组件中获取一个组件,如果是组件类型不存在,则添加
/// </summary>
public static T GetOrAddComponent<T>(
this GameObject obj) where T : Component
{
var component = obj.GetComponent<T>();
if (component == null)
{
component = obj.gameObject.AddComponent<T>();
}
return component;
}
/// <summary>
/// 检查目标组件上是否有一个或多个特定类型的组件
/// </summary>
public static bool HasComponent(
this GameObject obj, System.Type type)
{
return obj.GetComponent(type) != null;
}
/// <summary>
/// 检查目标组件上是否有一个或多个特定类型的组件
/// </summary>
public static bool HasComponent<T>(
this GameObject obj) where T : Component
{
return obj.GetComponent<T>() != null;
}
/// <summary>
/// 为GameObject及其所有子对象设置图层。
/// </summary>
public static void SetLayerRecursively(this GameObject obj, int layer)
{
obj.layer = layer;
foreach (Transform t in obj.transform)
{
t.gameObject.SetLayerRecursively(layer);
}
}
/// <summary>
/// 在parent中查找组件即使该组件处于非活动状态或禁用状态。
/// </summary>
public static T GetComponentInParentHard<T>(
this GameObject obj) where T : Component
{
Assert.IsNotNull(obj);
var transform = obj.transform;
while (transform != null)
{
var component = transform.GetComponent<T>();
if (component != null)
{
return component;
}
transform = transform.parent;
}
return null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 13290aaa4b6649b787fc3f8a6cb1275c
timeCreated: 1679041183

View File

@@ -0,0 +1,284 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace YIUIFramework
{
public static class ListExt
{
/// <summary>
/// 将列表转为字典
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TItem"></typeparam>
/// <param name="list"></param>
/// <param name="getKeyHandler"></param>
/// <returns></returns>
public static Dictionary<TKey, TItem> ToDictionary<TKey, TItem>(
this IList<TItem> list, Func<TItem, TKey> getKeyHandler)
{
if (list == null)
{
return EmptyValue<Dictionary<TKey, TItem>>.Value;
}
var dic = new Dictionary<TKey, TItem>(list.Count);
for (int i = 0; i < list.Count; i++)
{
dic[getKeyHandler(list[i])] = list[i];
}
return dic;
}
/// <summary>
/// 排序自身
/// </summary>
/// <typeparam name="TSource"></typeparam>
/// <typeparam name="TKey"></typeparam>
/// <param name="source"></param>
/// <param name="keySelector"></param>
/// <param name="isDescending"></param>
public static void OrderSelf<TSource, TKey>(this IList<TSource> source, Func<TSource, TKey> keySelector,
bool isDescending = false)
{
IOrderedEnumerable<TSource> result;
if (isDescending)
{
result = source.OrderByDescending(keySelector);
}
else
{
result = source.OrderBy(keySelector);
}
int i = 0;
foreach (TSource item in result)
{
source[i] = item;
i++;
}
}
/// <summary>
/// 取出数据最后一个元素(取出后,这个元素就不在数据里)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
/// <returns></returns>
public static T Pop<T>(this IList<T> list)
{
if (list.Count < 1)
{
return default;
}
var lastIndex = list.Count - 1;
var lastItem = list[lastIndex];
list.RemoveAt(lastIndex);
return lastItem;
}
/// <summary>
/// 取出数据第一个元素(取出后,这个元素就不在数据里)
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
/// <returns></returns>
public static T Shift<T>(this IList<T> list)
{
if (list.Count < 1)
{
return default;
}
var firstItem = list[0];
list.RemoveAt(0);
return firstItem;
}
/// <summary>
/// 在数组开头,添加一个或多个元素
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="inst"></param>
/// <param name="items"></param>
/// <returns></returns>
public static T[] Unshift<T>(this IList<T> inst, params T[] items)
{
var addCount = items.Length;
var newArr = new T[addCount + inst.Count];
for (int i = 0; i < addCount; i++)
{
newArr[i] = items[i];
}
for (int i = 0; i < inst.Count; i++)
{
newArr[addCount + i] = inst[i];
}
return newArr;
}
/// <summary>
/// 用于IndexOf
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
public static bool EqualsUInt(uint a, uint b)
{
return a == b;
}
public static int IndexOf<T>(this IList<T> list, T value,
int start = 0, int count = 0, Func<T, T, bool> equalsFun = null)
{
count = count < 1
? list.Count
: MathUtil.FixedByRange(count, 0, list.Count);
if (equalsFun == null)
{
for (int i = start; i < count; i++)
{
if (list[i].Equals(value))
{
return i;
}
}
}
else
{
for (int i = start; i < count; i++)
{
if (equalsFun(list[i], value))
{
return i;
}
}
}
return -1;
}
/// <summary>
/// 快速数组数据移除方法
/// 当数组顺序不敏感时使用
/// </summary>
/// <param name="list"></param>
/// <param name="index"></param>
/// <returns></returns>
public static bool FastRemoveAt(this IList list, int index)
{
return FastRemoveAt(list, index, out _);
}
/// <summary>
/// 快速数组数据移除方法
/// 当数组顺序不敏感时使用
/// </summary>
/// <param name="list"></param>
/// <param name="index"></param>
/// <param name="curMoveItemIndex">被移动的对象现在所在的index, 当值小于零时表示没有被移动的物体</param>
/// <returns></returns>
public static bool FastRemoveAt(this IList list, int index, out int curMoveItemIndex)
{
int len = list.Count;
if (len < 1 || index >= len)
{
curMoveItemIndex = -1;
return false;
}
int lastIndex = len - 1;
object lastItem = list[lastIndex];
list.RemoveAt(lastIndex);
if (index != lastIndex)
{
list[index] = lastItem;
curMoveItemIndex = index;
}
else
{
curMoveItemIndex = -1;
}
return true;
}
public static bool FastRemove(this IList list, object item)
{
var index = list.IndexOf(item);
if (index < 0)
{
return false;
}
return FastRemoveAt(list, index, out _);
}
public static bool VerifyIndex(this IList list, int index, object item)
{
int len = list.Count;
if (len < 1
|| index >= len
|| index < 0)
{
return false;
}
return list[index] == item;
}
public static bool SafeSetValue<T>(this IList<T> list, int index, T value)
{
if (null == list
|| index < 0
|| index >= list.Count)
{
return false;
}
list[index] = value;
return true;
}
public static T SafeGetValue<T>(this IList<T> list, int index, T defValue = default(T))
{
if (list == null ||
index >= list.Count)
{
return defValue;
}
return list[index];
}
public static T GetRnd<T>(this IList<T> list, Random random)
{
int len = list.Count;
if (len < 1)
{
return default(T);
}
return list[random.Next(0, len)];
}
public static bool ContainsByUint(this uint[] list, uint value)
{
for (int i = 0; i < list.Length; i++)
{
if (list[i] == value)
{
return true;
}
}
return false;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 689b50cce9e840aeb66c81fabf27db5b
timeCreated: 1681720464

View File

@@ -0,0 +1,46 @@
using System.Collections.Generic;
using Random = UnityEngine.Random;
namespace YIUIFramework
{
/// <summary>
/// <see cref="List"/>.
/// </summary>
public static class ListExtensions
{
/// <summary>
/// 洗牌
/// </summary>
public static void Shuffle<T>(this IList<T> array)
{
for (int i = 0; i < array.Count; ++i)
{
var randIdx = Random.Range(0, array.Count);
(array[randIdx], array[i]) = (array[i], array[randIdx]);
}
}
/// <summary>
/// 删除重复元素。
/// </summary>
public static void RemoveDuplicate<T>(this List<T> list)
{
var lookup = new Dictionary<T, int>();
foreach (var i in list)
{
int value = 0;
if (!lookup.TryGetValue(i, out value))
{
lookup.Add(i, 0);
}
}
list.Clear();
foreach (var i in lookup)
{
list.Add(i.Key);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: df81df60414f4f6689c3d57cec624bae
timeCreated: 1679041183

View File

@@ -0,0 +1,23 @@
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// <see cref="UnityEngine.Quaternion"/>.
/// </summary>
public static class QuaternionExtensions
{
/// <summary>
/// 从字符串中解析四元素
/// </summary>
public static Quaternion Parse(string text)
{
var elements = text.Substring(1, text.Length - 2).Split(',');
float x = float.Parse(elements[0]);
float y = float.Parse(elements[1]);
float z = float.Parse(elements[2]);
float w = float.Parse(elements[3]);
return new Quaternion(x, y, z, w);
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9802e51fadd64f95a771dd6a037fea4c
timeCreated: 1679041183

View File

@@ -0,0 +1,74 @@
using System;
using System.Text.RegularExpressions;
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// <see cref="Rect"/>
/// </summary>
public static class RectExtensions
{
private static Regex parseRegex;
public static Rect Parse(string text)
{
Rect value;
if (!TryParse(text, out value))
{
var msg = string.Format(
"The string {0} can not convert to Rect.", text);
throw new FormatException(msg);
}
return value;
}
public static bool TryParse(string text, out Rect rect)
{
if (parseRegex == null)
{
parseRegex = new Regex(
@"^\(x:(.*), y:(.*), width:(.*), height:(.*)\)$");
}
var match = parseRegex.Match(text);
if (!match.Success || match.Groups.Count != 5)
{
rect = Rect.zero;
return false;
}
float x;
if (!float.TryParse(match.Groups[1].Value, out x))
{
rect = Rect.zero;
return false;
}
float y;
if (!float.TryParse(match.Groups[2].Value, out y))
{
rect = Rect.zero;
return false;
}
float width;
if (!float.TryParse(match.Groups[3].Value, out width))
{
rect = Rect.zero;
return false;
}
float height;
if (!float.TryParse(match.Groups[4].Value, out height))
{
rect = Rect.zero;
return false;
}
rect = new Rect(x, y, width, height);
return true;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 9c7ddd6439c541a78db4c52118ebab44
timeCreated: 1679041183

View File

@@ -0,0 +1,49 @@
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// <see cref="RectTransform"/>.
/// </summary>
public static class RectTransformExtensions
{
private static Vector3[] corners = new Vector3[4];
/// <summary>
/// 获取世界中心位置
/// </summary>
public static Vector3 GetWorldCenter(this RectTransform transform)
{
transform.GetWorldCorners(corners);
return (corners[0] + corners[2]) / 2;
}
/// <summary>
/// 获取世界中心位置 X
/// </summary>
public static float GetWorldCenterX(this RectTransform transform)
{
transform.GetWorldCorners(corners);
return (corners[0].x + corners[2].x) / 2;
}
/// <summary>
/// 获取世界中心位置 Y
/// </summary>
public static float GetWorldCenterY(this RectTransform transform)
{
transform.GetWorldCorners(corners);
return (corners[0].y + corners[2].y) / 2;
}
/// <summary>
/// 获取世界中心位置 Z
/// </summary>
public static float GetWorldCenterZ(this RectTransform transform)
{
transform.GetWorldCorners(corners);
return (corners[0].z + corners[2].z) / 2;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 88964973e0524b3f806e5726a3fd5643
timeCreated: 1679041183

View File

@@ -0,0 +1,276 @@
using System.Text;
using UnityEngine;
using UnityEngine.Assertions;
namespace YIUIFramework
{
/// <summary>
/// <see cref="StringBuilder"/>.
/// </summary>
public static class StringBuilderExtensions
{
// These digits are here in a static array to support hex with simple,
// easily-understandable code. Since A-Z don't sit next to 0-9 in the
// ASCII table.
private static readonly char[] Digits = new char[]
{
'0', '1', '2', '3', '4',
'5', '6', '7', '8', '9',
'A', 'B', 'C', 'D', 'E', 'F'
};
// Matches standard .NET formatting dp's
private static readonly uint DefaultDecimalPlaces = 5;
private static readonly char DefaultPadChar = '0';
/// <summary>
/// Convert a given unsigned integer value to a string and concatenate
/// onto the StringBuilder. Any base value allowed.
/// </summary>
public static StringBuilder Concat(
this StringBuilder builder,
uint uintVal,
uint padAmount,
char padChar,
uint baseVal)
{
Assert.IsTrue(padAmount >= 0);
Assert.IsTrue(baseVal > 0 && baseVal <= 16);
// Calculate length of integer when written out
uint length = 0;
uint lengthCalc = uintVal;
do
{
lengthCalc /= baseVal;
++length;
} while (lengthCalc > 0);
// Pad out space for writing.
builder.Append(padChar, (int)Mathf.Max(padAmount, length));
int strpos = builder.Length;
// We're writing backwards, one character at a time.
while (length > 0)
{
--strpos;
// Lookup from static char array, to cover hex values too
builder[strpos] = Digits[uintVal % baseVal];
uintVal /= baseVal;
--length;
}
return builder;
}
/// <summary>
/// Convert a given unsigned integer value to a string and concatenate
/// onto the StringBuilder. Assume no padding and base ten.
/// </summary>
public static StringBuilder Concat(
this StringBuilder builder, uint uintVal)
{
builder.Concat(uintVal, 0, DefaultPadChar, 10);
return builder;
}
/// <summary>
/// Convert a given unsigned integer value to a string and concatenate
/// onto the StringBuilder. Assume base ten.
/// </summary>
public static StringBuilder Concat(
this StringBuilder builder, uint uintVal, uint padAmount)
{
builder.Concat(uintVal, padAmount, DefaultPadChar, 10);
return builder;
}
/// <summary>
/// Convert a given unsigned integer value to a string and concatenate
/// onto the StringBuilder. Assume base ten.
/// </summary>
public static StringBuilder Concat(
this StringBuilder builder,
uint uintVal,
uint padAmount,
char padChar)
{
builder.Concat(uintVal, padAmount, padChar, 10);
return builder;
}
/// <summary>
/// Convert a given signed integer value to a string and concatenate
/// onto the StringBuilder. Any base value allowed.
/// </summary>
public static StringBuilder Concat(
this StringBuilder builder,
int intVal,
uint padAmount,
char padChar,
uint baseVal)
{
Assert.IsTrue(padAmount >= 0);
Assert.IsTrue(baseVal > 0 && baseVal <= 16);
// Deal with negative numbers
if (intVal < 0)
{
builder.Append('-');
// This is to deal with Int32.MinValue
uint uintVal = uint.MaxValue - ((uint)intVal) + 1;
builder.Concat(uintVal, padAmount, padChar, baseVal);
}
else
{
builder.Concat((uint)intVal, padAmount, padChar, baseVal);
}
return builder;
}
/// <summary>
/// Convert a given signed integer value to a string and concatenate
/// onto the StringBuilder. Assume no padding and base ten.
/// </summary>
public static StringBuilder Concat(
this StringBuilder builder, int intVal)
{
builder.Concat(intVal, 0, DefaultPadChar, 10);
return builder;
}
/// <summary>
/// Convert a given signed integer value to a string and concatenate
/// onto the StringBuilder. Assume base ten.
/// </summary>
public static StringBuilder Concat(
this StringBuilder builder, int intVal, uint padAmount)
{
builder.Concat(intVal, padAmount, DefaultPadChar, 10);
return builder;
}
/// <summary>
/// Convert a given signed integer value to a string and concatenate
/// onto the StringBuilder. Assume base ten.
/// </summary>
public static StringBuilder Concat(
this StringBuilder builder,
int intVal,
uint padAmount,
char padChar)
{
builder.Concat(intVal, padAmount, padChar, 10);
return builder;
}
/// <summary>
/// Convert a given float value to a string and concatenate onto the
/// StringBuilder
/// </summary>
public static StringBuilder Concat(
this StringBuilder builder,
float floatVal,
uint decimalPlaces,
uint padAmount,
char padChar)
{
Assert.IsTrue(padAmount >= 0);
if (decimalPlaces == 0)
{
// No decimal places, just round up and print it as an int
// Agh, Math.Floor() just works on doubles/decimals. Don't want
// to cast! Let's do this the old-fashioned way.
int intVal;
if (floatVal >= 0.0f)
{
// Round up
intVal = (int)(floatVal + 0.5f);
}
else
{
// Round down for negative numbers
intVal = (int)(floatVal - 0.5f);
}
builder.Concat(intVal, padAmount, padChar, 10);
}
else
{
int intPart = (int)floatVal;
// First part is easy, just cast to an integer
builder.Concat(intPart, padAmount, padChar, 10);
// Decimal point
builder.Append('.');
// Work out remainder we need to print after the d.p.
float remainder = Mathf.Abs(floatVal - intPart);
// Multiply up to become an int that we can print
do
{
remainder *= 10;
--decimalPlaces;
} while (decimalPlaces > 0);
// Round up. It's guaranteed to be a positive number, so no
// extra work required here.
remainder += 0.5f;
// All done, print that as an int!
builder.Concat((uint)remainder, 0, '0', 10);
}
return builder;
}
/// <summary>
/// Convert a given float value to a string and concatenate onto the
/// StringBuilder. Assumes five decimal places, and no padding.
/// </summary>
public static StringBuilder Concat(
this StringBuilder builder, float floatVal)
{
builder.Concat(
floatVal, DefaultDecimalPlaces, 0, DefaultPadChar);
return builder;
}
/// <summary>
/// Convert a given float value to a string and concatenate onto the
/// StringBuilder. Assumes no padding.
/// </summary>
public static StringBuilder Concat(
this StringBuilder builder,
float floatVal,
uint decimalPlaces)
{
builder.Concat(floatVal, decimalPlaces, 0, DefaultPadChar);
return builder;
}
/// <summary>
/// Convert a given float value to a string and concatenate onto the
/// StringBuilder.
/// </summary>
public static StringBuilder Concat(
this StringBuilder builder,
float floatVal,
uint decimalPlaces,
uint padAmount)
{
builder.Concat(floatVal, decimalPlaces, padAmount, DefaultPadChar);
return builder;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 055773ae5da5440584d6eda463e00cb6
timeCreated: 1679041183

View File

@@ -0,0 +1,139 @@
using UnityEngine;
namespace YIUIFramework
{
public static class TransformExtensions
{
public static void SetPosition(
this Transform transform, float x, float y, float z)
{
transform.position = new Vector3(x, y, z);
}
public static void SetLocalPosition(
this Transform transform, float x, float y, float z)
{
transform.localPosition = new Vector3(x, y, z);
}
public static void SetLocalScale(
this Transform transform, float x, float y, float z)
{
transform.localScale = new Vector3(x, y, z);
}
public static Transform FindHard(this Transform trans, string path)
{
if (path == string.Empty)
{
return trans;
}
var target = trans;
var names = path.Split('/');
foreach (var name in names)
{
bool find = false;
foreach (Transform child in target)
{
if (child.name == name)
{
target = child;
find = true;
break;
}
}
if (!find)
{
target = null;
break;
}
}
return target;
}
public static Transform FindByName(
this Transform trans, string name1, string name2)
{
if (trans.name.Equals(name1) || trans.name.Equals(name2))
{
return trans;
}
for (int i = 0; i < trans.childCount; ++i)
{
var child = trans.GetChild(i);
var result = FindByName(child, name1, name2);
if (result != null)
{
return result;
}
}
return null;
}
public static Transform FindByName(
this Transform trans,
string name1,
string name2,
string name3)
{
if (trans.name.Equals(name1) ||
trans.name.Equals(name2) ||
trans.name.Equals(name3))
{
return trans;
}
for (int i = 0; i < trans.childCount; ++i)
{
var child = trans.GetChild(i);
var result = FindByName(child, name1, name2, name3);
if (result != null)
{
return result;
}
}
return null;
}
public static Transform FindByName(this Transform trans, string name)
{
if (trans.name == name)
{
return trans;
}
for (int i = 0; i < trans.childCount; ++i)
{
var child = trans.GetChild(i);
var result = FindByName(child, name);
if (result != null)
{
return result;
}
}
return null;
}
public static Transform FindChildByName(this Transform trans, string childName)
{
var childT = trans.Find(childName);
if (childT != null) return childT;
for (int i = 0; i < trans.childCount; i++)
{
childT = FindChildByName(trans.GetChild(i), childName);
if (childT != null) return childT;
}
return null;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d17bb502fad1478db8bf90f7271e1623
timeCreated: 1679041183

View File

@@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Reflection;
namespace YIUIFramework
{
/// <summary>
/// <see cref="System.Type"/>.
/// </summary>
public static class TypeExtensions
{
/// <summary>
/// Check whether the type if a struct
/// </summary>
public static bool IsStruct(this Type type)
{
return type.IsValueType && !type.IsPrimitive && !type.IsEnum;
}
/// <summary>
/// Gets <see cref="FieldInfo"/> including base classes.
/// </summary>
public static FieldInfo[] GetFieldInfosIncludingBaseClasses(
this Type type, BindingFlags bindingFlags)
{
var fieldInfos = type.GetFields(bindingFlags);
if (type.BaseType == typeof(object))
{
return fieldInfos;
}
var fieldInfoList = new List<FieldInfo>(fieldInfos);
while (type.BaseType != typeof(object))
{
type = type.BaseType;
fieldInfos = type.GetFields(bindingFlags);
// Look for fields we do not have listed yet and merge them
// into the main list
foreach (var fieldInfo in fieldInfos)
{
bool found = false;
foreach (var recordField in fieldInfoList)
{
if (recordField.Name == fieldInfo.Name &&
recordField.DeclaringType == fieldInfo.DeclaringType)
{
found = true;
break;
}
}
if (!found)
{
fieldInfoList.Add(fieldInfo);
}
}
}
return fieldInfoList.ToArray();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ba003288a4b040d2a12e1e2a7864e230
timeCreated: 1679041183

View File

@@ -0,0 +1,22 @@
using UnityEngine;
namespace YIUIFramework
{
public static class UnityObjectExtensions
{
public static void SafeDestroySelf(
this Object obj)
{
if (obj == null) return;
#if UNITY_EDITOR
if (!Application.isPlaying)
Object.DestroyImmediate(obj);
else
Object.Destroy(obj);
#else
Object.Destroy(obj);
#endif
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: def020af107b4215a45d6a16deae0dda
timeCreated: 1679041183

View File

@@ -0,0 +1,53 @@
using System;
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// <see cref="UnityEngine.Vector2"/>.
/// </summary>
public static class Vector2Extensions
{
/// <summary>
/// Parse Vector2 from a string.
/// </summary>
public static Vector2 Parse(string text)
{
Vector2 value;
if (!TryParse(text, out value))
{
var msg = string.Format(
"The string {0} can not convert to Rect.", text);
throw new FormatException(msg);
}
return value;
}
/// <summary>
/// Try to parse Vector2 from a string.
/// </summary>
public static bool TryParse(string text, out Vector2 v)
{
if (text.Length < 2 ||
text[0] != '(' ||
text[text.Length - 1] != ')')
{
v = Vector2.zero;
return false;
}
var elements = text.Substring(1, text.Length - 2).Split(',');
if (elements.Length != 2)
{
v = Vector2.zero;
return false;
}
float x = float.Parse(elements[0]);
float y = float.Parse(elements[1]);
v = new Vector2(x, y);
return true;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0eb3073cc14c4083a8dd642774507315
timeCreated: 1679041183

View File

@@ -0,0 +1,54 @@
using System;
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// <see cref="UnityEngine.Vector3"/>.
/// </summary>
public static class Vector3Extensions
{
/// <summary>
/// Parse Vector3 from a string.
/// </summary>
public static Vector3 Parse(string text)
{
Vector3 value;
if (!TryParse(text, out value))
{
var msg = string.Format(
"The string {0} can not convert to Rect.", text);
throw new FormatException(msg);
}
return value;
}
/// <summary>
/// Try to parse Vector3 from a string.
/// </summary>
public static bool TryParse(string text, out Vector3 v)
{
if (text.Length < 2 ||
text[0] != '(' ||
text[text.Length - 1] != ')')
{
v = Vector3.zero;
return false;
}
var elements = text.Substring(1, text.Length - 2).Split(',');
if (elements.Length != 3)
{
v = Vector3.zero;
return false;
}
float x = float.Parse(elements[0]);
float y = float.Parse(elements[1]);
float z = float.Parse(elements[2]);
v = new Vector3(x, y, z);
return true;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: cd59ae2e96fb4d30a4c52e771688bcf1
timeCreated: 1679041183

View File

@@ -0,0 +1,55 @@
using System;
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// <see cref="UnityEngine.Vector4"/>.
/// </summary>
public static class Vector4Extensions
{
/// <summary>
/// Parse Vector4 from a string.
/// </summary>
public static Vector4 Parse(string text)
{
Vector4 value;
if (!TryParse(text, out value))
{
var msg = string.Format(
"The string {0} can not convert to Rect.", text);
throw new FormatException(msg);
}
return value;
}
/// <summary>
/// Try to parse Vector4 from a string.
/// </summary>
public static bool TryParse(string text, out Vector4 v)
{
if (text.Length < 2 ||
text[0] != '(' ||
text[text.Length - 1] != ')')
{
v = Vector4.zero;
return false;
}
var elements = text.Substring(1, text.Length - 2).Split(',');
if (elements.Length != 4)
{
v = Vector4.zero;
return false;
}
float x = float.Parse(elements[0]);
float y = float.Parse(elements[1]);
float z = float.Parse(elements[2]);
float w = float.Parse(elements[3]);
v = new Vector4(x, y, z, w);
return true;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5d17403b8e9e4fcfab6d272865eb9937
timeCreated: 1679041183

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1938d733cecd4d57af9c7c5c9aa280de
timeCreated: 1679038577

View File

@@ -0,0 +1,15 @@
using System;
namespace YIUIFramework
{
/// <summary>
/// ID 助手 生成唯一ID
/// </summary>
public static class IDHelper
{
public static int GetGuid()
{
return Guid.NewGuid().GetHashCode();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e3f727fdf4894a82b6d58cbc84ea6cb2
timeCreated: 1689078504

View File

@@ -0,0 +1,74 @@
using UnityEngine;
using Object = UnityEngine.Object;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace YIUIFramework
{
/// <summary>
/// 日志封装@l
/// </summary>
public static class Logger
{
public static void Log(object message)
{
Debug.Log(message);
}
public static void Log(string format, params object[] args)
{
Debug.LogFormat(format, args);
}
public static void LogWarning(object message)
{
Debug.LogWarning(message);
}
public static void LogWarning(string format, params object[] args)
{
Debug.LogWarningFormat(format, args);
}
public static void LogError(object message)
{
Debug.LogError(message);
}
public static void LogError(string format, params object[] args)
{
Debug.LogErrorFormat(format, args);
}
public static void LogErrorContext(Object context, object message)
{
Debug.LogError(message, context);
}
public static void LogWarningContext(Object context, object message)
{
Debug.LogWarning(message, context);
}
public static void LogErrorContextFormat(Object context, string format, params object[] args)
{
Debug.LogErrorFormat(context, format, args);
}
public static void LogError(Object obj, object message)
{
#if UNITY_EDITOR
SelectObj(obj);
#endif
Debug.LogError(message);
}
#if UNITY_EDITOR
public static void SelectObj(Object obj)
{
Selection.activeObject = obj;
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6d48c96345004f669f57a59fc73f8a3b
timeCreated: 1679038968

View File

@@ -0,0 +1,127 @@
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace YIUIFramework
{
/// <summary>
/// 检查是否可以进行UI操作
/// </summary>
public static class UIOperationHelper
{
public static bool IsPlaying()
{
if (Application.isPlaying)
{
//编辑时点结束的一瞬间 还是在运行中的 所以要判断是否正在退出
//如果正在退出 算非运行
if (SingletonMgr.IsQuitting)
{
return false;
}
return true;
}
#if UNITY_EDITOR
//编辑器时 点开始的一瞬间是不算正在运行的 在我这里算运行中
return EditorApplication.isPlayingOrWillChangePlaymode;
#endif
return false;
}
public static bool RunTimeCheckIsPlaying(bool log = true)
{
if (IsPlaying())
{
if (log)
Debug.LogError($"当前正在运行时 请不要在运行时使用");
return false;
}
return true;
}
#if UNITY_EDITOR
//UI通用判断 运行时是否可显示
//通过切换宏可以在运行时提供可修改
public static bool CommonShowIf()
{
#if YIUIMACRO_BIND_RUNTIME_EDITOR
return true;
#endif
if (IsPlaying())
{
return false;
}
return true;
}
//运行时不可用
public static bool CheckUIOperation(bool log = true)
{
if (IsPlaying())
{
if (log)
UnityTipsHelper.ShowError($"当前正在运行时 请不要在运行时使用");
return false;
}
return true;
}
public static bool CheckUIOperation(Object obj, bool log = true)
{
if (IsPlaying())
{
if (log)
UnityTipsHelper.ShowErrorContext(obj, $"当前正在运行时 请不要在运行时使用");
return false;
}
var checkInstance = PrefabUtility.IsPartOfPrefabInstance(obj);
if (checkInstance)
{
if (log)
UnityTipsHelper.ShowErrorContext(obj, $"不能对实体进行操作 必须进入预制体编辑!!!");
return false;
}
return true;
}
public static bool CheckUIOperationAll(Object obj, bool log = true)
{
if (IsPlaying())
{
if (log)
UnityTipsHelper.ShowErrorContext(obj, $"当前正在运行时 请不要在运行时使用");
return false;
}
var checkInstance = PrefabUtility.IsPartOfPrefabInstance(obj);
if (checkInstance)
{
if (log)
UnityTipsHelper.ShowErrorContext(obj, $"不能对实体进行操作 必须进入预制体编辑!!!");
return false;
}
var checkAsset = PrefabUtility.IsPartOfPrefabAsset(obj);
if (!checkAsset)
{
if (log)
UnityTipsHelper.ShowErrorContext(obj, $"1: 必须是预制体 2: 不能在Hierarchy面板中使用 必须在Project面板下的预制体原件才能使用使用 ");
return false;
}
return true;
}
#endif
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: f4be78be90914636ba403ff49dcd9c36
timeCreated: 1682408026

View File

@@ -0,0 +1,138 @@
using System;
using Object = UnityEngine.Object;
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
#endif
namespace YIUIFramework
{
/// <summary>
/// Unity提示框@sy
/// </summary>
public static class UnityTipsHelper
{
/// <summary>
/// 展示提示
/// </summary>
/// <param name="content"></param>
public static void Show(string content)
{
#if UNITY_EDITOR
EditorUtility.DisplayDialog("提示", content, "确认");
#endif
}
/// <summary>
/// 提示 同时error 报错
/// </summary>
public static void ShowError(string message)
{
#if UNITY_EDITOR
Show(message);
Logger.LogError(message);
#endif
}
/// <summary>
/// 提示 同时error 报错
/// </summary>
public static void ShowError(object message)
{
#if UNITY_EDITOR
Show(message.ToString());
Logger.LogError(message);
#endif
}
/// <summary>
/// 提示 同时error 报错
/// </summary>
public static void ShowErrorContext(Object context, string message)
{
#if UNITY_EDITOR
Show(message);
Logger.LogErrorContext(context, message);
#endif
}
/// <summary>
/// 提示 同时error 报错
/// </summary>
public static void ShowErrorContext(Object context, object message)
{
#if UNITY_EDITOR
Show(message.ToString());
Logger.LogErrorContext(context, message);
#endif
}
/// <summary>
/// 确定 取消 回调的提示框
/// </summary>
public static void CallBack(string content, Action okCallBack, Action cancelCallBack = null)
{
#if UNITY_EDITOR
var selectIndex = EditorUtility.DisplayDialogComplex("提示", content, "确认", "取消", null);
if (selectIndex == 0) //确定
{
try
{
okCallBack?.Invoke();
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
else
{
try
{
cancelCallBack?.Invoke();
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
#endif
}
/// <summary>
/// 只有确定的提示框
/// </summary>
public static void CallBackOk(string content, Action okCallBack, Action cancelCallBack = null)
{
#if UNITY_EDITOR
var result = EditorUtility.DisplayDialog("提示", content, "确认");
if (result) //确定
{
try
{
okCallBack?.Invoke();
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
else
{
try
{
cancelCallBack?.Invoke();
}
catch (Exception e)
{
Logger.LogError(e);
throw;
}
}
#endif
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2c4b46307b99428f931c06158c6bc800
timeCreated: 1679022167

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 32de73b17d47495896ec54442d4a2bf3
timeCreated: 1681720464

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace YIUIFramework
{
public static class AppDomainExt
{
/// <summary>
/// 得到对应Assembly名字内所有type的集合
/// 例: GetTypesByDllName("Framework")
/// </summary>
/// <param name="owner"></param>
/// <param name="names"></param>
/// <returns></returns>
public static Type[] GetTypesByAssemblyName(this AppDomain owner, params string[] names)
{
if (names.Length < 1)
{
return Array.Empty<Type>();
}
var nameMap = new Dictionary<string, bool>(names.Length);
foreach (string assemblyName in names)
{
nameMap[assemblyName] = true;
}
List<Type> allType = new List<Type>();
Assembly[] assemblyArr = owner.GetAssemblies();
foreach (Assembly assembly in assemblyArr)
{
if (!nameMap.ContainsKey(assembly.GetName().Name))
{
continue;
}
allType.AddRange(assembly.GetTypes());
}
return allType.ToArray();
}
/// <summary>
/// 得到一个域下的所有实现interfaceType的类型
/// </summary>
/// <param name="owner"></param>
/// <param name="interfaceType"></param>
/// <returns></returns>
public static Type[] GetTypesByInterface(this AppDomain owner, Type interfaceType)
{
return AppDomain.CurrentDomain.GetAssemblies().SelectMany(a =>
{
return a.GetTypes()
.Where(t => t.GetInterfaces()
.Contains(interfaceType));
}).ToArray();
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: ef0dd73e8d4e44f28b9cc9478fa34c84
timeCreated: 1681720464

View File

@@ -0,0 +1,56 @@
using System;
namespace YIUIFramework
{
public partial class AppTick
{
private static readonly AppTick g_inst = new AppTick();
public static int Count
{
get { return g_inst.Get(); }
}
}
/// <summary>
/// 为了解决系统的TickCount时间不足问题
/// 这个Tick是从第一次调用开始计数
/// 注意,为了性能,所以没有加锁
/// 所以线程不安全
/// </summary>
public partial class AppTick
{
private int m_lastTick;
private int m_count;
public AppTick()
{
m_lastTick = Environment.TickCount;
}
/// <summary>
/// 单位是MS
/// 可以支撑程序跑24.9天不翻转
/// 如果他真的一直开着应用24天我认了
/// 这里不把单位定成uint,以让他支持48天
/// 是因为多了代码转换考虑到24天已经足够用
/// 并且这个方法是会频繁调用,所以越简单越好
/// </summary>
public int Get()
{
int cur = Environment.TickCount;
if (cur < m_lastTick)
{
m_count += int.MaxValue - m_lastTick;
m_count += cur - int.MinValue;
}
else
{
m_count += cur - m_lastTick;
}
m_lastTick = cur;
return m_count;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1453d57101cb4929863b7d503c949455
timeCreated: 1681720464

View File

@@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using Logger = YIUIFramework.Logger;
namespace YIUIFramework
{
/// <summary>
/// 用于只等待一次的延迟计时器。
/// </summary>
public sealed class DelayTimer : IDisposable
{
private LinkedListNode<Action> updateHandle;
private float delayTime;
private float leftTime;
private Action task;
/// <summary>
/// 在指定秒后调用任务
/// </summary>
/// <param name="delay">调用任务的时间</param>
/// <param name="task">要执行的任务</param>
public static DelayTimer Delay(float delay, Action task)
{
var timer = new DelayTimer();
timer.delayTime = delay;
timer.task = task;
timer.Start();
return timer;
}
public void Dispose()
{
SchedulerMgr.RemoveFrameListener(this.updateHandle);
this.updateHandle = null;
}
private void Start()
{
this.leftTime = this.delayTime;
this.updateHandle = SchedulerMgr.AddFrameListener(this.Update);
}
private void Update()
{
this.leftTime -= Time.deltaTime;
if (this.leftTime <= 0.0f)
{
try
{
this.task?.Invoke();
}
catch (Exception e)
{
Logger.LogError(e);
}
finally
{
this.Dispose();
}
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a2ee27bc48f44dfd8a3680237a22a5ac
timeCreated: 1679041382

View File

@@ -0,0 +1,23 @@
namespace YIUIFramework
{
/// <summary>
/// 静态获取对应空值的类型
/// </summary>
public static class EmptyValue<T> where T : new()
{
private static T g_value;
public static T Value
{
get
{
if (g_value == null)
{
g_value = new T();
}
return g_value;
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 7a26fef3d4284b65a557593f6cf42db9
timeCreated: 1681720464

View File

@@ -0,0 +1,50 @@
namespace YIUIFramework
{
/// <summary>
/// The utility class help for CPU endian transform.
/// </summary>
public static class Endian
{
/// <summary>
/// Reverse the bytes order (16-bit).
/// </summary>
/// <param name="value">The value wait for reverse.</param>
/// <returns>The reversed byte.</returns>
public static ushort ReverseBytes(ushort value)
{
return (ushort)((value & 0xFFU) << 8 | (value & 0xFF00U) >> 8);
}
/// <summary>
/// Reverse the bytes order (32-bit).
/// </summary>
/// <param name="value">The value wait for reverse.</param>
/// <returns>The reversed byte.</returns>
public static uint ReverseBytes(uint value)
{
return
(value & 0x000000FFU) << 24 |
(value & 0x0000FF00U) << 8 |
(value & 0x00FF0000U) >> 8 |
(value & 0xFF000000U) >> 24;
}
/// <summary>
/// Reverse the bytes order (64-bit).
/// </summary>
/// <param name="value">The value wait for reverse.</param>
/// <returns>The reversed byte.</returns>
public static ulong ReverseBytes(ulong value)
{
return
(value & 0x00000000000000FFUL) << 56 |
(value & 0x000000000000FF00UL) << 40 |
(value & 0x0000000000FF0000UL) << 24 |
(value & 0x00000000FF000000UL) << 8 |
(value & 0x000000FF00000000UL) >> 8 |
(value & 0x0000FF0000000000UL) >> 24 |
(value & 0x00FF000000000000UL) >> 40 |
(value & 0xFF00000000000000UL) >> 56;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e4d0485b01714b68a2ea7f4246fcf87b
timeCreated: 1679041382

View File

@@ -0,0 +1,56 @@
using System;
using System.Reflection;
using UnityEngine;
namespace YIUIFramework
{
/// <summary>
/// 支持光线投射与网格。
/// </summary>
public static class GeometryUtilityHelper
{
private static readonly Action<Plane[], Matrix4x4>
ExtractPlanesDelegate;
static GeometryUtilityHelper()
{
var methodInfo = typeof(GeometryUtility).GetMethod(
"Internal_ExtractPlanes",
BindingFlags.NonPublic | BindingFlags.Static);
if (methodInfo != null)
{
ExtractPlanesDelegate = (Action<Plane[], Matrix4x4>)
Delegate.CreateDelegate(
typeof(Action<Plane[], Matrix4x4>),
methodInfo,
false);
}
}
/// <summary>
/// Extract the planes.
/// </summary>
public static void ExtractPlanes(Plane[] planes, Camera camera)
{
var mat = camera.projectionMatrix * camera.worldToCameraMatrix;
ExtractPlanes(planes, mat);
}
/// <summary>
/// Extract the planes.
/// </summary>
public static void ExtractPlanes(
Plane[] planes, Matrix4x4 worldToProjectionMatrix)
{
if (ExtractPlanesDelegate != null)
{
ExtractPlanesDelegate(planes, worldToProjectionMatrix);
}
else
{
GeometryUtility.CalculateFrustumPlanes(
worldToProjectionMatrix, planes);
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 2bdab850f1354f8f84a0819bc2df880c
timeCreated: 1679041383

View File

@@ -0,0 +1,10 @@
namespace YIUIFramework
{
/// <summary>
/// 时间提供器
/// </summary>
public interface ITimeProvider
{
int Time { get; }
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a047931866164c1bae6cda0c00bcb292
timeCreated: 1681720464

View File

@@ -0,0 +1,47 @@
using System.Collections.Generic;
using System.Linq;
namespace YIUIFramework
{
/// <summary>
/// The list comparer.
/// </summary>
public sealed class ListComparer<T> : IEqualityComparer<List<T>>
{
private static volatile ListComparer<T> defaultComparer;
/// <summary>
/// Gets a default instance of the <see cref="ListComparer{T}"/>.
/// </summary>
public static ListComparer<T> Default
{
get
{
if (defaultComparer == null)
{
defaultComparer = new ListComparer<T>();
}
return defaultComparer;
}
}
/// <inheritdoc />
public bool Equals(List<T> x, List<T> y)
{
return x.SequenceEqual(y);
}
/// <inheritdoc />
public int GetHashCode(List<T> obj)
{
int hashcode = 0;
foreach (T t in obj)
{
hashcode ^= t.GetHashCode();
}
return hashcode;
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 73cedaab2e584912b039630ae9e446a5
timeCreated: 1679041382

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: c11e918a1c5c44069ae4bfef8ea9b007
timeCreated: 1711881986

View File

@@ -0,0 +1,43 @@
using System;
using System.Threading;
using Cysharp.Threading.Tasks;
namespace YIUIFramework
{
public class AsyncLockComponent : IDisposable, IRefPool
{
private readonly SemaphoreSlim m_Semaphore = new SemaphoreSlim(1, 1);
private long m_Key;
private int m_MillisecondsTimeout;
public AsyncLockComponent()
{
}
public void Reset(long key, int millisecondsTimeout = -1)
{
m_Key = key;
m_MillisecondsTimeout = millisecondsTimeout;
}
public async UniTask<AsyncLockComponent> WaitAsync()
{
await m_Semaphore.WaitAsync(m_MillisecondsTimeout);
return this;
}
public void Dispose()
{
m_Semaphore.Release();
if (AsyncLockMgr.Inst.Release(m_Key))
{
RefPool.Put(this);
}
}
public void Recycle()
{
Reset(0);
}
}
}

Some files were not shown because too many files have changed in this diff Show More