From 9bb253d5aebd3861a67d1ec5117e431e80510840 Mon Sep 17 00:00:00 2001 From: ninemine <1371605831@qq.com> Date: Thu, 4 Dec 2025 15:58:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=97=B6=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Assets/Scripts/Framework/DDT.cs | 34 +++++++++++--------------- Assets/Scripts/Framework/Updatement.cs | 6 ++--- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/Assets/Scripts/Framework/DDT.cs b/Assets/Scripts/Framework/DDT.cs index 1ce13fd..0ca99eb 100644 --- a/Assets/Scripts/Framework/DDT.cs +++ b/Assets/Scripts/Framework/DDT.cs @@ -3,10 +3,12 @@ using System.Collections.Generic; using Convention; using UnityEngine; using System; +using Unity.Collections; +using UnityEngine.Rendering; namespace Demo.Game { - public class DDT : ScriptableObject, IEnumerable + public class DDT : ScriptableObject { protected override bool IsSelfEnableUpdate => false; public static DDT Make() @@ -14,27 +16,31 @@ namespace Demo.Game return new GameObject().AddComponent(); } - public List Datas = new(); + public NativeArray Datas = new(128, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); + public int Count { get; private set; } = 0; [Convention.RScript.Variable.Attr.Method] public void Add(float value) { - Datas.Add(value); + if (Count >= Datas.Length) + Datas.ResizeArray(Mathf.FloorToInt(Count * 1.5f)); + Datas[Count] = value; + Count++; } [Convention.RScript.Variable.Attr.Method] public void Add(int barSplitTimes, int barCount, int tickCount) { - Datas.Add((barCount + tickCount / (float)barSplitTimes) * OneBarTime); + Add((barCount + tickCount / (float)barSplitTimes) * OneBarTime); } [Convention.RScript.Variable.Attr.Method] public float At(int index) { if (index < 0) - index = Datas.Count + index; - if (index < 0 || index >= Datas.Count) - throw new IndexOutOfRangeException($"{index} is out of [0, {Datas.Count})"); + index = Count + index; + if (index < 0 || index >= Count) + throw new IndexOutOfRangeException($"{index} is out of [0, {Count})"); return Datas[index]; } @@ -45,19 +51,7 @@ namespace Demo.Game [Convention.RScript.Variable.Attr.Method] public int GetCount() { - return Datas.Count; + return Count; } - - public IEnumerator GetEnumerator() - { - return ((IEnumerable)Datas).GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return ((IEnumerable)Datas).GetEnumerator(); - } - - public int Count => Datas.Count; } } diff --git a/Assets/Scripts/Framework/Updatement.cs b/Assets/Scripts/Framework/Updatement.cs index 9faac30..24e30ba 100644 --- a/Assets/Scripts/Framework/Updatement.cs +++ b/Assets/Scripts/Framework/Updatement.cs @@ -63,9 +63,9 @@ namespace Demo.Game { Entries.Sort((x, y) => x.TimePoint.CompareTo(y.TimePoint)); CompiledEntries = new( - new NativeArray(Entries.Count, Allocator.Persistent), - new NativeArray(Entries.Count, Allocator.Persistent), - new NativeArray(Entries.Count, Allocator.Persistent), + new NativeArray(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory), + new NativeArray(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory), + new NativeArray(Entries.Count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory), Entries.Count ); int index = 0;