refactor(fix-system): 移除 Engine 拉绳小游戏系统
Made-with: Cursor
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e4e107b3ecf9c547b40caab94412f3c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,138 +0,0 @@
|
||||
using AibisDream.Framework;
|
||||
using AibisDream.Utility;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class CordPull : MonoBehaviour, IInteraction
|
||||
{
|
||||
private static readonly int ShineFade = Shader.PropertyToID("_ShineFade");
|
||||
|
||||
private EventTriggerEx _trigger;
|
||||
private SpriteRenderer _sprite;
|
||||
private EngineSystem _engineSystem;
|
||||
private Vector3 _initPos;
|
||||
public float maxDistance;
|
||||
|
||||
private Vector3 _dragPoint;
|
||||
private bool _isDragging;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// 记录当前位置
|
||||
InitRefs();
|
||||
}
|
||||
|
||||
private void InitRefs()
|
||||
{
|
||||
_initPos = transform.position;
|
||||
|
||||
_trigger = GetComponent<EventTriggerEx>();
|
||||
_engineSystem = transform.parent.GetComponent<EngineSystem>();
|
||||
_sprite = GetComponent<SpriteRenderer>();
|
||||
|
||||
_trigger.Register(EventTriggerType.BeginDrag, OnBeginDrag);
|
||||
_trigger.Register(EventTriggerType.EndDrag, OnEndDrag);
|
||||
_trigger.Register(EventTriggerType.Drag, OnDrag);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_isDragging)
|
||||
{
|
||||
MoveToDragPos();
|
||||
}
|
||||
}
|
||||
|
||||
private void MoveToDragPos()
|
||||
{
|
||||
float curY;
|
||||
// 如果拖拽点在上方,直接移动
|
||||
if (_dragPoint.y > transform.position.y)
|
||||
{
|
||||
curY = _dragPoint.y;
|
||||
}
|
||||
// 如果拖拽点在下方,限速移动
|
||||
else
|
||||
{
|
||||
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.z);
|
||||
}
|
||||
|
||||
private void OnDrag(BaseEventData data)
|
||||
{
|
||||
// 这里是一些阻碍拖动的情况
|
||||
if (!IsActive) return;
|
||||
|
||||
// 正常情况下不会出错
|
||||
if (data is not PointerEventData pointerData) return;
|
||||
|
||||
// 设置拖拽目标点
|
||||
SetDragTarget(pointerData.position);
|
||||
}
|
||||
|
||||
private void OnBeginDrag(BaseEventData data)
|
||||
{
|
||||
// 这里是一些阻碍拖动的情况
|
||||
if (!IsActive) return;
|
||||
|
||||
// 首次拖拽后关闭高亮
|
||||
if (GlobalVariableKit.IsCordHighLight)
|
||||
{
|
||||
GlobalVariableKit.IsCordHighLight = false;
|
||||
_sprite.material.SetFloat(ShineFade, 0);
|
||||
}
|
||||
|
||||
// 正常情况下不会出错
|
||||
if (data is not PointerEventData pointerData) return;
|
||||
// 设置拖拽目标点
|
||||
SetDragTarget(pointerData.position);
|
||||
|
||||
// 开始拖动的时候把原有的动画删掉
|
||||
transform.DOKill();
|
||||
_isDragging = true;
|
||||
}
|
||||
|
||||
private void OnEndDrag(BaseEventData data)
|
||||
{
|
||||
_isDragging = false;
|
||||
// 松手后抽回去
|
||||
var retractTime = (_initPos.y - transform.localPosition.y) / _engineSystem.engineConfig.returnSpeed;
|
||||
transform.DOMove(_initPos, retractTime);
|
||||
}
|
||||
|
||||
private void SetDragTarget(Vector3 mousePos)
|
||||
{
|
||||
var worldPos = CameraKit.GetMouseWorldPos(mousePos);
|
||||
|
||||
var dragY = CommonUtil.Limit(worldPos.y, _initPos.y, _initPos.y - maxDistance);
|
||||
|
||||
_dragPoint = new Vector3(transform.position.x, dragY, transform.position.z);
|
||||
}
|
||||
|
||||
public void ActiveShine()
|
||||
{
|
||||
_sprite.material.SetFloat(ShineFade, 1);
|
||||
}
|
||||
|
||||
#region 交互限制相关
|
||||
|
||||
public bool IsActive => _engineSystem.isPullActive;
|
||||
|
||||
public bool IsAvailable => _engineSystem.isAvailable;
|
||||
|
||||
public GameObject GetGameObject()
|
||||
{
|
||||
return gameObject;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a6d9bb0e6b84b14a9d78479d5462d41
|
||||
timeCreated: 1737097199
|
||||
@@ -1,140 +0,0 @@
|
||||
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
|
||||
{
|
||||
[SerializeField]private SpriteRenderer cover;
|
||||
|
||||
[Header("系统配置")] public EngineConfig engineConfig;
|
||||
public bool isAvailable;
|
||||
public bool isPullActive;
|
||||
private bool _isSuccess;
|
||||
|
||||
public float curSpeed;
|
||||
public float targetSpeed = 0.95f;
|
||||
[SerializeField] private float coverMoveDuration = 5f;
|
||||
[SerializeField] private float coverMoveDistance = 2.8f;
|
||||
|
||||
public UnityEvent<float, float> updateSpeedEvent = new();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
FixSystemCenter.SystemDic.Register(this);
|
||||
|
||||
// 注册相机
|
||||
var virtualCam = transform.Find("Engine Camera").GetComponent<ICinemachineCamera>();
|
||||
CameraKit.Instance.RegisterCamera(CameraEnum.Engine, virtualCam);
|
||||
}
|
||||
|
||||
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>
|
||||
private void EnableSystem()
|
||||
{
|
||||
isAvailable = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭系统交互
|
||||
/// </summary>
|
||||
private void DisableSystem()
|
||||
{
|
||||
isAvailable = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开盖板
|
||||
/// 关闭系统交互
|
||||
/// </summary>
|
||||
/// <returns>动画序列</returns>
|
||||
public Tween OpenCover()
|
||||
{
|
||||
var sq = DOTween.Sequence();
|
||||
// 盖板上移
|
||||
var moveDis = new Vector3(0, coverMoveDistance, 0);
|
||||
sq.Join(cover.transform.DOBlendableMoveBy(moveDis, coverMoveDuration));
|
||||
// 盖板淡出
|
||||
sq.Join(cover.DOFade(0, coverMoveDuration));
|
||||
|
||||
// 为引擎系统解锁
|
||||
sq.OnComplete(EnableSystem);
|
||||
|
||||
return sq;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 关闭盖板
|
||||
/// </summary>
|
||||
/// <returns>动画序列</returns>
|
||||
public Tween CloseCover()
|
||||
{
|
||||
var sq = DOTween.Sequence();
|
||||
sq.Join(cover.DOFade(1, coverMoveDuration));
|
||||
|
||||
var moveDis = new Vector3(0, -coverMoveDistance, 0);
|
||||
sq.Join(cover.transform.DOBlendableMoveBy(moveDis, coverMoveDuration));
|
||||
|
||||
// 锁定引擎系统
|
||||
sq.OnComplete(DisableSystem);
|
||||
|
||||
return sq;
|
||||
}
|
||||
|
||||
public void ActivePull()
|
||||
{
|
||||
isPullActive = true;
|
||||
var pull = GetComponentInChildren<CordPull>();
|
||||
pull.ActiveShine();
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public struct EngineConfig
|
||||
{
|
||||
[Header("齿轮基础速度")] public float gearSpeed;
|
||||
[Header("齿轮速度倍率")] public float speedRate;
|
||||
[Header("拉满几次到全速")] public float pullCount;
|
||||
[Header("拉绳回缩速度")] public float returnSpeed;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 10324e3c30ee1924893a08455ce65e0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,46 +0,0 @@
|
||||
using System.Collections;
|
||||
using AibisDream.FixSystem;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public static class EngineYarnCommand
|
||||
{
|
||||
private static EngineSystem EngineSystem => FixSystemCenter.SystemDic.Get<EngineSystem>();
|
||||
|
||||
// 打开引擎盖
|
||||
[YarnCommand("open_engine_cover")]
|
||||
public static IEnumerator OpenEngineCover()
|
||||
{
|
||||
yield return EngineSystem.OpenCover();
|
||||
}
|
||||
|
||||
// 打开引擎盖
|
||||
[YarnCommand("close_engine_cover")]
|
||||
public static IEnumerator CloseEngineCover()
|
||||
{
|
||||
yield return EngineSystem.CloseCover();
|
||||
}
|
||||
|
||||
/// <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.ActivePull();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 25506a4586954f8db428372d3644fcf9
|
||||
timeCreated: 1736336596
|
||||
@@ -1,70 +0,0 @@
|
||||
using System;
|
||||
using AibisDream.FixSystem;
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class MoveablePartGroup : MonoBehaviour
|
||||
{
|
||||
#region 动件索引
|
||||
|
||||
[Header("可动组件索引")] public EngineGear[] engineGears;
|
||||
private EngineSystem EngineSystem => FixSystemCenter.SystemDic.Get<EngineSystem>();
|
||||
|
||||
#endregion
|
||||
|
||||
private EngineSystem _engineSystem;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 赋予初始速度
|
||||
foreach (var gear in engineGears)
|
||||
{
|
||||
gear.Rotate(EngineSystem.engineConfig.gearSpeed);
|
||||
}
|
||||
EngineSystem.updateSpeedEvent.AddListener(OnSpeedUpdate);
|
||||
}
|
||||
|
||||
private void OnSpeedUpdate(float originSpeed, float speedScale)
|
||||
{
|
||||
// 处理齿轮速度
|
||||
foreach (var gear in engineGears)
|
||||
{
|
||||
gear.SetSpeedScale(speedScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class EngineGear
|
||||
{
|
||||
public Transform gear;
|
||||
public float speedRadio;
|
||||
|
||||
private Tween _rotateTween;
|
||||
|
||||
/// <summary>
|
||||
/// 设置速度
|
||||
/// </summary>
|
||||
/// <param name="speedScale">基础速度</param>
|
||||
public void SetSpeedScale(float speedScale)
|
||||
{
|
||||
if (_rotateTween != null)
|
||||
{
|
||||
_rotateTween.timeScale = speedScale;
|
||||
}
|
||||
// _rotateTween.timeScale = speedScale;
|
||||
}
|
||||
|
||||
public void Rotate(float initSpeed)
|
||||
{
|
||||
var duration = 1 / Mathf.Abs(initSpeed * speedRadio);
|
||||
|
||||
var target = speedRadio >= 0 ? new Vector3(0, 0, 360) : new Vector3(0, 0, -360);
|
||||
_rotateTween = gear.DORotate(target, duration, RotateMode.LocalAxisAdd)
|
||||
.SetEase(Ease.Linear)
|
||||
.SetLoops(-1, LoopType.Incremental);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8fa4ca1b14430cb49b015ee8d5a5eaf4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3388932338827fc4785c8f4c4012b38e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1 +0,0 @@
|
||||
{"oilDownRatio":0.2,"oilUpRatio":0.4,"acceleratedSpeed":1.0,"resistance":1.0,"airMaxRatio":0.45,"airMinRatio":0.37,"baseAirMax":0.2,"maxLevel":5,"targetSpeed":0.8,"invalidTime":0.7}
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa0525ab5423c9c4f9e29f9580bc5939
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user