Merge remote-tracking branch 'origin/master' into LouDi_Pig

This commit is contained in:
李浩 2025-01-22 09:09:09 +08:00
commit 4adefdd889
22 changed files with 299 additions and 100 deletions

View File

@ -92,10 +92,10 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_Padding: m_Padding:
m_Left: 0 m_Left: 100
m_Right: 0 m_Right: 100
m_Top: 10 m_Top: 15
m_Bottom: 10 m_Bottom: 15
m_ChildAlignment: 4 m_ChildAlignment: 4
m_Spacing: 5 m_Spacing: 5
m_ChildForceExpandWidth: 0 m_ChildForceExpandWidth: 0
@ -177,7 +177,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {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_SizeDelta: {x: 20, y: 22}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &2796669925366751870 --- !u!222 &2796669925366751870

View File

@ -194,8 +194,8 @@ public class ActionHelper
} }
case "ResultTip": case "ResultTip":
{ {
var strAction = (XMLTool.StringListAction)act; var strAction = (XMLTool.DictionaryAction)act;
return ResultTipAction.Allocate(act.Value, strAction.args[0], strAction.args[1]); return ResultTipAction.Allocate(act.Value, strAction.args);
} }
case "Led": case "Led":
{ {
@ -254,27 +254,30 @@ public class ActionHelper
/// <returns></returns> /// <returns></returns>
public static ICondition GetCondition(XMLTool.ActionItem condition) public static ICondition GetCondition(XMLTool.ActionItem condition)
{ {
switch (condition.Type) if (condition!=null)
{ {
case "And": switch (condition.Type)
case "Or": {
var group = ConditionGroup.Allocate(condition.Type); case "And":
foreach (var item in condition.SubActions) case "Or":
{ var group = ConditionGroup.Allocate(condition.Type);
group.AddCondition(GetCondition(item)); foreach (var item in condition.SubActions)
} {
return group; group.AddCondition(GetCondition(item));
case "UIClick": }
return UIClickCondition.Allocate(condition.Value); return group;
case "ObjClick": case "UIClick":
var dict = (XMLTool.DictionaryCondition)condition; return UIClickCondition.Allocate(condition.Value);
return ObjClickCondition.Allocate(dict.Value, dict.args); case "ObjClick":
case "Input": var dict = (XMLTool.DictionaryCondition)condition;
return InputCondition.Allocate(condition.Value); return ObjClickCondition.Allocate(dict.Value, dict.args);
case "Var": case "Input":
return VarCondition.Allocate(condition.Name, condition.Value); return InputCondition.Allocate(condition.Value);
case "StrEvent": case "Var":
return StrEventCondition.Allocate(condition.Value); return VarCondition.Allocate(condition.Name, condition.Value);
case "StrEvent":
return StrEventCondition.Allocate(condition.Value);
}
} }
return null; return null;
} }

View File

@ -1,8 +1,11 @@
using DG.Tweening; using DG.Tweening;
using DG.Tweening.Core;
using DG.Tweening.Plugins.Options;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.Rendering.Universal; using UnityEngine.Rendering.Universal;
using static OperationController;
namespace QFramework namespace QFramework
{ {
@ -27,6 +30,8 @@ namespace QFramework
string frame; string frame;
string speed; string speed;
string deviceName; string deviceName;
float totalTime;
public static AnimationAction Allocate(string path, Dictionary<string, string> datas, System.Action OnFinished = null) public static AnimationAction Allocate(string path, Dictionary<string, string> datas, System.Action OnFinished = null)
{ {
var retNode = mPool.Allocate(); var retNode = mPool.Allocate();
@ -43,7 +48,7 @@ namespace QFramework
} }
public ulong ActionID { get; set; } public ulong ActionID { get; set; }
public ActionStatus Status { get; set; } public ActionStatus Status { get; set; }
TweenerCore<float, float, FloatOptions> animDot;
public void OnStart() public void OnStart()
{ {
GameObject obj = null; GameObject obj = null;
@ -87,7 +92,8 @@ namespace QFramework
{ {
anim.Play(animName); anim.Play(animName);
anim[animName].normalizedTime = 1; 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(); anim.Stop();
}; };
@ -95,16 +101,13 @@ namespace QFramework
else else
{ {
anim[animName].speed = curSpeed; anim[animName].speed = curSpeed;
anim.Play(animName); anim.Play(animName);
if (anim[animName].wrapMode == WrapMode.Loop) if (anim[animName].wrapMode == WrapMode.Loop)
{ {
this.Finish(); this.Finish();
} }
} }
totalTime = Math.Abs(anim[animName].length / curSpeed);
} }
} }
catch (Exception) catch (Exception)
@ -120,9 +123,11 @@ namespace QFramework
} }
} }
public void OnExecute(float dt) public void OnExecute(float dt)
{ {
if (anim != null && anim.isPlaying == false) totalTime -= Time.deltaTime;
if (anim != null && (anim.isPlaying == false || totalTime <= 0))
{ {
this.Finish(); this.Finish();
} }
@ -144,6 +149,8 @@ namespace QFramework
{ {
if (!Deinited) if (!Deinited)
{ {
animDot?.Kill();
anim?.Stop();
OnFinished = null; OnFinished = null;
Deinited = true; Deinited = true;
mPool.Recycle(this); mPool.Recycle(this);

View File

@ -47,9 +47,14 @@ namespace QFramework
} }
else else
{ {
data.nearPos = Utility.GetVector3FromStrArray(datas["nearPos"]); if (datas.ContainsKey("nearPos"))
data.nearRot = Utility.GetVector3FromStrArray(datas["nearRot"]); {
data.nearPos = Utility.GetVector3FromStrArray(datas["nearPos"]);
}
if (datas.ContainsKey("nearRot"))
{
data.nearRot = Utility.GetVector3FromStrArray(datas["nearRot"]);
}
} }
if (datas.ContainsKey("normalDevice")) if (datas.ContainsKey("normalDevice"))
@ -60,8 +65,14 @@ namespace QFramework
} }
else else
{ {
data.normalPos = Utility.GetVector3FromStrArray(datas["normalPos"]); if (datas.ContainsKey("normalPos"))
data.normalRot = Utility.GetVector3FromStrArray(datas["normalRot"]); {
data.normalPos = Utility.GetVector3FromStrArray(datas["normalPos"]);
}
if (datas.ContainsKey("normalRot"))
{
data.normalRot = Utility.GetVector3FromStrArray(datas["normalRot"]);
}
} }
if (datas.ContainsKey("isOn")) if (datas.ContainsKey("isOn"))
{ {

View File

@ -24,6 +24,7 @@ namespace QFramework
string deviceName; string deviceName;
string matName; string matName;
string index; string index;
string mainTexture;
public static MatAction Allocate(Dictionary<string, string> datas, System.Action OnFinished = null) public static MatAction Allocate(Dictionary<string, string> datas, System.Action OnFinished = null)
{ {
var retNode = mPool.Allocate(); var retNode = mPool.Allocate();
@ -34,6 +35,7 @@ namespace QFramework
retNode.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : ""; retNode.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : "";
retNode.matName = datas.ContainsKey("matName") ? datas["matName"] : ""; retNode.matName = datas.ContainsKey("matName") ? datas["matName"] : "";
retNode.index = datas.ContainsKey("index") ? datas["index"] : "0"; retNode.index = datas.ContainsKey("index") ? datas["index"] : "0";
retNode.mainTexture = datas.ContainsKey("mainTexture") ? datas["mainTexture"] : null;
retNode.OnFinished = OnFinished; retNode.OnFinished = OnFinished;
return retNode; return retNode;
} }
@ -56,7 +58,22 @@ namespace QFramework
var mesh = obj.GetComponent<Renderer>(); var mesh = obj.GetComponent<Renderer>();
int matIndex = 0; int matIndex = 0;
int.TryParse(index, out matIndex); int.TryParse(index, out matIndex);
mesh.materials[matIndex] = Resources.Load<Material>("Mat/" + matName); if (string.IsNullOrEmpty(matName) == false)
{
mesh.materials[matIndex] = Resources.Load<Material>("Mat/" + matName);
}
if (mainTexture != null)
{
if (mainTexture == "")
{
mesh.materials[matIndex].mainTexture = null;
}
else
{
mesh.materials[matIndex].mainTexture = Resources.Load<Texture>("Mat/" + mainTexture);
}
}
this.Finish(); this.Finish();
} }

View File

@ -1,5 +1,6 @@
using QFramework.Example; using QFramework.Example;
using System; using System;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
namespace QFramework namespace QFramework
@ -19,15 +20,17 @@ namespace QFramework
public string txt; public string txt;
public string isRight; public string isRight;
public string finishedEvent; 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<string, string> datas, System.Action OnFinished = null)
{ {
var retNode = mPool.Allocate(); var retNode = mPool.Allocate();
retNode.ActionID = ActionKit.ID_GENERATOR++; retNode.ActionID = ActionKit.ID_GENERATOR++;
retNode.Deinited = false; retNode.Deinited = false;
retNode.Reset(); retNode.Reset();
retNode.txt = txt; retNode.txt = txt;
retNode.isRight = isRight; retNode.isRight = datas.ContainsKey("isRight") ? datas["isRight"] : "";
retNode.finishedEvent = finishedEvent; retNode.finishedEvent = datas.ContainsKey("finishedEvent") ? datas["finishedEvent"] : "";
retNode.autoHide = datas.ContainsKey("autoHide") ? datas["autoHide"] : "-1";
retNode.OnFinished = OnFinished; retNode.OnFinished = OnFinished;
return retNode; return retNode;
} }
@ -45,6 +48,7 @@ namespace QFramework
{ {
data.callback = () => StringEventSystem.Global.Send(finishedEvent); data.callback = () => StringEventSystem.Global.Send(finishedEvent);
} }
float.TryParse(autoHide, out data.autoHideTime);
UIKit.OpenPanelAsync<UIResultTip>(uiData: data, canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() => this.Finish()); UIKit.OpenPanelAsync<UIResultTip>(uiData: data, canvasLevel: UILevel.PopUI).ToAction().StartGlobal(() => this.Finish());
} }

View File

@ -75,7 +75,7 @@ public class ShowAction : IAction
if (obj == null) if (obj == null)
{ {
Debug.LogError("没有找到物体 :" + path); Debug.LogError($"没有找到物体 path:{path} deviceName:{deviceName}");
} }
else else
{ {

View File

@ -23,6 +23,7 @@ public class UIToolsAction : IAction
string wrongEvent; string wrongEvent;
string rightScore; string rightScore;
string wrongScore; string wrongScore;
string totalScore;
string scoreStepName; string scoreStepName;
string autoHide; string autoHide;
public static UIToolsAction Allocate(Dictionary<string, string> datas, System.Action onDelayFinish = null) public static UIToolsAction Allocate(Dictionary<string, string> datas, System.Action onDelayFinish = null)
@ -40,6 +41,7 @@ public class UIToolsAction : IAction
retNode.wrongEvent = datas.ContainsKey("wrongEvent") ? datas["wrongEvent"] : ""; retNode.wrongEvent = datas.ContainsKey("wrongEvent") ? datas["wrongEvent"] : "";
retNode.rightScore = datas.ContainsKey("rightScore") ? datas["rightScore"] : ""; retNode.rightScore = datas.ContainsKey("rightScore") ? datas["rightScore"] : "";
retNode.wrongScore = datas.ContainsKey("wrongScore") ? datas["wrongScore"] : ""; retNode.wrongScore = datas.ContainsKey("wrongScore") ? datas["wrongScore"] : "";
retNode.totalScore = datas.ContainsKey("totalScore") ? datas["totalScore"] : "";
retNode.scoreStepName = datas.ContainsKey("scoreStepName") ? datas["scoreStepName"] : ""; retNode.scoreStepName = datas.ContainsKey("scoreStepName") ? datas["scoreStepName"] : "";
retNode.autoHide = datas.ContainsKey("autoHide") ? datas["autoHide"] : ""; retNode.autoHide = datas.ContainsKey("autoHide") ? datas["autoHide"] : "";
return retNode; return retNode;
@ -75,6 +77,7 @@ public class UIToolsAction : IAction
data.wrongEvent = wrongEvent; data.wrongEvent = wrongEvent;
float.TryParse(rightScore, out data.rightScore); float.TryParse(rightScore, out data.rightScore);
float.TryParse(wrongScore, out data.wrongScore); float.TryParse(wrongScore, out data.wrongScore);
float.TryParse(totalScore, out data.totalScore);
data.scoreStepName = scoreStepName; data.scoreStepName = scoreStepName;
bool.TryParse(setActive, out data.SetActive); bool.TryParse(setActive, out data.SetActive);
if (float.TryParse(autoHide, out data.autoHideResult) == false) if (float.TryParse(autoHide, out data.autoHideResult) == false)

View File

@ -7,24 +7,65 @@ using XMLTool;
public class ScoreController : MonoSingleton<ScoreController> public class ScoreController : MonoSingleton<ScoreController>
{ {
public Dictionary<string, ScoreStep> scoreDict; public class Data
{
public Dictionary<string, ScoreStep> scoreDict;
}
public Dictionary<string, Data> moduleDict;
public override void OnSingletonInit() public override void OnSingletonInit()
{ {
base.OnSingletonInit(); base.OnSingletonInit();
scoreDict = new Dictionary<string, ScoreStep>(); InitData();
TypeEventSystem.Global.Register<OnModuleStart>(OnStart).UnRegisterWhenGameObjectDestroyed(gameObject);
TypeEventSystem.Global.Register<OnModuleQuit>(OnQuit).UnRegisterWhenGameObjectDestroyed(gameObject);
} }
public void Init()
{
if (Global.Instance.curModule.type == "Exam" || Global.Instance.curModule.type == "All")
{
TypeEventSystem.Global.Register<OnModuleStart>(OnStart);
TypeEventSystem.Global.Register<OnModuleQuit>(OnQuit);
}
}
public void InitData()
{
moduleDict = new Dictionary<string, Data>();
foreach (var item in Global.Instance.appData.Modules)
{
if (item.type == "Exam" || item.type == "All")
{
Data data = new Data() { scoreDict = new Dictionary<string, ScoreStep>() };
moduleDict.Add(item.ModuleName, data);
}
}
}
private void OnStart(OnModuleStart start) private void OnStart(OnModuleStart start)
{ {
var data = moduleDict[Global.Instance.curModule.ModuleName];
data.scoreDict.Clear();
foreach (var item in Global.Instance.curModule.score.scores) foreach (var item in Global.Instance.curModule.score.scores)
{ {
item.value = 0; item.value = 0;
scoreDict.Add(item.step + item.name, item); data.scoreDict.Add(item.step + item.name, item);
} }
} }
public Dictionary<string, ScoreStep> GetCurScore()
{
var data = moduleDict[Global.Instance.curModule.ModuleName];
return data.scoreDict;
}
public void Add(string key, float value) public void Add(string key, float value)
{ {
var data = moduleDict[Global.Instance.curModule.ModuleName];
var scoreDict = data.scoreDict;
if (scoreDict.ContainsKey(key)) if (scoreDict.ContainsKey(key))
{ {
scoreDict[key].value += value; scoreDict[key].value += value;
@ -43,6 +84,8 @@ public class ScoreController : MonoSingleton<ScoreController>
public void Set(string key, float value) public void Set(string key, float value)
{ {
var data = moduleDict[Global.Instance.curModule.ModuleName];
var scoreDict = data.scoreDict;
if (scoreDict.ContainsKey(key)) if (scoreDict.ContainsKey(key))
{ {
scoreDict[key].value = value; scoreDict[key].value = value;
@ -53,7 +96,11 @@ public class ScoreController : MonoSingleton<ScoreController>
private void OnQuit(OnModuleQuit quit) private void OnQuit(OnModuleQuit quit)
{ {
var data = moduleDict[Global.Instance.curModule.ModuleName];
var scoreDict = data.scoreDict;
scoreDict.Clear(); scoreDict.Clear();
TypeEventSystem.Global.UnRegister<OnModuleStart>(OnStart);
TypeEventSystem.Global.UnRegister<OnModuleQuit>(OnQuit);
} }

View File

@ -48,31 +48,22 @@ public class StateMachineController : MonoSingleton<StateMachineController>
{ {
firstState = state.Key; firstState = state.Key;
} }
IAction enterAct = null; var vfState = new VfState();
IAction exitAct = null; vfState.OnEnter(() =>
fsm.State(state.Key).OnEnter(() =>
{ {
if (state.Value.Enter != null) vfState.enterAct = ActionHelper.GetActionAndSub(state.Value.Enter?.Action);
{ vfState.enterAct?.Start(this);
enterAct = ActionHelper.GetActionAndSub(state.Value.Enter.Action);
enterAct?.Start(this);
}
}).OnExit(() => }).OnExit(() =>
{ {
if (enterAct != null) if (vfState.enterAct != null)
{ {
enterAct.Deinit(); vfState.enterAct.Deinit();
} }
if (state.Value.Exit != null) vfState.exitAct = ActionHelper.GetActionAndSub(state.Value.Exit?.Action);
{ vfState.exitAct?.Start(this);
exitAct = ActionHelper.GetActionAndSub(state.Value.Exit.Action);
exitAct?.Start(this);
}
}); });
fsm.AddState(state.Key, vfState);
} }
foreach (var transision in item.Value.Transisions) foreach (var transision in item.Value.Transisions)
{ {
@ -84,7 +75,7 @@ public class StateMachineController : MonoSingleton<StateMachineController>
} }
fsmInfo.fsm = fsm; fsmInfo.fsm = fsm;
fsmInfo.fsm.StartState(firstState); fsmInfo.fsm.StartState(firstState);
if (FSMDitc.ContainsKey(item.Key)==false) if (FSMDitc.ContainsKey(item.Key) == false)
{ {
FSMDitc.Add(item.Key, fsmInfo); FSMDitc.Add(item.Key, fsmInfo);
} }
@ -106,14 +97,18 @@ public class StateMachineController : MonoSingleton<StateMachineController>
{ {
foreach (var item in FSMDitc) foreach (var item in FSMDitc)
{ {
var curState = item.Value.fsm.CurrentStateId; VfState state = item.Value.fsm.CurrentState as VfState;
foreach (var trans in item.Value.transisions) 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;
}
} }
} }
} }

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 6d7f9813c337725468c8739dba68c439 guid: 8b474fbd8dd5f4c49b70b10f5328d67e
folderAsset: yes folderAsset: yes
DefaultImporter: DefaultImporter:
externalObjects: {} externalObjects: {}

View File

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

View File

@ -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;
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0a5f77690765e1f44b3f3ac7783076fc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -5,6 +5,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using static OperationController;
public class DeviceItem : MonoBehaviour public class DeviceItem : MonoBehaviour
{ {
@ -19,6 +20,7 @@ public class DeviceItem : MonoBehaviour
gameObject.GetOrAddComponent<HighlightTrigger>(); gameObject.GetOrAddComponent<HighlightTrigger>();
effect.outlineColor = Color.green; effect.outlineColor = Color.green;
StringEventSystem.Global.Register<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent); StringEventSystem.Global.Register<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent);
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged);
} }
if (device.MeshCollider) if (device.MeshCollider)
{ {
@ -40,11 +42,21 @@ public class DeviceItem : MonoBehaviour
} }
} }
private void OnStepChanged(StepStatusOnChange change)
{
var effect = gameObject.GetComponent<HighlightEffect>();
if (effect != null)
{
effect.highlighted = false;
}
}
public void Close() public void Close()
{ {
device = null; device = null;
tipItem = null; tipItem = null;
StringEventSystem.Global.UnRegister<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent); StringEventSystem.Global.UnRegister<string[]>(Global.HighLightTrigger, OnHighLightTriggerEvent);
TypeEventSystem.Global.UnRegister<StepStatusOnChange>(OnStepChanged);
} }
private void OnHighLightTriggerEvent(string[] obj) private void OnHighLightTriggerEvent(string[] obj)

View File

@ -4,6 +4,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using XMLTool; using XMLTool;
using static OperationController;
public class Point3DItem : MonoBehaviour public class Point3DItem : MonoBehaviour
{ {
@ -35,12 +36,20 @@ public class Point3DItem : MonoBehaviour
} }
rotSpeed = data.rotateSpeed; rotSpeed = data.rotateSpeed;
gameObject.GetComponent<SpriteRenderer>().sortingOrder = data.order;
TypeEventSystem.Global.Register<OnPoint3DQuestionDestroy>(OnObjDestroy).UnRegisterWhenGameObjectDestroyed(gameObject); TypeEventSystem.Global.Register<OnPoint3DQuestionDestroy>(OnObjDestroy).UnRegisterWhenGameObjectDestroyed(gameObject);
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged);
} }
private void OnStepChanged(StepStatusOnChange change)
{
OnObjDestroy(default);
}
private void OnObjDestroy(OnPoint3DQuestionDestroy destroy) private void OnObjDestroy(OnPoint3DQuestionDestroy destroy)
{ {
TypeEventSystem.Global.UnRegister<StepStatusOnChange>(OnStepChanged);
GameObject.Destroy(gameObject); GameObject.Destroy(gameObject);
} }

View File

@ -59,13 +59,18 @@ namespace QFramework.Example
protected override void OnOpen(IUIData uiData = null) protected override void OnOpen(IUIData uiData = null)
{ {
mData = uiData as UICameraSwitchData ?? new UICameraSwitchData(); mData = uiData as UICameraSwitchData ?? new UICameraSwitchData();
Near.gameObject.SetActive(mData.nearPos != default);
Far.gameObject.SetActive(mData.normalPos != default);
if (string.IsNullOrEmpty(mData.isOn)) if (string.IsNullOrEmpty(mData.isOn))
{ {
if (Near.isOn) if (Near.isOn && Near.gameObject.activeSelf)
{ {
SetNear(); SetNear();
} }
if (Far.isOn) if (Far.isOn && Far.gameObject.activeSelf)
{ {
SetNormal(); SetNormal();
} }
@ -75,13 +80,29 @@ namespace QFramework.Example
switch (mData.isOn) switch (mData.isOn)
{ {
case "near": case "near":
SetNear(); if (Near.isOn == false)
{
Near.isOn = true;
}
else
{
SetNear();
}
break; break;
case "normal": case "normal":
SetNormal(); if (Far.isOn == false)
{
Far.isOn = true;
}
else
{
SetNormal();
}
break; break;
} }
} }
} }
private void Update() private void Update()

View File

@ -84,7 +84,7 @@ namespace QFramework.Example
var machin = StateMachineController.Instance; var machin = StateMachineController.Instance;
var op = OperationController.Instance; var op = OperationController.Instance;
var dev = DeviceController.Instance; var dev = DeviceController.Instance;
var score = ScoreController.Instance; ScoreController.Instance.Init();
UIKit.OpenPanelAsync<UIRightTop>().ToAction().StartGlobal(() => UIKit.OpenPanelAsync<UIRightTop>().ToAction().StartGlobal(() =>
{ {

View File

@ -49,20 +49,26 @@ namespace QFramework.Example
{ {
Content.RemoveAllChildren(); Content.RemoveAllChildren();
float sum = 0; float sum = 0;
float score = 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); foreach (var item in moduleDict.Value.scoreDict)
obj.transform.Find("Step").GetComponent<TextMeshProUGUI>().text = item.Value.step; {
obj.transform.Find("Name").GetComponent<TextMeshProUGUI>().text = item.Value.name; GameObject obj = GameObject.Instantiate(ItemPrefab.gameObject, Content);
obj.transform.Find("Sum").GetComponent<TextMeshProUGUI>().text = item.Value.sum; obj.transform.Find("Step").GetComponent<TextMeshProUGUI>().text = item.Value.step;
obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString(); obj.transform.Find("Name").GetComponent<TextMeshProUGUI>().text = item.Value.name;
sum += float.Parse(item.Value.sum); obj.transform.Find("Sum").GetComponent<TextMeshProUGUI>().text = item.Value.sum;
score += item.Value.value; obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString();
sum += float.Parse(item.Value.sum);
score += item.Value.value;
}
} }
this.Score.text = score.ToString(); this.Score.text = score.ToString();
this.Sum.text = sum.ToString(); this.Sum.text = sum.ToString();
} }
protected override void OnShow() protected override void OnShow()

View File

@ -20,6 +20,7 @@ namespace QFramework.Example
public string wrongEvent; public string wrongEvent;
public float rightScore; public float rightScore;
public float wrongScore; public float wrongScore;
public float totalScore;
public string scoreStepName; public string scoreStepName;
public float autoHideResult = -1; public float autoHideResult = -1;
} }
@ -42,6 +43,10 @@ namespace QFramework.Example
protected override void OnOpen(IUIData uiData = null) protected override void OnOpen(IUIData uiData = null)
{ {
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged).UnRegisterWhenDisabled(gameObject); TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged).UnRegisterWhenDisabled(gameObject);
if (mData.totalScore > 0)
{
ScoreController.Instance.Add(mData.scoreStepName, mData.totalScore);
}
mResLoader = ResLoader.Allocate(); mResLoader = ResLoader.Allocate();
mData = uiData as UIToolsData ?? new UIToolsData(); mData = uiData as UIToolsData ?? new UIToolsData();
if (string.IsNullOrEmpty(mData.answer) == false) if (string.IsNullOrEmpty(mData.answer) == false)

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using UnityEngine; using UnityEngine;
using static UnityEngine.Rendering.DebugUI;
namespace XMLTool namespace XMLTool
{ {
public class AppData public class AppData
@ -46,6 +47,9 @@ namespace XMLTool
} }
public class Score public class Score
{ {
public List<ScoreStep> scores; public List<ScoreStep> scores;
@ -85,6 +89,7 @@ namespace XMLTool
public Vector3 rotate; public Vector3 rotate;
public Vector3 scale; public Vector3 scale;
public float rotateSpeed; public float rotateSpeed;
public int order = 1;
public string clickEvent; public string clickEvent;
} }
public List<Data> datas = new List<Data>(); public List<Data> datas = new List<Data>();
@ -440,6 +445,11 @@ namespace XMLTool
{ {
act.args.Add("wrongScore", wrongScore.Value); 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"); var scoreStepName = action.Attribute("scoreStepName");
if (scoreStepName != null) if (scoreStepName != null)
{ {
@ -779,7 +789,7 @@ namespace XMLTool
} }
newAction = act; newAction = act;
} }
break; break;
case "LoadRes": case "LoadRes":
{ {
@ -884,24 +894,21 @@ namespace XMLTool
break; break;
case "ResultTip": case "ResultTip":
{ {
var act = new StringListAction(); var act = new DictionaryAction();
XAttribute isRight = action.Attribute("isRight"); XAttribute isRight = action.Attribute("isRight");
if (isRight != null) if (isRight != null)
{ {
act.args.Add(isRight.Value); act.args.Add("isRight", isRight.Value);
}
else
{
act.args.Add("false");
} }
XAttribute finishedEvent = action.Attribute("finishedEvent"); XAttribute finishedEvent = action.Attribute("finishedEvent");
if (finishedEvent != null) 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; newAction = act;
} }
@ -1088,6 +1095,12 @@ namespace XMLTool
data.scale = Utility.GetVector3FromStrArray(item.Attribute("scale")?.Value); data.scale = Utility.GetVector3FromStrArray(item.Attribute("scale")?.Value);
} }
float.TryParse(item.Attribute("rotateSpeed")?.Value, out data.rotateSpeed); 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; data.clickEvent = item.Attribute("clickEvent")?.Value;
act.datas.Add(data); act.datas.Add(data);
} }
@ -1117,6 +1130,11 @@ namespace XMLTool
{ {
act.args.Add("index", index.Value); act.args.Add("index", index.Value);
} }
XAttribute mainTexture = action.Attribute("mainTexture");
if (mainTexture != null)
{
act.args.Add("mainTexture", mainTexture.Value);
}
newAction = act; newAction = act;
} }
break; break;
@ -1136,6 +1154,10 @@ namespace XMLTool
public static Condition ParseCondition(XElement action) public static Condition ParseCondition(XElement action)
{ {
if (action == null)
{
return null;
}
Condition newAction = null; Condition newAction = null;
string type = action.Attribute("type")?.Value; string type = action.Attribute("type")?.Value;
switch (type) switch (type)

View File

@ -23,7 +23,8 @@
<Action type="Btns" value="按钮1,按钮2,按钮3"></Action> <Action type="Btns" value="按钮1,按钮2,按钮3"></Action>
<!--用于右侧道具栏选择正确的道具 event用于配合StrEventCondition 做检测 <!--用于右侧道具栏选择正确的道具 event用于配合StrEventCondition 做检测
rightScore 正确选择一个 得分 wrongScore 错误一个 得分 scoreStepName是评分的key rightScore 正确选择一个 得分 wrongScore 错误一个 得分 scoreStepName是评分的key
autoHide =-1 则点击结束 否则 等待对应时间后自动结束--> autoHide =-1 则点击结束 否则 等待对应时间后自动结束
totalScore 是配合wrongScore的用于初始化一个分数 然后选择扣分-->
<Action type="UITools" devices="道具名字1" answers="正确道具" <Action type="UITools" devices="道具名字1" answers="正确道具"
setActive="true" setActive="true"
rightLabel="提示:器械选择正确。" rightLabel="提示:器械选择正确。"
@ -32,6 +33,7 @@
wrongEvent="" wrongEvent=""
rightScore="" rightScore=""
wrongScore="" wrongScore=""
totalScore=""
scoreStepName="手术准备器械选择" scoreStepName="手术准备器械选择"
autoHide="-1"></Action> autoHide="-1"></Action>
@ -72,6 +74,7 @@
<Action type="SetScore" name="步骤名字" value="1"></Action> <Action type="SetScore" name="步骤名字" value="1"></Action>
<!--镜头切换 近距离和默认 如果有了nearDevice就可以不用nearPos和nearRot了 按照device的坐标和旋转来处理镜头 normalDevice同理 <!--镜头切换 近距离和默认 如果有了nearDevice就可以不用nearPos和nearRot了 按照device的坐标和旋转来处理镜头 normalDevice同理
只设置坐标 不执行镜头切换 是否执行要根据UI的按钮操作来 只设置坐标 不执行镜头切换 是否执行要根据UI的按钮操作来
如果不配置 nearPos或者normalPos 则自动隐藏对应的视角UI按钮
--> -->
<Action type="CameraSwitch" nearDevice="肠钳" normalDevice="组织钳" nearPos="-3.942,3.24,-4.319" nearRot="16.42331,180,0" nearTime="1" normalPos="-3.942,3.24,-3.946" normalRot="16.42331,180,-5.305351E-14" normalTime="1"></Action> <Action type="CameraSwitch" nearDevice="肠钳" normalDevice="组织钳" nearPos="-3.942,3.24,-4.319" nearRot="16.42331,180,0" nearTime="1" normalPos="-3.942,3.24,-3.946" normalRot="16.42331,180,-5.305351E-14" normalTime="1"></Action>
<!--文字弹窗 按钮可以多个 点击事件使用UIClick--> <!--文字弹窗 按钮可以多个 点击事件使用UIClick-->
@ -113,7 +116,7 @@
<!--相机锁定 是否可以移动 isMove 是否可以旋转镜头 isRotate--> <!--相机锁定 是否可以移动 isMove 是否可以旋转镜头 isRotate-->
<Action type="CameraLock" isMove="false" isRotate="false"></Action> <Action type="CameraLock" isMove="false" isRotate="false"></Action>
<!--正确和错误的弹窗 isRight 是否正确--> <!--正确和错误的弹窗 isRight 是否正确-->
<Action type="ResultTip" value="这里是一个弹窗" isRight="true" finishedEvent="关闭弹窗事件"></Action> <Action type="ResultTip" value="这里是一个弹窗" isRight="true" finishedEvent="关闭弹窗事件" autoHide="1"></Action>
<!--Led数字显示 要求每个数字单独一个模型面片,所有数字面片放在一个物体的子级,第一个物体是最右侧的数字,只能放数字面片模型 不要放其他的东西 <!--Led数字显示 要求每个数字单独一个模型面片,所有数字面片放在一个物体的子级,第一个物体是最右侧的数字,只能放数字面片模型 不要放其他的东西
number 是数值 支持 小数点和横线 例如 12.34 3-5 --> number 是数值 支持 小数点和横线 例如 12.34 3-5 -->
@ -159,7 +162,8 @@
<!--弹窗 btns可支持多个按钮--> <!--弹窗 btns可支持多个按钮-->
<Action type="TipWindow" value="恭喜你完成当前模块" btns="确定,取消" audio=""></Action> <Action type="TipWindow" value="恭喜你完成当前模块" btns="确定,取消" audio=""></Action>
<!--动态更换材质球和主贴图 材质球优先级高于贴图 同时写的情况下 先换材质球再换贴图-->
<Action type="Mat" value="Models/zhudao/nan_shoushufu.012" matName="yiyongshoutao_yellow1" index="1" mainTexture="贴图名字"></Action>
<!--预加载模块 要在app.xml的Data标签内--> <!--预加载模块 要在app.xml的Data标签内-->
<PreLoad> <PreLoad>