WXMC/.svn/pristine/89/898294f01c1e0f334ea5c331635e709ac8bd38a1.svn-base

72 lines
1.8 KiB
Plaintext
Raw Normal View History

2024-12-04 16:18:46 +08:00
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class PuzzleDamageText : MonoBehaviour
{
#region Define
[System.Serializable]
public struct TimingConfig
{
public PuzzleGameMode.TimingNames Timing;
public Color TextColor;
}
#endregion
public float Speed;
public float HorizontalRand;
public TMP_Text DamageText;
[SerializeField]
private List<TimingConfig> m_timingConfigs;
private Dictionary<PuzzleGameMode.TimingNames, TimingConfig> m_timingConfigDict;
private void EnsureConfig()
{
if (m_timingConfigDict != null)
{
return;
}
m_timingConfigDict = new Dictionary<PuzzleGameMode.TimingNames, TimingConfig>();
foreach (var config in m_timingConfigs)
{
m_timingConfigDict.Add(config.Timing, config);
}
}
public void SetDamageText(PuzzleGameMode.DamageMonsterParam damageParam)
{
EnsureConfig();
TimingConfig config;
if (!m_timingConfigDict.TryGetValue(damageParam.TimingUsed, out config))
{
Debug.LogError("Timing config not found");
return;
}
DamageText.text = $"{damageParam.Composition.Damage}";
DamageText.color = config.TextColor;
}
// Start is called before the first frame update
void Start()
{
Destroy(gameObject, 1.0f);
RectTransform rectTransform = GetComponent<RectTransform>();
rectTransform.anchoredPosition += Vector2.right * Random.Range(-HorizontalRand, HorizontalRand);
}
// Update is called once per frame
void Update()
{
RectTransform rectTransform = GetComponent<RectTransform>();
rectTransform.anchoredPosition += Vector2.up * Speed * Time.deltaTime;
}
}