引擎修改

This commit is contained in:
2025-01-23 18:32:25 +08:00
parent c60602424a
commit 2825fbef47
23 changed files with 726 additions and 227 deletions
@@ -135,6 +135,18 @@ namespace AibisDream
return false;
}
}
/// <summary>
/// 跳到下一句
/// </summary>
public void JumpLine()
{
if (!DialogCanvasManager.GetCurView().TrySkipLine())
{
AudioManager.Instance.StopVoice();
DialogCanvasManager.GetCurView().NextStep();
}
}
#region
-25
View File
@@ -68,30 +68,5 @@ namespace AibisDream
var options = DialogOption.GeneOptions(dialogueOptions, onOptionSelected);
DialogCanvasManager.GetCurView().ShowOptions(options);
}
private void Update()
{
if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
{
JumpLine();
}
}
/// <summary>
/// 跳到下一句
/// </summary>
private void JumpLine()
{
if (_isInCommand)
{
return;
}
if (!DialogCanvasManager.GetCurView().TrySkipLine())
{
AudioManager.Instance.StopVoice();
DialogCanvasManager.GetCurView().NextStep();
}
}
}
}
@@ -16,7 +16,7 @@ namespace AibisDream.FixSystem
// 初始化状态机
StateMachine = new FixStateMachine();
StartCoroutine(StateMachine.SwitchState(FixState.Clinic));
StartCoroutine(StateMachine.SwitchState(FixState.Engine));
}
public override void OnSingletonDestroy()
@@ -1,5 +1,4 @@
using System;
using AibisDream.FixSystem;
using UnityEngine;
namespace AibisDream.Framework
@@ -47,14 +46,6 @@ namespace AibisDream.Framework
{
public void OnUpdate()
{
if (Input.GetKeyDown(KeyCode.K))
{
MonoCenter.Mono.StartCoroutine(CameraKit.Instance.TransCameraAsync(new Vector3(5f, 5f, -10), 5, 5f));
}
if (Input.GetKeyDown(KeyCode.A))
{
}
}
}
+3 -3
View File
@@ -8,7 +8,8 @@ namespace AibisDream
{
NextYarn,
PlugIn,
PlugOut
PlugOut,
Menu
}
public enum DialogEventEnum
@@ -17,8 +18,7 @@ namespace AibisDream
LineShowed,
LineEnd,
OptionShow,
OptionSelected,
Command
OptionSelected
}
public enum InteractionEventEnum
+10 -16
View File
@@ -34,11 +34,6 @@ namespace AibisDream
_trigger.Register(EventTriggerType.Drag, OnDrag);
}
public float GetCurOil()
{
return Mathf.Abs((transform.localPosition.y - _initPos.y) / maxDistance);
}
private void Update()
{
if (_isDragging)
@@ -58,15 +53,10 @@ namespace AibisDream
// 如果拖拽点在下方,限速移动
else
{
if (Mathf.Abs(_dragPoint.y - transform.position.y) / Time.deltaTime >
_engineSystem.engineConfig.pullMaxSpeed)
{
curY = transform.position.y - _engineSystem.engineConfig.pullMaxSpeed * Time.deltaTime;
}
else
{
curY = _dragPoint.y;
}
curY = _dragPoint.y;
var pullDelta = Mathf.Abs(curY - transform.position.y) / maxDistance;
// 将增量同步给Engine
_engineSystem.AddAirPress(pullDelta);
}
transform.position = new Vector3(transform.position.x, curY, transform.position.y);
@@ -75,7 +65,8 @@ namespace AibisDream
private void OnDrag(BaseEventData data)
{
// 这里是一些阻碍拖动的情况
if (!IsActive) return;
// 正常情况下不会出错
if (data is not PointerEventData pointerData) return;
@@ -85,6 +76,9 @@ namespace AibisDream
private void OnBeginDrag(BaseEventData data)
{
// 这里是一些阻碍拖动的情况
if (!IsActive) return;
// 正常情况下不会出错
if (data is not PointerEventData pointerData) return;
// 设置拖拽目标点
@@ -112,7 +106,7 @@ namespace AibisDream
_dragPoint = new Vector3(transform.position.x, dragY, transform.position.z);
}
public bool IsActive => true;
public bool IsActive => _engineSystem.isPullActive;
public bool IsAvailable => _engineSystem.isAvailable;
+29 -83
View File
@@ -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;
}
}
}
@@ -1,4 +1,5 @@
using System.Collections;
using AibisDream.FixSystem;
using UnityEngine;
using Yarn.Unity;
@@ -6,6 +7,8 @@ namespace AibisDream
{
public static class EngineYarnCommand
{
private static EngineSystem EngineSystem => FixSystemCenter.SystemDic.Get<EngineSystem>();
// 打开引擎盖
[YarnCommand("open_engine_cover")]
public static IEnumerator OpenEngineCover()
@@ -21,5 +24,26 @@ namespace AibisDream
Debug.LogWarning("关闭引擎盖命令已废弃,请尽快删除");
yield break;
}
/// <summary>
/// 踩油门
/// </summary>
/// <param name="targetSpeed">目标速度</param>
/// <param name="duration">用时</param>
/// <returns>协程</returns>
[YarnCommand("step_on_gas")]
public static IEnumerator StepOnGas(float targetSpeed, float duration)
{
return EngineSystem.StepOnGas(targetSpeed, duration);
}
/// <summary>
/// 激活拉绳
/// </summary>
[YarnCommand("active_engine_pull")]
public static void ActivePull()
{
EngineSystem.isPullActive = true;
}
}
}
@@ -1,25 +1,24 @@
using UnityEngine;
using UnityEngine;
namespace AibisDream
{
public class SpeedDashboard : MonoBehaviour
{
private Transform _pointer;
[SerializeField] private float leftRot;
[SerializeField] private float rightRot;
private Material _material;
private EngineSystem _engineSystem;
private static readonly int Progress1 = Shader.PropertyToID("_Progress");
protected void OnStart()
private void Awake()
{
_pointer = transform.Find("Pointer");
_material = GetComponent<SpriteRenderer>().material;
_engineSystem = transform.parent.GetComponent<EngineSystem>();
_engineSystem.updateSpeedEvent.AddListener(OnSpeedChange);
}
protected void UpdateDashboard(EngineData data)
private void OnSpeedChange(float originSpeed, float speedScale)
{
var targetRot = (rightRot - leftRot) * data.curSpeed + leftRot;
_pointer.eulerAngles = new Vector3(0, 0, -targetRot);
_material.SetFloat(Progress1, originSpeed);
}
}
}
}
@@ -1,11 +1,3 @@
fileFormatVersion: 2
guid: 73c497ccb39448718a07911a5e674d5f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 4d9cead340d34293bf0fd9631aede238
timeCreated: 1737626210
+2 -6
View File
@@ -22,12 +22,8 @@ namespace AibisDream
.SetEase(Ease.Linear)
.SetLoops(-1, LoopType.Incremental);
}
/// <summary>
/// 为旋转加速
/// </summary>
/// <param name="speed">速度倍率</param>
private void UpdateSpeedScale(float speed)
private void UpdateSpeedScale(float originSpeed, float speed)
{
_rotateTween.timeScale = speed;
}
@@ -39,6 +39,8 @@ namespace AibisDream
private bool _isTargetReached;
private bool _isDiscReady;
public float initSpeed = 1;
private void Awake()
{
Init();
@@ -65,6 +67,10 @@ namespace AibisDream
var panelShafts = _panel.GetComponentsInChildren<Shaft>();
_shaftGraph = new ShaftGraph(shafts, panelShafts);
var engine = FixSystemCenter.SystemDic.Get<EngineSystem>();
_shaftGraph.StartRotate(initSpeed);
engine.updateSpeedEvent.AddListener(_shaftGraph.Accelerate);
_panel.gameObject.SetActive(false);
}
+1 -8
View File
@@ -23,9 +23,6 @@ namespace AibisDream
[SerializeField] private Gear childGear;
// 初始角速度
[SerializeField] private float initialSpeed;
// 目标角速度
[SerializeField] private float targetSpeed;
@@ -70,8 +67,7 @@ namespace AibisDream
// 如果带齿轮,要根据齿轮类型生成
childGear = InitGear(initRadius, initSprite, isInitGearBroken, isInitGearDisc);
speed = initialSpeed;
childGear.UpdateRotation(speed, _speedScale);
}
@@ -274,7 +270,6 @@ namespace AibisDream
isInitGearBroken = levelData.isGearBroken;
isInitGearDisc = levelData.isDisc;
discIdx = levelData.discIdx;
initialSpeed = levelData.initialSpeed;
targetSpeed = levelData.targetSpeed;
initRadius = levelData.radius;
}
@@ -291,7 +286,6 @@ namespace AibisDream
isGearBroken = isInitGearBroken,
isDisc = isInitGearDisc,
discIdx = discIdx,
initialSpeed = initialSpeed,
targetSpeed = targetSpeed,
radius = initRadius
};
@@ -315,7 +309,6 @@ namespace AibisDream
// 关卡数据
public ShaftType shaftType;
public float initialSpeed;
public float targetSpeed;
public bool hasChildGear;
public float radius;
+18 -12
View File
@@ -43,6 +43,24 @@ namespace AibisDream
UpdateSpeed();
}
/// <summary>
/// 初始化速度
/// </summary>
/// <param name="initSpeed">初始速度</param>
public void StartRotate(float initSpeed)
{
_vertexArray[_rootIdx].speed = initSpeed;
UpdateSpeed();
}
public void Accelerate(float originSpeed, float speed)
{
foreach (var shaft in _vertexArray)
{
if (shaft.HasChildGear()) shaft.UpdateSpeedScale(speed);
}
}
private int FindDriverIdx()
{
for (int i = 0; i < _vertexSize; i++)
@@ -261,17 +279,5 @@ namespace AibisDream
return isShaftAvailable;
}
/// <summary>
/// 通过引擎系统加速
/// </summary>
/// <param name="curSpeed">当前速度</param>
private void Accelerate(float curSpeed)
{
foreach (var shaft in _vertexArray)
{
if (shaft.HasChildGear()) shaft.UpdateSpeedScale(1 + curSpeed);
}
}
}
}
+36 -2
View File
@@ -15,13 +15,13 @@ namespace AibisDream
public Sprite nextTalk, talking, option, interactive, holding, disable, eye;
private Image _cursor;
private RectTransform _cursorCanvas;
#region
private Coroutine _switchCoroutine;
private CursorState _curState = CursorState.Default;
private bool _isTalking;
[HideInInspector] public bool isInMenu;
#endregion
@@ -59,12 +59,18 @@ namespace AibisDream
private void InitRefs()
{
_cursor = transform.Find("Cursor").GetComponent<Image>();
_cursorCanvas = GetComponent<RectTransform>();
}
private void RegisterEvent()
{
// 此处监听所有可能对鼠标状态产生影响的事件
RegisterDialogEvent();
RegisterTriggerEvent();
RegisterMenu();
}
private void RegisterDialogEvent()
{
// 对话相关
_unRegisters.Add(EnumEventSystem.Global.Register<DialogEventEnum, DialogLine>(DialogEventEnum.LineStart,
OnLineStart));
@@ -74,7 +80,10 @@ namespace AibisDream
_unRegisters.Add(
EnumEventSystem.Global.Register<DialogEventEnum, DialogLine>(DialogEventEnum.OptionSelected,
OnOptionSelect));
}
private void RegisterTriggerEvent()
{
// 交互相关
_unRegisters.Add(EnumEventSystem.Global.Register(InteractionEventEnum.Start, OnInteractiveStart));
_unRegisters.Add(EnumEventSystem.Global.Register(InteractionEventEnum.End, OnInteractiveEnd));
@@ -89,6 +98,22 @@ namespace AibisDream
EnumEventSystem.Global.Register<TriggerEnum, IInteraction>(TriggerEnum.PointerUp, OnPointerUp));
}
private void RegisterMenu()
{
_unRegisters.Add(EnumEventSystem.Global.Register<EventEnum, bool>(EventEnum.Menu, OnMenuChange));
}
private void Update()
{
if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
{
if (_isTalking && !isInMenu)
{
DialogController.Instance.JumpLine();
}
}
}
private void LateUpdate()
{
// // 将虚拟指针与鼠标位置同步
@@ -190,6 +215,15 @@ namespace AibisDream
#endregion
#region
private void OnMenuChange(bool isMenuOpen)
{
isInMenu = isMenuOpen;
}
#endregion
#region
/// <summary>
@@ -162,6 +162,7 @@ namespace AibisDream
{
var logObj = transform.Find("Dialogue Log").gameObject;
logObj.SetActive(!logObj.activeSelf);
EnumEventSystem.Global.Send(EventEnum.Menu, logObj.activeSelf);
}
#endregion