115 lines
4.2 KiB
C#
115 lines
4.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DefaultNamespace.Dto;
|
|
using DG.Tweening;
|
|
using MotionFramework;
|
|
using Newtonsoft.Json;
|
|
using UnityEngine;
|
|
|
|
namespace DefaultNamespace.ProcessMode
|
|
{
|
|
public class test : MonoBehaviour
|
|
{
|
|
private AnimationProcessManager processManager;
|
|
|
|
|
|
private IEnumerator Start()
|
|
{
|
|
processManager = MotionEngine.GetModule<AnimationProcessManager>();
|
|
|
|
|
|
yield return new WaitForSeconds(1);
|
|
|
|
processManager.AddProcess("Teaching");
|
|
|
|
string json = System.IO.File.ReadAllText(Application.streamingAssetsPath + "/DataConfig/StepData.json");
|
|
StepsContainer stepsContainer = JsonConvert.DeserializeObject<StepsContainer>(json);
|
|
|
|
|
|
foreach (var stepData in stepsContainer.Steps)
|
|
{
|
|
List<ActionWithDescription> actions = new List<ActionWithDescription>();
|
|
|
|
foreach (var actionData in stepData.Actions)
|
|
{
|
|
List<GameObject> targetObjects = new List<GameObject>();
|
|
foreach (var objectName in actionData.TargetObjects)
|
|
{
|
|
GameObject obj = GameObject.Find(objectName);
|
|
if (obj != null)
|
|
{
|
|
targetObjects.Add(obj);
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError($"Object not found: {objectName}");
|
|
}
|
|
}
|
|
|
|
Action action = () => { Debug.Log(actionData.Description); };
|
|
actions.Add(new ActionWithDescription(targetObjects, action, actionData.Description, actionData.IsSequential));
|
|
}
|
|
|
|
AnimationStep step = new AnimationStep(stepData.StepDescription, stepData.Score, actions);
|
|
processManager.AddStepToProcess("Teaching", step);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
// 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;
|
|
// }
|
|
|
|
// 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;
|
|
// }
|
|
}
|
|
} |