81 lines
3.0 KiB
C#
81 lines
3.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using DefaultNamespace.Dto;
|
|
using DG.Tweening;
|
|
using MotionFramework;
|
|
using Newtonsoft.Json;
|
|
using UnityEngine;
|
|
|
|
namespace DefaultNamespace.ProcessMode
|
|
{
|
|
[ScriptDescription("现场场景的流程启动器")]
|
|
public class SceneProcessLauncher : MonoBehaviour
|
|
{
|
|
private AnimationProcessManager processManager;
|
|
|
|
|
|
private async void Start()
|
|
{
|
|
await Task.Delay(TimeSpan.FromSeconds(1));
|
|
|
|
|
|
processManager = MotionEngine.GetModule<AnimationProcessManager>();
|
|
|
|
|
|
processManager.ClearProcess();
|
|
|
|
processManager.AddProcess(MotionEngine.GetModule<DataConfigManager>().GetProcessMode().ToString());
|
|
|
|
string json = System.IO.File.ReadAllText(Application.streamingAssetsPath + "/DataConfig/SceneStepData.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 = () => { };
|
|
actions.Add(new ActionWithDescription(targetObjects, action, actionData.Description, actionData.IsSequential,stepData.StepDescription));
|
|
}
|
|
|
|
AnimationStep step = new AnimationStep(stepData.StepDescription, stepData.Score, actions);
|
|
processManager.AddStepToProcess(MotionEngine.GetModule<DataConfigManager>().GetProcessMode().ToString(), step);
|
|
}
|
|
|
|
InitializeFirstStep();
|
|
|
|
}
|
|
|
|
private void InitializeFirstStep()
|
|
{
|
|
ProcessMode initialMode = ProcessMode.Training; // 假设初始模式是教学模式
|
|
MotionEngine.GetModule<AnimationProcessManager>().SetCurrentMode(initialMode);
|
|
|
|
if (MotionEngine.GetModule<AnimationProcessManager>().CurrentProcess.Steps.Count > 0)
|
|
{
|
|
AnimationStep firstStep = MotionEngine.GetModule<AnimationProcessManager>().CurrentProcess.Steps[0];
|
|
if (firstStep.Actions.Count > 0)
|
|
{
|
|
MotionEngine.GetModule<AnimationProcessManager>().PrepareNextStep(initialMode, firstStep.Actions[0]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |