365 lines
15 KiB
C#
365 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using HighlightPlus;
|
|
using MotionFramework;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Type = System.Type;
|
|
|
|
namespace DefaultNamespace.ProcessMode
|
|
{
|
|
[ScriptDescription("流程模式管理器")]
|
|
public class AnimationProcessManager : ModuleSingleton<AnimationProcessManager>, IModule
|
|
{
|
|
private Dictionary<string, AnimationProcess> processes = new Dictionary<string, AnimationProcess>();
|
|
public ProcessMode currentMode; // 当前模式
|
|
private int currentStepIndex; // 当前步骤索引
|
|
private int currentActionIndex; // 当前动作索引,确保动作顺序
|
|
private int currentActionGameIndex; // 当前动作索引,确保动作顺序
|
|
private List<IncorrectClick> incorrectClicks; // 错误点击的记录列表
|
|
public AnimationProcess CurrentProcess => processes[currentMode.ToString()];
|
|
|
|
public delegate void CompleteEventHandler();
|
|
|
|
public delegate void UIEventHandler();
|
|
|
|
public delegate void SendMessagePrompt(string message);
|
|
|
|
// 定义一个事件,使用委托类型
|
|
public event CompleteEventHandler OnCompleteEvent;
|
|
public event UIEventHandler OnUIEvent;
|
|
public event SendMessagePrompt OnSendMessagePrompt;
|
|
|
|
public void AddProcess(string type)
|
|
{
|
|
// if (!processes.ContainsKey(type))
|
|
// {
|
|
// processes[type] = new AnimationProcess(type);
|
|
// Enum.TryParse(type, true, out currentMode);
|
|
// }
|
|
|
|
processes[type] = new AnimationProcess(type);
|
|
Enum.TryParse(type, true, out currentMode);
|
|
}
|
|
|
|
public void ClearProcess()
|
|
{
|
|
processes.Clear();
|
|
}
|
|
|
|
|
|
public void AddStepToProcess(string type, AnimationStep step)
|
|
{
|
|
if (processes.ContainsKey(type))
|
|
{
|
|
processes[type].AddStep(step);
|
|
}
|
|
}
|
|
|
|
public void HandleClick(GameObject clickedObject)
|
|
{
|
|
string type = currentMode.ToString();
|
|
|
|
if (processes.ContainsKey(type))
|
|
{
|
|
AnimationProcess process = processes[type];
|
|
|
|
if (currentStepIndex < process.Steps.Count)
|
|
{
|
|
AnimationStep step = process.Steps[currentStepIndex];
|
|
ActionWithDescription currentAction = step.Actions[currentActionIndex];
|
|
|
|
if (currentAction.IsSequential)
|
|
{
|
|
// 按顺序点击的逻辑
|
|
if (currentAction.CurrentObjectIndex < currentAction.TargetObjects.Count &&
|
|
currentAction.TargetObjects[currentAction.CurrentObjectIndex] == clickedObject)
|
|
{
|
|
Debug.Log($"正确点击了:{clickedObject.name}");
|
|
currentAction.CurrentObjectIndex++; // 正确点击,递增对象索引
|
|
currentAction.ClickedObjects.Add(clickedObject); // 添加到已点击对象集合
|
|
HandleModeSpecificFeedback(currentMode, currentAction); // 处理模式特定的反馈
|
|
|
|
if (currentAction.CurrentObjectIndex >= currentAction.TargetObjects.Count)
|
|
{
|
|
CompleteAction(step, currentAction); // 完成当前动作
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string correctObjectName = currentAction.TargetObjects[currentAction.CurrentObjectIndex].name;
|
|
Debug.Log($"错误点击或顺序错误:{clickedObject.name}。正确的物体是:{correctObjectName}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 不按顺序点击的逻辑
|
|
if (currentAction.TargetObjects.Any(obj => obj.name == clickedObject.name))
|
|
{
|
|
if (currentAction.ClickedObjects.Any(obj => obj.name == clickedObject.name))
|
|
{
|
|
Debug.Log($"错误点击:{clickedObject.name}。这个物体已经点击过。");
|
|
return; // 如果物体已经点击过,不继续处理
|
|
}
|
|
|
|
if (!currentAction.ClickedObjects.Contains(clickedObject))
|
|
{
|
|
Debug.Log($"正确点击了:{clickedObject.name}");
|
|
currentAction.ClickedObjects.Add(clickedObject); // 添加到已点击对象集合
|
|
HandleModeSpecificFeedback(currentMode, currentAction); // 处理模式特定的反馈
|
|
|
|
if (currentAction.ClickedObjects.Count >= currentAction.TargetObjects.Count)
|
|
{
|
|
CompleteAction(step, currentAction); // 完成当前动作
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log($"错误点击:{clickedObject.name}");
|
|
List<string> correctObjectNames = new List<string>();
|
|
foreach (var obj in currentAction.TargetObjects)
|
|
{
|
|
if (!currentAction.ClickedObjects.Contains(obj))
|
|
{
|
|
correctObjectNames.Add(obj.name);
|
|
}
|
|
}
|
|
|
|
string correctObjects = string.Join(", ", correctObjectNames);
|
|
Debug.Log($"正确的物体是:{correctObjects}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理完成当前动作的逻辑
|
|
/// </summary>
|
|
/// <param name="step">当前步骤</param>
|
|
/// <param name="currentAction">当前动作</param>
|
|
private void CompleteAction(AnimationStep step, ActionWithDescription currentAction)
|
|
{
|
|
Debug.Log($"完成了动作 {currentActionIndex + 1}");
|
|
step.PlayAnimation(currentActionIndex); // 播放当前动作的动画
|
|
DisplayActionFeedback(currentMode, currentAction); // 显示模式特定的反馈
|
|
|
|
currentActionIndex++;
|
|
currentAction.CurrentObjectIndex = 0; // 重置当前动作对象索引
|
|
currentAction.ClickedObjects.Clear(); // 重置已点击对象集合
|
|
currentAction.FeedbackDisplayed = false; // 重置反馈显示标志
|
|
|
|
if (currentActionIndex >= step.Actions.Count)
|
|
{
|
|
Debug.Log("所有动作完成!");
|
|
currentActionIndex = 0; // 重置动作索引或进入下一个大步骤
|
|
currentStepIndex++;
|
|
if (currentStepIndex < processes[currentMode.ToString()].Steps.Count)
|
|
{
|
|
var nextStep = processes[currentMode.ToString()].Steps[currentStepIndex];
|
|
PrepareNextStep(currentMode, nextStep.Actions[0]); // 准备下一个步骤
|
|
|
|
// if (nextStep.Actions[0].StepDescription == "临时用电")
|
|
// {
|
|
// Debug.Log("临时用电临时用电临时用电临时用电临时用电临时用电临时用电临时用电临时用电临时用电");
|
|
// OnUIEvent();
|
|
// }
|
|
}
|
|
else
|
|
{
|
|
if (MotionEngine.GetModule<ToolsPackManager>().GetToolsPackScene() == ToolsPackScene.其他)
|
|
{
|
|
OnCompleteEvent();
|
|
}
|
|
|
|
Debug.Log("全部完成了!!!!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("开始下一个动作!");
|
|
PrepareNextStep(currentMode, step.Actions[currentActionIndex]); // 传递下一个动作对象
|
|
|
|
// if (step.Actions[currentActionIndex].StepDescription == "临时用电")
|
|
// {
|
|
// Debug.Log("临时用电临时用电临时用电临时用电临时用电临时用电临时用电临时用电临时用电临时用电");
|
|
// OnUIEvent();
|
|
// }
|
|
}
|
|
}
|
|
// Start is called before the first frame update
|
|
|
|
/// <summary>
|
|
/// 根据当前模式显示相应的动作反馈
|
|
/// </summary>
|
|
/// <param name="mode">当前的流程模式</param>
|
|
/// <param name="action">当前的动作</param>
|
|
private void DisplayActionFeedback(ProcessMode mode, ActionWithDescription action)
|
|
{
|
|
switch (mode)
|
|
{
|
|
case ProcessMode.Teaching:
|
|
HighlightNextObject(action); // 高亮下一个需要点击的物体
|
|
break;
|
|
case ProcessMode.Training:
|
|
//ShowTrainingStep(action); // 在右上角显示流程步骤
|
|
break;
|
|
case ProcessMode.Practice:
|
|
ShowPracticeStep(action); // 只显示当前步骤
|
|
break;
|
|
case ProcessMode.Assessment:
|
|
// 考核模式无提示
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 准备下一个步骤或动作,并根据模式处理相应的提示或反馈
|
|
/// </summary>
|
|
/// <param name="mode">当前的流程模式</param>
|
|
/// <param name="nextStepOrAction">下一个步骤或动作</param>
|
|
public void PrepareNextStep(ProcessMode mode, object nextStepOrAction)
|
|
{
|
|
switch (mode)
|
|
{
|
|
case ProcessMode.Teaching:
|
|
HighlightNextObject(nextStepOrAction as ActionWithDescription); // 高亮显示下一个需要点击的物体
|
|
break;
|
|
case ProcessMode.Training:
|
|
// 在培训模式下只打印下一步骤或动作的描述
|
|
if (nextStepOrAction is ActionWithDescription action)
|
|
{
|
|
Debug.Log($"培训模式:{action.Description}");
|
|
OnSendMessagePrompt("提示:" + action.Description);
|
|
}
|
|
else if (nextStepOrAction is AnimationStep step)
|
|
{
|
|
if (step.Actions.Count > 0)
|
|
{
|
|
Debug.Log($"培训模式:{step.Actions[0].Description}");
|
|
OnSendMessagePrompt("提示:" + step.Actions[0].Description);
|
|
}
|
|
}
|
|
|
|
break;
|
|
case ProcessMode.Practice:
|
|
// 练习模式下不需要提前显示下一个步骤的描述
|
|
break;
|
|
case ProcessMode.Assessment:
|
|
// 考核模式无提示
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 处理模式特定的反馈逻辑
|
|
/// </summary>
|
|
/// <param name="mode">当前的流程模式</param>
|
|
/// <param name="action">当前的动作</param>
|
|
private void HandleModeSpecificFeedback(ProcessMode mode, ActionWithDescription action)
|
|
{
|
|
if (action.FeedbackDisplayed)
|
|
{
|
|
return; // 已经显示过反馈,不再重复显示
|
|
}
|
|
|
|
switch (mode)
|
|
{
|
|
case ProcessMode.Teaching:
|
|
HighlightNextObject(action); // 高亮下一个需要点击的物体
|
|
break;
|
|
case ProcessMode.Training:
|
|
//ShowTrainingStep(action.Description); // 在右上角显示流程步骤
|
|
break;
|
|
case ProcessMode.Practice:
|
|
ShowPracticeStep(action.Description); // 只显示当前步骤
|
|
break;
|
|
case ProcessMode.Assessment:
|
|
// 考核模式无提示
|
|
break;
|
|
}
|
|
|
|
action.FeedbackDisplayed = true; // 标记反馈已显示
|
|
}
|
|
|
|
/// <summary>
|
|
/// 高亮显示下一个需要点击的物体
|
|
/// </summary>
|
|
/// <param name="action">当前的动作</param>
|
|
private void HighlightNextObject(ActionWithDescription action)
|
|
{
|
|
if (action != null)
|
|
{
|
|
for (int i = action.CurrentObjectIndex; i < action.TargetObjects.Count; i++)
|
|
{
|
|
GameObject nextObject = action.TargetObjects[i];
|
|
if (!action.ClickedObjects.Contains(nextObject))
|
|
{
|
|
// 添加高亮效果的逻辑
|
|
GameObject.Find(nextObject.name).GetComponent<HighlightEffect>().highlighted = true;
|
|
|
|
Debug.Log($"高亮显示:{nextObject.name}");
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设置当前模式
|
|
/// </summary>
|
|
/// <param name="mode">模式</param>
|
|
public void SetCurrentMode(ProcessMode mode)
|
|
{
|
|
currentMode = mode;
|
|
currentStepIndex = 0;
|
|
currentActionIndex = 0;
|
|
}
|
|
|
|
private void ShowTrainingStep(object nextStepOrAction)
|
|
{
|
|
if (nextStepOrAction is AnimationStep step)
|
|
{
|
|
Debug.Log($"培训模式:{step.StepDescription}");
|
|
}
|
|
else if (nextStepOrAction is ActionWithDescription action)
|
|
{
|
|
Debug.Log($"培训模式:{action.Description}");
|
|
}
|
|
}
|
|
|
|
private void ShowPracticeStep(object nextStepOrAction)
|
|
{
|
|
if (nextStepOrAction is AnimationStep step)
|
|
{
|
|
Debug.Log($"练习模式:{step.StepDescription}");
|
|
}
|
|
else if (nextStepOrAction is ActionWithDescription action)
|
|
{
|
|
Debug.Log($"练习模式:{action.Description}");
|
|
}
|
|
}
|
|
|
|
public void OnCreate(object createParam)
|
|
{
|
|
processes = new Dictionary<string, AnimationProcess>();
|
|
incorrectClicks = new List<IncorrectClick>();
|
|
}
|
|
|
|
public void OnUpdate()
|
|
{
|
|
}
|
|
|
|
public void OnDestroy()
|
|
{
|
|
}
|
|
|
|
public void OnGUI()
|
|
{
|
|
}
|
|
}
|
|
} |