diff --git a/Runtime/Logger/MergeDebug.cs b/Runtime/Logger/MergeDebug.cs index d9ca5d8..040daa2 100644 --- a/Runtime/Logger/MergeDebug.cs +++ b/Runtime/Logger/MergeDebug.cs @@ -1,4 +1,4 @@ -using log4net.Util; + using System; using System.Collections; @@ -8,7 +8,7 @@ using System.Text; using UnityEngine; -using static Codice.CM.WorkspaceServer.WorkspaceTreeDataStore; + namespace XericLibrary.Runtime.MacroLibrary { diff --git a/Runtime/MicroLibrary/MacroEnum.cs b/Runtime/MicroLibrary/MacroEnum.cs index 258b831..5f48469 100644 --- a/Runtime/MicroLibrary/MacroEnum.cs +++ b/Runtime/MicroLibrary/MacroEnum.cs @@ -1,4 +1,4 @@ -using Codice.CM.WorkspaceServer.Tree.GameUI.HeadTree; + using System; using System.Collections; @@ -6,7 +6,9 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; +#if UNITY_EDITOR using Unity.VisualScripting.YamlDotNet.Core.Tokens; +#endif using UnityEngine; diff --git a/Runtime/MicroLibrary/MacroEvent.cs b/Runtime/MicroLibrary/MacroEvent.cs index 2b20e70..8c3940e 100644 --- a/Runtime/MicroLibrary/MacroEvent.cs +++ b/Runtime/MicroLibrary/MacroEvent.cs @@ -1,7 +1,10 @@ using System; using System.Collections; using System.Collections.Generic; + +#if UNITY_EDITOR using UnityEditor.Experimental.GraphView; +#endif using System.Runtime.CompilerServices; diff --git a/Runtime/MicroLibrary/MacroList.cs b/Runtime/MicroLibrary/MacroList.cs index 179dadf..223b9ab 100644 --- a/Runtime/MicroLibrary/MacroList.cs +++ b/Runtime/MicroLibrary/MacroList.cs @@ -21,9 +21,12 @@ namespace XericLibrary.Runtime.MacroLibrary /// public static List FisherYatesShuffle(int length, int select) { + if(select > length) + throw new ArgumentOutOfRangeException("在进行洗牌时,要求输出的项目比拥有的项目更多,这是不合理的。"); + var random = new System.Random(); - List arr = Enumerable.Range(1, length).ToList(); + List arr = Enumerable.Range(0, length).ToList(); List res = new List(); for(int i = 0; i < select; ++i) diff --git a/Runtime/MicroLibrary/TypeExtend.cs b/Runtime/MicroLibrary/TypeExtend.cs index b3b27db..b7c15d9 100644 --- a/Runtime/MicroLibrary/TypeExtend.cs +++ b/Runtime/MicroLibrary/TypeExtend.cs @@ -1,7 +1,10 @@ using System; using System.Collections; using System.Collections.Generic; + +#if UNITY_EDITOR using UnityEditor.Experimental.GraphView; +#endif using System.Runtime.CompilerServices; diff --git a/Runtime/SpatialTransform.meta b/Runtime/SpatialTransform.meta new file mode 100644 index 0000000..410cca9 --- /dev/null +++ b/Runtime/SpatialTransform.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 785b6db82960d6c49acaedc81c113019 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/SpatialTransform/OffsetFromTrackTarget.cs b/Runtime/SpatialTransform/OffsetFromTrackTarget.cs new file mode 100644 index 0000000..beb7cfc --- /dev/null +++ b/Runtime/SpatialTransform/OffsetFromTrackTarget.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +using XericLibrary.Runtime.Type; + +namespace XericLibrary.Runtime.SpatialTransform +{ + /// + /// 设定偏移来自追踪目标 + /// + public class OffsetFromTrackTarget : WeaklyMonoBase + { + /// + /// 追踪目标 + /// + public Transform TrackTarget; + + /// + /// 偏移量 + /// + public Vector3 Offset; + + + private void Update() + { + if(TrackTarget != null) + { + var pos = transform.position; + pos.y = 0; + var trackPos = TrackTarget.position; + trackPos.y = 0; + + + transform.position = TrackTarget.position + TrackTarget.rotation * Offset; + + transform.rotation = Quaternion.LookRotation(pos - trackPos); + } + } + + /// + /// 初始化 + /// + /// + public void Initialized(Transform tracK, Vector3 offset) + { + TrackTarget = tracK; + Offset = offset; + } + } +} diff --git a/Runtime/SpatialTransform/OffsetFromTrackTarget.cs.meta b/Runtime/SpatialTransform/OffsetFromTrackTarget.cs.meta new file mode 100644 index 0000000..0f64c1e --- /dev/null +++ b/Runtime/SpatialTransform/OffsetFromTrackTarget.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dc5062889e515554690f2a00becd6359 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Type/BatchProcessor.cs b/Runtime/Type/BatchProcessor.cs new file mode 100644 index 0000000..7328f4f --- /dev/null +++ b/Runtime/Type/BatchProcessor.cs @@ -0,0 +1,160 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +using UnityEngine; + +using static XericLibrary.Runtime.Type.BatchProcessor; + +namespace XericLibrary.Runtime.Type +{ + /// + /// 流程批处理器,用于减少调用栈切换时的耗时 + /// + /// 一般一次切换耗时 <2us; + /// 此举会使得编译器不再追踪及其细致的更新时间调用栈,谨慎使用。 + /// + /// + public abstract class BatchProcessor : SingleMonoBase + { + #region 字段属性 + + /// + /// 所有处理脚本的流程列表 + /// + internal List ProcessorList; + + /// + /// 注册添加或移除处理器项目 + /// + public event Action AnonymousProcessing + { + add => AddProcess(value); + remove => RemoveProcess(value); + } + + + + /// + /// 在更新时需要被移除的对象 + /// + private List needRemove = new List(); + + #endregion + + #region 类内类 + + /// + /// 带有归属类的事件 + /// + public class ActionAttribution + { + /// + /// 事件 + /// + internal Action EventAction; + + /// + /// 目标归属脚本 + /// + internal MonoBehaviour TargetScript; + + /// + /// 建立一个归属类 + /// + /// + /// + public ActionAttribution(MonoBehaviour script, Action action) + { + EventAction = action; + TargetScript = script; + } + + } + + #endregion + + #region 生命周期 + + protected override void Awake() + { + base.Awake(); + } + + protected virtual void Update() + { + foreach(var processor in ProcessorList) + { + if(ReferenceEquals(processor.TargetScript, null)) + needRemove.Add(processor); + + processor.EventAction(); + } + + if(needRemove.Count > 0) + { + ProcessorList = ProcessorList.Except(needRemove).ToList(); + needRemove.Clear(); + } + } + + #endregion + + #region 方法 + + /// + /// 添加匿名处理器 + /// + /// + protected internal void AddProcess(Action actuator) + { + ProcessorList.Add(new ActionAttribution(this, actuator)); + } + + /// + /// 添加处理器 + /// + /// + /// + public void AddProcess(MonoBehaviour script, Action actuator) + { + ProcessorList.Add(new ActionAttribution(script, actuator)); + } + + /// + /// 移除匿名处理器 + /// + /// + protected internal void RemoveProcess(Action actuator) + { + RemoveProcess(a => a.EventAction == actuator && a.TargetScript == this); + } + + /// + /// 移除处理器 + /// + /// + public void RemoveProcess(MonoBehaviour script, Action actuator) + { + RemoveProcess(a => a.EventAction == actuator && a.TargetScript == script); + } + + /// + /// 移除处理器 + /// + /// + private void RemoveProcess(Func func) + { + var target = ProcessorList + .Where(func) + .FirstOrDefault(); + + if(target != null) + ProcessorList.Remove(target); + } + + #endregion + + } +} diff --git a/Runtime/Type/BatchProcessor.cs.meta b/Runtime/Type/BatchProcessor.cs.meta new file mode 100644 index 0000000..bc00bb6 --- /dev/null +++ b/Runtime/Type/BatchProcessor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c968745f30c2aa9418d51be4291a0ccd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Type/SingleMonoBase.cs b/Runtime/Type/SingleMonoBase.cs index b577b82..ecdef91 100644 --- a/Runtime/Type/SingleMonoBase.cs +++ b/Runtime/Type/SingleMonoBase.cs @@ -3,6 +3,7 @@ using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using System.Collections; using System.Collections.Generic; using UnityEngine; + namespace XericLibrary.Runtime.Type { /// @@ -18,7 +19,7 @@ namespace XericLibrary.Runtime.Type /// /// 根节点名称 /// - private static string rootNodeName = "DoNotDestroyThis"; + internal static string rootNodeName = "DoNotDestroyThis"; /// /// 组件单例 diff --git a/Runtime/Type/WeaklyHistoryMonoBase.cs b/Runtime/Type/WeaklyHistoryMonoBase.cs new file mode 100644 index 0000000..e831349 --- /dev/null +++ b/Runtime/Type/WeaklyHistoryMonoBase.cs @@ -0,0 +1,48 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +using XericLibrary.Runtime.Type; + +namespace XericLibrary.Runtime.Type +{ + /// + /// 带有历史记录的脚本 + /// + public class WeaklyHistoryMonoBase : WeaklyMonoBase + { + #region 字段属性 + + /// + /// 历史坐标 + /// + private Vector3 history_Position; + + /// + /// 历史旋转 + /// + private Quaternion history_Rotation; + + /// + /// 历史缩放 + /// + private Vector3 history_Scale; + + /// + /// 获取历史坐标 + /// + public Vector3 HistoryPosition => history_Position; + + /// + /// 获取历史旋转 + /// + public Quaternion HistoryRotation => history_Rotation; + + /// + /// 获取历史缩放 + /// + public Vector3 HistoryScale => history_Scale; + + #endregion + } +} \ No newline at end of file diff --git a/Runtime/Type/WeaklyHistoryMonoBase.cs.meta b/Runtime/Type/WeaklyHistoryMonoBase.cs.meta new file mode 100644 index 0000000..1d63299 --- /dev/null +++ b/Runtime/Type/WeaklyHistoryMonoBase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 997bea0a9f4ef3846b808872a727eb65 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Type/WeaklyMonoBase.cs b/Runtime/Type/WeaklyMonoBase.cs index 6c85f7b..3a31b96 100644 --- a/Runtime/Type/WeaklyMonoBase.cs +++ b/Runtime/Type/WeaklyMonoBase.cs @@ -1,5 +1,3 @@ -#define _HISTORY_ - using System; using System.Collections; using System.Collections.Generic; @@ -19,27 +17,6 @@ namespace XericLibrary.Runtime.Type private WeaklyObjectBase weaklyBase = null; -#if _HISTORY_ - - /// - /// 历史坐标 - /// - private Vector3 history_Position; - - /// - /// 历史旋转 - /// - private Quaternion history_Rotation; - - /// - /// 历史缩放 - /// - private Vector3 history_Scale; - - //private - -#endif - #if UNITY_EDITOR private static PlayModeStateChange playModeState; @@ -53,29 +30,6 @@ namespace XericLibrary.Runtime.Type private set; } -#endif - - #endregion - - #region 属性 - -#if _HISTORY_ - - /// - /// 获取历史坐标 - /// - public Vector3 HistoryPosition => history_Position; - - /// - /// 获取历史旋转 - /// - public Quaternion HistoryRotation => history_Rotation; - - /// - /// 获取历史缩放 - /// - public Vector3 HistoryScale => history_Scale; - #endif #endregion