From efb219557143535023a6fc9d46604e3da580a272 Mon Sep 17 00:00:00 2001 From: shenjianxing <”315615051@qq.com“> Date: Mon, 23 Dec 2024 11:30:18 +0800 Subject: [PATCH] =?UTF-8?q?Show=E5=92=8CCameraSwitch=20=E4=B8=A4=E4=B8=AAA?= =?UTF-8?q?ction=E6=94=AF=E6=8C=81=E4=BB=A5Device=E4=B8=BA=E7=9B=AE?= =?UTF-8?q?=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Actions/ActionBase.cs | 6 ++ Assets/Scripts/Actions/ActionHelper.cs | 6 +- Assets/Scripts/Actions/CameraSwitchAction.cs | 56 ++++++++----- Assets/Scripts/Actions/ShowAction.cs | 14 +++- Assets/Scripts/UI/UICameraSwitch.cs | 36 ++++++--- Assets/Scripts/Xml/XmlParser.cs | 83 +++++++++++--------- Data/App.xml | 6 +- Doc/Xml配置文档.xml | 10 +-- 8 files changed, 141 insertions(+), 76 deletions(-) diff --git a/Assets/Scripts/Actions/ActionBase.cs b/Assets/Scripts/Actions/ActionBase.cs index b1dafcd9..dd46b2ba 100644 --- a/Assets/Scripts/Actions/ActionBase.cs +++ b/Assets/Scripts/Actions/ActionBase.cs @@ -18,6 +18,12 @@ namespace XMLTool } + public class DictionaryAction : Action + { + public Dictionary args = new Dictionary(); + } + + } diff --git a/Assets/Scripts/Actions/ActionHelper.cs b/Assets/Scripts/Actions/ActionHelper.cs index bc557228..91e2cf01 100644 --- a/Assets/Scripts/Actions/ActionHelper.cs +++ b/Assets/Scripts/Actions/ActionHelper.cs @@ -128,7 +128,7 @@ public class ActionHelper case "Show": { var strAction = (XMLTool.StringListAction)act; - return ShowAction.Allocate(act.Value, strAction.args[0]); + return ShowAction.Allocate(act.Value, strAction.args[0], strAction.args[1]); } case "TextTip": { @@ -144,8 +144,8 @@ public class ActionHelper return SetScoreAction.Allocate(act.Name, act.Value); case "CameraSwitch": { - var strAction = (XMLTool.StringListAction)act; - return CameraSwitchAction.Allocate(strAction.args[0], strAction.args[1], strAction.args[2], strAction.args[3], strAction.args[4], strAction.args[5], strAction.args[6]); + var dictAction = (XMLTool.DictionaryAction)act; + return CameraSwitchAction.Allocate(dictAction.args); } case "CameraLock": { diff --git a/Assets/Scripts/Actions/CameraSwitchAction.cs b/Assets/Scripts/Actions/CameraSwitchAction.cs index d12d6b48..d9a4d589 100644 --- a/Assets/Scripts/Actions/CameraSwitchAction.cs +++ b/Assets/Scripts/Actions/CameraSwitchAction.cs @@ -1,5 +1,6 @@ using QFramework.Example; using System; +using System.Collections.Generic; using Unity.VisualScripting; using UnityEngine; @@ -17,27 +18,16 @@ namespace QFramework private static readonly SimpleObjectPool mPool = new SimpleObjectPool(() => new CameraSwitchAction(), null, 10); - string nearPos; - string nearRot; - string normalPos; - string normalRot; - string isNear; - string nearTime; - string farTime; - public static CameraSwitchAction Allocate(string nearPos, string nearRot, string nearTime, string normalPos, string normalRot, string farTime, string isNear, System.Action OnFinished = null) + + Dictionary datas; + public static CameraSwitchAction Allocate(Dictionary dict, System.Action OnFinished = null) { var retNode = mPool.Allocate(); retNode.ActionID = ActionKit.ID_GENERATOR++; retNode.Deinited = false; retNode.Reset(); retNode.OnFinished = OnFinished; - retNode.nearPos = nearPos; - retNode.nearRot = nearRot; - retNode.nearTime = nearTime; - retNode.normalPos = normalPos; - retNode.normalRot = normalRot; - retNode.farTime = farTime; - retNode.isNear = isNear; + retNode.datas = dict; return retNode; } @@ -48,11 +38,37 @@ namespace QFramework public void OnStart() { UICameraSwitchData data = new UICameraSwitchData(); - data.nearPos = Utility.GetVector3FromStrArray(nearPos); - data.nearRot = Utility.GetVector3FromStrArray(nearRot); - data.normalPos = Utility.GetVector3FromStrArray(normalPos); - data.normalRot = Utility.GetVector3FromStrArray(normalRot); - bool.TryParse(isNear, out data.isNear); + + if (datas.ContainsKey("nearDevice")) + { + GameObject obj = DeviceController.Instance.GetDeviceObj(datas["nearDevice"]); + data.nearPos = obj.Position(); + data.nearRot = obj.EulerAngles(); + + } + else + { + data.nearPos = Utility.GetVector3FromStrArray(datas["nearPos"]); + data.nearRot = Utility.GetVector3FromStrArray(datas["nearRot"]); + + } + + if (datas.ContainsKey("normalDevice")) + { + GameObject obj = DeviceController.Instance.GetDeviceObj(datas["normalDevice"]); + data.normalPos = obj.Position(); + data.normalRot = obj.EulerAngles(); + } + else + { + data.normalPos = Utility.GetVector3FromStrArray(datas["normalPos"]); + data.normalRot = Utility.GetVector3FromStrArray(datas["normalRot"]); + } + + bool.TryParse(datas["isNear"], out data.isNear); + float.TryParse(datas["nearTime"], out data.nearTime); + float.TryParse(datas["normalTime"], out data.normalTime); + UIKit.OpenPanelAsync(uiData: data, canvasLevel: UILevel.RightBottom).ToAction().StartGlobal(() => this.Finish()); } diff --git a/Assets/Scripts/Actions/ShowAction.cs b/Assets/Scripts/Actions/ShowAction.cs index a31b2928..0f80c46e 100644 --- a/Assets/Scripts/Actions/ShowAction.cs +++ b/Assets/Scripts/Actions/ShowAction.cs @@ -18,7 +18,8 @@ public class ShowAction : IAction new SimpleObjectPool(() => new ShowAction(), null, 10); string path; bool isShow = true; - public static ShowAction Allocate(string path, string isShow, System.Action onDelayFinish = null) + bool isDevice = false; + public static ShowAction Allocate(string path, string isShow, string isDevice, System.Action onDelayFinish = null) { var retNode = mPool.Allocate(); retNode.ActionID = ActionKit.ID_GENERATOR++; @@ -26,6 +27,7 @@ public class ShowAction : IAction retNode.Reset(); retNode.path = path; bool.TryParse(isShow, out retNode.isShow); + bool.TryParse(isDevice, out retNode.isDevice); return retNode; } @@ -50,8 +52,16 @@ public class ShowAction : IAction public void OnStart() { + GameObject obj = null; + if (isDevice) + { + obj = DeviceController.Instance.GetDeviceObj(path); + } + else + { - GameObject obj = Utility.FindObj(path); + obj = Utility.FindObj(path); + } if (obj == null) { Debug.LogError("ûҵ :" + path); diff --git a/Assets/Scripts/UI/UICameraSwitch.cs b/Assets/Scripts/UI/UICameraSwitch.cs index b6d924d4..7890ac3b 100644 --- a/Assets/Scripts/UI/UICameraSwitch.cs +++ b/Assets/Scripts/UI/UICameraSwitch.cs @@ -2,16 +2,20 @@ using UnityEngine; using UnityEngine.UI; using QFramework; using DG.Tweening; +using System.Collections.Generic; namespace QFramework.Example { public class UICameraSwitchData : UIPanelData { + public string nearDevice; + public string normalDevice; public Vector3 nearPos; public Vector3 nearRot; public Vector3 normalPos; public Vector3 normalRot; - + public float nearTime; + public float normalTime; public bool isNear = false; } @@ -25,25 +29,39 @@ namespace QFramework.Example { if (isOn) { - Camera.main.transform.DOMove(mData.nearPos, 0); - Camera.main.transform.DORotate(mData.nearRot, 0); + SetNear(); } Near.transform.Find("Bg/Line").gameObject.SetActive(isOn); }); Far.onValueChanged.AddListener(isOn => - { + { if (isOn) { - Camera.main.transform.DOMove(mData.normalPos, 0); - Camera.main.transform.DORotate(mData.normalRot, 0); + SetNormal(); } Far.transform.Find("Bg/Line").gameObject.SetActive(isOn); }); } + public void SetNear() + { + Camera.main.transform.DOMove(mData.nearPos, mData.nearTime); + Camera.main.transform.DORotate(mData.nearRot, mData.nearTime); + } + + public void SetNormal() + { + + Camera.main.transform.DOMove(mData.normalPos, mData.normalTime); + Camera.main.transform.DORotate(mData.normalRot, mData.normalTime); + } protected override void OnOpen(IUIData uiData = null) { mData = uiData as UICameraSwitchData ?? new UICameraSwitchData(); + + + + if (mData.isNear) { if (Near.isOn == false) @@ -52,8 +70,7 @@ namespace QFramework.Example } else { - Camera.main.transform.DOMove(mData.nearPos, 0); - Camera.main.transform.DORotate(mData.nearRot, 0); + SetNear(); } } else @@ -64,8 +81,7 @@ namespace QFramework.Example } else { - Camera.main.transform.DOMove(mData.normalPos, 0); - Camera.main.transform.DORotate(mData.normalRot, 0); + SetNormal(); } } } diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index 73c73dbb..b8cc804b 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -534,74 +534,87 @@ namespace XMLTool { act.args.Add("true"); } + + XAttribute isDevice = action.Attribute("isDevice"); + if (isDevice != null) + { + act.args.Add(isDevice.Value); + } + else + { + act.args.Add("false"); + } newAction = act; } break; case "CameraSwitch": { - var act = new StringListAction(); - XAttribute isShow = action.Attribute("nearPos"); - if (isShow != null) + var act = new DictionaryAction(); + XAttribute nearDevice = action.Attribute("nearDevice"); + if (nearDevice != null) { - act.args.Add(isShow.Value); + act.args.Add("nearDevice", nearDevice.Value); } else { - act.args.Add("0,0,0"); + XAttribute nearPos = action.Attribute("nearPos"); + if (nearPos != null) + { + act.args.Add("nearPos", nearPos.Value); + } + XAttribute nearRot = action.Attribute("nearRot"); + if (nearRot != null) + { + act.args.Add("nearRot", nearRot.Value); + } } - XAttribute nearRot = action.Attribute("nearRot"); - if (nearRot != null) + + XAttribute normalDevice = action.Attribute("normalDevice"); + if (normalDevice != null) { - act.args.Add(nearRot.Value); + act.args.Add("normalDevice", normalDevice.Value); } else { - act.args.Add("0,0,0"); + XAttribute normalPos = action.Attribute("normalPos"); + if (normalPos != null) + { + act.args.Add("normalPos", normalPos.Value); + } + XAttribute normalRot = action.Attribute("normalRot"); + if (normalRot != null) + { + act.args.Add("normalRot", normalRot.Value); + } } + XAttribute nearTime = action.Attribute("nearTime"); if (nearTime != null) { - act.args.Add(nearTime.Value); + act.args.Add("nearTime", nearTime.Value); } else { - act.args.Add("0"); + act.args.Add("nearTime","0"); } - XAttribute normalPos = action.Attribute("normalPos"); - if (normalPos != null) + + XAttribute normalTime = action.Attribute("farTinormalTimeme"); + if (normalTime != null) { - act.args.Add(normalPos.Value); + act.args.Add("normalTime", normalTime.Value); } else { - act.args.Add("0,0,0"); - } - XAttribute normalRot = action.Attribute("normalRot"); - if (normalRot != null) - { - act.args.Add(normalRot.Value); - } - else - { - act.args.Add("0,0,0"); - } - XAttribute farTime = action.Attribute("farTime"); - if (farTime != null) - { - act.args.Add(farTime.Value); - } - else - { - act.args.Add("0"); + act.args.Add("normalTime","0"); } XAttribute isNear = action.Attribute("isNear"); if (isNear != null) { - act.args.Add(isNear.Value); + act.args.Add("isNear", isNear.Value); } else { - act.args.Add("false"); + act.args.Add("isNear", "false"); } newAction = act; } diff --git a/Data/App.xml b/Data/App.xml index 2c00a7cb..4660d60c 100644 --- a/Data/App.xml +++ b/Data/App.xml @@ -639,6 +639,10 @@ + + + + @@ -758,7 +762,7 @@ - + diff --git a/Doc/Xml配置文档.xml b/Doc/Xml配置文档.xml index 2bc2e01f..85463c34 100644 --- a/Doc/Xml配置文档.xml +++ b/Doc/Xml配置文档.xml @@ -39,18 +39,18 @@ - - + + - + - - + +