Files
Convention-Unity-Demo/Assets/Scripts/Framework/DDT.cs

58 lines
1.6 KiB
C#
Raw Normal View History

2025-11-25 17:04:19 +08:00
using System.Collections;
2025-09-25 19:04:05 +08:00
using System.Collections.Generic;
using Convention;
using UnityEngine;
using System;
2025-12-04 15:58:38 +08:00
using Unity.Collections;
using UnityEngine.Rendering;
2025-09-25 19:04:05 +08:00
namespace Demo.Game
{
2025-12-04 15:58:38 +08:00
public class DDT : ScriptableObject
2025-09-25 19:04:05 +08:00
{
2025-11-29 00:44:05 +08:00
protected override bool IsSelfEnableUpdate => false;
2025-09-25 19:04:05 +08:00
public static DDT Make()
{
return new GameObject().AddComponent<DDT>();
}
2025-12-04 15:58:38 +08:00
public NativeArray<float> Datas = new(128, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
public int Count { get; private set; } = 0;
2025-09-25 19:04:05 +08:00
2025-11-12 10:09:26 +08:00
[Convention.RScript.Variable.Attr.Method]
public void Add(float value)
{
2025-12-04 15:58:38 +08:00
if (Count >= Datas.Length)
Datas.ResizeArray(Mathf.FloorToInt(Count * 1.5f));
Datas[Count] = value;
Count++;
2025-11-12 10:09:26 +08:00
}
[Convention.RScript.Variable.Attr.Method]
public void Add(int barSplitTimes, int barCount, int tickCount)
{
2025-12-04 15:58:38 +08:00
Add((barCount + tickCount / (float)barSplitTimes) * OneBarTime);
2025-11-12 10:09:26 +08:00
}
2025-11-25 17:04:19 +08:00
[Convention.RScript.Variable.Attr.Method]
public float At(int index)
{
if (index < 0)
2025-12-04 15:58:38 +08:00
index = Count + index;
if (index < 0 || index >= Count)
throw new IndexOutOfRangeException($"{index} is out of [0, {Count})");
2025-11-25 17:04:19 +08:00
return Datas[index];
}
/// <summary>
/// <20><>ȡ<EFBFBD><C8A1><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD>
/// </summary>
/// <returns></returns>
[Convention.RScript.Variable.Attr.Method]
public int GetCount()
{
2025-12-04 15:58:38 +08:00
return Count;
}
2025-09-25 19:04:05 +08:00
}
}