This commit is contained in:
yzx 2024-06-21 17:35:13 +08:00
parent aab0b3f40d
commit 0d1767ad0a
12 changed files with 378 additions and 78 deletions

View File

@ -51,7 +51,7 @@ public class GameLauncher : MonoBehaviour
// DeveloperConsole.Draw();
}
private void CreateGameModules()
private async void CreateGameModules()
{
//webrequest管理器
MotionEngine.CreateModule<WebRequestManager>();
@ -68,6 +68,11 @@ public class GameLauncher : MonoBehaviour
//加载配置信息
MotionEngine.CreateModule<InfoDataManager>();
//获取网络步骤分数
MotionEngine.GetModule<AnimationProcessManager>().GetNetworkSetpData();
//初始化步骤
MotionEngine.GetModule<AnimationProcessManager>().InitializeFirstStep();
}
private void HandleMotionFrameworkLog(ELogLevel logLevel, string log)

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 80770744552e04a4cbb4360f68db8f11
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -7491,7 +7491,6 @@ GameObject:
- component: {fileID: 505215071}
- component: {fileID: 505215072}
- component: {fileID: 505215073}
- component: {fileID: 505215074}
m_Layer: 0
m_Name: APP
m_TagString: Untagged
@ -7572,20 +7571,6 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 0d3b1a9715a34aa8ab0530af2056aaf9, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &505215074
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 505215068}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 51f73ee94f284a86b677a6bc74544094, type: 3}
m_Name:
m_EditorClassIdentifier:
_toolsPackScene: 0
_processMode: 0
--- !u!1 &514951653
GameObject:
m_ObjectHideFlags: 0

View File

@ -0,0 +1,68 @@
using System.Collections.Generic;
namespace DefaultNamespace.Dto
{
public class SceneStepListItem
{
/// <summary>
/// 填写工作票
/// </summary>
public string stepName { get; set; }
/// <summary>
/// 填写工作票
/// </summary>
public string testPoint { get; set; }
/// <summary>
///
/// </summary>
public int defaultScore { get; set; }
}
public class SceneStepTaskListItem
{
/// <summary>
/// 抄表
/// </summary>
public string sceneName { get; set; }
/// <summary>
///
/// </summary>
public string sceneCode { get; set; }
/// <summary>
///
/// </summary>
public string type { get; set; }
/// <summary>
///
/// </summary>
public List<SceneStepListItem> stepList { get; set; }
}
public class SceneStepData
{
/// <summary>
/// 用电采集终端模拟仿真
/// </summary>
public string trainingName { get; set; }
/// <summary>
///
/// </summary>
public string appId { get; set; }
/// <summary>
///
/// </summary>
public string version { get; set; }
/// <summary>
///
/// </summary>
public List<SceneStepTaskListItem> taskList { get; set; }
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 5f6ba8b2926a4829b00157cab2d6c47b
timeCreated: 1718959393

View File

@ -12,6 +12,11 @@ public class MessageManager : MonoBehaviour
public TMP_Text text;
void Start()
{
if ( MotionEngine.GetModule<AnimationProcessManager>().GetProcessMode() == ProcessMode.Teaching || MotionEngine.GetModule<AnimationProcessManager>().GetProcessMode() == ProcessMode.Assessment)
{
this.gameObject.SetActive(false);
}
MotionEngine.GetModule<AnimationProcessManager>().OnSendMessagePrompt += SendMessagePrompt;
}

View File

@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DefaultNamespace.Dto;
using HighlightPlus;
using MotionFramework;
using MotionFramework.Scripts.Runtime.Engine.Engine.Network.WebRequest;
using Newtonsoft.Json;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
@ -18,7 +21,9 @@ namespace DefaultNamespace.ProcessMode
private int currentStepIndex; // 当前步骤索引
private int currentActionIndex; // 当前动作索引,确保动作顺序
private int currentActionGameIndex; // 当前动作索引,确保动作顺序
private List<IncorrectClick> incorrectClicks; // 错误点击的记录列表
private Dictionary<int, List<string>> incorrectClicksPerStep; // 每个步骤的错误点击记录
private SceneStepData _sceneStepData;
public AnimationProcess CurrentProcess => processes[currentMode.ToString()];
public delegate void CompleteEventHandler();
@ -62,6 +67,22 @@ namespace DefaultNamespace.ProcessMode
}
}
/// <summary>
/// 添加错误点击记录
/// </summary>
/// <param name="stepIndex">当前步骤索引</param>
/// <param name="clickedObject">错误点击的物体</param>
private void AddIncorrectClick(int stepIndex, string clickedObject)
{
if (!incorrectClicksPerStep.ContainsKey(stepIndex))
{
incorrectClicksPerStep[stepIndex] = new List<string>();
}
incorrectClicksPerStep[stepIndex].Add(clickedObject);
Debug.Log($"步骤 {stepIndex + 1} 错误点击的物体: {clickedObject}");
}
public void HandleClick(string clickedObject)
{
string type = currentMode.ToString();
@ -95,6 +116,7 @@ namespace DefaultNamespace.ProcessMode
{
string correctObjectName = currentAction.TargetObjects[currentAction.CurrentObjectIndex];
Debug.Log($"错误点击或顺序错误:{clickedObject}。正确的物体是:{correctObjectName}");
AddIncorrectClick(currentStepIndex, clickedObject);
}
}
else
@ -134,6 +156,7 @@ namespace DefaultNamespace.ProcessMode
string correctObjects = string.Join(",", correctObjectNames);
Debug.Log($"正确的物体是:{correctObjects}");
AddIncorrectClick(currentStepIndex, clickedObject);
}
}
}
@ -171,9 +194,15 @@ namespace DefaultNamespace.ProcessMode
var nextStep = processes[currentMode.ToString()].Steps[currentStepIndex];
HandleModeFeedback(currentMode, nextStep.Actions[0]); // 准备下一个步骤
currentActionIndex = 0; // 重置动作索引或进入下一个大步骤
currentStepIndex++;
if (currentStepIndex == processes[currentMode.ToString()].Steps.Count)
{
CalculateTotalScore();
Debug.Log("全部完成了!!!!");
}
}
else
{
@ -182,6 +211,7 @@ namespace DefaultNamespace.ProcessMode
OnCompleteEvent?.Invoke();
}
CalculateTotalScore();
Debug.Log("全部完成了!!!!");
}
}
@ -207,13 +237,10 @@ namespace DefaultNamespace.ProcessMode
OnCompleteEvent?.Invoke();
}
CalculateTotalScore();
Debug.Log("全部完成了!!!!");
}
}
}
else
{
@ -373,10 +400,32 @@ namespace DefaultNamespace.ProcessMode
}
}
/// <summary>
/// 计算总分
/// </summary>
private void CalculateTotalScore()
{
float totalScore = 0;
foreach (var step in processes[currentMode.ToString()].Steps)
{
int stepIndex = processes[currentMode.ToString()].Steps.IndexOf(step);
if (incorrectClicksPerStep.ContainsKey(stepIndex))
{
Debug.Log($"步骤 {stepIndex + 1} 错误点击的物体: {string.Join(", ", incorrectClicksPerStep[stepIndex])}");
}
else
{
totalScore += step.Score; // 每个步骤满分为10
}
}
Debug.Log($"总分: {totalScore}");
}
public void OnCreate(object createParam)
{
processes = new Dictionary<string, AnimationProcess>();
incorrectClicks = new List<IncorrectClick>();
incorrectClicksPerStep = new Dictionary<int, List<string>>();
}
public void OnUpdate()
@ -390,5 +439,150 @@ namespace DefaultNamespace.ProcessMode
public void OnGUI()
{
}
public async void GetNetworkSetpData()
{
// string json = await MotionEngine.GetModule<WebRequestManager>().GetTextAsync("", null);
string jsonString = @"{
'trainingName':'仿',
'appId':'ydcjzdmnfz001',
'version':'1.0.0',
'taskList':[{
'sceneName':'',
'sceneCode':'cb',
'type':'1',
'stepList':[{
'stepName':'',
'testPoint':'',
'defaultScore':10
},
{
'stepName':'',
'testPoint':'线l型集中器',
'defaultScore':20
},
{
'stepName':'',
'testPoint':'',
'defaultScore':5
},
{
'stepName':'',
'testPoint':'',
'defaultScore':10
},
{
'stepName':'',
'testPoint':'使',
'defaultScore':10
},
{
'stepName':'',
'testPoint':'线',
'defaultScore':4
},
{
'stepName':'',
'testPoint':'线线线线',
'defaultScore':4
},
{
'stepName':'',
'testPoint':'',
'defaultScore':4
},
{
'stepName':'',
'testPoint':'',
'defaultScore':4
},
{
'stepName':'',
'testPoint':'',
'defaultScore':4
},
{
'stepName':'',
'testPoint':'线线',
'defaultScore':4
},
{
'stepName':'',
'testPoint':'',
'defaultScore':4
},
{
'stepName':'',
'testPoint':'线',
'defaultScore':4
}]
}]
}";
_sceneStepData = JsonConvert.DeserializeObject<SceneStepData>(jsonString);
Debug.Log(_sceneStepData.appId);
}
/// <summary>
/// 初始化步骤
/// </summary>
public void InitializeFirstStep()
{
currentMode = MotionEngine.GetModule<DataConfigManager>().GetProcessMode();
AddProcess(currentMode.ToString());
string json = System.IO.File.ReadAllText(Application.streamingAssetsPath + "/DataConfig/ToolsSceneStepData.json");
StepsContainer stepsContainer = JsonConvert.DeserializeObject<StepsContainer>(json);
int index = 0;
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, _sceneStepData.taskList[0].stepList[index].defaultScore, actions);
AnimationStep step = new AnimationStep(stepData.StepDescription,stepData.Score , actions);
index++;
AddStepToProcess(currentMode.ToString(), step);
}
//教学模式和培训模式需要初始化一下
if (currentMode == ProcessMode.Teaching || currentMode == ProcessMode.Training)
{
if (CurrentProcess.Steps.Count > 0)
{
AnimationStep firstStep = CurrentProcess.Steps[0];
if (firstStep.Actions.Count > 0)
{
HandleModeFeedback(currentMode, firstStep.Actions[0]);
}
}
}
}
public ProcessMode GetProcessMode()
{
return currentMode;
}
}
}

View File

@ -17,23 +17,19 @@ namespace DefaultNamespace.ProcessMode
[SerializeField] private ToolsPackScene _toolsPackScene;
[SerializeField] private ProcessMode _processMode;
[SerializeField] private GameObject messageGame;
private async void Start()
private void Awake()
{
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.)
@ -67,9 +63,25 @@ namespace DefaultNamespace.ProcessMode
processManager.AddStepToProcess(_processMode.ToString(), step);
}
if (_processMode == ProcessMode.Practice || _processMode == ProcessMode.Training)
{
messageGame.SetActive(true);
}
else
{ messageGame.SetActive(false);
}
//教学模式和培训模式需要初始化一下
if (_processMode == ProcessMode.Teaching||_processMode == ProcessMode.Training)
InitializeFirstStep();
}
private void InitializeFirstStep()

View File

@ -1,4 +1,6 @@
using System;
using DefaultNamespace.ProcessMode;
using MotionFramework;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
@ -12,6 +14,7 @@ namespace ToolsPack
{
this.GetComponent<Button>().onClick.AddListener(delegate
{
MotionEngine.GetModule<AnimationProcessManager>().HandleClick("前往现场");
SceneManager.LoadScene(Scenename);
});
}

View File

@ -13,10 +13,15 @@ public class test1 : MonoBehaviour
// Start is called before the first frame update
void Start()
{
string json =
@"{""scenename"":""场景名称"",""questbooks"":""本次训练任务默认停电作业,现场集中器损坏,需要查看情况,并处理。"",""userinformation"":""用户基本信息"",""energyinformation"":""现场电能表信息内容"",""energylist"":[{""work"":""正向有功"",""worklist"":[{""keywork"":""总"",""valuework"":630732.86},{""keywork"":""尖"",""valuework"":0},{""keywork"":""峰"",""valuework"":600227.02},{""keywork"":""平"",""valuework"":0},{""keywork"":""谷"",""valuework"":30505.84}]},{""work"":""正向无功"",""worklist"":[{""keywork"":""总"",""valuework"":90704.72},{""keywork"":""尖"",""valuework"":0},{""keywork"":""峰"",""valuework"":82394.39},{""keywork"":""平"",""valuework"":0},{""keywork"":""谷"",""valuework"":8310.33}]},{""work"":""反向有功"",""worklist"":[{""keywork"":""总"",""valuework"":0},{""keywork"":""尖"",""valuework"":0},{""keywork"":""峰"",""valuework"":0},{""keywork"":""平"",""valuework"":0},{""keywork"":""谷"",""valuework"":0}]},{""work"":""反向无功"",""worklist"":[{""keywork"":""总"",""valuework"":18385.2},{""keywork"":""尖"",""valuework"":0},{""keywork"":""峰"",""valuework"":13222.55},{""keywork"":""平"",""valuework"":0},{""keywork"":""谷"",""valuework"":5162.65}]}]}";
SceneInformation sceneInfo = JsonConvert.DeserializeObject<SceneInformation>(json);
Debug.Log("Scene Name: " + sceneInfo.SceneName);
this.GetComponent<MeshRenderer>().material.SetFloat("_SwitchOfEmi",0);
// string json =
// @"{""scenename"":""场景名称"",""questbooks"":""本次训练任务默认停电作业,现场集中器损坏,需要查看情况,并处理。"",""userinformation"":""用户基本信息"",""energyinformation"":""现场电能表信息内容"",""energylist"":[{""work"":""正向有功"",""worklist"":[{""keywork"":""总"",""valuework"":630732.86},{""keywork"":""尖"",""valuework"":0},{""keywork"":""峰"",""valuework"":600227.02},{""keywork"":""平"",""valuework"":0},{""keywork"":""谷"",""valuework"":30505.84}]},{""work"":""正向无功"",""worklist"":[{""keywork"":""总"",""valuework"":90704.72},{""keywork"":""尖"",""valuework"":0},{""keywork"":""峰"",""valuework"":82394.39},{""keywork"":""平"",""valuework"":0},{""keywork"":""谷"",""valuework"":8310.33}]},{""work"":""反向有功"",""worklist"":[{""keywork"":""总"",""valuework"":0},{""keywork"":""尖"",""valuework"":0},{""keywork"":""峰"",""valuework"":0},{""keywork"":""平"",""valuework"":0},{""keywork"":""谷"",""valuework"":0}]},{""work"":""反向无功"",""worklist"":[{""keywork"":""总"",""valuework"":18385.2},{""keywork"":""尖"",""valuework"":0},{""keywork"":""峰"",""valuework"":13222.55},{""keywork"":""平"",""valuework"":0},{""keywork"":""谷"",""valuework"":5162.65}]}]}";
// SceneInformation sceneInfo = JsonConvert.DeserializeObject<SceneInformation>(json);
// Debug.Log("Scene Name: " + sceneInfo.SceneName);
}
private void HandleStringEvent(string message)

View File

@ -1,5 +1,61 @@
{
"steps": [
{
"stepDescription": "填写工作票",
"score": 0,
"actions": [
{
"description": "填写工作票",
"score": 0,
"isSequential": true,
"targetObjects": [
"工作单"
]
}
]
},
{
"stepDescription": "领取工器具及仪器设备",
"score": 0,
"actions": [
{
"description": "领取工器具及仪器设备",
"score": 0,
"isSequential": false,
"targetObjects": [
"螺丝刀"
]
}
]
},
{
"stepDescription": "佩戴装备检视",
"score": 0,
"actions": [
{
"description": "佩戴装备检视",
"score": 0,
"isSequential": false,
"targetObjects": [
"梳妆镜"
]
}
]
},
{
"stepDescription": "前往现场",
"score": 0,
"actions": [
{
"description": "前往现场",
"score": 0,
"isSequential": false,
"targetObjects": [
"前往现场"
]
}
]
},
{
"stepDescription": "前往现场",
"score": 0,

View File

@ -2,11 +2,11 @@
"steps": [
{
"stepDescription": "填写工作票",
"score": 0,
"score": 11,
"actions": [
{
"description": "填写工作票",
"score": 0,
"score": 11,
"isSequential": true,
"targetObjects": [
"工作单"
@ -16,45 +16,17 @@
},
{
"stepDescription": "领取工器具及仪器设备",
"score": 0,
"score": 22,
"actions": [
{
"description": "领取工器具及仪器设备",
"score": 0,
"score": 22,
"isSequential": false,
"targetObjects": [
"螺丝刀"
]
}
]
},
{
"stepDescription": "佩戴装备检视",
"score": 0,
"actions": [
{
"description": "佩戴装备检视",
"score": 0,
"isSequential": false,
"targetObjects": [
"梳妆镜"
]
}
]
},
{
"stepDescription": "前往现场",
"score": 0,
"actions": [
{
"description": "前往现场",
"score": 0,
"isSequential": false,
"targetObjects": [
"null"
]
}
]
}
]
}