100 lines
2.8 KiB
C#
100 lines
2.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using AibisDream.FixSystem;
|
|
using AibisDream.Framework;
|
|
using AibisDream.Utility;
|
|
using Cinemachine;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
|
|
namespace AibisDream
|
|
{
|
|
public class EngineSystem : MonoBehaviour
|
|
{
|
|
private StaticGear _centerGear;
|
|
|
|
[Header("系统配置")] public EngineConfig engineConfig;
|
|
public bool isAvailable;
|
|
public bool isPullActive;
|
|
private bool _isSuccess;
|
|
|
|
public float curSpeed;
|
|
public float targetSpeed=0.95f;
|
|
[HideInInspector] public UnityEvent<float, float> updateSpeedEvent = new();
|
|
|
|
private void Awake()
|
|
{
|
|
FixSystemCenter.SystemDic.Register(this);
|
|
_centerGear = transform.Find("中央齿轮").GetComponent<StaticGear>();
|
|
_centerGear.initSpeed = engineConfig.gearSpeed;
|
|
|
|
// 注册相机
|
|
var virtualCam = transform.Find("Engine Camera").GetComponentInChildren<ICinemachineCamera>();
|
|
CameraKit.Instance.RegisterCamera(CameraEnum.Engine, virtualCam);
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_centerGear.StartRotate();
|
|
}
|
|
|
|
public IEnumerator StepOnGas(float target, float duration)
|
|
{
|
|
// 逐渐加速
|
|
yield return DOTween.To(() => curSpeed, x => { curSpeed = x; }, target, duration).WaitForCompletion();
|
|
}
|
|
|
|
public void AddAirPress(float speedDelta)
|
|
{
|
|
curSpeed = CommonUtil.Limit(curSpeed + speedDelta / engineConfig.pullCount, 1, 0);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
CameraKit.Instance.UnRegisterCamera(CameraEnum.Engine);
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
updateSpeedEvent.Invoke(curSpeed, GetSpeedScale());
|
|
if (curSpeed >= targetSpeed && !_isSuccess)
|
|
{
|
|
_isSuccess = true;
|
|
isPullActive = false;
|
|
DialogController.Instance?.StartDialogNode("EngineSuccess");
|
|
}
|
|
}
|
|
|
|
private float GetSpeedScale()
|
|
{
|
|
return 1 + curSpeed * engineConfig.speedRate;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 开启系统交互
|
|
/// </summary>
|
|
public void EnableSystem()
|
|
{
|
|
isAvailable = true;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 关闭系统交互
|
|
/// </summary>
|
|
public void DisableSystem()
|
|
{
|
|
isAvailable = false;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public struct EngineConfig
|
|
{
|
|
[Header("齿轮基础速度")] public float gearSpeed;
|
|
[Header("齿轮速度倍率")] public float speedRate;
|
|
[Header("拉满几次到全速")] public float pullCount;
|
|
[Header("拉绳最大速度")] public float pullMaxSpeed;
|
|
[Header("拉绳回缩速度")] public float returnSpeed;
|
|
}
|
|
} |