This commit is contained in:
lujiajian 2025-11-05 09:17:21 +08:00
parent 08ecf8d7dc
commit 3edd635583
3 changed files with 462 additions and 372 deletions

View File

@ -24,11 +24,6 @@ namespace Framework.Manager
[SerializeField] [SerializeField]
private TutorialGuideConfig guideConfig; private TutorialGuideConfig guideConfig;
[Space(5)]
[Tooltip("是否启用引导跳转功能")]
[SerializeField]
private bool enableSmartGuideJump = true;
[Space(10)] [Space(10)]
[Header("状态信息")] [Header("状态信息")]
[SerializeField, ReadOnly] [SerializeField, ReadOnly]
@ -38,11 +33,6 @@ namespace Framework.Manager
// [SerializeField, ReadOnly] private bool isGuideDisabled = false; // [SerializeField, ReadOnly] private bool isGuideDisabled = false;
[Space(5)]
[Tooltip("是否启用UI显示状态检测")]
[SerializeField]
private bool enableUIStateCheck = true;
// 运行时存储UI对象的字典 // 运行时存储UI对象的字典
private Dictionary<string, GameObject> uiObjects = new Dictionary<string, GameObject>(); private Dictionary<string, GameObject> uiObjects = new Dictionary<string, GameObject>();
@ -52,15 +42,9 @@ namespace Framework.Manager
// ProcessManager引用用于获取当前流程步骤信息 // ProcessManager引用用于获取当前流程步骤信息
// private ProcessManager processManager; // private ProcessManager processManager;
// 记录已匹配引导的步骤名称,避免同一步骤内重复匹配
private string lastMatchedStepName = string.Empty;
// 记录被隐藏但需要重新显示的步骤名称 // 记录被隐藏但需要重新显示的步骤名称
private HashSet<string> hiddenStepsToRedisplay = new HashSet<string>(); private HashSet<string> hiddenStepsToRedisplay = new HashSet<string>();
// 记录当前步骤名称下已执行的引导数量,用于支持同一步骤下的多个引导按顺序执行
private Dictionary<string, int> stepExecutionCount = new Dictionary<string, int>();
// 安全帽点击特殊处理状态 // 安全帽点击特殊处理状态
private bool hasHelmetClicked = false; // 是否已点击安全帽 private bool hasHelmetClicked = false; // 是否已点击安全帽
private string helmetClickedObjectName = string.Empty; // 点击的安全帽对象名称 private string helmetClickedObjectName = string.Empty; // 点击的安全帽对象名称
@ -474,6 +458,107 @@ namespace Framework.Manager
} }
} }
/// <summary>
/// 验证UI名称匹配
/// </summary>
/// <returns>如果应该继续引导返回true如果应该停止返回false如果不需要验证返回null</returns>
private bool? ValidateUINameMatch(string uiName)
{
if (string.IsNullOrEmpty(uiName))
{
if (uiName == "")
{
Debug.Log("TutorialGuideManager: 传入空字符串,自动跳到下一步引导");
}
else
{
Debug.Log("TutorialGuideManager: 未传入uiName参数使用原有引导逻辑");
}
return null;
}
var currentStep = GetCurrentStep();
if (currentStep == null)
{
Debug.LogWarning("TutorialGuideManager: 无法获取当前引导步骤,跳过参数匹配检查");
return false;
}
// 处理特殊UI名称
if (uiName == "下一步")
{
return null; // 继续执行
}
if (IsSpecialUIName(uiName))
{
return HandleSpecialUIName(uiName, currentStep);
}
// 普通UI名称匹配
if (uiName != currentStep.uiObjectName)
{
Debug.Log($"TutorialGuideManager: 参数匹配失败 - 传入的uiName: '{uiName}' 与当前步骤的uiObjectName: '{currentStep.uiObjectName}' 不匹配,停止引导");
return false;
}
Debug.Log($"TutorialGuideManager: 参数匹配成功 - 传入的uiName: '{uiName}' 与当前步骤的uiObjectName: '{currentStep.uiObjectName}' 匹配,继续引导");
return null; // 继续执行
}
/// <summary>
/// 检查是否为特殊UI名称
/// </summary>
private bool IsSpecialUIName(string uiName)
{
return uiName == "大厅位置" || uiName == "地磅位置" || uiName == "电脑房" || uiName == "关闭" || uiName == "对话";
}
/// <summary>
/// 处理特殊UI名称
/// </summary>
private bool HandleSpecialUIName(string uiName, GuideStepConfig currentStep)
{
if (uiName != currentStep.uiObjectName)
{
return false;
}
if (uiName != "对话")
{
currentIndex++;
}
HideGuide();
return true;
}
/// <summary>
/// 执行引导步骤
/// </summary>
private async UniTask<bool> ExecuteGuideStep(GuideStepConfig currentStep)
{
if (uiObjects.TryGetValue(currentStep.uiObjectName, out GameObject uiObject))
{
if (IsUIObjectFullyDisplayed(uiObject))
{
Debug.Log($"执行引导步骤: {currentStep.stepName} 查询的对象:{uiObject.name}");
GuideMask.Instance.CreateRectangleMask(uiObject);
FocusInputFieldIfApplicable(uiObject);
return true;
}
else
{
Debug.Log($"UI对象 {uiObject.name} 存在但未完全显示,使用延迟查找");
return await DelayedFindUIObjectAsync(currentStep);
}
}
else
{
return await DelayedFindUIObjectAsync(currentStep);
}
}
//触发上一个引导步骤 //触发上一个引导步骤
public async UniTask<bool> TriggerPrevGuide() public async UniTask<bool> TriggerPrevGuide()
{ {
@ -722,9 +807,7 @@ namespace Framework.Manager
{ {
isGuiding = false; isGuiding = false;
currentIndex = -1; currentIndex = -1;
lastMatchedStepName = string.Empty; // 清除已匹配步骤记录
hiddenStepsToRedisplay.Clear(); // 清除待重新显示步骤记录 hiddenStepsToRedisplay.Clear(); // 清除待重新显示步骤记录
stepExecutionCount.Clear(); // 清除步骤执行计数记录
// 重置安全帽点击状态 // 重置安全帽点击状态
hasHelmetClicked = false; hasHelmetClicked = false;
@ -882,18 +965,19 @@ namespace Framework.Manager
/// 触发当前UI对象的事件 /// 触发当前UI对象的事件
/// 自动检测UI组件类型并触发相应的事件 /// 自动检测UI组件类型并触发相应的事件
/// </summary> /// </summary>
/// <returns>是否成功触发了事件</returns>
public void TriggerCurrentUIEvent() public void TriggerCurrentUIEvent()
{ {
var currentStep = GetCurrentStep(); var currentStep = GetCurrentStep();
if (currentStep == null) if (currentStep == null)
{ {
Debug.LogWarning("TutorialGuideManager: 无法获取当前引导步骤无法触发UI事件"); Debug.LogWarning("TutorialGuideManager: 无法获取当前引导步骤无法触发UI事件");
return;
} }
if (!uiObjects.TryGetValue(currentStep.uiObjectName, out GameObject uiObject)) if (!uiObjects.TryGetValue(currentStep.uiObjectName, out GameObject uiObject))
{ {
Debug.LogWarning($"TutorialGuideManager: 当前UI对象 {currentStep.uiObjectName} 未注册,无法触发事件"); Debug.LogWarning($"TutorialGuideManager: 当前UI对象 {currentStep.uiObjectName} 未注册,无法触发事件");
return;
} }
Debug.Log($"TutorialGuideManager: 开始触发UI对象 {currentStep.uiObjectName} 的事件"); Debug.Log($"TutorialGuideManager: 开始触发UI对象 {currentStep.uiObjectName} 的事件");
@ -1453,7 +1537,6 @@ namespace Framework.Manager
var orderedSteps = guideConfig.GetOrderedSteps(); var orderedSteps = guideConfig.GetOrderedSteps();
int count = 0; int count = 0;
string lastNonEmptyStepName = string.Empty;
bool foundTargetStep = false; bool foundTargetStep = false;
// 遍历所有步骤,计算指定步骤名称下的引导数量 // 遍历所有步骤,计算指定步骤名称下的引导数量
@ -1469,18 +1552,12 @@ namespace Framework.Manager
{ {
foundTargetStep = true; foundTargetStep = true;
count++; count++;
lastNonEmptyStepName = step.stepName;
} }
// 如果已经找到目标步骤,但遇到了新的步骤名称,停止计数 // 如果已经找到目标步骤,但遇到了新的步骤名称,停止计数
else if (foundTargetStep) else if (foundTargetStep)
{ {
break; break;
} }
// 更新lastNonEmptyStepName
else
{
lastNonEmptyStepName = step.stepName;
}
} }
// 如果当前步骤的stepName为空 // 如果当前步骤的stepName为空
else else
@ -1497,7 +1574,6 @@ namespace Framework.Manager
if (count == 0) if (count == 0)
{ {
foundTargetStep = false; foundTargetStep = false;
lastNonEmptyStepName = string.Empty;
for (int i = 0; i < orderedSteps.Count; i++) for (int i = 0; i < orderedSteps.Count; i++)
{ {
@ -1509,16 +1585,11 @@ namespace Framework.Manager
{ {
foundTargetStep = true; foundTargetStep = true;
count++; count++;
lastNonEmptyStepName = step.stepName;
} }
else if (foundTargetStep) else if (foundTargetStep)
{ {
break; break;
} }
else
{
lastNonEmptyStepName = step.stepName;
}
} }
else if (foundTargetStep) else if (foundTargetStep)
{ {
@ -1553,106 +1624,17 @@ namespace Framework.Manager
} }
var orderedSteps = guideConfig.GetOrderedSteps(); var orderedSteps = guideConfig.GetOrderedSteps();
List<int> matchedIndices = FindExactMatchIndices(orderedSteps, stepName);
// 收集所有匹配的引导步骤索引
List<int> matchedIndices = new List<int>();
string lastNonEmptyStepName = string.Empty;
bool foundTargetStep = false;
// 精确匹配(包括顺序延续逻辑)
for (int i = 0; i < orderedSteps.Count; i++)
{
var step = orderedSteps[i];
// 如果当前步骤的stepName不为空
if (!string.IsNullOrEmpty(step.stepName))
{
// 如果找到了目标步骤,开始收集
if (step.stepName == stepName)
{
foundTargetStep = true;
matchedIndices.Add(i);
lastNonEmptyStepName = step.stepName;
Debug.Log($"TutorialGuideManager: 精确匹配找到引导步骤: 索引={i}, stepName='{step.stepName}', uiObjectName='{step.uiObjectName}'");
}
// 如果已经找到目标步骤,但遇到了新的步骤名称,停止收集
else if (foundTargetStep)
{
break;
}
// 更新lastNonEmptyStepName
else
{
lastNonEmptyStepName = step.stepName;
}
}
// 如果当前步骤的stepName为空
else
{
// 如果已经找到目标步骤,继续收集(顺序延续)
if (foundTargetStep)
{
matchedIndices.Add(i);
Debug.Log($"TutorialGuideManager: 顺序延续找到引导步骤: 索引={i}, stepName='{step.stepName}', uiObjectName='{step.uiObjectName}', lastNonEmptyStepName='{lastNonEmptyStepName}'");
}
}
}
// 如果精确匹配没有结果,尝试包含匹配 // 如果精确匹配没有结果,尝试包含匹配
if (matchedIndices.Count == 0) if (matchedIndices.Count == 0)
{ {
foundTargetStep = false; matchedIndices = FindContainsMatchIndices(orderedSteps, stepName);
lastNonEmptyStepName = string.Empty;
for (int i = 0; i < orderedSteps.Count; i++)
{
var step = orderedSteps[i];
if (!string.IsNullOrEmpty(step.stepName))
{
if (step.stepName.Contains(stepName))
{
foundTargetStep = true;
matchedIndices.Add(i);
lastNonEmptyStepName = step.stepName;
Debug.Log($"TutorialGuideManager: 包含匹配找到引导步骤: 索引={i}, stepName='{step.stepName}', uiObjectName='{step.uiObjectName}'");
}
else if (foundTargetStep)
{
break;
}
else
{
lastNonEmptyStepName = step.stepName;
}
}
else if (foundTargetStep)
{
matchedIndices.Add(i);
Debug.Log($"TutorialGuideManager: 包含匹配顺序延续找到引导步骤: 索引={i}, stepName='{step.stepName}', uiObjectName='{step.uiObjectName}', lastNonEmptyStepName='{lastNonEmptyStepName}'");
}
}
} }
Debug.Log($"TutorialGuideManager: 步骤名称 '{stepName}' 总共找到 {matchedIndices.Count} 个匹配的引导步骤"); Debug.Log($"TutorialGuideManager: 步骤名称 '{stepName}' 总共找到 {matchedIndices.Count} 个匹配的引导步骤");
// 根据执行索引返回对应的引导步骤 return SelectGuideIndexByExecutionIndex(matchedIndices, orderedSteps, stepName, executionIndex);
if (executionIndex >= 0 && executionIndex < matchedIndices.Count)
{
int guideIndex = matchedIndices[executionIndex];
Debug.Log($"TutorialGuideManager: 找到匹配的引导步骤: {stepName} -> 执行索引: {executionIndex}, 引导索引: {guideIndex}, UI对象: {orderedSteps[guideIndex].uiObjectName}");
return guideIndex;
}
else if (matchedIndices.Count > 0)
{
// 如果执行索引超出范围,说明该步骤的所有引导都已执行完毕
// 返回-1让系统按顺序继续执行下一个引导而不是返回第一个匹配的
Debug.Log($"TutorialGuideManager: 执行索引超出范围,步骤 '{stepName}' 的所有引导步骤已执行完毕,将按顺序继续");
return -1;
}
Debug.Log($"TutorialGuideManager: 未找到匹配的引导步骤: {stepName}");
return -1;
} }
catch (System.Exception ex) catch (System.Exception ex)
{ {
@ -1661,6 +1643,109 @@ namespace Framework.Manager
} }
} }
/// <summary>
/// 查找精确匹配的引导步骤索引(包括顺序延续逻辑)
/// </summary>
private List<int> FindExactMatchIndices(List<GuideStepConfig> orderedSteps, string stepName)
{
List<int> matchedIndices = new List<int>();
bool foundTargetStep = false;
string lastNonEmptyStepName = string.Empty;
for (int i = 0; i < orderedSteps.Count; i++)
{
var step = orderedSteps[i];
if (!string.IsNullOrEmpty(step.stepName))
{
if (step.stepName == stepName)
{
foundTargetStep = true;
matchedIndices.Add(i);
lastNonEmptyStepName = step.stepName;
Debug.Log($"TutorialGuideManager: 精确匹配找到引导步骤: 索引={i}, stepName='{step.stepName}', uiObjectName='{step.uiObjectName}'");
}
else if (foundTargetStep)
{
break;
}
else
{
lastNonEmptyStepName = step.stepName;
}
}
else if (foundTargetStep)
{
matchedIndices.Add(i);
Debug.Log($"TutorialGuideManager: 顺序延续找到引导步骤: 索引={i}, stepName='{step.stepName}', uiObjectName='{step.uiObjectName}', lastNonEmptyStepName='{lastNonEmptyStepName}'");
}
}
return matchedIndices;
}
/// <summary>
/// 查找包含匹配的引导步骤索引(包括顺序延续逻辑)
/// </summary>
private List<int> FindContainsMatchIndices(List<GuideStepConfig> orderedSteps, string stepName)
{
List<int> matchedIndices = new List<int>();
bool foundTargetStep = false;
string lastNonEmptyStepName = string.Empty;
for (int i = 0; i < orderedSteps.Count; i++)
{
var step = orderedSteps[i];
if (!string.IsNullOrEmpty(step.stepName))
{
if (step.stepName.Contains(stepName))
{
foundTargetStep = true;
matchedIndices.Add(i);
lastNonEmptyStepName = step.stepName;
Debug.Log($"TutorialGuideManager: 包含匹配找到引导步骤: 索引={i}, stepName='{step.stepName}', uiObjectName='{step.uiObjectName}'");
}
else if (foundTargetStep)
{
break;
}
else
{
lastNonEmptyStepName = step.stepName;
}
}
else if (foundTargetStep)
{
matchedIndices.Add(i);
Debug.Log($"TutorialGuideManager: 包含匹配顺序延续找到引导步骤: 索引={i}, stepName='{step.stepName}', uiObjectName='{step.uiObjectName}', lastNonEmptyStepName='{lastNonEmptyStepName}'");
}
}
return matchedIndices;
}
/// <summary>
/// 根据执行索引选择引导步骤索引
/// </summary>
private int SelectGuideIndexByExecutionIndex(List<int> matchedIndices, List<GuideStepConfig> orderedSteps, string stepName, int executionIndex)
{
if (executionIndex >= 0 && executionIndex < matchedIndices.Count)
{
int guideIndex = matchedIndices[executionIndex];
Debug.Log($"TutorialGuideManager: 找到匹配的引导步骤: {stepName} -> 执行索引: {executionIndex}, 引导索引: {guideIndex}, UI对象: {orderedSteps[guideIndex].uiObjectName}");
return guideIndex;
}
else if (matchedIndices.Count > 0)
{
Debug.Log($"TutorialGuideManager: 执行索引超出范围,步骤 '{stepName}' 的所有引导步骤已执行完毕,将按顺序继续");
return -1;
}
Debug.Log($"TutorialGuideManager: 未找到匹配的引导步骤: {stepName}");
return -1;
}
#endregion #endregion
} }
} }

View File

@ -6,262 +6,265 @@ using UnityEngine;
namespace MotionFramework namespace MotionFramework
{ {
public static class MotionEngine public static class MotionEngine
{ {
private class ModuleWrapper private class ModuleWrapper
{ {
public int Priority { private set; get; } public int Priority { private set; get; }
public IModule Module { private set; get; } public IModule Module { private set; get; }
public ModuleWrapper(IModule module, int priority) public ModuleWrapper(IModule module, int priority)
{ {
Module = module; Module = module;
Priority = priority; Priority = priority;
} }
} }
private static readonly List<ModuleWrapper> _coms = new List<ModuleWrapper>(100); private static readonly List<ModuleWrapper> _coms = new List<ModuleWrapper>(100);
private static MonoBehaviour _behaviour; private static MonoBehaviour _behaviour;
private static bool _isDirty = false; private static bool _isDirty = false;
private static long _frame = 0; private static long _frame = 0;
/// <summary> /// <summary>
/// 初始化框架 /// 初始化框架
/// </summary> /// </summary>
public static void Initialize(MonoBehaviour behaviour, Action<ELogLevel, string> logCallback) public static void Initialize(MonoBehaviour behaviour, Action<ELogLevel, string> logCallback)
{ {
if (behaviour == null) if (behaviour == null)
throw new Exception("MotionFramework behaviour is null."); throw new ArgumentNullException(nameof(behaviour), "MotionFramework behaviour cannot be null");
if (_behaviour != null) if (_behaviour != null)
throw new Exception($"{nameof(MotionEngine)} is already initialized."); throw new InvalidOperationException($"{nameof(MotionEngine)} is already initialized");
UnityEngine.Object.DontDestroyOnLoad(behaviour.gameObject); UnityEngine.Object.DontDestroyOnLoad(behaviour.gameObject);
_behaviour = behaviour; _behaviour = behaviour;
// 注册日志回调 // 注册日志回调
if (logCallback != null) if (logCallback != null)
MotionLog.RegisterCallback(logCallback); MotionLog.RegisterCallback(logCallback);
behaviour.StartCoroutine(CheckFrame()); behaviour.StartCoroutine(CheckFrame());
} }
/// <summary> /// <summary>
/// 检测MotionEngine更新方法 /// 检测MotionEngine更新方法
/// </summary> /// </summary>
private static IEnumerator CheckFrame() private static IEnumerator CheckFrame()
{ {
var wait = new WaitForSeconds(1f); var wait = new WaitForSeconds(1f);
yield return wait; yield return wait;
// 说明初始化之后如果忘记更新MotionEngine这里会抛出异常 // 说明初始化之后如果忘记更新MotionEngine这里会记录警告而不是抛出异常
if (_frame == 0) // 避免在协程中抛出未处理的异常导致程序崩溃
throw new Exception($"Please call update method : MotionEngine.Update"); if (_frame == 0)
} {
MotionLog.Warning("MotionEngine.Update() has not been called. Please ensure Update() is called every frame.");
}
}
/// <summary> /// <summary>
/// 更新框架 /// 更新框架
/// </summary> /// </summary>
public static void Update() public static void Update()
{ {
_frame++; _frame++;
// 如果有新模块需要重新排序 // 如果有新模块需要重新排序
if (_isDirty) if (_isDirty)
{ {
_isDirty = false; _isDirty = false;
_coms.Sort((left, right) => _coms.Sort((left, right) =>
{ {
if (left.Priority > right.Priority) if (left.Priority > right.Priority)
return -1; return -1;
else if (left.Priority == right.Priority) else if (left.Priority == right.Priority)
return 0; return 0;
else else
return 1; return 1;
}); });
} }
// 轮询所有模块 // 轮询所有模块
for (int i = 0; i < _coms.Count; i++) for (int i = 0; i < _coms.Count; i++)
{ {
_coms[i].Module.OnUpdate(); _coms[i].Module.OnUpdate();
} }
} }
/// <summary> /// <summary>
/// 绘制所有模块的GUI内容 /// 绘制所有模块的GUI内容
/// </summary> /// </summary>
internal static void DrawModulesGUIContent() internal static void DrawModulesGUIContent()
{ {
for (int i = 0; i < _coms.Count; i++) for (int i = 0; i < _coms.Count; i++)
{ {
_coms[i].Module.OnGUI(); _coms[i].Module.OnGUI();
} }
} }
/// <summary> /// <summary>
/// 查询游戏模块是否存在 /// 查询游戏模块是否存在
/// </summary> /// </summary>
public static bool Contains<T>() where T : class, IModule public static bool Contains<T>() where T : class, IModule
{ {
System.Type type = typeof(T); System.Type type = typeof(T);
return Contains(type); return Contains(type);
} }
/// <summary> /// <summary>
/// 查询游戏模块是否存在 /// 查询游戏模块是否存在
/// </summary> /// </summary>
public static bool Contains(System.Type moduleType) public static bool Contains(System.Type moduleType)
{ {
for (int i = 0; i < _coms.Count; i++) for (int i = 0; i < _coms.Count; i++)
{ {
if (_coms[i].Module.GetType() == moduleType) if (_coms[i].Module.GetType() == moduleType)
return true; return true;
} }
return false; return false;
} }
/// <summary> /// <summary>
/// 创建游戏模块 /// 创建游戏模块
/// </summary> /// </summary>
/// <typeparam name="T">模块类</typeparam> /// <typeparam name="T">模块类</typeparam>
/// <param name="priority">运行时的优先级,优先级越大越早执行。如果没有设置优先级,那么会按照添加顺序执行</param> /// <param name="priority">运行时的优先级,优先级越大越早执行。如果没有设置优先级,那么会按照添加顺序执行</param>
public static T CreateModule<T>(int priority = 0) where T : class, IModule public static T CreateModule<T>(int priority = 0) where T : class, IModule
{ {
return CreateModule<T>(null, priority); return CreateModule<T>(null, priority);
} }
/// <summary> /// <summary>
/// 创建游戏模块 /// 创建游戏模块
/// </summary> /// </summary>
/// <typeparam name="T">模块类</typeparam> /// <typeparam name="T">模块类</typeparam>
/// <param name="createParam">创建参数</param> /// <param name="createParam">创建参数</param>
/// <param name="priority">运行时的优先级,优先级越大越早执行。如果没有设置优先级,那么会按照添加顺序执行</param> /// <param name="priority">运行时的优先级,优先级越大越早执行。如果没有设置优先级,那么会按照添加顺序执行</param>
public static T CreateModule<T>(System.Object createParam, int priority = 0) where T : class, IModule public static T CreateModule<T>(System.Object createParam, int priority = 0) where T : class, IModule
{ {
if (priority < 0) if (priority < 0)
throw new Exception("The priority can not be negative"); throw new ArgumentOutOfRangeException(nameof(priority), priority, "Priority cannot be negative");
if (Contains(typeof(T))) if (Contains(typeof(T)))
throw new Exception($"Game module {typeof(T)} is already existed"); throw new InvalidOperationException($"Game module {typeof(T)} already exists");
// 如果没有设置优先级
if (priority == 0)
{
int minPriority = GetMinPriority();
priority = --minPriority;
}
MotionLog.Log($"Create game module : {typeof(T)}");
T module = Activator.CreateInstance<T>();
ModuleWrapper wrapper = new ModuleWrapper(module, priority);
wrapper.Module.OnCreate(createParam);
_coms.Add(wrapper);
_isDirty = true;
return module;
}
/// <summary>
/// 销毁模块
/// </summary>
/// <typeparam name="T">模块类</typeparam>
public static bool DestroyModule<T>()
{
var moduleType = typeof(T);
for (int i = 0; i < _coms.Count; i++)
{
if (_coms[i].Module.GetType() == moduleType)
{
_coms[i].Module.OnDestroy();
_coms.RemoveAt(i);
return true;
}
}
return false;
}
/// <summary>
/// 获取游戏模块
/// </summary>
/// <typeparam name="T">模块类</typeparam>
public static T GetModule<T>() where T : class, IModule
{
System.Type type = typeof(T);
for (int i = 0; i < _coms.Count; i++)
{
if (_coms[i].Module.GetType() == type)
return _coms[i].Module as T;
}
MotionLog.Warning($"Not found game module {type}");
return null;
}
/// <summary>
/// 获取当前模块里最小的优先级
/// </summary>
private static int GetMinPriority()
{
int minPriority = 0;
for (int i = 0; i < _coms.Count; i++)
{
if (_coms[i].Priority < minPriority)
minPriority = _coms[i].Priority;
}
return minPriority; //小于等于零
}
#region
/// <summary>
/// 开启一个协程
/// </summary>
public static Coroutine StartCoroutine(IEnumerator coroutine)
{
if (_behaviour == null)
throw new InvalidOperationException($"{nameof(MotionEngine)} is not initialized. Use MotionEngine.Initialize");
return _behaviour.StartCoroutine(coroutine);
}
/// <summary>
/// 停止一个协程
/// </summary>
public static void StopCoroutine(Coroutine coroutine)
{
if (_behaviour == null)
throw new InvalidOperationException($"{nameof(MotionEngine)} is not initialized. Use MotionEngine.Initialize");
_behaviour.StopCoroutine(coroutine);
}
/// <summary>
/// 开启一个协程
/// </summary>
public static void StartCoroutine(string methodName)
{
if (_behaviour == null)
throw new InvalidOperationException($"{nameof(MotionEngine)} is not initialized. Use MotionEngine.Initialize");
_behaviour.StartCoroutine(methodName);
}
/// <summary>
/// 停止一个协程
/// </summary>
public static void StopCoroutine(string methodName)
{
if (_behaviour == null)
throw new InvalidOperationException($"{nameof(MotionEngine)} is not initialized. Use MotionEngine.Initialize");
_behaviour.StopCoroutine(methodName);
}
int minPriority = GetMinPriority(); /// <summary>
priority = --minPriority; /// 停止所有协程
/// </summary>
public static void StopAllCoroutines()
MotionLog.Log($"Create game module : {typeof(T)}"); {
T module = Activator.CreateInstance<T>(); if (_behaviour == null)
ModuleWrapper wrapper = new ModuleWrapper(module, priority); throw new InvalidOperationException($"{nameof(MotionEngine)} is not initialized. Use MotionEngine.Initialize");
wrapper.Module.OnCreate(createParam); _behaviour.StopAllCoroutines();
_coms.Add(wrapper); }
_isDirty = true; #endregion
return module; }
}
/// <summary>
/// 销毁模块
/// </summary>
/// <typeparam name="T">模块类</typeparam>
public static bool DestroyModule<T>()
{
var moduleType = typeof(T);
for (int i = 0; i < _coms.Count; i++)
{
if (_coms[i].Module.GetType() == moduleType)
{
_coms[i].Module.OnDestroy();
_coms.RemoveAt(i);
return true;
}
}
return false;
}
/// <summary>
/// 获取游戏模块
/// </summary>
/// <typeparam name="T">模块类</typeparam>
public static T GetModule<T>() where T : class, IModule
{
System.Type type = typeof(T);
for (int i = 0; i < _coms.Count; i++)
{
if (_coms[i].Module.GetType() == type)
return _coms[i].Module as T;
}
MotionLog.Warning($"Not found game module {type}");
return null;
}
/// <summary>
/// 获取当前模块里最小的优先级
/// </summary>
private static int GetMinPriority()
{
int minPriority = 0;
for (int i = 0; i < _coms.Count; i++)
{
if (_coms[i].Priority < minPriority)
minPriority = _coms[i].Priority;
}
return minPriority; //小于等于零
}
#region
/// <summary>
/// 开启一个协程
/// </summary>
public static Coroutine StartCoroutine(IEnumerator coroutine)
{
if (_behaviour == null)
throw new Exception($"{nameof(MotionEngine)} is not initialize. Use MotionEngine.Initialize");
return _behaviour.StartCoroutine(coroutine);
}
/// <summary>
/// 停止一个协程
/// </summary>
public static void StopCoroutine(Coroutine coroutine)
{
if (_behaviour == null)
throw new Exception($"{nameof(MotionEngine)} is not initialize. Use MotionEngine.Initialize");
_behaviour.StopCoroutine(coroutine);
}
/// <summary>
/// 开启一个协程
/// </summary>
public static void StartCoroutine(string methodName)
{
if (_behaviour == null)
throw new Exception($"{nameof(MotionEngine)} is not initialize. Use MotionEngine.Initialize");
_behaviour.StartCoroutine(methodName);
}
/// <summary>
/// 停止一个协程
/// </summary>
public static void StopCoroutine(string methodName)
{
if (_behaviour == null)
throw new Exception($"{nameof(MotionEngine)} is not initialize. Use MotionEngine.Initialize");
_behaviour.StopCoroutine(methodName);
}
/// <summary>
/// 停止所有协程
/// </summary>
public static void StopAllCoroutines()
{
if (_behaviour == null)
throw new Exception($"{nameof(MotionEngine)} is not initialize. Use MotionEngine.Initialize");
_behaviour.StopAllCoroutines();
}
#endregion
}
} }

View File

@ -370,10 +370,12 @@ public class DocumentManagement : MonoBehaviour
{ {
return; return;
} }
if (documentCollections != null)
for (int i = 0; i < documentCollections.Length; i++)
{ {
GenerateDocument(documentCollections[i].name); for (int i = 0; i < documentCollections.Length; i++)
{
GenerateDocument(documentCollections[i].name);
}
} }
////保存按钮 ////保存按钮