可配置引擎
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using UnityEditor;
|
||||
|
||||
namespace AibisDream.SystemEditor
|
||||
{
|
||||
[CustomEditor(typeof(EngineSystem))]
|
||||
public class EngineSystemEditor : SystemHasDataEditor
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4f1fc42dd0984554846404f2cc1e1b02
|
||||
timeCreated: 1732926273
|
||||
Binary file not shown.
@@ -1685,7 +1685,7 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 4cba880bf0a3caf41b1d03057b9c01b1, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
_curLevel: 0
|
||||
curLevel: 0
|
||||
heightY: 0.64
|
||||
--- !u!61 &551825979
|
||||
BoxCollider2D:
|
||||
@@ -3298,15 +3298,16 @@ MonoBehaviour:
|
||||
m_Script: {fileID: 11500000, guid: 10324e3c30ee1924893a08455ce65e0d, type: 3}
|
||||
m_Name:
|
||||
m_EditorClassIdentifier:
|
||||
oilDownRatio: 0.2
|
||||
oilUpRatio: 0.4
|
||||
acceleratedSpeed: 1
|
||||
resistance: 1
|
||||
airMaxRatio: 0.45
|
||||
airMinRatio: 0.37
|
||||
baseAirMax: 0.2
|
||||
maxLevel: 5
|
||||
invalidTime: 0
|
||||
config:
|
||||
oilDownRatio: 0.2
|
||||
oilUpRatio: 0.4
|
||||
acceleratedSpeed: 1
|
||||
resistance: 1
|
||||
airMaxRatio: 0.45
|
||||
airMinRatio: 0.37
|
||||
baseAirMax: 0.2
|
||||
maxLevel: 5
|
||||
invalidTime: 0.7
|
||||
engineData:
|
||||
curSpeed: 0
|
||||
curOil: 0
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3388932338827fc4785c8f4c4012b38e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1 @@
|
||||
{"oilDownRatio":0.2,"oilUpRatio":0.4,"acceleratedSpeed":1.0,"resistance":1.0,"airMaxRatio":0.45,"airMinRatio":0.37,"baseAirMax":0.2,"maxLevel":5,"invalidTime":0.7}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa0525ab5423c9c4f9e29f9580bc5939
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user