diff --git a/Assets/Scripts/Actions/ActionHelper.cs b/Assets/Scripts/Actions/ActionHelper.cs index ef39f9a8..49894bdf 100644 --- a/Assets/Scripts/Actions/ActionHelper.cs +++ b/Assets/Scripts/Actions/ActionHelper.cs @@ -173,6 +173,11 @@ public class ActionHelper var strAction = (XMLTool.DictionaryAction)act; return HighLightAction.Allocate(act.Value, strAction.args); } + case "HighLightFlash": + { + var strAction = (XMLTool.DictionaryAction)act; + return HighLightFlashAction.Allocate(act.Value, strAction.args); + } case "LoadRes": { var dictAction = (XMLTool.DictionaryAction)act; diff --git a/Assets/Scripts/Actions/HighLightAction.cs b/Assets/Scripts/Actions/HighLightAction.cs index c8da574f..24d390d5 100644 --- a/Assets/Scripts/Actions/HighLightAction.cs +++ b/Assets/Scripts/Actions/HighLightAction.cs @@ -93,6 +93,11 @@ namespace QFramework { effect.highlighted = false; } + var flash = obj.GetComponent(); + if (flash) + { + flash.Stop(); + } } } diff --git a/Assets/Scripts/Actions/HighLightFlashAction.cs b/Assets/Scripts/Actions/HighLightFlashAction.cs new file mode 100644 index 00000000..4746f384 --- /dev/null +++ b/Assets/Scripts/Actions/HighLightFlashAction.cs @@ -0,0 +1,149 @@ +using HighlightPlus; +using System; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace QFramework +{ + internal class HighLightFlashAction : IAction + { + + + public System.Action OnFinished { get; set; } + + + private HighLightFlashAction() + { + } + + private static readonly SimpleObjectPool mPool = + new SimpleObjectPool(() => new HighLightFlashAction(), null, 10); + + string path; + Color color = Color.green; + bool isHigh = true; + string deviceName = string.Empty; + string isIndependent; + string count; + string time; + string finishedEvent; + public static HighLightFlashAction Allocate(string path, Dictionary datas, System.Action OnFinished = null) + { + var retNode = mPool.Allocate(); + retNode.ActionID = ActionKit.ID_GENERATOR++; + retNode.Deinited = false; + retNode.Reset(); + retNode.path = path; + + if (datas.ContainsKey("color")) + { + + retNode.color = Utility.ToColor(datas["color"]); + + } + if (datas.ContainsKey("isHigh")) + { + bool.TryParse(datas["isHigh"], out retNode.isHigh); + } + retNode.deviceName = datas.ContainsKey("deviceName") ? datas["deviceName"] : string.Empty; + retNode.isIndependent = datas.ContainsKey("isIndependent") ? datas["isIndependent"] : string.Empty; + retNode.count = datas.ContainsKey("count") ? datas["count"] : string.Empty; + retNode.time = datas.ContainsKey("time") ? datas["time"] : string.Empty; + retNode.finishedEvent = datas.ContainsKey("finishedEvent") ? datas["finishedEvent"] : string.Empty; + retNode.OnFinished = OnFinished; + return retNode; + } + + + public ulong ActionID { get; set; } + public ActionStatus Status { get; set; } + + public void OnStart() + { + GameObject obj = null; + if (string.IsNullOrEmpty(deviceName) == false) + { + obj = DeviceController.Instance.GetDeviceObj(deviceName); + } + else + { + obj = Utility.FindObj(path); + } + + if (obj != null) + { + var flash = obj.GetOrAddComponent(); + if (isHigh) + { + var effect = obj.GetOrAddComponent(); + effect.outlineColor = color; + effect.highlighted = true; + obj.GetOrAddComponent(); + if (string.IsNullOrEmpty(isIndependent) == false) + { + switch (isIndependent) + { + case "true": + effect.outlineIndependent = true; + break; + case "false": + effect.outlineIndependent = false; + break; + } + } + float time = 1; + int count = -1; + float.TryParse(this.time, out time); + int.TryParse(this.count, out count); + flash.Init(time, count, finishedEvent); + } + else + { + var effect = obj.GetComponent(); + if (effect) + { + effect.highlighted = false; + } + if (flash) + { + flash.Stop(); + } + + } + } + } + + public void OnExecute(float dt) + { + this.Finish(); + OnFinished?.Invoke(); + } + + public void OnFinish() + { + } + + public void Reset() + { + Status = ActionStatus.NotStart; + Paused = false; + } + + public bool Paused { get; set; } + + public void Deinit() + { + if (!Deinited) + { + OnFinished = null; + Deinited = true; + mPool.Recycle(this); + } + } + + public bool Deinited { get; set; } + } + + +} \ No newline at end of file diff --git a/Assets/Scripts/Actions/HighLightFlashAction.cs.meta b/Assets/Scripts/Actions/HighLightFlashAction.cs.meta new file mode 100644 index 00000000..7a9e45dc --- /dev/null +++ b/Assets/Scripts/Actions/HighLightFlashAction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 96e63ca598764cf4abec4ed34f827731 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Item/HighLightFlashItem.cs b/Assets/Scripts/Item/HighLightFlashItem.cs new file mode 100644 index 00000000..fb9f89d4 --- /dev/null +++ b/Assets/Scripts/Item/HighLightFlashItem.cs @@ -0,0 +1,44 @@ +using DG.Tweening; +using DG.Tweening.Core; +using DG.Tweening.Plugins.Options; +using HighlightPlus; +using QFramework; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class HighLightFlashItem : MonoBehaviour +{ + + HighlightEffect high; + TweenerCore dotw; + private void Awake() + { + high = GetComponent(); + } + + public void Init(float time, int count = -1, string finishedEvent = null) + { + high.outline = 0; + dotw = DOTween.To(() => high.outline, (v) => high.outline = v, 1, time).SetEase(Ease.OutFlash).SetLoops(count, LoopType.Yoyo).OnComplete(() => + { + if (string.IsNullOrEmpty(finishedEvent)==false) + { + StringEventSystem.Global.Send(finishedEvent); + } + this.Stop(); + }); + } + + public void Stop() + { + if (dotw != null) + { + dotw.Kill(); + dotw = null; + } + high.highlighted = false; + } + + +} diff --git a/Assets/Scripts/Item/HighLightFlashItem.cs.meta b/Assets/Scripts/Item/HighLightFlashItem.cs.meta new file mode 100644 index 00000000..5eebf192 --- /dev/null +++ b/Assets/Scripts/Item/HighLightFlashItem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a2f23e7e41ba93044ab80cdc6be2e101 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index ce2a5804..6b56db69 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -789,7 +789,48 @@ namespace XMLTool } newAction = act; } - + break; + case "HighLightFlash": + { + var act = new DictionaryAction(); + XAttribute isHigh = action.Attribute("isHigh"); + if (isHigh != null) + { + act.args.Add("isHigh", isHigh.Value); + } + XAttribute color = action.Attribute("color"); + if (color != null) + { + act.args.Add("color", color.Value); + } + XAttribute deviceName = action.Attribute("deviceName"); + if (deviceName != null) + { + act.args.Add("deviceName", deviceName.Value); + } + newAction = act; + XAttribute isIndependent = action.Attribute("isIndependent"); + if (isIndependent != null) + { + act.args.Add("isIndependent", isIndependent.Value); + } + XAttribute time = action.Attribute("time"); + if (time != null) + { + act.args.Add("time", time.Value); + } + XAttribute count = action.Attribute("count"); + if (count != null) + { + act.args.Add("count", count.Value); + } + XAttribute finishedEvent = action.Attribute("finishedEvent"); + if (finishedEvent != null) + { + act.args.Add("finishedEvent", finishedEvent.Value); + } + newAction = act; + } break; case "LoadRes": { diff --git a/Doc/Xml配置文档.xml b/Doc/Xml配置文档.xml index 03d6ae63..dd234ef5 100644 --- a/Doc/Xml配置文档.xml +++ b/Doc/Xml配置文档.xml @@ -91,6 +91,12 @@ + +