新增闪烁功能

This commit is contained in:
shenjianxing 2025-02-06 16:26:44 +08:00
parent c9529a1216
commit 3c1a9f564b
8 changed files with 273 additions and 1 deletions

View File

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

View File

@ -93,6 +93,11 @@ namespace QFramework
{
effect.highlighted = false;
}
var flash = obj.GetComponent<HighLightFlashItem>();
if (flash)
{
flash.Stop();
}
}
}

View File

@ -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<HighLightFlashAction> mPool =
new SimpleObjectPool<HighLightFlashAction>(() => 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<string, string> 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<HighLightFlashItem>();
if (isHigh)
{
var effect = obj.GetOrAddComponent<HighlightEffect>();
effect.outlineColor = color;
effect.highlighted = true;
obj.GetOrAddComponent<HighLightOnStepChanged>();
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<HighlightEffect>();
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; }
}
}

View File

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

View File

@ -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<float, float, FloatOptions> dotw;
private void Awake()
{
high = GetComponent<HighlightEffect>();
}
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;
}
}

View File

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

View File

@ -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":
{

View File

@ -91,6 +91,12 @@
<Action type="Show" value="SM_QvanChangJing/sence/pPlane1" deviceName="设备名字" isShow="false" isDevice="false"></Action>
<!--设置物体高亮 deviceName可以用于设备名字 value是物体路径 color是rgba isHigh设置是否显示高亮 isIndependent为true 可以避免模型高亮被遮挡-->
<Action type="HighLight" deviceName="设备名字" value="路径" isHigh="true" color="0,255,0,255" isIndependent="true"></Action>
<!--设置物体高亮 deviceName可以用于设备名字 value是物体路径 color是rgba isHigh设置是否显示高亮 isIndependent为true 可以避免模型高亮被遮挡
time是从不显示到完全显示的时间
count是循环 -1为无限循环需要主动关闭
当count不为-1时 可以使用finishedEvent配合strEvent做闪烁结束的监听
-->
<Action type="HighLightFlash" deviceName="测试" isHigh="true" color="0,255,0,255" time="1" count="-1" finishedEvent="等待"></Action>
<!--延迟 value是秒-->
<Action type="Delay" value="2"></Action>
<!--