TH1/Unity/Assets/Scripts/TH1_Anim/Fragments/FragmentMoveExplorer.cs
2026-02-14 22:57:12 +08:00

139 lines
4.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* @Author: 白哉
* @Description:
* @Date: 2025年07月01日 星期二 14:07:05
* @Modify:
*/
using Logic.Audio;
using Logic.CrashSight;
using RuntimeData;
using TH1_Anim.UnitAtomAnim;
using TH1_DataAssetsScript;
using TH1_Logic.Core;
using TH1_Renderer.UnitAtomAnim;
using TH1Renderer;
using UnityEngine;
namespace TH1_Anim.Fragments
{
//用于探索者Explorer的每一次单次移动
public class FragmentMoveExplorer : FragmentBase
{
public FragmentMoveExplorerData Data;
private bool _step1_move;
private bool _step2_update;
private float _step1_time;
private float _step2_time;
public FragmentMoveExplorer(FragmentMoveExplorerData data) : base()
{
Data = data;
if (Data.Explorer == null || Data.OriginGrid == null || Data.TargetGrid == null)
{
State = FragmentState.Wrong;
return;
};
_step1_move = false;
_step1_time = Data.MoveType == FragmentMoveExplorerType.FirstMove ? 0.1f : 0.2f;
_step2_time = _step1_time + Table.Instance.AnimDataAssets.MoveAnimTime;
Duration = _step2_time;
State = FragmentState.Prepare;
}
public override bool CheckDone(float progressTime)
{
if (!_step1_move || !_step2_update)
return false;
if (progressTime <= Duration)
return false;
return true;
}
public override void OnFinished()
{
}
public override void OnUpdate(float progressTime)
{
// 检查 Data 是否为 null
if (Data == null)
{
LogSystem.LogError("FragmentMoveExplorer.OnUpdate Error: Data is null");
_step1_move = true;
_step2_update = true;
return;
}
//Step #0 处理超时情况2倍时长
if (progressTime > Duration + 10f)
{
_step1_move = true;
_step2_update = true;
return;
}
//Step #1 第一个动画播放move
if (progressTime >= _step1_time && !_step1_move)
{
_step1_move = true;
// 检查 MapRenderer.Instance 和 CameraController
if (MapRenderer.Instance?.CameraController != null && Data.TargetGrid != null)
{
MapRenderer.Instance.CameraController.CameraFocusOnGrid(Data.TargetGrid);
}
else
{
LogSystem.LogError($"FragmentMoveExplorer.OnUpdate Error: MapRenderer.Instance={MapRenderer.Instance}, CameraController={MapRenderer.Instance?.CameraController}, TargetGrid={Data.TargetGrid}");
}
if(Data.MoveType == FragmentMoveExplorerType.FirstMove && Data.OriginGrid != null)
{
Data.OriginGrid.Renderer(Main.MapData)?.PlayVFXInSight(new GridVFXParams(GridVFXType.Fog));
}
//AUDIO 播放移动音效
if (AudioManager.Instance != null)
{
AudioManager.Instance.PlayAudio("SFX/UNIT_move");
}
return;
}
//Step #1.5 渲染explorer的移动
if (progressTime >= 0 && progressTime < _step2_time && _step1_move)
{
float t = (progressTime - _step1_time) / (_step2_time - _step1_time);
if(Data.Explorer?.transform != null && Data.OriginGrid != null && Data.TargetGrid != null)
{
Data.Explorer.transform.position = Vector3.Lerp(Data.OriginGrid.V3(), Data.TargetGrid.V3(), t);
}
}
//Step #2 第二个动画(瞬时) update表现
if (progressTime >= _step2_time && !_step2_update)
{
_step2_update = true;
if (Data.MoveType == FragmentMoveExplorerType.LastMove)
{
if (Data.Explorer != null)
{
Object.Destroy(Data.Explorer);
}
if (Data.TargetGrid != null)
{
Data.TargetGrid.Renderer(Main.MapData)?.PlayVFXInSight(new GridVFXParams(GridVFXType.Fog));
}
}
}
}
}
}