运行时缓存优化
This commit is contained in:
@@ -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<float>
|
||||
public class DDT : ScriptableObject
|
||||
{
|
||||
protected override bool IsSelfEnableUpdate => false;
|
||||
public static DDT Make()
|
||||
@@ -14,27 +16,31 @@ namespace Demo.Game
|
||||
return new GameObject().AddComponent<DDT>();
|
||||
}
|
||||
|
||||
public List<float> Datas = new();
|
||||
public NativeArray<float> 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<float> GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<float>)Datas).GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable)Datas).GetEnumerator();
|
||||
}
|
||||
|
||||
public int Count => Datas.Count;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user