60 lines
1.5 KiB
C#
60 lines
1.5 KiB
C#
using System.Collections.Generic;
|
|
using Convention;
|
|
using UnityEngine;
|
|
|
|
namespace Demo.Game
|
|
{
|
|
public class DDT : ScriptableObject
|
|
{
|
|
public string BindingDataJson => $"{ScriptPath}.json";
|
|
|
|
public static DDT Make()
|
|
{
|
|
return new GameObject().AddComponent<DDT>();
|
|
}
|
|
|
|
public List<float> Datas = new();
|
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
|
public void Add(string value)
|
|
{
|
|
Datas.Add(Parse(value));
|
|
}
|
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
|
public void Add(float value)
|
|
{
|
|
Datas.Add(value);
|
|
}
|
|
|
|
[Convention.RScript.Variable.Attr.Method]
|
|
public void Add(int barSplitTimes, int barCount, int tickCount)
|
|
{
|
|
Datas.Add((barCount + tickCount / (float)barSplitTimes) * OneBarTime);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 从特定的json中读取数据, 并调用<see cref="Add(string)"/>
|
|
/// </summary>
|
|
[Convention.RScript.Variable.Attr.Method]
|
|
public void Load()
|
|
{
|
|
var file = new ToolFile(BindingDataJson);
|
|
if (file.Exists() == false)
|
|
{
|
|
file.MustExistsPath()
|
|
.SaveAsJson<List<string>>(new());
|
|
Datas.Clear();
|
|
}
|
|
else
|
|
{
|
|
Datas.Clear();
|
|
foreach (var item in file.LoadAsJson<List<string>>())
|
|
{
|
|
Add(item);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|