引擎修改
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using AibisDream.FixSystem;
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Utility;
|
||||
using Cinemachine;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
|
||||
@@ -10,15 +12,15 @@ namespace AibisDream
|
||||
{
|
||||
public class EngineSystem : MonoBehaviour
|
||||
{
|
||||
private CordPull _cordPull;
|
||||
private StaticGear _centerGear;
|
||||
|
||||
[Header("系统配置")] public EngineConfig engineConfig;
|
||||
[Header("系统数据")] public EngineData engineData;
|
||||
|
||||
public bool isAvailable;
|
||||
public bool isPullActive;
|
||||
private bool _isSuccess;
|
||||
|
||||
[HideInInspector] public UnityEvent<float> updateSpeedEvent = new();
|
||||
public float curSpeed;
|
||||
[HideInInspector] public UnityEvent<float, float> updateSpeedEvent = new();
|
||||
|
||||
[SerializeField] private float coverMoveDuration = 5f;
|
||||
|
||||
@@ -27,10 +29,9 @@ namespace AibisDream
|
||||
private void Awake()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Register(this);
|
||||
_cordPull = transform.Find("拉绳").GetComponent<CordPull>();
|
||||
_centerGear = transform.Find("中央齿轮").GetComponent<StaticGear>();
|
||||
_centerGear.initSpeed = engineConfig.gearSpeed;
|
||||
|
||||
|
||||
// 注册相机
|
||||
var virtualCam = transform.Find("Engine Camera").GetComponentInChildren<ICinemachineCamera>();
|
||||
CameraKit.Instance.RegisterCamera(CameraEnum.Engine, virtualCam);
|
||||
@@ -38,36 +39,41 @@ namespace AibisDream
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 初始化数据
|
||||
engineData = new EngineData
|
||||
{
|
||||
config = engineConfig
|
||||
};
|
||||
_centerGear.StartRotate();
|
||||
}
|
||||
|
||||
public IEnumerator StepOnGas(float targetSpeed, float duration)
|
||||
{
|
||||
// 逐渐加速
|
||||
yield return DOTween.To(() => curSpeed, x => { curSpeed = x; }, targetSpeed, duration).WaitForCompletion();
|
||||
}
|
||||
|
||||
public void AddAirPress(float speedDelta)
|
||||
{
|
||||
curSpeed = CommonUtil.Limit(curSpeed + speedDelta / engineConfig.pullCount, 1, 0);
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
CameraKit.Instance.UnRegisterCamera(CameraEnum.Engine);
|
||||
}
|
||||
|
||||
public void Update()
|
||||
private void Update()
|
||||
{
|
||||
// 收集数据
|
||||
engineData.curOil = _cordPull.GetCurOil();
|
||||
// 更新数据
|
||||
engineData.CalcSpeed();
|
||||
|
||||
// 传递速度
|
||||
updateSpeedEvent.Invoke(engineData.GetRealSpeed());
|
||||
|
||||
if (engineData.CheckSuccess())
|
||||
updateSpeedEvent.Invoke(curSpeed, GetSpeedScale());
|
||||
if (curSpeed >= 0.99f && !_isSuccess)
|
||||
{
|
||||
Debug.Log("引擎成功");
|
||||
_isSuccess = true;
|
||||
isPullActive = false;
|
||||
DialogController.Instance?.StartDialogNode("EngineSuccess");
|
||||
}
|
||||
}
|
||||
|
||||
private float GetSpeedScale()
|
||||
{
|
||||
return 1 + curSpeed * engineConfig.speedRate;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开启系统交互
|
||||
/// </summary>
|
||||
@@ -88,70 +94,10 @@ namespace AibisDream
|
||||
[Serializable]
|
||||
public struct EngineConfig
|
||||
{
|
||||
[Header("油门倍率")] public float oilRate;
|
||||
[Header("阻力倍率")] public float resistance;
|
||||
[Header("齿轮基础速度")] public float gearSpeed;
|
||||
[Header("齿轮速度倍率")] public float speedRate;
|
||||
[Header("成功所需时间")] public float targetDuration;
|
||||
[Header("拉满几次到全速")] public float pullCount;
|
||||
[Header("拉绳最大速度")] public float pullMaxSpeed;
|
||||
[Header("拉绳回缩速度")] public float returnSpeed;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct EngineData
|
||||
{
|
||||
public EngineConfig config;
|
||||
public float curSpeed;
|
||||
public float curOil;
|
||||
public float curAcceleration;
|
||||
public bool isSuccess;
|
||||
public float reachTargetTime;
|
||||
|
||||
public void CalcSpeed()
|
||||
{
|
||||
if (curOil != 0)
|
||||
{
|
||||
curAcceleration = curAcceleration < 0 ? 0 : curAcceleration;
|
||||
curAcceleration = CommonUtil.Limit(curOil * config.oilRate * Time.deltaTime + curAcceleration, 100, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
curAcceleration = -config.resistance * (1f + curSpeed);
|
||||
}
|
||||
|
||||
|
||||
curSpeed = CommonUtil.Limit(curSpeed + curAcceleration * Time.deltaTime, 1, 0);
|
||||
}
|
||||
|
||||
public bool CheckSuccess()
|
||||
{
|
||||
// 已经成功就不用校验了
|
||||
if (isSuccess) return false;
|
||||
|
||||
if (curSpeed >= 0.95f)
|
||||
{
|
||||
reachTargetTime += Time.deltaTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
reachTargetTime = 0;
|
||||
}
|
||||
|
||||
// 如果速度达标时间足够就判断成功
|
||||
if (!(reachTargetTime >= config.targetDuration)) return false;
|
||||
|
||||
isSuccess = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取处理后的速度
|
||||
/// </summary>
|
||||
/// <returns>速度</returns>
|
||||
public float GetRealSpeed()
|
||||
{
|
||||
return 1 + curSpeed * config.speedRate;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user