修复BUG

This commit is contained in:
MuHua-123
2025-01-17 12:13:18 +08:00
parent 98187f2ced
commit 7f4071505d
9 changed files with 32 additions and 66 deletions
@@ -35,3 +35,24 @@ public class ModuleAssets<Data> {
/// <summary> 循环列表 </summary>
public virtual void ForEach(Action<Data> action) => Datas.ForEach(action);
}
/// <summary>
/// 资源模块工具
/// </summary>
public static class ModuleAssetsTool {
/// <summary> 头尾循环标准化索引 </summary>
public static Data LoopIndex<Data>(this ModuleAssets<Data> assets, int index) {
return assets[LoopIndex(index, assets.Count)];
}
/// <summary> 头尾循环标准化索引 </summary>
public static Data LoopIndex<Data>(this List<Data> list, int index) {
return list[LoopIndex(index, list.Count)];
}
/// <summary> 头尾循环标准化索引 </summary>
public static Data LoopIndex<Data>(this Data[] array, int index) {
return array[LoopIndex(index, array.Length)];
}
/// <summary> 头尾循环标准化索引 </summary>
public static int LoopIndex(int index, int maxIndex) {
return index % maxIndex;
}
}
+11
View File
@@ -8,3 +8,14 @@ using UnityEngine;
public class ModuleCore : Module<ModuleCore> {
}
/// <summary>
/// 模块基类
/// </summary>
/// <typeparam name="ModuleCore"></typeparam>
public class Module<ModuleCore> where ModuleCore : Module<ModuleCore>, new() {
/// <summary> 模块单例 </summary>
public static ModuleCore I => Instantiate();
private static ModuleCore core;
private static ModuleCore Instantiate() => core == null ? core = new ModuleCore() : core;
}