This commit is contained in:
yzx 2024-06-12 14:53:57 +08:00
parent 7d6745dd3e
commit 323984012e
9 changed files with 178 additions and 133 deletions

View File

@ -114,12 +114,12 @@ Material:
- _UVSec: 0
- _ZWrite: 1
- __dirty: 0
- _step_p1: 0
- _step_p2: 0
- _step_p3: 0
- _step_p4: 0
- _step_p5: 0
- _step_p6: 0
- _step_p1: 1
- _step_p2: 1
- _step_p3: 1
- _step_p4: 1
- _step_p5: 1
- _step_p6: 1
m_Colors:
- _BaseCol: {r: 0.23429155, g: 0.28497556, b: 0.3679245, a: 0}
- _Color: {r: 1, g: 1, b: 1, a: 1}

View File

@ -10200,6 +10200,18 @@ PrefabInstance:
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 5602562225628980618, guid: 8a244cdd2f00e534aadd2512c3bbfda1, type: 3}
propertyPath: m_LocalPosition.x
value: -0.298
objectReference: {fileID: 0}
- target: {fileID: 5602562225628980618, guid: 8a244cdd2f00e534aadd2512c3bbfda1, type: 3}
propertyPath: m_LocalPosition.y
value: 0.017
objectReference: {fileID: 0}
- target: {fileID: 5602562225628980618, guid: 8a244cdd2f00e534aadd2512c3bbfda1, type: 3}
propertyPath: m_LocalPosition.z
value: -0.097
objectReference: {fileID: 0}
- target: {fileID: 5725098936793829084, guid: 8a244cdd2f00e534aadd2512c3bbfda1, type: 3}
propertyPath: m_Enabled
value: 1
@ -10220,6 +10232,18 @@ PrefabInstance:
propertyPath: m_Color.rgba
value: 4294967295
objectReference: {fileID: 0}
- target: {fileID: 7745216743049305763, guid: 8a244cdd2f00e534aadd2512c3bbfda1, type: 3}
propertyPath: m_LocalPosition.x
value: -2.19
objectReference: {fileID: 0}
- target: {fileID: 7745216743049305763, guid: 8a244cdd2f00e534aadd2512c3bbfda1, type: 3}
propertyPath: m_LocalPosition.y
value: -0.006
objectReference: {fileID: 0}
- target: {fileID: 7745216743049305763, guid: 8a244cdd2f00e534aadd2512c3bbfda1, type: 3}
propertyPath: m_LocalPosition.z
value: -0.38
objectReference: {fileID: 0}
- target: {fileID: 7745216743049305763, guid: 8a244cdd2f00e534aadd2512c3bbfda1, type: 3}
propertyPath: m_LocalRotation.w
value: 0.7071068

View File

@ -1,6 +1,8 @@
using DG.Tweening;
using System.Collections;
using System.Collections.Generic;
using DefaultNamespace.ProcessMode;
using MotionFramework;
using UnityEngine;
/// <summary>
@ -101,6 +103,7 @@ public class Screwdriver : MonoBehaviour
if (hit.collider.gameObject.name == ScrewObj[i].name)
{
Debug.Log(hit.collider.gameObject.name);
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject);
ScrewObj[i].gameObject.SetActive(false);
}
//if (!ScrewObj[i].gameObject.activeInHierarchy)

View File

@ -6,6 +6,8 @@ namespace DefaultNamespace.Dto
{
public string Description { get; set; }
public int Score { get; set; }
public bool IsSequential { get; set; }
public List<string> TargetObjects { get; set; }
}

View File

@ -6,19 +6,24 @@ namespace DefaultNamespace.ProcessMode
{
public class ActionWithDescription
{
public List<GameObject> TargetObjects { get; set; } // 需要点击的目标物体列表
public Action Action { get; set; } // 与点击关联的动画或反应
public string Description { get; set; } // 动作描述
public int CurrentObjectIndex { 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 ActionWithDescription(List<GameObject> targetObjects, Action action, string description)
public ActionWithDescription(List<GameObject> targetObjects, Action action, string description, bool isSequential)
{
TargetObjects = targetObjects ?? new List<GameObject>();
Action = action;
Description = description;
IsSequential = isSequential;
ClickedObjects = new HashSet<GameObject>(); // 初始化已点击的对象集合
CurrentObjectIndex = 0; // 初始化为第一个对象
}
}
}

View File

@ -34,35 +34,73 @@ namespace DefaultNamespace.ProcessMode
}
public void HandleClick(GameObject clickedObject)
{
string type = currentMode.ToString();
if (processes.ContainsKey(type))
{
AnimationProcess process = processes[type];
if (currentStepIndex < process.Steps.Count)
{
string type = currentMode.ToString();
AnimationStep step = process.Steps[currentStepIndex];
ActionWithDescription currentAction = step.Actions[currentActionIndex];
if (processes.ContainsKey(type))
if (currentAction.IsSequential)
{
AnimationProcess process = processes[type];
if (currentStepIndex < process.Steps.Count)
// 按顺序点击的逻辑
if (currentAction.CurrentObjectIndex < currentAction.TargetObjects.Count &&
currentAction.TargetObjects[currentAction.CurrentObjectIndex] == clickedObject)
{
AnimationStep step = process.Steps[currentStepIndex];
ActionWithDescription currentAction = step.Actions[currentActionIndex];
Debug.Log($"正确点击了:{clickedObject.name}");
currentAction.CurrentObjectIndex++; // 正确点击,递增对象索引
// 检查当前点击是否为当前动作预期的对象
if (currentAction.CurrentObjectIndex < currentAction.TargetObjects.Count &&
currentAction.TargetObjects[currentAction.CurrentObjectIndex] == clickedObject)
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}");
}
}
else
{
// 不按顺序点击的逻辑
if (currentAction.TargetObjects.Contains(clickedObject))
{
if (!currentAction.ClickedObjects.Contains(clickedObject))
{
Debug.Log($"正确点击了:{clickedObject.name}");
currentAction.CurrentObjectIndex++; // 正确点击,递增对象索引
currentAction.ClickedObjects.Add(clickedObject); // 添加到已点击对象集合
// 检查是否完成了当前动作中的所有对象点击
if (currentAction.CurrentObjectIndex >= currentAction.TargetObjects.Count)
if (currentAction.ClickedObjects.Count >= currentAction.TargetObjects.Count)
{
Debug.Log($"完成了动作 {currentActionIndex + 1}");
step.PlayAnimation(currentActionIndex); // 播放当前动作的动画
DisplayActionFeedback(currentMode, currentAction); // 显示反馈
// 重置当前动作对象索引,并准备下一个动作
currentActionIndex++;
currentAction.CurrentObjectIndex = 0;
currentAction.ClickedObjects.Clear(); // 重置已点击对象集合
if (currentActionIndex >= step.Actions.Count)
{
@ -77,14 +115,16 @@ namespace DefaultNamespace.ProcessMode
}
}
}
else
{
Debug.Log($"错误点击或顺序错误:{clickedObject.name}");
// 错误点击处理,可以选择重置当前动作的索引或其他处理逻辑
}
}
else
{
Debug.Log($"错误点击:{clickedObject.name}");
}
}
}
}
}
private void DisplayActionFeedback(ProcessMode mode, ActionWithDescription action)

View File

@ -48,7 +48,7 @@ namespace DefaultNamespace.ProcessMode
}
Action action = () => { Debug.Log(actionData.Description); };
actions.Add(new ActionWithDescription(targetObjects, action, actionData.Description));
actions.Add(new ActionWithDescription(targetObjects, action, actionData.Description, actionData.IsSequential));
}
AnimationStep step = new AnimationStep(stepData.StepDescription, stepData.Score, actions);
@ -56,75 +56,60 @@ namespace DefaultNamespace.ProcessMode
}
//
// processManager.AddProcess("Teaching");
//
// List<ActionWithDescription> actions = CreateStepActions();
// AnimationStep step = new AnimationStep($"描述步骤", 100, actions);
// processManager.AddStepToProcess("Teaching", step);
// List<ActionWithDescription> actions1 = CreateStepActions1();
// AnimationStep step1 = new AnimationStep($"描述步骤", 100, actions1);
// processManager.AddStepToProcess("Teaching", step1);
}
private List<ActionWithDescription> CreateStepActions()
{
List<ActionWithDescription> actions = new List<ActionWithDescription>();
// private List<ActionWithDescription> CreateStepActions()
// {
// List<ActionWithDescription> actions = new List<ActionWithDescription>();
//
// GameObject obj1 = GameObject.Find("变电箱_门");
// GameObject 插座 = GameObject.Find("插座");
// Action action1 = () => { };
// Action action2 = () => { };
//
// actions.Add(new ActionWithDescription(new List<GameObject>() { obj1,插座 }, action1, $"步骤 {1} 的动作描述"));
// actions.Add(new ActionWithDescription(new List<GameObject>() { 插座,obj1}, action1, $"步骤 {2} 的动作描述"));
//
// return actions;
// }
//
// private List<ActionWithDescription> CreateStepActions1()
// {
// List<ActionWithDescription> actions = new List<ActionWithDescription>();
//
// GameObject obj1 = GameObject.Find("变电箱_门");
// GameObject 插座 = GameObject.Find("插座");
// Action action1 = () => { };
//
// actions.Add(new ActionWithDescription(new List<GameObject>() { obj1 }, action1, $"步骤 {1} 的动作描述"));
// actions.Add(new ActionWithDescription(new List<GameObject>() { 插座 }, action1, $"步骤 {2} 的动作描述"));
//
// return actions;
// }
GameObject obj1 = GameObject.Find("变电箱_门");
GameObject = GameObject.Find("插座");
Action action1 = () => { };
Action action2 = () => { };
actions.Add(new ActionWithDescription(new List<GameObject>() { obj1, }, action1, $"步骤 {1} 的动作描述"));
actions.Add(new ActionWithDescription(new List<GameObject>() { ,obj1}, action1, $"步骤 {2} 的动作描述"));
return actions;
}
private List<ActionWithDescription> CreateStepActions1()
{
List<ActionWithDescription> actions = new List<ActionWithDescription>();
GameObject obj1 = GameObject.Find("变电箱_门");
GameObject = GameObject.Find("插座");
Action action1 = () => { };
actions.Add(new ActionWithDescription(new List<GameObject>() { obj1 }, action1, $"步骤 {1} 的动作描述"));
actions.Add(new ActionWithDescription(new List<GameObject>() { }, action1, $"步骤 {2} 的动作描述"));
return actions;
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
// 假设您有方法来检测点击对象
GameObject clickedObject = DetectClickedObject();
if (clickedObject != null)
{
processManager.HandleClick(clickedObject);
}
}
}
private GameObject DetectClickedObject()
{
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit))
{
return hit.collider.gameObject;
}
return null;
}
// private void Update()
// {
// if (Input.GetMouseButtonDown(0))
// {
// // 假设您有方法来检测点击对象
// GameObject clickedObject = DetectClickedObject();
// if (clickedObject != null)
// {
// processManager.HandleClick(clickedObject);
// }
// }
// }
//
// private GameObject DetectClickedObject()
// {
// Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
// RaycastHit hit;
// if (Physics.Raycast(ray, out hit))
// {
// return hit.collider.gameObject;
// }
//
// return null;
// }
}
}

View File

@ -1,43 +1,26 @@
{
"steps": [
{
"stepDescription": "步骤 1 描述",
"score": 100,
"stepDescription": "步骤 4 描述",
"score": 0,
"actions": [
{
"description": "动作 1 的描述",
"score": 50,
"description": "将集中器连接线的螺丝全部拧开,拧开两个固定该线的螺丝后,线消失。;",
"score": 0,
"isSequential": false,
"targetObjects": [
"变电箱_门",
"插座"
]
},
{
"description": "动作 2 的描述",
"score": 50,
"targetObjects": [
"插座",
"变电箱_门"
]
}
]
},
{
"stepDescription": "步骤 2 描述",
"score": 100,
"actions": [
{
"description": "动作 1 的描述",
"score": 50,
"targetObjects": [
"插座"
]
},
{
"description": "动作 2 的描述",
"score": 50,
"targetObjects": [
"变电箱_门"
"JZQ_螺丝005",
"JZQ_螺丝006",
"JZQ_螺丝009",
"JZQ_螺丝010",
"JZQ_螺丝015",
"JZQ_螺丝016",
"JZQ_螺丝021",
"JZQ_螺丝022",
"JZQ_螺丝023",
"JZQ_螺丝024",
"JZQ_螺丝041",
"JZQ_螺丝042"
]
}
]

View File

@ -3,6 +3,8 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Threading.Tasks;
using DefaultNamespace.ProcessMode;
using MotionFramework;
using UnityEngine;
/// <summary>
@ -40,6 +42,7 @@ public class ElectricCheckPen : MonoBehaviour
bool raycast = Physics.Raycast(ray, out hit);
if (raycast)
{
MotionEngine.GetModule<AnimationProcessManager>().HandleClick(hit.collider.gameObject);
if (hit.collider.gameObject.name == "±äµçÏä_ÃÅ")
{
ElectricCheckPenOBJ.gameObject.transform.DOMove(new Vector3(303.038f, 2.655f, 163.822f), 2f);