72 lines
1.8 KiB
Plaintext
72 lines
1.8 KiB
Plaintext
|
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;
|
||
|
}
|
||
|
}
|