可配置引擎
This commit is contained in:
@@ -112,9 +112,8 @@ namespace AibisDream.FixSystem
|
||||
Debug.Log("配置项名称为空");
|
||||
return;
|
||||
}
|
||||
|
||||
string formattedKey = JsonUtil.FormatAsJsonPath(CurDataKey);
|
||||
if (!ConfigUtil.Instance.TryLoadConfig<BodyModuleSystemData>(DataPath + formattedKey,
|
||||
|
||||
if (!ConfigUtil.Instance.TryLoadConfig<BodyModuleSystemData>(DataPath + CurDataKey,
|
||||
out var data))
|
||||
{
|
||||
Debug.Log("没有找到配置项");
|
||||
@@ -180,8 +179,7 @@ namespace AibisDream.FixSystem
|
||||
moduleDataArray = moduleDataArray
|
||||
};
|
||||
|
||||
string formattedKey = JsonUtil.FormatAsJsonPath(key);
|
||||
ConfigUtil.Instance.SaveConfig(systemData, DataPath + formattedKey);
|
||||
ConfigUtil.Instance.SaveConfig(systemData, DataPath + key);
|
||||
}
|
||||
|
||||
public void AddBodyModule()
|
||||
|
||||
@@ -107,7 +107,8 @@ namespace AibisDream.Kit
|
||||
{
|
||||
try
|
||||
{
|
||||
res = JsonUtil.ReadBean<T>(path);
|
||||
string formattedKey = JsonUtil.FormatAsJsonPath(path);
|
||||
res = JsonUtil.ReadBean<T>(formattedKey);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
@@ -126,7 +127,8 @@ namespace AibisDream.Kit
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public void SaveConfig<T>(T bean, string path)
|
||||
{
|
||||
JsonUtil.SaveBean(bean, path);
|
||||
var jsonPath = JsonUtil.FormatAsJsonPath(path);
|
||||
JsonUtil.SaveBean(bean, jsonPath);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using AibisDream.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
@@ -7,7 +8,7 @@ namespace AibisDream
|
||||
{
|
||||
private EngineSystem _engineSystem;
|
||||
|
||||
[SerializeField] private int _curLevel;
|
||||
[SerializeField] private int curLevel;
|
||||
|
||||
[SerializeField] private float heightY;
|
||||
|
||||
@@ -28,13 +29,13 @@ namespace AibisDream
|
||||
{
|
||||
SwitchAirLevel(mousePos.y);
|
||||
UpdateTransform();
|
||||
_engineSystem.UpdateAirLevel(_curLevel);
|
||||
_engineSystem.UpdateAirLevel(curLevel);
|
||||
}
|
||||
|
||||
private void UpdateTransform()
|
||||
{
|
||||
float levelHeight = heightY / (_engineSystem.maxLevel - 1);
|
||||
var curY = levelHeight * _curLevel + _offset.y;
|
||||
float levelHeight = heightY / (_engineSystem.config.maxLevel - 1);
|
||||
var curY = levelHeight * curLevel + _offset.y;
|
||||
transform.position = new Vector3(transform.position.x, curY, transform.position.z);
|
||||
}
|
||||
|
||||
@@ -42,10 +43,10 @@ namespace AibisDream
|
||||
{
|
||||
mouseY -= _offset.y;
|
||||
|
||||
float levelHeight = heightY / _engineSystem.maxLevel;
|
||||
_curLevel = (int)((mouseY) / levelHeight);
|
||||
if (_curLevel >= _engineSystem.maxLevel) _curLevel = _engineSystem.maxLevel - 1;
|
||||
if (_curLevel < 0) _curLevel = 0;
|
||||
float levelHeight = heightY / _engineSystem.config.maxLevel;
|
||||
curLevel = (int)((mouseY) / levelHeight);
|
||||
if (curLevel >= _engineSystem.config.maxLevel) curLevel = _engineSystem.config.maxLevel - 1;
|
||||
if (curLevel < 0) curLevel = 0;
|
||||
}
|
||||
|
||||
public void StopMove()
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace AibisDream
|
||||
protected override void OnStart()
|
||||
{
|
||||
_pointer = transform.Find("Pointer");
|
||||
_maxLevel = engineSystem.maxLevel;
|
||||
_maxLevel = engineSystem.config.maxLevel;
|
||||
}
|
||||
|
||||
protected override void UpdateDashboard(EngineData data)
|
||||
|
||||
@@ -1,26 +1,22 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using AibisDream.FixSystem;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.Utility;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class EngineSystem : MonoBehaviour
|
||||
public class EngineSystem : SystemHasData
|
||||
{
|
||||
[SerializeField] private float oilDownRatio;
|
||||
[SerializeField] private float oilUpRatio;
|
||||
[SerializeField] private float acceleratedSpeed;
|
||||
[SerializeField] private float resistance;
|
||||
[SerializeField] private float airMaxRatio;
|
||||
[SerializeField] private float airMinRatio;
|
||||
[SerializeField] private float baseAirMax;
|
||||
[SerializeField] public int maxLevel;
|
||||
[SerializeField] public float invalidTime;
|
||||
public static string DataPath = Application.streamingAssetsPath + "/LevelData/EngineSystem/";
|
||||
|
||||
[Header("系统配置")] [SerializeField] public EngineConfig config;
|
||||
[Header("系统数据")] [SerializeField] private EngineData engineData;
|
||||
|
||||
private bool IsValid => engineData.isValid.Value;
|
||||
|
||||
[Header("系统数据")] [SerializeField] private EngineData engineData;
|
||||
|
||||
public event Action<EngineData> UpdateDashboard;
|
||||
|
||||
private void Awake()
|
||||
@@ -30,7 +26,7 @@ namespace AibisDream
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
engineData = new EngineData(invalidTime);
|
||||
engineData = new EngineData(config.invalidTime);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -44,10 +40,10 @@ namespace AibisDream
|
||||
private void DataAutoChange()
|
||||
{
|
||||
// 自然减速
|
||||
engineData.OilChange(-oilDownRatio);
|
||||
engineData.CalcAir(airMaxRatio, airMinRatio, baseAirMax);
|
||||
engineData.OilChange(-config.oilDownRatio);
|
||||
engineData.CalcAir(config.airMaxRatio, config.airMinRatio, config.baseAirMax);
|
||||
// 推算速度
|
||||
engineData.CalcSpeed(acceleratedSpeed, resistance);
|
||||
engineData.CalcSpeed(config.acceleratedSpeed, config.resistance);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -57,15 +53,76 @@ namespace AibisDream
|
||||
{
|
||||
if (IsValid)
|
||||
{
|
||||
engineData.OilChange(oilUpRatio);
|
||||
engineData.OilChange(config.oilUpRatio);
|
||||
}
|
||||
// 失效期无法加油门
|
||||
}
|
||||
|
||||
public void UpdateAirLevel(int curLevel)
|
||||
{
|
||||
engineData.UpdateAirLevel(curLevel, maxLevel);
|
||||
engineData.UpdateAirLevel(curLevel, config.maxLevel);
|
||||
}
|
||||
|
||||
#region 数据加载与保存
|
||||
|
||||
private string[] _keyOptions;
|
||||
|
||||
public override string CurDataKey { get; set; }
|
||||
|
||||
public override string[] GetDataKeyOptions()
|
||||
{
|
||||
return _keyOptions ??= ConfigUtil.Instance.GetFileNames(DataPath);
|
||||
}
|
||||
|
||||
public override void Load()
|
||||
{
|
||||
if (string.IsNullOrEmpty(CurDataKey))
|
||||
{
|
||||
Debug.Log("配置项名称为空");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ConfigUtil.Instance.TryLoadConfig<EngineConfig>(DataPath + CurDataKey,
|
||||
out var data))
|
||||
{
|
||||
Debug.Log("没有找到配置项");
|
||||
return;
|
||||
}
|
||||
|
||||
config = data;
|
||||
}
|
||||
|
||||
public override void Save()
|
||||
{
|
||||
if (string.IsNullOrEmpty(CurDataKey))
|
||||
{
|
||||
Debug.Log("名称不为空");
|
||||
return;
|
||||
}
|
||||
ConfigUtil.Instance.SaveConfig(config, DataPath + CurDataKey);
|
||||
|
||||
if (!_keyOptions.Contains(CurDataKey))
|
||||
{
|
||||
// 重新读取key
|
||||
_keyOptions = ConfigUtil.Instance.GetFileNames(DataPath);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct EngineConfig
|
||||
{
|
||||
public float oilDownRatio;
|
||||
public float oilUpRatio;
|
||||
public float acceleratedSpeed;
|
||||
public float resistance;
|
||||
public float airMaxRatio;
|
||||
public float airMinRatio;
|
||||
public float baseAirMax;
|
||||
public int maxLevel;
|
||||
public float invalidTime;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
|
||||
Reference in New Issue
Block a user