ShanxiKnowledgeBase/SXElectricityInformationAcq.../Assets/Scripts/ProcessMode/AnimationProcessManager.cs

156 lines
5.8 KiB
C#

using System;
using System.Collections.Generic;
using MotionFramework;
using UnityEngine;
using UnityEngine.UI;
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 void AddProcess(string type)
{
if (!processes.ContainsKey(type))
{
processes[type] = new AnimationProcess(type);
}
}
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.CurrentObjectIndex < currentAction.TargetObjects.Count &&
currentAction.TargetObjects[currentAction.CurrentObjectIndex] == clickedObject)
{
Debug.Log($"正确点击了:{clickedObject.name}");
currentAction.CurrentObjectIndex++; // 正确点击,递增对象索引
// 检查是否完成了当前动作中的所有对象点击
if (currentAction.CurrentObjectIndex >= currentAction.TargetObjects.Count)
{
Debug.Log($"完成了动作 {currentActionIndex + 1}");
step.PlayAnimation(currentActionIndex); // 播放当前动作的动画
DisplayActionFeedback(currentMode, currentAction); // 显示反馈
// 重置当前动作对象索引,并准备下一个动作
currentActionIndex++;
currentAction.CurrentObjectIndex = 0;
if (currentActionIndex >= step.Actions.Count)
{
Debug.Log("所有动作完成!");
currentActionIndex = 0; // 重置动作索引或进入下一个大步骤
currentStepIndex++;
}
else
{
Debug.Log("开始下一个动作!");
PrepareNextStep(currentMode, process, currentStepIndex);
}
}
}
else
{
Debug.Log($"错误点击或顺序错误:{clickedObject.name}");
// 错误点击处理,可以选择重置当前动作的索引或其他处理逻辑
}
}
}
}
private void DisplayActionFeedback(ProcessMode mode, ActionWithDescription action)
{
switch (mode)
{
case ProcessMode.Teaching:
// 高亮显示下一个需要点击的地方
// HighlightNextStep(action.);
break;
case ProcessMode.Training:
// 在画面右上角显示流程步骤
// uiManager.ShowTrainingStep(action.Description);
break;
case ProcessMode.Practice:
// 只显示当前步骤
// uiManager.ShowPracticeStep(action.Description);
break;
case ProcessMode.Assessment:
// 无任何提示
break;
}
}
private void PrepareNextStep(ProcessMode mode, AnimationProcess process, int nextStepIndex)
{
if (nextStepIndex < process.Steps.Count)
{
ActionWithDescription nextAction = process.Steps[nextStepIndex].Actions[0];
if (mode == ProcessMode.Teaching)
{
// HighlightNextStep(nextAction.TargetObject);
}
else if (mode == ProcessMode.Training)
{
// uiManager.ShowTrainingStep("开始下一个步骤...");
}
}
else
{
// uiManager.DisplayMessage("所有步骤完成!");
}
}
private void HighlightNextStep(GameObject target)
{
// 实现高亮逻辑,比如改变对象颜色或添加光环效果
}
public void OnCreate(object createParam)
{
processes = new Dictionary<string, AnimationProcess>();
incorrectClicks = new List<IncorrectClick>();
}
public void OnUpdate()
{
}
public void OnDestroy()
{
}
public void OnGUI()
{
}
}
}