TH1/Unity/Assets/Scripts/TH1_Anim/Fragments/FragmentGridUpdate.cs
2026-02-22 02:15:06 +08:00

124 lines
3.6 KiB
C#

/*
* @Author: 白哉
* @Description:
* @Date: 2025年07月01日 星期二 14:07:05
* @Modify:
*/
using JetBrains.Annotations;
using Logic.Audio;
using RuntimeData;
using TH1_Anim.UnitAtomAnim;
using TH1_DataAssetsScript;
using TH1_Logic.Core;
using TH1_Renderer;
using TH1_Renderer.UnitAtomAnim;
using TH1Renderer;
using UnityEngine;
namespace TH1_Anim.Fragments
{
public enum GridUpdateType
{
None,
FogDisappear,
BuildingUpdate,
BuildingDestroy,
Treasure,
LoseConnect,
Connect
}
public class FragmentGridUpdate : FragmentBase
{
public GridUpdateType Type;
public GridRenderer GridRenderer;
private float _step1_time;
private float _step2_time;
private bool _step1_start;
private bool _step2_end;
public FragmentGridUpdate(FragmentGridUpdateData data) : base()
{
Type = data.GridUpdateType;
GridRenderer = data.GridRenderer;
_step1_time = 0f;
_step2_time = Type switch
{
GridUpdateType.FogDisappear => data.Duration,
GridUpdateType.BuildingUpdate => 0.05f,
GridUpdateType.BuildingDestroy => 0.05f,
GridUpdateType.Treasure => 0.05f,
GridUpdateType.LoseConnect => 0.05f,
GridUpdateType.Connect => (data.GridRenderer?.IsBelongSelfPlayer() ?? false ) ? 0.3f : 0.05f,
_ => 0.05f
};
_step1_start = false;
_step2_end = false;
Duration = _step2_time;
}
public override bool CheckDone(float progressTime)
{
//超时保险
if (progressTime > Duration * 2)
{
Debug.Log($"Fragement Timeout {this.GetType()}");
return true;
}
if (!_step1_start || !_step2_end) return false;
if (progressTime <= Duration)
return false;
return true;
}
public override void OnUpdate(float progressTime)
{
//Step #1执行第一步
if (progressTime >= _step1_time && !_step1_start)
{
_step1_start = true;
switch (Type)
{
case GridUpdateType.FogDisappear:
GridRenderer?.FirstShowGrid();
break;
case GridUpdateType.BuildingUpdate:
GridRenderer?.PlayVFXInSight(new GridVFXParams(GridVFXType.Fog));
//只有自己玩家的建筑才有声音
if(Main.MapData?.CurPlayer == Main.MapData?.PlayerMap.SelfPlayerData)
AudioManager.Instance.PlayAudio("SFX/GRID_build");
GridRenderer?.InstantUpdateGrid();
break;
case GridUpdateType.BuildingDestroy:
break;
case GridUpdateType.Treasure:
break;
case GridUpdateType.LoseConnect:
break;
case GridUpdateType.Connect:
break;
default:
break;
}
return;
}
if (progressTime >= _step2_time && !_step2_end)
{
_step2_end = true;
}
}
}
}