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/ProgramFlowLinear.cs
LiRuoChen a658cc424b 添加了更多的材质函数,部分与引擎新特性重合,这是为了能够脱离引擎在多个版本中更具可移植性。
添加了多种对程序流程控制与保全的脚本,而且现在可以更快速的构建一个具有线性关系的协程了。
  添加了一个支持多种模式的单维梯度控制器,类似unity的颜色梯度类型。
  添加了一个用于看向某个物体的旋转控制器。
  添加了一个加载宏。
  完善了批处理脚本流程。
2023-11-23 11:10:40 +08:00

158 lines
3.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}
}