Archived
移除了影响打包的部分;
修正了洗牌算法中的错误; 将弱类型中历史记录的功能拆开了,减小了不必要的消耗;
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -21,9 +21,12 @@ namespace XericLibrary.Runtime.MacroLibrary
|
||||
/// <returns></returns>
|
||||
public static List<int> FisherYatesShuffle(int length, int select)
|
||||
{
|
||||
if(select > length)
|
||||
throw new ArgumentOutOfRangeException("在进行洗牌时,要求输出的项目比拥有的项目更多,这是不合理的。");
|
||||
|
||||
var random = new System.Random();
|
||||
|
||||
List<int> arr = Enumerable.Range(1, length).ToList();
|
||||
List<int> arr = Enumerable.Range(0, length).ToList();
|
||||
List<int> res = new List<int>();
|
||||
|
||||
for(int i = 0; i < select; ++i)
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 785b6db82960d6c49acaedc81c113019
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using XericLibrary.Runtime.Type;
|
||||
|
||||
namespace XericLibrary.Runtime.SpatialTransform
|
||||
{
|
||||
/// <summary>
|
||||
/// 设定偏移来自追踪目标
|
||||
/// </summary>
|
||||
public class OffsetFromTrackTarget : WeaklyMonoBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 追踪目标
|
||||
/// </summary>
|
||||
public Transform TrackTarget;
|
||||
|
||||
/// <summary>
|
||||
/// 偏移量
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 初始化
|
||||
/// </summary>
|
||||
/// <param name="tracK"></param>
|
||||
public void Initialized(Transform tracK, Vector3 offset)
|
||||
{
|
||||
TrackTarget = tracK;
|
||||
Offset = offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dc5062889e515554690f2a00becd6359
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 流程批处理器,用于减少调用栈切换时的耗时
|
||||
/// <code>
|
||||
/// 一般一次切换耗时 <2us;
|
||||
/// 此举会使得编译器不再追踪及其细致的更新时间调用栈,谨慎使用。
|
||||
/// </code>
|
||||
/// </summary>
|
||||
public abstract class BatchProcessor : SingleMonoBase<BatchProcessor>
|
||||
{
|
||||
#region 字段属性
|
||||
|
||||
/// <summary>
|
||||
/// 所有处理脚本的流程列表
|
||||
/// </summary>
|
||||
internal List<ActionAttribution> ProcessorList;
|
||||
|
||||
/// <summary>
|
||||
/// 注册添加或移除处理器项目
|
||||
/// </summary>
|
||||
public event Action AnonymousProcessing
|
||||
{
|
||||
add => AddProcess(value);
|
||||
remove => RemoveProcess(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 在更新时需要被移除的对象
|
||||
/// </summary>
|
||||
private List<ActionAttribution> needRemove = new List<ActionAttribution>();
|
||||
|
||||
#endregion
|
||||
|
||||
#region 类内类
|
||||
|
||||
/// <summary>
|
||||
/// 带有归属类的事件
|
||||
/// </summary>
|
||||
public class ActionAttribution
|
||||
{
|
||||
/// <summary>
|
||||
/// 事件
|
||||
/// </summary>
|
||||
internal Action EventAction;
|
||||
|
||||
/// <summary>
|
||||
/// 目标归属脚本
|
||||
/// </summary>
|
||||
internal MonoBehaviour TargetScript;
|
||||
|
||||
/// <summary>
|
||||
/// 建立一个归属类
|
||||
/// </summary>
|
||||
/// <param name="script"></param>
|
||||
/// <param name="action"></param>
|
||||
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 方法
|
||||
|
||||
/// <summary>
|
||||
/// 添加匿名处理器
|
||||
/// </summary>
|
||||
/// <param name="actuator"></param>
|
||||
protected internal void AddProcess(Action actuator)
|
||||
{
|
||||
ProcessorList.Add(new ActionAttribution(this, actuator));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加处理器
|
||||
/// </summary>
|
||||
/// <param name="script"></param>
|
||||
/// <param name="actuator"></param>
|
||||
public void AddProcess(MonoBehaviour script, Action actuator)
|
||||
{
|
||||
ProcessorList.Add(new ActionAttribution(script, actuator));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除匿名处理器
|
||||
/// </summary>
|
||||
/// <param name="actuator"></param>
|
||||
protected internal void RemoveProcess(Action actuator)
|
||||
{
|
||||
RemoveProcess(a => a.EventAction == actuator && a.TargetScript == this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除处理器
|
||||
/// </summary>
|
||||
/// <param name="actuator"></param>
|
||||
public void RemoveProcess(MonoBehaviour script, Action actuator)
|
||||
{
|
||||
RemoveProcess(a => a.EventAction == actuator && a.TargetScript == script);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 移除处理器
|
||||
/// </summary>
|
||||
/// <param name="func"></param>
|
||||
private void RemoveProcess(Func<ActionAttribution, bool> func)
|
||||
{
|
||||
var target = ProcessorList
|
||||
.Where(func)
|
||||
.FirstOrDefault();
|
||||
|
||||
if(target != null)
|
||||
ProcessorList.Remove(target);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c968745f30c2aa9418d51be4291a0ccd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -3,6 +3,7 @@ using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace XericLibrary.Runtime.Type
|
||||
{
|
||||
/// <summary>
|
||||
@@ -18,7 +19,7 @@ namespace XericLibrary.Runtime.Type
|
||||
/// <summary>
|
||||
/// 根节点名称
|
||||
/// </summary>
|
||||
private static string rootNodeName = "DoNotDestroyThis";
|
||||
internal static string rootNodeName = "DoNotDestroyThis";
|
||||
|
||||
/// <summary>
|
||||
/// 组件单例
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
using XericLibrary.Runtime.Type;
|
||||
|
||||
namespace XericLibrary.Runtime.Type
|
||||
{
|
||||
/// <summary>
|
||||
/// 带有历史记录的脚本
|
||||
/// </summary>
|
||||
public class WeaklyHistoryMonoBase : WeaklyMonoBase
|
||||
{
|
||||
#region 字段属性
|
||||
|
||||
/// <summary>
|
||||
/// 历史坐标
|
||||
/// </summary>
|
||||
private Vector3 history_Position;
|
||||
|
||||
/// <summary>
|
||||
/// 历史旋转
|
||||
/// </summary>
|
||||
private Quaternion history_Rotation;
|
||||
|
||||
/// <summary>
|
||||
/// 历史缩放
|
||||
/// </summary>
|
||||
private Vector3 history_Scale;
|
||||
|
||||
/// <summary>
|
||||
/// 获取历史坐标
|
||||
/// </summary>
|
||||
public Vector3 HistoryPosition => history_Position;
|
||||
|
||||
/// <summary>
|
||||
/// 获取历史旋转
|
||||
/// </summary>
|
||||
public Quaternion HistoryRotation => history_Rotation;
|
||||
|
||||
/// <summary>
|
||||
/// 获取历史缩放
|
||||
/// </summary>
|
||||
public Vector3 HistoryScale => history_Scale;
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 997bea0a9f4ef3846b808872a727eb65
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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_
|
||||
|
||||
/// <summary>
|
||||
/// 历史坐标
|
||||
/// </summary>
|
||||
private Vector3 history_Position;
|
||||
|
||||
/// <summary>
|
||||
/// 历史旋转
|
||||
/// </summary>
|
||||
private Quaternion history_Rotation;
|
||||
|
||||
/// <summary>
|
||||
/// 历史缩放
|
||||
/// </summary>
|
||||
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_
|
||||
|
||||
/// <summary>
|
||||
/// 获取历史坐标
|
||||
/// </summary>
|
||||
public Vector3 HistoryPosition => history_Position;
|
||||
|
||||
/// <summary>
|
||||
/// 获取历史旋转
|
||||
/// </summary>
|
||||
public Quaternion HistoryRotation => history_Rotation;
|
||||
|
||||
/// <summary>
|
||||
/// 获取历史缩放
|
||||
/// </summary>
|
||||
public Vector3 HistoryScale => history_Scale;
|
||||
|
||||
#endif
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user