Archived
添加一些单例系统,材质方法
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Experimental.GraphView;
|
||||
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
using Xorti = XericLibrary.Runtime.MacroLibrary.MacroMath;
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
namespace XericLibrary.Runtime.MacroLibrary
|
||||
{
|
||||
public static class MacroEvent
|
||||
{
|
||||
#region 控制器
|
||||
|
||||
/// <summary>
|
||||
/// 保守事件控制器
|
||||
/// </summary>
|
||||
class ConservativeManager
|
||||
{
|
||||
#region 字段属性
|
||||
|
||||
/// <summary>
|
||||
/// 事件索引器
|
||||
/// </summary>
|
||||
private Dictionary<int, int> EventIndex;
|
||||
|
||||
/// <summary>
|
||||
/// 事件状态寄存器
|
||||
/// </summary>
|
||||
private List<int> eventRegister;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 方法
|
||||
|
||||
public ConservativeManager()
|
||||
{
|
||||
EventIndex = new Dictionary<int, int>();
|
||||
eventRegister = new List<int>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保守地利用控制器调用一个事件分发器
|
||||
/// </summary>
|
||||
public void InvokeConservative(Delegate targetevent)
|
||||
{
|
||||
var code = targetevent.GetHashCode();
|
||||
int index = 0;
|
||||
if(!EventIndex.TryGetValue(code, out index))
|
||||
EventIndex.Add(code, EventIndex.Count);
|
||||
targetevent.DynamicInvoke();// dynmic代表动态类型,包含装箱拆箱,速度会非常慢
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 事件
|
||||
|
||||
/// <summary>
|
||||
/// 保守地调用一个事件分发器
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool InvokeConservative(this Action invokedEvent, int sign, ref int register)
|
||||
{
|
||||
if(Xorti.GetByteState(register, sign))
|
||||
return false;
|
||||
Xorti.SetByteState(ref register, sign, true);
|
||||
invokedEvent?.Invoke();
|
||||
Xorti.SetByteState(ref register, sign, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保守地调用一个事件分发器
|
||||
/// </summary>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static bool InvokeConservative<PARAM>(this Action<PARAM> invokedEvent, PARAM input, int sign, ref int register)
|
||||
{
|
||||
if(Xorti.GetByteState(register, sign))
|
||||
return false;
|
||||
Xorti.SetByteState(ref register, sign, true);
|
||||
invokedEvent?.Invoke(input);
|
||||
Xorti.SetByteState(ref register, sign, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user