diff --git a/Assets/Art/UIPrefab/UIHint.prefab b/Assets/Art/UIPrefab/UIHint.prefab index 601d07bc..2481b853 100644 --- a/Assets/Art/UIPrefab/UIHint.prefab +++ b/Assets/Art/UIPrefab/UIHint.prefab @@ -92,10 +92,10 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Padding: - m_Left: 0 - m_Right: 0 - m_Top: 10 - m_Bottom: 10 + m_Left: 100 + m_Right: 100 + m_Top: 15 + m_Bottom: 15 m_ChildAlignment: 4 m_Spacing: 5 m_ChildForceExpandWidth: 0 @@ -177,7 +177,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 1} m_AnchorMax: {x: 0, y: 1} - m_AnchoredPosition: {x: -14.2, y: -11} + m_AnchoredPosition: {x: -14.200012, y: -11} m_SizeDelta: {x: 20, y: 22} m_Pivot: {x: 0.5, y: 0.5} --- !u!222 &2796669925366751870 diff --git a/Assets/Scripts/Actions/ActionHelper.cs b/Assets/Scripts/Actions/ActionHelper.cs index 166975b3..b1ff7e73 100644 --- a/Assets/Scripts/Actions/ActionHelper.cs +++ b/Assets/Scripts/Actions/ActionHelper.cs @@ -194,8 +194,8 @@ public class ActionHelper } case "ResultTip": { - var strAction = (XMLTool.StringListAction)act; - return ResultTipAction.Allocate(act.Value, strAction.args[0], strAction.args[1]); + var strAction = (XMLTool.DictionaryAction)act; + return ResultTipAction.Allocate(act.Value, strAction.args); } case "Led": { @@ -254,27 +254,30 @@ public class ActionHelper /// public static ICondition GetCondition(XMLTool.ActionItem condition) { - switch (condition.Type) + if (condition!=null) { - case "And": - case "Or": - var group = ConditionGroup.Allocate(condition.Type); - foreach (var item in condition.SubActions) - { - group.AddCondition(GetCondition(item)); - } - return group; - case "UIClick": - return UIClickCondition.Allocate(condition.Value); - case "ObjClick": - var dict = (XMLTool.DictionaryCondition)condition; - return ObjClickCondition.Allocate(dict.Value, dict.args); - case "Input": - return InputCondition.Allocate(condition.Value); - case "Var": - return VarCondition.Allocate(condition.Name, condition.Value); - case "StrEvent": - return StrEventCondition.Allocate(condition.Value); + switch (condition.Type) + { + case "And": + case "Or": + var group = ConditionGroup.Allocate(condition.Type); + foreach (var item in condition.SubActions) + { + group.AddCondition(GetCondition(item)); + } + return group; + case "UIClick": + return UIClickCondition.Allocate(condition.Value); + case "ObjClick": + var dict = (XMLTool.DictionaryCondition)condition; + return ObjClickCondition.Allocate(dict.Value, dict.args); + case "Input": + return InputCondition.Allocate(condition.Value); + case "Var": + return VarCondition.Allocate(condition.Name, condition.Value); + case "StrEvent": + return StrEventCondition.Allocate(condition.Value); + } } return null; } diff --git a/Assets/Scripts/Actions/AnimationAction.cs b/Assets/Scripts/Actions/AnimationAction.cs index d22a624f..c212e4a6 100644 --- a/Assets/Scripts/Actions/AnimationAction.cs +++ b/Assets/Scripts/Actions/AnimationAction.cs @@ -1,8 +1,11 @@ using DG.Tweening; +using DG.Tweening.Core; +using DG.Tweening.Plugins.Options; using System; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering.Universal; +using static OperationController; namespace QFramework { @@ -27,6 +30,8 @@ namespace QFramework string frame; string speed; string deviceName; + + float totalTime; public static AnimationAction Allocate(string path, Dictionary datas, System.Action OnFinished = null) { var retNode = mPool.Allocate(); @@ -43,7 +48,7 @@ namespace QFramework } public ulong ActionID { get; set; } public ActionStatus Status { get; set; } - + TweenerCore animDot; public void OnStart() { GameObject obj = null; @@ -87,7 +92,8 @@ namespace QFramework { anim.Play(animName); anim[animName].normalizedTime = 1; - DOTween.To(() => anim[animName].normalizedTime, v => anim[animName].normalizedTime = v, 0, anim[animName].length / Math.Abs(curSpeed)).onComplete = () => + animDot = DOTween.To(() => anim[animName].normalizedTime, v => anim[animName].normalizedTime = v, 0, anim[animName].length / Math.Abs(curSpeed)); + animDot.onComplete = () => { anim.Stop(); }; @@ -95,16 +101,13 @@ namespace QFramework else { anim[animName].speed = curSpeed; - anim.Play(animName); - if (anim[animName].wrapMode == WrapMode.Loop) { this.Finish(); } } - - + totalTime = Math.Abs(anim[animName].length / curSpeed); } } catch (Exception) @@ -120,9 +123,11 @@ namespace QFramework } } + public void OnExecute(float dt) { - if (anim != null && anim.isPlaying == false) + totalTime -= Time.deltaTime; + if (anim != null && (anim.isPlaying == false || totalTime <= 0)) { this.Finish(); } @@ -144,6 +149,8 @@ namespace QFramework { if (!Deinited) { + animDot?.Kill(); + anim?.Stop(); OnFinished = null; Deinited = true; mPool.Recycle(this); diff --git a/Assets/Scripts/Actions/CameraSwitchAction.cs b/Assets/Scripts/Actions/CameraSwitchAction.cs index 48f0e77d..beaa5066 100644 --- a/Assets/Scripts/Actions/CameraSwitchAction.cs +++ b/Assets/Scripts/Actions/CameraSwitchAction.cs @@ -47,9 +47,14 @@ namespace QFramework } else { - data.nearPos = Utility.GetVector3FromStrArray(datas["nearPos"]); - data.nearRot = Utility.GetVector3FromStrArray(datas["nearRot"]); - + if (datas.ContainsKey("nearPos")) + { + data.nearPos = Utility.GetVector3FromStrArray(datas["nearPos"]); + } + if (datas.ContainsKey("nearRot")) + { + data.nearRot = Utility.GetVector3FromStrArray(datas["nearRot"]); + } } if (datas.ContainsKey("normalDevice")) @@ -60,8 +65,14 @@ namespace QFramework } else { - data.normalPos = Utility.GetVector3FromStrArray(datas["normalPos"]); - data.normalRot = Utility.GetVector3FromStrArray(datas["normalRot"]); + if (datas.ContainsKey("normalPos")) + { + data.normalPos = Utility.GetVector3FromStrArray(datas["normalPos"]); + } + if (datas.ContainsKey("normalRot")) + { + data.normalRot = Utility.GetVector3FromStrArray(datas["normalRot"]); + } } if (datas.ContainsKey("isOn")) { diff --git a/Assets/Scripts/Actions/MatAction.cs b/Assets/Scripts/Actions/MatAction.cs index 14af6ca1..0ee2c157 100644 --- a/Assets/Scripts/Actions/MatAction.cs +++ b/Assets/Scripts/Actions/MatAction.cs @@ -24,6 +24,7 @@ namespace QFramework string deviceName; string matName; string index; + string mainTexture; public static MatAction Allocate(Dictionary datas, System.Action OnFinished = null) { var retNode = mPool.Allocate(); @@ -34,6 +35,7 @@ namespace QFramework retNode.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : ""; retNode.matName = datas.ContainsKey("matName") ? datas["matName"] : ""; retNode.index = datas.ContainsKey("index") ? datas["index"] : "0"; + retNode.mainTexture = datas.ContainsKey("mainTexture") ? datas["mainTexture"] : null; retNode.OnFinished = OnFinished; return retNode; } @@ -56,7 +58,22 @@ namespace QFramework var mesh = obj.GetComponent(); int matIndex = 0; int.TryParse(index, out matIndex); - mesh.materials[matIndex] = Resources.Load("Mat/" + matName); + if (string.IsNullOrEmpty(matName) == false) + { + mesh.materials[matIndex] = Resources.Load("Mat/" + matName); + } + if (mainTexture != null) + { + if (mainTexture == "") + { + mesh.materials[matIndex].mainTexture = null; + } + else + { + mesh.materials[matIndex].mainTexture = Resources.Load("Mat/" + mainTexture); + } + } + this.Finish(); } diff --git a/Assets/Scripts/Actions/ResultTipAction.cs b/Assets/Scripts/Actions/ResultTipAction.cs index 998c7abc..ac21c186 100644 --- a/Assets/Scripts/Actions/ResultTipAction.cs +++ b/Assets/Scripts/Actions/ResultTipAction.cs @@ -1,5 +1,6 @@ using QFramework.Example; using System; +using System.Collections.Generic; using UnityEngine; namespace QFramework @@ -19,15 +20,17 @@ namespace QFramework public string txt; public string isRight; public string finishedEvent; - public static ResultTipAction Allocate(string txt, string isRight, string finishedEvent, System.Action OnFinished = null) + string autoHide; + public static ResultTipAction Allocate(string txt, Dictionary datas, System.Action OnFinished = null) { var retNode = mPool.Allocate(); retNode.ActionID = ActionKit.ID_GENERATOR++; retNode.Deinited = false; retNode.Reset(); retNode.txt = txt; - retNode.isRight = isRight; - retNode.finishedEvent = finishedEvent; + retNode.isRight = datas.ContainsKey("isRight") ? datas["isRight"] : ""; + retNode.finishedEvent = datas.ContainsKey("finishedEvent") ? datas["finishedEvent"] : ""; + retNode.autoHide = datas.ContainsKey("autoHide") ? datas["autoHide"] : "-1"; retNode.OnFinished = OnFinished; return retNode; } @@ -45,6 +48,7 @@ namespace QFramework { data.callback = () => StringEventSystem.Global.Send(finishedEvent); } + float.TryParse(autoHide, out data.autoHideTime); UIKit.OpenPanelAsync(uiData: data, canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() => this.Finish()); } diff --git a/Assets/Scripts/Actions/ShowAction.cs b/Assets/Scripts/Actions/ShowAction.cs index 096d196a..a34ce52b 100644 --- a/Assets/Scripts/Actions/ShowAction.cs +++ b/Assets/Scripts/Actions/ShowAction.cs @@ -75,7 +75,7 @@ public class ShowAction : IAction if (obj == null) { - Debug.LogError("没有找到物体 :" + path); + Debug.LogError($"没有找到物体 path:{path} deviceName:{deviceName}"); } else { diff --git a/Assets/Scripts/Actions/UIToolsAction.cs b/Assets/Scripts/Actions/UIToolsAction.cs index b5ef95dc..df5ebfab 100644 --- a/Assets/Scripts/Actions/UIToolsAction.cs +++ b/Assets/Scripts/Actions/UIToolsAction.cs @@ -23,6 +23,7 @@ public class UIToolsAction : IAction string wrongEvent; string rightScore; string wrongScore; + string totalScore; string scoreStepName; string autoHide; public static UIToolsAction Allocate(Dictionary datas, System.Action onDelayFinish = null) @@ -40,6 +41,7 @@ public class UIToolsAction : IAction retNode.wrongEvent = datas.ContainsKey("wrongEvent") ? datas["wrongEvent"] : ""; retNode.rightScore = datas.ContainsKey("rightScore") ? datas["rightScore"] : ""; retNode.wrongScore = datas.ContainsKey("wrongScore") ? datas["wrongScore"] : ""; + retNode.totalScore = datas.ContainsKey("totalScore") ? datas["totalScore"] : ""; retNode.scoreStepName = datas.ContainsKey("scoreStepName") ? datas["scoreStepName"] : ""; retNode.autoHide = datas.ContainsKey("autoHide") ? datas["autoHide"] : ""; return retNode; @@ -75,6 +77,7 @@ public class UIToolsAction : IAction data.wrongEvent = wrongEvent; float.TryParse(rightScore, out data.rightScore); float.TryParse(wrongScore, out data.wrongScore); + float.TryParse(totalScore, out data.totalScore); data.scoreStepName = scoreStepName; bool.TryParse(setActive, out data.SetActive); if (float.TryParse(autoHide, out data.autoHideResult) == false) diff --git a/Assets/Scripts/Controller/ScoreController.cs b/Assets/Scripts/Controller/ScoreController.cs index 2d8834bb..460ded4d 100644 --- a/Assets/Scripts/Controller/ScoreController.cs +++ b/Assets/Scripts/Controller/ScoreController.cs @@ -7,24 +7,65 @@ using XMLTool; public class ScoreController : MonoSingleton { - public Dictionary scoreDict; + public class Data + { + public Dictionary scoreDict; + } + + public Dictionary moduleDict; public override void OnSingletonInit() { base.OnSingletonInit(); - scoreDict = new Dictionary(); - TypeEventSystem.Global.Register(OnStart).UnRegisterWhenGameObjectDestroyed(gameObject); - TypeEventSystem.Global.Register(OnQuit).UnRegisterWhenGameObjectDestroyed(gameObject); + InitData(); } + + public void Init() + { + if (Global.Instance.curModule.type == "Exam" || Global.Instance.curModule.type == "All") + { + TypeEventSystem.Global.Register(OnStart); + TypeEventSystem.Global.Register(OnQuit); + } + } + + public void InitData() + { + moduleDict = new Dictionary(); + foreach (var item in Global.Instance.appData.Modules) + { + if (item.type == "Exam" || item.type == "All") + { + Data data = new Data() { scoreDict = new Dictionary() }; + moduleDict.Add(item.ModuleName, data); + } + } + } + + + private void OnStart(OnModuleStart start) { + var data = moduleDict[Global.Instance.curModule.ModuleName]; + data.scoreDict.Clear(); foreach (var item in Global.Instance.curModule.score.scores) { item.value = 0; - scoreDict.Add(item.step + item.name, item); + data.scoreDict.Add(item.step + item.name, item); } + } + + public Dictionary GetCurScore() + { + var data = moduleDict[Global.Instance.curModule.ModuleName]; + return data.scoreDict; + } + + public void Add(string key, float value) { + var data = moduleDict[Global.Instance.curModule.ModuleName]; + var scoreDict = data.scoreDict; if (scoreDict.ContainsKey(key)) { scoreDict[key].value += value; @@ -43,6 +84,8 @@ public class ScoreController : MonoSingleton public void Set(string key, float value) { + var data = moduleDict[Global.Instance.curModule.ModuleName]; + var scoreDict = data.scoreDict; if (scoreDict.ContainsKey(key)) { scoreDict[key].value = value; @@ -53,7 +96,11 @@ public class ScoreController : MonoSingleton private void OnQuit(OnModuleQuit quit) { + var data = moduleDict[Global.Instance.curModule.ModuleName]; + var scoreDict = data.scoreDict; scoreDict.Clear(); + TypeEventSystem.Global.UnRegister(OnStart); + TypeEventSystem.Global.UnRegister(OnQuit); } diff --git a/Assets/Scripts/Controller/StateMachineController.cs b/Assets/Scripts/Controller/StateMachineController.cs index ae0d95c9..0baae4d2 100644 --- a/Assets/Scripts/Controller/StateMachineController.cs +++ b/Assets/Scripts/Controller/StateMachineController.cs @@ -48,31 +48,22 @@ public class StateMachineController : MonoSingleton { firstState = state.Key; } - IAction enterAct = null; - IAction exitAct = null; - - - fsm.State(state.Key).OnEnter(() => + var vfState = new VfState(); + vfState.OnEnter(() => { - if (state.Value.Enter != null) - { - enterAct = ActionHelper.GetActionAndSub(state.Value.Enter.Action); - enterAct?.Start(this); - } - + vfState.enterAct = ActionHelper.GetActionAndSub(state.Value.Enter?.Action); + vfState.enterAct?.Start(this); }).OnExit(() => { - if (enterAct != null) + if (vfState.enterAct != null) { - enterAct.Deinit(); + vfState.enterAct.Deinit(); } - if (state.Value.Exit != null) - { - exitAct = ActionHelper.GetActionAndSub(state.Value.Exit.Action); - exitAct?.Start(this); + vfState.exitAct = ActionHelper.GetActionAndSub(state.Value.Exit?.Action); + vfState.exitAct?.Start(this); - } }); + fsm.AddState(state.Key, vfState); } foreach (var transision in item.Value.Transisions) { @@ -84,7 +75,7 @@ public class StateMachineController : MonoSingleton } fsmInfo.fsm = fsm; fsmInfo.fsm.StartState(firstState); - if (FSMDitc.ContainsKey(item.Key)==false) + if (FSMDitc.ContainsKey(item.Key) == false) { FSMDitc.Add(item.Key, fsmInfo); } @@ -106,14 +97,18 @@ public class StateMachineController : MonoSingleton { foreach (var item in FSMDitc) { - var curState = item.Value.fsm.CurrentStateId; - foreach (var trans in item.Value.transisions) + VfState state = item.Value.fsm.CurrentState as VfState; + if (state.enterAct == null || state.enterAct.Status == ActionStatus.Finished) { - if (trans.from == "any" || trans.from == item.Value.fsm.CurrentStateId) + foreach (var trans in item.Value.transisions) { - if (trans.condition.Check()) + if ((trans.from == "any" && trans.to != item.Value.fsm.CurrentStateId) || trans.from == item.Value.fsm.CurrentStateId) { - item.Value.fsm.ChangeState(trans.to); + if (trans.condition == null || trans.condition.Check()) + { + item.Value.fsm.ChangeState(trans.to); + break; + } } } } diff --git a/Assets/Scripts/CustomAction.meta b/Assets/Scripts/FSM.meta similarity index 77% rename from Assets/Scripts/CustomAction.meta rename to Assets/Scripts/FSM.meta index ce6f5980..b88a0616 100644 --- a/Assets/Scripts/CustomAction.meta +++ b/Assets/Scripts/FSM.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 6d7f9813c337725468c8739dba68c439 +guid: 8b474fbd8dd5f4c49b70b10f5328d67e folderAsset: yes DefaultImporter: externalObjects: {} diff --git a/Assets/Scripts/FSM/CustomState.meta b/Assets/Scripts/FSM/CustomState.meta new file mode 100644 index 00000000..8f6a5fc8 --- /dev/null +++ b/Assets/Scripts/FSM/CustomState.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5feaaac014488434681db44e2face542 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/FSM/CustomState/VfState.cs b/Assets/Scripts/FSM/CustomState/VfState.cs new file mode 100644 index 00000000..d1c8df38 --- /dev/null +++ b/Assets/Scripts/FSM/CustomState/VfState.cs @@ -0,0 +1,14 @@ +using QFramework; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class VfState : CustomState +{ + + + public IAction enterAct = null; + public IAction exitAct = null; + + +} diff --git a/Assets/Scripts/FSM/CustomState/VfState.cs.meta b/Assets/Scripts/FSM/CustomState/VfState.cs.meta new file mode 100644 index 00000000..210d47cd --- /dev/null +++ b/Assets/Scripts/FSM/CustomState/VfState.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0a5f77690765e1f44b3f3ac7783076fc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Item/DeviceItem.cs b/Assets/Scripts/Item/DeviceItem.cs index 5cd14286..13dff345 100644 --- a/Assets/Scripts/Item/DeviceItem.cs +++ b/Assets/Scripts/Item/DeviceItem.cs @@ -5,6 +5,7 @@ using System; using System.Collections; using System.Collections.Generic; using UnityEngine; +using static OperationController; public class DeviceItem : MonoBehaviour { @@ -19,6 +20,7 @@ public class DeviceItem : MonoBehaviour gameObject.GetOrAddComponent(); effect.outlineColor = Color.green; StringEventSystem.Global.Register(Global.HighLightTrigger, OnHighLightTriggerEvent); + TypeEventSystem.Global.Register(OnStepChanged); } if (device.MeshCollider) { @@ -40,11 +42,21 @@ public class DeviceItem : MonoBehaviour } } + private void OnStepChanged(StepStatusOnChange change) + { + var effect = gameObject.GetComponent(); + if (effect != null) + { + effect.highlighted = false; + } + } + public void Close() { device = null; tipItem = null; StringEventSystem.Global.UnRegister(Global.HighLightTrigger, OnHighLightTriggerEvent); + TypeEventSystem.Global.UnRegister(OnStepChanged); } private void OnHighLightTriggerEvent(string[] obj) diff --git a/Assets/Scripts/Item/Point3DItem.cs b/Assets/Scripts/Item/Point3DItem.cs index 49555550..d8ca8442 100644 --- a/Assets/Scripts/Item/Point3DItem.cs +++ b/Assets/Scripts/Item/Point3DItem.cs @@ -4,6 +4,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; using XMLTool; +using static OperationController; public class Point3DItem : MonoBehaviour { @@ -35,12 +36,20 @@ public class Point3DItem : MonoBehaviour } rotSpeed = data.rotateSpeed; + gameObject.GetComponent().sortingOrder = data.order; TypeEventSystem.Global.Register(OnObjDestroy).UnRegisterWhenGameObjectDestroyed(gameObject); + TypeEventSystem.Global.Register(OnStepChanged); } + private void OnStepChanged(StepStatusOnChange change) + { + OnObjDestroy(default); + } + private void OnObjDestroy(OnPoint3DQuestionDestroy destroy) { + TypeEventSystem.Global.UnRegister(OnStepChanged); GameObject.Destroy(gameObject); } diff --git a/Assets/Scripts/UI/UICameraSwitch.cs b/Assets/Scripts/UI/UICameraSwitch.cs index 839b2ac1..e63756f0 100644 --- a/Assets/Scripts/UI/UICameraSwitch.cs +++ b/Assets/Scripts/UI/UICameraSwitch.cs @@ -59,13 +59,18 @@ namespace QFramework.Example protected override void OnOpen(IUIData uiData = null) { mData = uiData as UICameraSwitchData ?? new UICameraSwitchData(); + + Near.gameObject.SetActive(mData.nearPos != default); + Far.gameObject.SetActive(mData.normalPos != default); + + if (string.IsNullOrEmpty(mData.isOn)) { - if (Near.isOn) + if (Near.isOn && Near.gameObject.activeSelf) { SetNear(); } - if (Far.isOn) + if (Far.isOn && Far.gameObject.activeSelf) { SetNormal(); } @@ -75,13 +80,29 @@ namespace QFramework.Example switch (mData.isOn) { case "near": - SetNear(); + if (Near.isOn == false) + { + Near.isOn = true; + } + else + { + SetNear(); + } break; case "normal": - SetNormal(); + if (Far.isOn == false) + { + Far.isOn = true; + } + else + { + SetNormal(); + } break; } } + + } private void Update() diff --git a/Assets/Scripts/UI/UIModuleSelect.cs b/Assets/Scripts/UI/UIModuleSelect.cs index 279c9bb3..bb867b3c 100644 --- a/Assets/Scripts/UI/UIModuleSelect.cs +++ b/Assets/Scripts/UI/UIModuleSelect.cs @@ -84,7 +84,7 @@ namespace QFramework.Example var machin = StateMachineController.Instance; var op = OperationController.Instance; var dev = DeviceController.Instance; - var score = ScoreController.Instance; + ScoreController.Instance.Init(); UIKit.OpenPanelAsync().ToAction().StartGlobal(() => { diff --git a/Assets/Scripts/UI/UIScore.cs b/Assets/Scripts/UI/UIScore.cs index a4636f5e..0805b625 100644 --- a/Assets/Scripts/UI/UIScore.cs +++ b/Assets/Scripts/UI/UIScore.cs @@ -49,20 +49,26 @@ namespace QFramework.Example { Content.RemoveAllChildren(); + float sum = 0; float score = 0; - foreach (var item in ScoreController.Instance.scoreDict) + foreach (var moduleDict in ScoreController.Instance.moduleDict) { - GameObject obj = GameObject.Instantiate(ItemPrefab.gameObject, Content); - obj.transform.Find("Step").GetComponent().text = item.Value.step; - obj.transform.Find("Name").GetComponent().text = item.Value.name; - obj.transform.Find("Sum").GetComponent().text = item.Value.sum; - obj.transform.Find("Score").GetComponent().text = item.Value.value.ToString(); - sum += float.Parse(item.Value.sum); - score += item.Value.value; + foreach (var item in moduleDict.Value.scoreDict) + { + GameObject obj = GameObject.Instantiate(ItemPrefab.gameObject, Content); + obj.transform.Find("Step").GetComponent().text = item.Value.step; + obj.transform.Find("Name").GetComponent().text = item.Value.name; + obj.transform.Find("Sum").GetComponent().text = item.Value.sum; + obj.transform.Find("Score").GetComponent().text = item.Value.value.ToString(); + sum += float.Parse(item.Value.sum); + score += item.Value.value; + } } + this.Score.text = score.ToString(); this.Sum.text = sum.ToString(); + } protected override void OnShow() diff --git a/Assets/Scripts/UI/UITools.cs b/Assets/Scripts/UI/UITools.cs index 4b34c2ee..70a1e97a 100644 --- a/Assets/Scripts/UI/UITools.cs +++ b/Assets/Scripts/UI/UITools.cs @@ -20,6 +20,7 @@ namespace QFramework.Example public string wrongEvent; public float rightScore; public float wrongScore; + public float totalScore; public string scoreStepName; public float autoHideResult = -1; } @@ -42,6 +43,10 @@ namespace QFramework.Example protected override void OnOpen(IUIData uiData = null) { TypeEventSystem.Global.Register(OnStepChanged).UnRegisterWhenDisabled(gameObject); + if (mData.totalScore > 0) + { + ScoreController.Instance.Add(mData.scoreStepName, mData.totalScore); + } mResLoader = ResLoader.Allocate(); mData = uiData as UIToolsData ?? new UIToolsData(); if (string.IsNullOrEmpty(mData.answer) == false) diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index 46be7080..ab5080b1 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using UnityEngine; +using static UnityEngine.Rendering.DebugUI; namespace XMLTool { public class AppData @@ -46,6 +47,9 @@ namespace XMLTool } + + + public class Score { public List scores; @@ -85,6 +89,7 @@ namespace XMLTool public Vector3 rotate; public Vector3 scale; public float rotateSpeed; + public int order = 1; public string clickEvent; } public List datas = new List(); @@ -440,6 +445,11 @@ namespace XMLTool { act.args.Add("wrongScore", wrongScore.Value); } + var totalScore = action.Attribute("totalScore"); + if (totalScore != null) + { + act.args.Add("totalScore", totalScore.Value); + } var scoreStepName = action.Attribute("scoreStepName"); if (scoreStepName != null) { @@ -779,7 +789,7 @@ namespace XMLTool } newAction = act; } - + break; case "LoadRes": { @@ -884,24 +894,21 @@ namespace XMLTool break; case "ResultTip": { - var act = new StringListAction(); + var act = new DictionaryAction(); XAttribute isRight = action.Attribute("isRight"); if (isRight != null) { - act.args.Add(isRight.Value); - } - else - { - act.args.Add("false"); + act.args.Add("isRight", isRight.Value); } XAttribute finishedEvent = action.Attribute("finishedEvent"); if (finishedEvent != null) { - act.args.Add(finishedEvent.Value); + act.args.Add("finishedEvent", finishedEvent.Value); } - else + XAttribute autoHide = action.Attribute("autoHide"); + if (autoHide != null) { - act.args.Add(""); + act.args.Add("autoHide", autoHide.Value); } newAction = act; } @@ -1088,6 +1095,12 @@ namespace XMLTool data.scale = Utility.GetVector3FromStrArray(item.Attribute("scale")?.Value); } float.TryParse(item.Attribute("rotateSpeed")?.Value, out data.rotateSpeed); + var order = item.Attribute("order"); + if (order != null) + { + int.TryParse(order.Value, out data.order); + } + data.clickEvent = item.Attribute("clickEvent")?.Value; act.datas.Add(data); } @@ -1117,6 +1130,11 @@ namespace XMLTool { act.args.Add("index", index.Value); } + XAttribute mainTexture = action.Attribute("mainTexture"); + if (mainTexture != null) + { + act.args.Add("mainTexture", mainTexture.Value); + } newAction = act; } break; @@ -1136,6 +1154,10 @@ namespace XMLTool public static Condition ParseCondition(XElement action) { + if (action == null) + { + return null; + } Condition newAction = null; string type = action.Attribute("type")?.Value; switch (type) diff --git a/Doc/Xml閰嶇疆鏂囨。.xml b/Doc/Xml閰嶇疆鏂囨。.xml index 9a1cef33..cd4c1799 100644 --- a/Doc/Xml閰嶇疆鏂囨。.xml +++ b/Doc/Xml閰嶇疆鏂囨。.xml @@ -23,7 +23,8 @@ + autoHide =-1 鍒欑偣鍑荤粨鏉 鍚﹀垯 绛夊緟瀵瑰簲鏃堕棿鍚庤嚜鍔ㄧ粨鏉 + totalScore 鏄厤鍚坵rongScore鐨勭敤浜庡垵濮嬪寲涓涓垎鏁 鐒跺悗閫夋嫨鎵e垎--> @@ -72,6 +74,7 @@ @@ -113,7 +116,7 @@ - + @@ -159,7 +162,8 @@ - + +