添加一些单例系统,材质方法

This commit is contained in:
2023-10-24 08:44:11 +08:00
parent a024cf600b
commit 498e56bb69
36 changed files with 16499 additions and 384 deletions
+25 -2
View File
@@ -21,7 +21,6 @@ namespace XericLibrary.Runtime.MacroLibrary
/// </summary>
public const decimal Rad2Ang_m = 57.295779513082320876798154814105m;
/// <summary>
/// 角度转弧度
/// </summary>
@@ -35,6 +34,31 @@ namespace XericLibrary.Runtime.MacroLibrary
/// </summary>
public const decimal Ang2Rad_m = .01745329251994329576923690768489m;
/// <summary>
/// 45度余弦值
/// </summary>
public const float Cos45 = 0.70710678118654752440084436210485f;
/// <summary>
/// 45度余弦值
/// </summary>
public const double Cos45_d = 0.70710678118654752440084436210485d;
/// <summary>
/// 45度余弦值
/// </summary>
public const decimal Cos45_m = 0.70710678118654752440084436210485m;
/// <summary>
/// 45度正弦值
/// </summary>
public const float Sin45 = 0.70710678118654752440084436210485f;
/// <summary>
/// 45度正弦值
/// </summary>
public const double Sin45_d = 0.70710678118654752440084436210485d;
/// <summary>
/// 45度正弦值
/// </summary>
public const decimal Sin45_m = 0.70710678118654752440084436210485m;
/// <summary>
/// 最大可接受的误差
@@ -49,7 +73,6 @@ namespace XericLibrary.Runtime.MacroLibrary
/// </summary>
public const decimal MaxError_m = .00000001m;
/// <summary>
/// 根号2的一半,用于快速平方根除以二
/// </summary>
+15
View File
@@ -140,5 +140,20 @@ namespace XericLibrary.Runtime.MacroLibrary
{
target ^= Convert.ToInt32(value);
}
/// <summary>
/// 检查是否包含给定,且只关注是否完全包含
/// </summary>
/// <param name="examineCC">要检查的特征</param>
/// <param name="filterCC">过滤的特征</param>
/// <returns></returns>
public static bool CheckEnum(T examineCC, T filterCC)
{
var cc = Convert.ToInt32(filterCC);
var isValid = Convert.ToInt32(examineCC) & cc;
var isFull = isValid ^ cc;
return isValid > 0 && isFull <= 0;
}
}
}
+94
View File
@@ -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
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2153f3f51f4097846b1b3442123f4433
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+16
View File
@@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
using UnityEngine.Windows;
namespace XericLibrary.Runtime.MacroLibrary
{
@@ -50,6 +51,21 @@ namespace XericLibrary.Runtime.MacroLibrary
#region 数学
/// <summary>
/// pmod
/// </summary>
/// <param name="a"></param>
/// <param name="b"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int PMod(int a, int b)
{
if(b <= 0)
return 0;
var mod = a % b;
return a < 0 ? (b + mod) % b : mod;
}
/// <summary>
/// pmod
/// </summary>
+87
View File
@@ -8,6 +8,93 @@ namespace XericLibrary.Runtime.MacroLibrary
{
#region 对象操作
/// <summary>
/// 获取一个变换节点下所有的子成员
/// </summary>
/// <param name="trans"></param>
/// <returns></returns>
public static IEnumerable<Transform> GetChildren(this Transform trans)
{
for(int i = 0; i < trans.childCount; i++)
{
yield return trans.GetChild(i);
}
}
/// <summary>
/// 在所有子成员中深度优先找到第一个组件
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="trans"></param>
/// <param name="recursion">遍历深度,0表示仅在此处寻找,1表示在包含下一级在内的所有成员中寻找</param>
/// <returns></returns>
public static IEnumerable<T> GetChildrenRecursionComponents<T>(this Transform trans, int recursion = 1)
where T : Component
{
int newRecursion = recursion - 1;
foreach(var item in trans.GetChildren())
{
var comp = item.GetComponent<T>();
if(comp == null && newRecursion > 0)
comp = item.GetChildrenRecursionComponent<T>(newRecursion);
yield return comp;
}
}
/// <summary>
/// 按深度优先寻找一个组件
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="trans"></param>
/// <param name="depth">遍历深度,0表示仅在第一子集中寻找,1表示在包含下一级在内的所有成员中寻找</param>
/// <returns></returns>
public static T GetChildrenRecursionComponent<T>(this Transform trans, int depth = 1)
where T : Component
{
T result;
int newDepth = depth - 1;
#if true // 如果不知道这里在找什么的可以打开调试看看
foreach(var item in trans.GetChildren())
{
result = item.GetComponent<T>();
if(result == null && newDepth > 0)
result = item.GetChildrenRecursionComponent<T>(newDepth);
if(result != null)
return result;
}
#else
string info = $"{depth}. 开始在{trans.name}中寻找\r\n";
foreach(var item in trans.GetChildren())
{
info += $"{depth}. > 正在{item.name}中寻找\r\n";
result = item.GetComponent<T>();
info += $"{depth}. 当前节点{(result == null ? "不包含组件":"包含组件")}\r\n";
if(result == null && newDepth >= 0)
{
info += $"{depth}. 前往深层寻找 > \r\n";
result = item.GetRecursionComponent<T>(newDepth);
info += $"{depth}. 深层查找返回 < \r\n";
}
if(result != null)
{
info += $"{depth}. 已找到结果:{result.name} \r\n";
Debug.Log(info);
return result;
}
info += $"{depth}. 没有找到任何东西 \r\n";
}
Debug.Log(info + "没有找到,空结束");
#endif
return null;
}
/// <summary>
/// 无论如何都要获取一个组件
/// </summary>
+22 -1
View File
@@ -1,5 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using UnityEngine;
namespace Xeric.Runtime.MicroLibrary
@@ -46,7 +48,26 @@ namespace Xeric.Runtime.MicroLibrary
return new Vector3(input.x, input.y, input.z);
}
/// <summary>
/// 世界向上表面坐标转换方法
/// </summary>
/// <param name="vec"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 ToVector3(this Vector2 vec)
=> new Vector3(vec.x, 0, vec.y);
/// <summary>
/// 世界向上表面坐标转换方法
/// </summary>
/// <param name="vec"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 ToVector2(this Vector3 vec)
=> new Vector2(vec.x, vec.z);
#endregion
}
}
}
-32
View File
@@ -123,38 +123,6 @@ namespace XericLibrary.Runtime.MacroLibrary
#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
#region 对象
/// <summary>
-9
View File
@@ -9,15 +9,6 @@ namespace XericLibrary.Runtime.MacroLibrary
{
public static class Vector2Extend
{
/// <summary>
/// 李若辰规定的编辑表面坐标转换方法
/// </summary>
/// <param name="vec"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector3 ToVector3(this Vector2 vec)
=> new Vector3(vec.x, 0, vec.y);
[Obsolete("unfinished")]
public static Vector2 Projection(this Vector2 point, Vector3 start, Vector3 end)
{
-10
View File
@@ -209,16 +209,6 @@ namespace XericLibrary.Runtime.MacroLibrary
public static Vector3 Negative(this Vector3 a)
=> new Vector3(-a.x, -a.y, -a.z);
/// <summary>
/// 李若辰规定的编辑表面坐标转换方法
/// </summary>
/// <param name="vec"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static Vector2 ToVector2(this Vector3 vec)
=> new Vector2(vec.x, vec.z);
[MethodImpl(MethodImplOptions.NoInlining)]
public static Vector2 ToVector2(this Vector3 vec, string format)
{
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 587860aad7413cb448a73fafadcc68c9
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+134
View File
@@ -0,0 +1,134 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XericLibrary.Runtime.Type;
namespace XericLibrary.Runtime.Security
{
/// <summary>
/// 程序流程保全
/// </summary>
public class ProgramFlowSecurity : WeaklyObject
{
#region 字段属性
/// <summary>
/// 保护标志位
/// </summary>
private int conservativeFlag;
/// <summary>
/// 单步标志位
/// </summary>
private int DoOnceFlag;
#endregion
#region 构造
public ProgramFlowSecurity()
{
conservativeFlag = 0;
DoOnceFlag = 0;
}
#endregion
#region 方法
/// <summary>
/// 标志一段程序的开始
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="site"></param>
public void Start<T>(T site)
where T : struct, Enum
{
conservativeFlag |= Convert.ToInt32(site);
}
/// <summary>
/// 标志一段程序的结束
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="site"></param>
public void Finish<T>(T site)
where T : struct, Enum
{
conservativeFlag &= ~Convert.ToInt32(site);
}
/// <summary>
/// 尝试开始一段程序
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="site"></param>
/// <returns></returns>
public bool TryStart<T>(T site)
where T : struct, Enum
{
if(GetFlag(site))
return false;
Start(site);
return true;
}
/// <summary>
/// 开始执行一次
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="site"></param>
/// <returns></returns>
public bool DoOnceStart<T>(T site)
where T : struct, Enum
{
if(GetFlag(site))
return false;
DoOnceFlag |= Convert.ToInt32(site);
return true;
}
/// <summary>
/// 复位执行一次的标志
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="site"></param>
public void ResetDoOnce<T>(T site)
where T : struct, Enum
{
DoOnceFlag &= ~Convert.ToInt32(site);
}
/// <summary>
/// 获取一段程序的标志位
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="site"></param>
/// <returns></returns>
private bool GetFlag<T>(T site)
where T : struct, Enum
{
return (conservativeFlag & Convert.ToInt32(site)) > 0;
}
/// <summary>
/// 获取一段程序的标志位
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="site"></param>
/// <returns></returns>
private bool GetDoOnce<T>(T site)
where T : struct, Enum
{
return (DoOnceFlag & Convert.ToInt32(site)) > 0;
}
#endregion
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: a7fec265b4bc05249b53e040d279b079
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+88
View File
@@ -0,0 +1,88 @@
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace XericLibrary.Runtime.Type
{
/// <summary>
/// 单例基础类,
/// </summary>
/// <typeparam name="T"></typeparam>
public class SingleMonoBase<T> : MonoBehaviour
where T : Component
{
#region 字段属性
/// <summary>
/// 组件单例
/// </summary>
private static T inst;
/// <summary>
/// 获取组件单例
/// </summary>
public static T Inst
{
get
{
if(inst == null)
InstanceLaunch();
return inst;
}
}
/// <summary>
/// 所有没有指定的目标的单例脚本组件的挂载节点
/// </summary>
private static GameObject globalEmptyNode;
#endregion
#region 生命周期
/// <summary>
/// 基本单例组件中默认保留旧的成员,如果需要移除旧成员,请在base调用前调用DestroyInstanc()
/// </summary>
/// <exception cref="System.Exception"></exception>
protected virtual void Awake()
{
//if(DestroyInstance())
// Debug.LogError("初始警告:存在多个单例对象,已移除旧的项目");
inst = this as T;
if(inst == null)
throw new System.Exception("单例脚本给定类型错误");
}
#endregion
#region 方法
/// <summary>
/// 移除一个单例实例
/// </summary>
protected bool DestroyInstance()
{
if(inst != null)
{
Destroy(inst.gameObject);
return true;
}
return false;
}
/// <summary>
/// 实例在场景中无中生有时通过此过程进行初始化
/// </summary>
private static void InstanceLaunch()
{
if (globalEmptyNode == null)
globalEmptyNode = new GameObject("DoNotDestroyThis");
globalEmptyNode.AddComponent<T>();
}
#endregion
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7ffeec192c3ef0845b82859ad7f17b65
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+2 -5
View File
@@ -125,10 +125,7 @@ namespace XericLibrary.Runtime.Type
public static bool operator ==(WeaklyMonoBase lhs, WeaklyMonoBase rhs)
{
if(lhs == null)
return rhs == null;
if(rhs == null)
return lhs == null;
if(rhs is null) return lhs is null;
return lhs.Equals(rhs);
}
@@ -139,7 +136,7 @@ namespace XericLibrary.Runtime.Type
public static implicit operator bool(WeaklyMonoBase lhs)
{
return lhs.Equals(null);
return lhs is not null;
}
#endregion
+2 -5
View File
@@ -24,10 +24,7 @@ namespace XericLibrary.Runtime.Type
public static bool operator ==(WeaklyObject lhs, WeaklyObject rhs)
{
if(lhs == null)
return rhs == null;
if(rhs == null)
return lhs == null;
if(rhs is null) return lhs is null;
return lhs.Equals(rhs);
}
@@ -38,7 +35,7 @@ namespace XericLibrary.Runtime.Type
public static implicit operator bool(WeaklyObject lhs)
{
return lhs.Equals(null);
return lhs is not null;
}
}
}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5d1285a3067988d44852b9da9116fc3f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: baa6dfb306418024797d8a44d7ec382f
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 8467cf9b285124f44b7abf3252dc65eb
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 82621b0cec53f174c9bc1cfab8d74a12
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0fd1e240ff69c444481507d83de222a3
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: a13229ea43109f14c9eabc333c48ff22
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 03b1d8a2a8aeea449843adbf61ab0e9a
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ea08eb5d0b2c0e3479804a22fa882c5c
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}
+8
View File
@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 87f7cc264fd00c24a84aa845acabbb73
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 7fe925c1442acfe48b0b6a939df46beb
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3}