96 lines
3.1 KiB
C#
96 lines
3.1 KiB
C#
using asap.core;
|
|
using DG.Tweening;
|
|
using Game;
|
|
using Script.RuntimeScript.GameLogic;
|
|
using System.Collections;
|
|
using UnityEngine;
|
|
|
|
namespace Script.RuntimeScript
|
|
{
|
|
public partial class GameBroadLogic
|
|
{
|
|
private float _animationDelay = 0.05f;
|
|
private float _animationDuration = 0.3f;
|
|
private int _completedAnimations = 0;
|
|
private int _totalAnimations;
|
|
private void BeginWaveEffect()
|
|
{
|
|
GContext.container.Resolve<DiggingGameManager>().GameState = SandDigGameState.WaveEffect;
|
|
MonoBehaviour mono = GContext.container.Resolve<DiggingGameManager>().BaseMono;
|
|
mono.StartCoroutine(PlayWaveAnimation());
|
|
}
|
|
|
|
private IEnumerator PlayWaveAnimation()
|
|
{
|
|
|
|
_completedAnimations = 0;
|
|
_totalAnimations = GetEffectGridCount();
|
|
int columns = GContext.container.Resolve<DiggingGameManager>().GetGridWidth();
|
|
|
|
|
|
for (int j = 0; j < columns; j++)
|
|
{
|
|
for (int i = 0; i < _allGrids.Count; i++)
|
|
{
|
|
if (_allGrids[i].Data.IsBorder == false && _allGrids[i].Data.Row == j)
|
|
{
|
|
DoTweenCube(_allGrids[i]);
|
|
yield return null;
|
|
}
|
|
}
|
|
yield return new WaitForSeconds(_animationDelay);
|
|
}
|
|
}
|
|
private void DoTweenCube(GridItem cube)
|
|
{
|
|
Vector3 startPosition = cube.transform.position;
|
|
Vector3 endPosition = startPosition + new Vector3(0, 0, -1);
|
|
|
|
cube.transform.DOMove(endPosition, _animationDuration / 2).SetEase(Ease.OutQuad).OnComplete(() =>
|
|
{
|
|
cube.transform.DOMove(startPosition, _animationDuration / 2).SetEase(Ease.InQuad).OnComplete(() =>
|
|
{
|
|
GContext.Publish(new EventUISound("audio_ui_sanddig_gridshow"));
|
|
_completedAnimations++;
|
|
if (_completedAnimations >= _totalAnimations)
|
|
{
|
|
OnAllAnimationsComplete();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保持与上面相同算法 ,防止 格子参数配置错误导致 数量不一样
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
|
|
private int GetEffectGridCount()
|
|
{
|
|
int count = 0;
|
|
int columns = GContext.container.Resolve<DiggingGameManager>().GetGridWidth();
|
|
|
|
for (int j = 0; j < columns; j++)
|
|
{
|
|
for (int i = 0; i < _allGrids.Count; i++)
|
|
{
|
|
if (_allGrids[i].Data.IsBorder == false && _allGrids[i].Data.Row == j)
|
|
{
|
|
count++;
|
|
}
|
|
}
|
|
|
|
}
|
|
return count;
|
|
|
|
}
|
|
|
|
private void OnAllAnimationsComplete()
|
|
{
|
|
DiggingGameManager.LogError("开始动画完毕!!");
|
|
GContext.container.Resolve<DiggingGameManager>().GameState = SandDigGameState.Going;
|
|
//ShowAllGridProps();
|
|
}
|
|
}
|
|
}
|