This commit is contained in:
2025-02-22 02:42:57 +08:00
parent 1a38ae4572
commit 8cdf40a9ad
10 changed files with 400 additions and 846 deletions
@@ -1,5 +1,7 @@
using System;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UIElements;
namespace AibisDream
{
@@ -7,8 +9,7 @@ namespace AibisDream
{
#region
[Header("可动组件索引")]
public EngineGear[] engineGears;
[Header("可动组件索引")] public EngineGear[] engineGears;
public GameObject piston;
#endregion
@@ -22,7 +23,13 @@ namespace AibisDream
private void Start()
{
// 赋予初始速度
foreach (var gear in engineGears)
{
gear.Rotate(_engineSystem.engineConfig.gearSpeed);
}
_engineSystem.updateSpeedEvent.AddListener(OnSpeedUpdate);
}
private void OnSpeedUpdate(float originSpeed, float speedScale)
@@ -30,17 +37,18 @@ namespace AibisDream
// 处理齿轮速度
foreach (var gear in engineGears)
{
gear.SetSpeedScale(speedScale * _engineSystem.engineConfig.gearSpeed);
gear.SetSpeedScale(speedScale);
}
}
}
[Serializable]
public struct EngineGear
public class EngineGear
{
public Renderer renderer;
public Transform gear;
public float speedRadio;
private static readonly int UVRotateSpeed = Shader.PropertyToID("_UVRotateSpeed");
private Tween _rotateTween;
/// <summary>
/// 设置速度
@@ -48,8 +56,23 @@ namespace AibisDream
/// <param name="speedScale">基础速度</param>
public void SetSpeedScale(float speedScale)
{
renderer.material.SetFloat(UVRotateSpeed, speedRadio * 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);
Debug.Log("Rotate");
_rotateTween = gear.DORotate(target, duration, RotateMode.LocalAxisAdd)
.SetEase(Ease.Linear)
.SetLoops(-1, LoopType.Incremental);
}
}
}
}
@@ -1,32 +0,0 @@
using AibisDream.FixSystem;
using DG.Tweening;
using UnityEngine;
namespace AibisDream
{
public class StaticGear : MonoBehaviour
{
public float initSpeed;
private Tween _rotateTween;
private void Start()
{
FixSystemCenter.SystemDic.Get<EngineSystem>().updateSpeedEvent.AddListener(UpdateSpeedScale);
}
/// <summary>
/// 开始旋转
/// </summary>
public void StartRotate()
{
_rotateTween = transform.DORotate(new Vector3(0, 0, 360), 1 / Mathf.Abs(initSpeed), RotateMode.LocalAxisAdd)
.SetEase(Ease.Linear)
.SetLoops(-1, LoopType.Incremental);
}
private void UpdateSpeedScale(float originSpeed, float speed)
{
_rotateTween.timeScale = speed;
}
}
}
@@ -1,3 +0,0 @@
fileFormatVersion: 2
guid: 79006d3d747c4b8482204874bbbf6ae3
timeCreated: 1737104031
+1 -1
View File
@@ -6,7 +6,7 @@ namespace AibisDream
{
[SerializeField] protected GameObject choiceButton;
private void Start()
protected override void OnAwake()
{
// 初始化选择按钮
choiceButtonPrefab = choiceButton;
@@ -61,6 +61,12 @@ namespace AibisDream
_dialogText = transform.Find(DialogText)?.gameObject.GetComponent<TypewriterByCharacter>();
_nextArray = transform.Find(NextArray)?.gameObject;
_choiceBox = transform.Find(ChoiceBox)?.gameObject;
OnAwake();
}
protected virtual void OnAwake()
{
}
#endregion