Archived
添加一些单例系统,材质方法
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2153f3f51f4097846b1b3442123f4433
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user