206 lines
8.6 KiB
C#
206 lines
8.6 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.IsSequential)
|
|
{
|
|
// 按顺序点击的逻辑
|
|
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
|
|
{
|
|
string correctObjectName = currentAction.TargetObjects[currentAction.CurrentObjectIndex].name;
|
|
Debug.Log($"错误点击或顺序错误:{clickedObject.name}。正确的物体是:{correctObjectName}");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// 不按顺序点击的逻辑
|
|
if (currentAction.TargetObjects.Contains(clickedObject))
|
|
{
|
|
if (!currentAction.ClickedObjects.Contains(clickedObject))
|
|
{
|
|
Debug.Log($"正确点击了:{clickedObject.name}");
|
|
currentAction.ClickedObjects.Add(clickedObject); // 添加到已点击对象集合
|
|
|
|
if (currentAction.ClickedObjects.Count >= currentAction.TargetObjects.Count)
|
|
{
|
|
Debug.Log($"完成了动作 {currentActionIndex + 1}");
|
|
step.PlayAnimation(currentActionIndex); // 播放当前动作的动画
|
|
DisplayActionFeedback(currentMode, currentAction); // 显示反馈
|
|
|
|
currentActionIndex++;
|
|
currentAction.ClickedObjects.Clear(); // 重置已点击对象集合
|
|
|
|
if (currentActionIndex >= step.Actions.Count)
|
|
{
|
|
Debug.Log("所有动作完成!");
|
|
currentActionIndex = 0; // 重置动作索引或进入下一个大步骤
|
|
currentStepIndex++;
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("开始下一个动作!");
|
|
PrepareNextStep(currentMode, process, currentStepIndex);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
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($"错误点击:{clickedObject.name} 正确的物体是:{correctObjects}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
{
|
|
}
|
|
}
|
|
} |