This repository has been archived on 2025-09-23. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
XericLibrary-OLD/Runtime/Security/ProgramFlowSecurityExtend.cs
LiRuoChen a658cc424b 添加了更多的材质函数,部分与引擎新特性重合,这是为了能够脱离引擎在多个版本中更具可移植性。
添加了多种对程序流程控制与保全的脚本,而且现在可以更快速的构建一个具有线性关系的协程了。
  添加了一个支持多种模式的单维梯度控制器,类似unity的颜色梯度类型。
  添加了一个用于看向某个物体的旋转控制器。
  添加了一个加载宏。
  完善了批处理脚本流程。
2023-11-23 11:10:40 +08:00

142 lines
2.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using XericLibrary.Runtime.Type;
namespace XericLibrary.Runtime.Security
{
/// <summary>
/// 程序流程保全
/// </summary>
public class ProgramFlowSecurityExtend : WeaklyObject
{
#region
/// <summary>
/// 可扩展事件
/// </summary>
public event Action ExtensibleDelegation
{
add
{
if(!DelegateContains(value))
DelegateAdd(value);
}
remove
{
DelegateRemove(value);
}
}
/// <summary>
/// 事件列表
/// </summary>
private List<DelegateExtensibleFlag> delegateList;
#endregion
#region
/// <summary>
/// 事件扩展标识
/// </summary>
public class DelegateExtensibleFlag
{
/// <summary>
/// 事件
/// </summary>
public Action Event;
/// <summary>
/// 单步执行
/// </summary>
public bool Doonce;
/// <summary>
/// 调用保护
/// </summary>
public bool Conservate;
public DelegateExtensibleFlag(Action action, bool doonce = false)
{
this.Event = action;
this.Doonce = doonce;
this.Conservate = false;
}
public override bool Equals(object obj)
{
if(obj is DelegateExtensibleFlag def)
return def.Event == this.Event;
return false;
}
public override int GetHashCode()
{
return Event.GetHashCode();
}
}
public DelegateExtensibleFlag DelegateFind(Action action)
{
return delegateList
.Where(a => a.Event == action)
.FirstOrDefault();
}
public bool DelegateContains(Action action)
{
return DelegateFind(action) == null;
}
public void DelegateAdd(Action action, bool doonce = false)
{
delegateList.Add(new DelegateExtensibleFlag(action, doonce));
}
public bool DelegateRemove(Action action)
{
return delegateList.Remove(new DelegateExtensibleFlag(action));
}
#endregion
#region
public ProgramFlowSecurityExtend()
{
}
#endregion
#region
/// <summary>
/// 调用所有的已注册扩展事件,注意:这会比使用繁琐的外部方法更慢。
/// </summary>
public void InvokedAllDelegate()
{
for(int i = 0; i < delegateList.Count; i++)
{
if(delegateList[i].Conservate)
continue;
try
{
delegateList[i].Event.Invoke();
}
catch(Exception e)
{
delegateList[i].Conservate = true;
Debug.LogError(e);
}
}
}
#endregion
}
}