86 lines
3.0 KiB
C#
86 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;
|
|
[SerializeField] private ToolsPackScene _toolsPackScene;
|
|
[SerializeField] private ProcessMode _processMode;
|
|
|
|
private async void Start()
|
|
{
|
|
await Task.Delay(TimeSpan.FromSeconds(1));
|
|
|
|
|
|
processManager = MotionEngine.GetModule<AnimationProcessManager>();
|
|
|
|
|
|
processManager.ClearProcess();
|
|
|
|
_processMode = MotionEngine.GetModule<DataConfigManager>().GetProcessMode();
|
|
|
|
|
|
processManager.AddProcess(_processMode.ToString());
|
|
|
|
string json = "";
|
|
|
|
if (_toolsPackScene == ToolsPackScene.工具间)
|
|
{
|
|
json = System.IO.File.ReadAllText(Application.streamingAssetsPath + "/DataConfig/ToolsSceneStepData.json");
|
|
}
|
|
else
|
|
{
|
|
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<string> targetObjects = new List<string>();
|
|
foreach (var objectName in actionData.TargetObjects)
|
|
{
|
|
targetObjects.Add(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(_processMode.ToString(), step);
|
|
}
|
|
|
|
if (_processMode == ProcessMode.Teaching)
|
|
InitializeFirstStep();
|
|
}
|
|
|
|
private void InitializeFirstStep()
|
|
{
|
|
MotionEngine.GetModule<AnimationProcessManager>().SetCurrentMode(_processMode);
|
|
|
|
if (MotionEngine.GetModule<AnimationProcessManager>().CurrentProcess.Steps.Count > 0)
|
|
{
|
|
AnimationStep firstStep = MotionEngine.GetModule<AnimationProcessManager>().CurrentProcess.Steps[0];
|
|
if (firstStep.Actions.Count > 0)
|
|
{
|
|
MotionEngine.GetModule<AnimationProcessManager>().HandleModeFeedback(_processMode, firstStep.Actions[0]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |