diff --git a/Editor/Initializer.meta b/Editor/Initializer.meta new file mode 100644 index 0000000..6c237a7 --- /dev/null +++ b/Editor/Initializer.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 44450adff1997d74f8382bb7ecbaa7f0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Initializer/InitializedXeric.cs b/Editor/Initializer/InitializedXeric.cs new file mode 100644 index 0000000..b94af4b --- /dev/null +++ b/Editor/Initializer/InitializedXeric.cs @@ -0,0 +1,42 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEditor; +using UnityEditor.Callbacks; + +using UnityEngine; + +namespace XericLibrary.Editor +{ + /// + /// 插件初始化 + /// + [InitializeOnLoad] + public class InitializedXeric + { + static InitializedXeric() + { + //Debug.Log("Editor is loaded. Initializing..."); + } + + [InitializeOnLoadMethod] + static void MyMethod() + { + //Debug.Log("InitializeOnLoadMethod is called."); + } + + [PostProcessScene] + public static void OnPostProcessScene() + { + Debug.Log("OnPostProcessScene is called."); + } + } + + [DidReloadScripts] + public class MyScript + { + static void OnScriptsReloaded() + { + Debug.Log("OnScriptsReloaded is called."); + } + } +} \ No newline at end of file diff --git a/Editor/Initializer/InitializedXeric.cs.meta b/Editor/Initializer/InitializedXeric.cs.meta new file mode 100644 index 0000000..98bc9ee --- /dev/null +++ b/Editor/Initializer/InitializedXeric.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 90ef394b99d429642aee067ce4d220b4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Lrss3.XericLibrary.Editor.asmdef b/Editor/Lrss3.XericLibrary.Editor.asmdef index 4f85763..95b7ec0 100644 --- a/Editor/Lrss3.XericLibrary.Editor.asmdef +++ b/Editor/Lrss3.XericLibrary.Editor.asmdef @@ -1,10 +1,18 @@ { "name": "Lrss3.XericLibrary.Editor", + "rootNamespace": "XericLibrary.Editor", "references": [ - "Lrss3.XericLibrary" + "Lrss3.XericLibrary" ], "includePlatforms": [ "Editor" ], - "excludePlatforms": [] -} + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Runtime/CollisionLOD.meta b/Runtime/CollisionLOD.meta new file mode 100644 index 0000000..675ecc8 --- /dev/null +++ b/Runtime/CollisionLOD.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: ce8d9db674f10b94c89f78d4a196f3b0 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/CollisionLOD/LodBoxCollider.cs b/Runtime/CollisionLOD/LodBoxCollider.cs new file mode 100644 index 0000000..84e229a --- /dev/null +++ b/Runtime/CollisionLOD/LodBoxCollider.cs @@ -0,0 +1,35 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +using XericLibrary.Runtime.Type; + +namespace XericLibrary.Runtime.CollisionLOD +{ + public class LodBoxCollider : LodColliderBase + { + #region 字段属性 + + /// + /// 启用轴向 + /// + public Bool3 EnableCollisionAxis = new Bool3(1,0,1); + + #endregion + + #region 生命周期 + + + + #endregion + + #region 碰撞检测 + + private bool CheckCollision() + { + return false; + } + + #endregion + } +} diff --git a/Runtime/CollisionLOD/LodBoxCollider.cs.meta b/Runtime/CollisionLOD/LodBoxCollider.cs.meta new file mode 100644 index 0000000..ed9fcaf --- /dev/null +++ b/Runtime/CollisionLOD/LodBoxCollider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 05ae1487ca501af4583c3f2d5307c5b5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/CollisionLOD/LodSphereCollider.cs b/Runtime/CollisionLOD/LodSphereCollider.cs new file mode 100644 index 0000000..2b73b1d --- /dev/null +++ b/Runtime/CollisionLOD/LodSphereCollider.cs @@ -0,0 +1,12 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + + +namespace XericLibrary.Runtime.CollisionLOD +{ + public class LodSphereCollider : LodColliderBase + { + + } +} diff --git a/Runtime/CollisionLOD/LodSphereCollider.cs.meta b/Runtime/CollisionLOD/LodSphereCollider.cs.meta new file mode 100644 index 0000000..1b295f8 --- /dev/null +++ b/Runtime/CollisionLOD/LodSphereCollider.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6882978c69b0a1f40b440f8ef70f8fc2 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/CollisionLOD/base.meta b/Runtime/CollisionLOD/base.meta new file mode 100644 index 0000000..819939f --- /dev/null +++ b/Runtime/CollisionLOD/base.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 2d3709d62d6ccbc40acfb2b368f8aa5b +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/CollisionLOD/base/LodColliderBase.cs b/Runtime/CollisionLOD/base/LodColliderBase.cs new file mode 100644 index 0000000..86fb9ee --- /dev/null +++ b/Runtime/CollisionLOD/base/LodColliderBase.cs @@ -0,0 +1,120 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +using UnityEditor; + +using UnityEngine; + +using XericLibrary.Runtime.Type; + +namespace XericLibrary.Runtime.CollisionLOD +{ + /// + /// 具有基本缩放的碰撞器基类 + /// + public abstract class LodColliderBase : WeaklyMonoBase , IComparable + { + /* + * 碰撞体需要及时性,不建议使用协程,异步等方法处理事件 + */ + + #region 静态成员 + + #region 字段属性 + + /// + /// 碰撞处理流程 + /// + protected static ProgramFlowLinear ProgramFlow; + + #endregion + + #region 静态方法 + + + + #endregion + + #endregion + + #region 字段属性 + + /// + /// 处理等级 + /// + public int SeqLevels = -1; + + /// + /// 表示序列等级是否不需要处理 + /// + [SerializeField] + private bool noInitializationRequired = false; + + /// + /// 盒体尺寸信息 + /// + public Bounds BoundSize; + + /// + /// 碰撞器集合 + /// + private List allLodColliderList = null; + + #endregion + + #region 生命周期 + + private void OnValidate() + { + noInitializationRequired = true; + + var allColliders = transform.GetComponents(); + if(SeqLevels < 0) + SeqLevels = allColliders.Length; + + var genList = allColliders.ToList(); + MakeLevelLinearArray(genList); + } + + private void Start() + { + if(noInitializationRequired) + return; + // 动态添加的处理 + //allLodColliderList = transform.GetComponents() + //.ToList(); + //MakeLevelLinearArray(allLodColliderList); + } + + #endregion + + #region 方法 + + /// + /// 使列表等级完全不重复 + /// + private void MakeLevelLinearArray(List genList) + { + genList.Sort(); + int seqIndex = 0; + foreach(var item in genList) + item.SeqLevels = seqIndex++; + } + + #endregion + + #region 接口 + + public int CompareTo(object obj) + { + if(obj is LodColliderBase lod) + return SeqLevels.CompareTo(lod.SeqLevels); + else + return this.CompareTo(obj); + } + + #endregion + } +} diff --git a/Runtime/CollisionLOD/base/LodColliderBase.cs.meta b/Runtime/CollisionLOD/base/LodColliderBase.cs.meta new file mode 100644 index 0000000..c6c09e2 --- /dev/null +++ b/Runtime/CollisionLOD/base/LodColliderBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 306fe8a0033a9e74bb27f07803ead32b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Lrss3.XericLibrary.asmdef b/Runtime/Lrss3.XericLibrary.asmdef index 624474b..ba5e4a2 100644 --- a/Runtime/Lrss3.XericLibrary.asmdef +++ b/Runtime/Lrss3.XericLibrary.asmdef @@ -1,6 +1,6 @@ { "name": "Lrss3.XericLibrary", - "rootNamespace": "XericLibrary", + "rootNamespace": "XericLibrary.Runtime", "references": [], "includePlatforms": [], "excludePlatforms": [], diff --git a/Runtime/MicroLibrary/MacroEnum.cs b/Runtime/MicroLibrary/MacroEnum.cs index 5f48469..2b5c2dc 100644 --- a/Runtime/MicroLibrary/MacroEnum.cs +++ b/Runtime/MicroLibrary/MacroEnum.cs @@ -1,5 +1,3 @@ - - using System; using System.Collections; using System.Collections.Generic; @@ -73,6 +71,21 @@ namespace XericLibrary.Runtime.MacroLibrary } + /// + /// 检查是否包含给定,且只关注是否完全包含 + /// + /// 要检查的特征 + /// 过滤的特征 + /// + 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; + } + /// /// 设置目标的枚举值 /// @@ -146,25 +159,28 @@ namespace XericLibrary.Runtime.MacroLibrary target ^= Convert.ToInt32(value); } - /// - /// 检查是否包含给定,且只关注是否完全包含 - /// - /// 要检查的特征 - /// 过滤的特征 - /// - 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; - } } public static partial class MacroMath { + + /// + /// 获取给定索引下的位是否为真 + /// + /// + /// + /// + public static bool GetEnumIndex(this int target, int index) + { + return 0 != ((target >> index) & 1); + } + + public static void SetEnumIndex(this ref int target, int index) + { + target |= 1 << index; + } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static int EnumToInt32(this Enum target) { diff --git a/Runtime/Type/Base.meta b/Runtime/Type/Base.meta new file mode 100644 index 0000000..eb5b8f9 --- /dev/null +++ b/Runtime/Type/Base.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: c7294966259431443ae3001869eef2b5 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Type/Base/Bool3.cs b/Runtime/Type/Base/Bool3.cs new file mode 100644 index 0000000..a9dc066 --- /dev/null +++ b/Runtime/Type/Base/Bool3.cs @@ -0,0 +1,154 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEditor; + +using UnityEngine; + +using XericLibrary.Runtime.MacroLibrary; + +namespace XericLibrary.Runtime.Type +{ + [Serializable] + public struct Bool3 + { + #region 字段构造 + + [SerializeField] + private int axis; + + public bool x + { + get => axis.GetEnumIndex(0); + set => axis.SetEnumIndex(0); + } + public bool y + { + get => axis.GetEnumIndex(1); + set => axis.SetEnumIndex(1); + } + public bool z + { + get => axis.GetEnumIndex(2); + set => axis.SetEnumIndex(2); + } + + public Bool3(bool x, bool y, bool z) + { + axis = x ? 1 : 0; + axis |= y ? 2 : 0; + axis |= z ? 4 : 0; + } + + public Bool3(int x, int y, int z) + { + axis = x > 0 ? 1 : 0; + axis |= y > 0 ? 2 : 0; + axis |= z > 0 ? 4 : 0; + } + + #endregion + + #region 运算 + + public static implicit operator Bool3(int x) + { + var res = new Bool3(); + res.axis = x; + return res; + } + + public static implicit operator int(Bool3 x) + => x.axis; + + #endregion + + } + + [CustomPropertyDrawer(typeof(Bool3))] + public class Bool3DDrawer : PropertyDrawer + { + private readonly GUIContent[] labels = { new GUIContent("X"), new GUIContent("Y"), new GUIContent("Z") }; + + //public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + //{ + // EditorGUI.BeginProperty(position, label, property); + + // // 使用SerializedObject和SerializedProperty来获取子属性 + // SerializedProperty xProp = property.FindPropertyRelative("x"); + // SerializedProperty yProp = property.FindPropertyRelative("y"); + // SerializedProperty zProp = property.FindPropertyRelative("z"); + + // // 设置布尔框的位置 + // float labelWidth = EditorGUIUtility.labelWidth; + // float checkboxWidth = 30f; + // Rect labelRect = new Rect(position.x, position.y, labelWidth, position.height); + + // EditorGUI.LabelField(labelRect, label); + + // for(int i = 0; i < 3; i++) + // { + // float checkboxX = position.x + labelWidth + i * (checkboxWidth + 2); + // Rect checkboxRect = new Rect(checkboxX, position.y, checkboxWidth, position.height); + // EditorGUI.PrefixLabel(checkboxRect, GUIUtility.GetControlID(FocusType.Passive), labels[i]); + + // Rect toggleRect = new Rect(checkboxX + 12, position.y, checkboxWidth, position.height); + // switch(i) + // { + // case 0: + // xProp.boolValue = EditorGUI.Toggle(toggleRect, xProp.boolValue); + // break; + // case 1: + // yProp.boolValue = EditorGUI.Toggle(toggleRect, yProp.boolValue); + // break; + // case 2: + // zProp.boolValue = EditorGUI.Toggle(toggleRect, zProp.boolValue); + // break; + // } + // } + + // EditorGUI.EndProperty(); + //} + + public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) + { + EditorGUI.BeginProperty(position, label, property); + + // 使用SerializedObject和SerializedProperty来获取子属性 + SerializedProperty axisProp = property.FindPropertyRelative("axis"); + + // 设置布尔框的位置 + float labelWidth = EditorGUIUtility.labelWidth; + float checkboxWidth = 30f; + Rect labelRect = new Rect(position.x, position.y, labelWidth, position.height); + + EditorGUI.LabelField(labelRect, label); + + bool[] axisValue = new bool[3]; + for(int i = 0; i < 3; i++) + { + float checkboxX = position.x + labelWidth + i * (checkboxWidth + 2); + Rect checkboxRect = new Rect(checkboxX, position.y, checkboxWidth, position.height); + EditorGUI.PrefixLabel(checkboxRect, GUIUtility.GetControlID(FocusType.Passive), labels[i]); + + Rect toggleRect = new Rect(checkboxX + 12, position.y, checkboxWidth, position.height); + switch(i) + { + case 0: + axisValue[0] = EditorGUI.Toggle(toggleRect, axisProp.intValue.GetEnumIndex(0)); + break; + case 1: + axisValue[1] = EditorGUI.Toggle(toggleRect, axisProp.intValue.GetEnumIndex(1)); + break; + case 2: + axisValue[2] = EditorGUI.Toggle(toggleRect, axisProp.intValue.GetEnumIndex(2)); + break; + } + } + + axisProp.intValue = new Bool3(axisValue[0], axisValue[1], axisValue[2]); + + EditorGUI.EndProperty(); + } + } +} diff --git a/Runtime/Type/Base/Bool3.cs.meta b/Runtime/Type/Base/Bool3.cs.meta new file mode 100644 index 0000000..ee50c6f --- /dev/null +++ b/Runtime/Type/Base/Bool3.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 101054efc7a817b4aa6080d90116d08e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: