This commit is contained in:
parent
4fece283a9
commit
0a531125b2
|
|
@ -6,12 +6,13 @@ namespace DefaultNamespace.ProcessMode
|
|||
{
|
||||
public class ActionWithDescription
|
||||
{
|
||||
public List<GameObject> TargetObjects { get; set; }//需要点击的对象
|
||||
public Action Action { get; set; }//动作
|
||||
public string Description { get; set; } //描述
|
||||
public bool IsSequential { get; set; } // 指示是否需要按顺序点击
|
||||
public List<GameObject> TargetObjects { get; set; }
|
||||
public Action Action { get; set; }
|
||||
public string Description { get; set; }
|
||||
public bool IsSequential { get; set; } // 是否按顺序点击
|
||||
public HashSet<GameObject> ClickedObjects { get; private set; } // 已点击的对象集合
|
||||
public int CurrentObjectIndex { get; set; } // 当前对象的点击索引,仅用于按顺序点击的情况
|
||||
public bool FeedbackDisplayed { get; set; } // 是否已经显示过反馈
|
||||
|
||||
public ActionWithDescription(List<GameObject> targetObjects, Action action, string description, bool isSequential)
|
||||
{
|
||||
|
|
@ -19,11 +20,13 @@ namespace DefaultNamespace.ProcessMode
|
|||
Action = action;
|
||||
Description = description;
|
||||
IsSequential = isSequential;
|
||||
ClickedObjects = new HashSet<GameObject>();
|
||||
CurrentObjectIndex = 0;
|
||||
ClickedObjects = new HashSet<GameObject>(); // 初始化已点击的对象集合
|
||||
CurrentObjectIndex = 0; // 初始化为第一个对象
|
||||
FeedbackDisplayed = false; // 初始化反馈未显示
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using HighlightPlus;
|
||||
using MotionFramework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using Type = System.Type;
|
||||
|
||||
namespace DefaultNamespace.ProcessMode
|
||||
{
|
||||
|
|
@ -22,6 +24,9 @@ namespace DefaultNamespace.ProcessMode
|
|||
if (!processes.ContainsKey(type))
|
||||
{
|
||||
processes[type] = new AnimationProcess(type);
|
||||
if (Enum.TryParse(type, true, out currentMode))
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -54,28 +59,12 @@ namespace DefaultNamespace.ProcessMode
|
|||
{
|
||||
Debug.Log($"正确点击了:{clickedObject.name}");
|
||||
currentAction.CurrentObjectIndex++; // 正确点击,递增对象索引
|
||||
currentAction.ClickedObjects.Add(clickedObject); // 添加到已点击对象集合
|
||||
HandleModeSpecificFeedback(currentMode, currentAction); // 处理模式特定的反馈
|
||||
|
||||
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);
|
||||
}
|
||||
CompleteAction(step, currentAction); // 完成当前动作
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -93,32 +82,17 @@ namespace DefaultNamespace.ProcessMode
|
|||
{
|
||||
Debug.Log($"正确点击了:{clickedObject.name}");
|
||||
currentAction.ClickedObjects.Add(clickedObject); // 添加到已点击对象集合
|
||||
HandleModeSpecificFeedback(currentMode, currentAction); // 处理模式特定的反馈
|
||||
|
||||
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);
|
||||
}
|
||||
CompleteAction(step, currentAction); // 完成当前动作
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"错误点击:{clickedObject.name}");
|
||||
List<string> correctObjectNames = new List<string>();
|
||||
foreach (var obj in currentAction.TargetObjects)
|
||||
{
|
||||
|
|
@ -127,63 +101,189 @@ namespace DefaultNamespace.ProcessMode
|
|||
correctObjectNames.Add(obj.name);
|
||||
}
|
||||
}
|
||||
|
||||
string correctObjects = string.Join(", ", correctObjectNames);
|
||||
Debug.Log($"错误点击:{clickedObject.name} 正确的物体是:{correctObjects}");
|
||||
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]); // 准备下一个步骤
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("开始下一个动作!");
|
||||
PrepareNextStep(currentMode, step.Actions[currentActionIndex]); // 传递下一个动作对象
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 根据当前模式显示相应的动作反馈
|
||||
/// </summary>
|
||||
/// <param name="mode">当前的流程模式</param>
|
||||
/// <param name="action">当前的动作</param>
|
||||
private void DisplayActionFeedback(ProcessMode mode, ActionWithDescription action)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case ProcessMode.Teaching:
|
||||
// 高亮显示下一个需要点击的地方
|
||||
// HighlightNextStep(action.);
|
||||
HighlightNextObject(action); // 高亮下一个需要点击的物体
|
||||
break;
|
||||
case ProcessMode.Training:
|
||||
// 在画面右上角显示流程步骤
|
||||
// uiManager.ShowTrainingStep(action.Description);
|
||||
//ShowTrainingStep(action); // 在右上角显示流程步骤
|
||||
break;
|
||||
case ProcessMode.Practice:
|
||||
// 只显示当前步骤
|
||||
// uiManager.ShowPracticeStep(action.Description);
|
||||
ShowPracticeStep(action); // 只显示当前步骤
|
||||
break;
|
||||
case ProcessMode.Assessment:
|
||||
// 无任何提示
|
||||
// 考核模式无提示
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareNextStep(ProcessMode mode, AnimationProcess process, int nextStepIndex)
|
||||
|
||||
/// <summary>
|
||||
/// 准备下一个步骤或动作,并根据模式处理相应的提示或反馈
|
||||
/// </summary>
|
||||
/// <param name="mode">当前的流程模式</param>
|
||||
/// <param name="nextStepOrAction">下一个步骤或动作</param>
|
||||
private void PrepareNextStep(ProcessMode mode, object nextStepOrAction)
|
||||
{
|
||||
if (nextStepIndex < process.Steps.Count)
|
||||
switch (mode)
|
||||
{
|
||||
ActionWithDescription nextAction = process.Steps[nextStepIndex].Actions[0];
|
||||
if (mode == ProcessMode.Teaching)
|
||||
{
|
||||
// HighlightNextStep(nextAction.TargetObject);
|
||||
}
|
||||
else if (mode == ProcessMode.Training)
|
||||
{
|
||||
// uiManager.ShowTrainingStep("开始下一个步骤...");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// uiManager.DisplayMessage("所有步骤完成!");
|
||||
case ProcessMode.Teaching:
|
||||
HighlightNextObject(nextStepOrAction as ActionWithDescription); // 高亮显示下一个需要点击的物体
|
||||
break;
|
||||
case ProcessMode.Training:
|
||||
// 在培训模式下只打印下一步骤或动作的描述
|
||||
if (nextStepOrAction is ActionWithDescription action)
|
||||
{
|
||||
Debug.Log($"培训模式:{action.Description}");
|
||||
}
|
||||
else if (nextStepOrAction is AnimationStep step)
|
||||
{
|
||||
if (step.Actions.Count > 0)
|
||||
{
|
||||
Debug.Log($"培训模式:{step.Actions[0].Description}");
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case ProcessMode.Practice:
|
||||
// 练习模式下不需要提前显示下一个步骤的描述
|
||||
break;
|
||||
case ProcessMode.Assessment:
|
||||
// 考核模式无提示
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void HighlightNextStep(GameObject target)
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ namespace DefaultNamespace.ProcessMode
|
|||
if (index >= 0 && index < Actions.Count)
|
||||
{
|
||||
Actions[index].Action?.Invoke(); // 执行动画
|
||||
Debug.Log(Actions[index].Description); // 输出动作描述
|
||||
// Debug.Log(Actions[index].Description); // 输出动作描述
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue