Files
2026-05-26 16:15:54 +08:00

75 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using asap.core;
using UnityEngine;
using UnityEngine.Assertions;
public class ShootingRound : MonoBehaviour
{
private List<ShootingTarget> _targetList;
private EventShootingRangeData _data;
private void Awake()
{
_targetList = new List<ShootingTarget>();
foreach (Transform child in transform)
{
var target = child.GetComponent<ShootingTarget>();
if (!target) continue;
_targetList.Add(target);
}
_data = GContext.container.Resolve<EventShootingRangeData>();
}
private const float TargetPopupDuration = 0.5f;
public async System.Threading.Tasks.Task ShowAsync()
{
gameObject.SetActive(true);
foreach (var target in _targetList)
{
target.gameObject.SetActive(false);
}
if (_targetList.Count <= 0)
return;
var delay = TargetPopupDuration / _targetList.Count;
for (int i = 0; i < _targetList.Count; i++)
{
bool isHit = _data.IsTargetHit(i);
_targetList[i].InitAndPlayAppearAnimation(isHit, _data.CurrentStageIdx, i);
if (!isHit)
await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(delay));
}
}
public void Show()
{
gameObject.SetActive(true);
foreach (var target in _targetList)
{
target.gameObject.SetActive(false);
}
if (_targetList.Count <= 0)
return;
var delay = TargetPopupDuration / _targetList.Count;
for (int i = 0; i < _targetList.Count; i++)
{
bool isHit = _data.IsTargetHit(i);
_targetList[i].InitAndPlayAppearAnimation(isHit, _data.CurrentStageIdx, i);
// if (!isHit)
// await System.Threading.Tasks.Task.Delay(TimeSpan.FromSeconds(delay));
}
}
public void Hide()
{
gameObject.SetActive(false);
}
private static int ParseTargetIndex(string goName)
{
var tokens = goName.Split('(', ')');
Assert.IsTrue(tokens.Length >= 3, $"Name {goName} is supposed to contain brackets.");
return int.Parse(tokens[1]);
}
}