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

130 lines
4.6 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));
}
AnimationStep step = new AnimationStep(stepData.StepDescription, stepData.Score, actions);
processManager.AddStepToProcess("Teaching", step);
}
//
// 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>();
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;
}
}
}