Archived
添加了更多的材质函数,部分与引擎新特性重合,这是为了能够脱离引擎在多个版本中更具可移植性。
添加了多种对程序流程控制与保全的脚本,而且现在可以更快速的构建一个具有线性关系的协程了。 添加了一个支持多种模式的单维梯度控制器,类似unity的颜色梯度类型。 添加了一个用于看向某个物体的旋转控制器。 添加了一个加载宏。 完善了批处理脚本流程。
This commit is contained in:
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using XericLibrary.Runtime.Type;
|
||||
|
||||
namespace XericLibrary
|
||||
{
|
||||
/// <summary>
|
||||
/// 线性处理流程
|
||||
/// </summary>
|
||||
public class ProgramFlowLinear : WeaklyObject
|
||||
{
|
||||
#region 委托事件
|
||||
|
||||
/// <summary>
|
||||
/// 恢复待执行事件列表
|
||||
/// </summary>
|
||||
public event Action RecoveredCoroutineList;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 字段属性
|
||||
|
||||
/// <summary>
|
||||
/// 设定是否循环处理所有协程
|
||||
/// </summary>
|
||||
public bool LoopProgramFlow
|
||||
{
|
||||
get => loopProgramFlow;
|
||||
set
|
||||
{
|
||||
if(TargetEvent == null)
|
||||
loopProgramFlow = value;
|
||||
else
|
||||
Debug.LogError("不允许在协程运行中进行处理流程模式的切换");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 循环处理所有协程
|
||||
/// </summary>
|
||||
private bool loopProgramFlow = true;
|
||||
|
||||
/// <summary>
|
||||
/// 最大执行计数
|
||||
/// </summary>
|
||||
public int MaxEmbeddedLoopCount = 100;
|
||||
|
||||
/// <summary>
|
||||
/// 当前协程内执行流程计数
|
||||
/// </summary>
|
||||
private int embeddedLoopCount = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 等待执行的协程
|
||||
/// </summary>
|
||||
private LinkedList<IEnumerator> routines = new LinkedList<IEnumerator>();
|
||||
|
||||
/// <summary>
|
||||
/// 当前执行的协程
|
||||
/// </summary>
|
||||
private Coroutine TargetEvent;
|
||||
|
||||
/// <summary>
|
||||
/// 持久担保者
|
||||
/// </summary>
|
||||
private MonoBehaviour assure;
|
||||
|
||||
/// <summary>
|
||||
/// 第一次执行
|
||||
/// </summary>
|
||||
private bool firstTime = true;
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 线性协程处理器,将一系列协程进行线性处理;
|
||||
/// </summary>
|
||||
/// <param name="recoveredListTodo">将添加协程的过程进行定义</param>
|
||||
/// <param name="assure">协程处理的担保脚本</param>
|
||||
/// <param name="executeImmediately">在定义完成后立即执行协程</param>
|
||||
/// <param name="loopProgram">设定协程循环执行,如果不循环则需要手动调用start方法</param>
|
||||
public ProgramFlowLinear(Action recoveredListTodo, MonoBehaviour assure, bool executeImmediately = true, bool loopProgram = true)
|
||||
{
|
||||
RecoveredCoroutineList = recoveredListTodo;
|
||||
this.loopProgramFlow = loopProgram;
|
||||
firstTime = true;
|
||||
if(executeImmediately)
|
||||
StartCoroutine();
|
||||
}
|
||||
|
||||
#region 方法
|
||||
|
||||
/// <summary>
|
||||
/// 添加待处理协程
|
||||
/// </summary>
|
||||
/// <param name="routine"></param>
|
||||
public void AddCoroutine(IEnumerator routine)
|
||||
{
|
||||
routines.AddLast(routine);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 协程!启动!
|
||||
/// </summary>
|
||||
public void StartCoroutine()
|
||||
{
|
||||
if(TargetEvent == null)
|
||||
{
|
||||
if(firstTime && routines.Count <= 0)
|
||||
RecoveredCoroutineList();
|
||||
if(routines.Count <= 0)
|
||||
{
|
||||
Debug.LogError("协程步骤为空,可能是并非初始,或复位栈为空");
|
||||
return;
|
||||
}
|
||||
TargetEvent = assure.StartCoroutine(routines.First.Value);
|
||||
|
||||
routines.RemoveFirst();
|
||||
firstTime = false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行下一个协程
|
||||
/// </summary>
|
||||
public void NextCoroutine()
|
||||
{
|
||||
if(loopProgramFlow && routines.Count <= 0)
|
||||
RecoveredCoroutineList();
|
||||
if(TargetEvent != null)
|
||||
TargetEvent = null;
|
||||
else
|
||||
Debug.LogError("执行的协程步骤来自初始?");
|
||||
StartCoroutine();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试增加协程执行计数,当计数超越预设范围后将提示停止协程
|
||||
/// </summary>
|
||||
public bool TryPromoteEmbedded()
|
||||
{
|
||||
if(++embeddedLoopCount > MaxEmbeddedLoopCount)
|
||||
{
|
||||
embeddedLoopCount = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a614d165b036beb41ad5f542b02fdf12
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,26 +1,29 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
using XericLibrary.Runtime.Type;
|
||||
|
||||
namespace XericLibrary.Runtime.Security
|
||||
{
|
||||
/// <summary>
|
||||
/// 程序流程保全
|
||||
/// </summary>
|
||||
/// <summary>
|
||||
/// 基本的保全调用方法;
|
||||
/// 需要手动在委托的前后安置保全标识
|
||||
/// </summary>
|
||||
public class ProgramFlowSecurity : WeaklyObject
|
||||
{
|
||||
#region 字段属性
|
||||
{
|
||||
#region 字段属性
|
||||
|
||||
/// <summary>
|
||||
/// 保护标志位
|
||||
/// 外部保护标志位
|
||||
/// </summary>
|
||||
private int conservativeFlag;
|
||||
|
||||
/// <summary>
|
||||
/// 单步标志位
|
||||
/// 外部单步标志位
|
||||
/// </summary>
|
||||
private int DoOnceFlag;
|
||||
|
||||
@@ -36,7 +39,7 @@ namespace XericLibrary.Runtime.Security
|
||||
|
||||
#endregion
|
||||
|
||||
#region 方法
|
||||
#region 外部方法
|
||||
|
||||
/// <summary>
|
||||
/// 标志一段程序的开始
|
||||
@@ -131,4 +134,4 @@ namespace XericLibrary.Runtime.Security
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7fec265b4bc05249b53e040d279b079
|
||||
guid: 3aa1a126b33b746438d102310ab9e983
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7fec265b4bc05249b53e040d279b079
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using XericLibrary.Runtime.Type;
|
||||
|
||||
namespace XericLibrary.Runtime.Security
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用委托名称契约进行调用的保全,
|
||||
/// 性能上应该比使用try catch更好。
|
||||
/// </summary>
|
||||
public class ProgramFlowSecuttyContract : WeaklyObject
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d167ce6ade4403e4d8ef2b75925a0ba0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user