LaboratoryProtection/Assets/UnityTest/ZXL/Scripts/UI/RoleLabel.cs

71 lines
1.9 KiB
C#

using System;
using System.Collections;
using Mono.Event;
using Script;
using Sirenix.OdinInspector;
using TMPro;
using UnityEngine;
namespace UnityTest.ZXL
{
public class RoleLabel : Label
{
public RoleLabelType roleLabelType;
public TextMeshProUGUI roleName;
public TextMeshProUGUI speakContent;
private AudioSource _audioSource;
private void Awake()
{
EventManager.Instance.Subscribe(RoleLabelEventArgs.EventId, RoleLabelEvent);
roleName.text = roleLabelType.ToString();
_audioSource = transform.GetChild(1).GetComponent<AudioSource>();
}
private void RoleLabelEvent(object sender, GameEventArgs e)
{
var args = e as RoleLabelEventArgs;
speakContent.text = args.speakContent;
if (args.data != null)
{
var str = args.data as string;
// EventManager.Instance.FireNow(this, new AudioEventArgs(str));
var clip = Resources.Load<AudioClip>($"Sounds/6-4/{str}");
_audioSource.clip = clip;
}
}
private void OnDestroy()
{
EventManager.Instance.Unsubscribe(RoleLabelEventArgs.EventId, RoleLabelEvent);
}
#if UNITY_EDITOR
[Button]
void Add()
{
roleName = transform.GetChild(0).GetChild(0).GetComponent<TextMeshProUGUI>();
speakContent = transform.GetChild(1).GetChild(0).GetComponent<TextMeshProUGUI>();
roleName.text = roleLabelType.ToString();
UnityEditor.EditorUtility.SetDirty(this);
}
#endif
}
public enum RoleLabelType
{
A,
B,
C,
D,
E,
F,
G,
J,
L,
,
F,
}
}