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

71 lines
1.9 KiB
C#
Raw Normal View History

using System;
2023-10-05 02:31:29 +08:00
using System.Collections;
using Mono.Event;
2023-10-05 02:31:29 +08:00
using Script;
2023-09-25 02:08:58 +08:00
using Sirenix.OdinInspector;
using TMPro;
using UnityEngine;
namespace UnityTest.ZXL
{
2023-09-25 02:08:58 +08:00
public class RoleLabel : Label
{
public RoleLabelType roleLabelType;
public TextMeshProUGUI roleName;
public TextMeshProUGUI speakContent;
2023-10-05 02:31:29 +08:00
private AudioSource _audioSource;
private void Awake()
{
EventManager.Instance.Subscribe(RoleLabelEventArgs.EventId, RoleLabelEvent);
roleName.text = roleLabelType.ToString();
2023-10-05 02:31:29 +08:00
_audioSource = transform.GetChild(1).GetComponent<AudioSource>();
}
private void RoleLabelEvent(object sender, GameEventArgs e)
{
var args = e as RoleLabelEventArgs;
speakContent.text = args.speakContent;
2023-10-05 02:31:29 +08:00
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);
}
2023-09-25 02:08:58 +08:00
#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();
2023-10-05 02:31:29 +08:00
UnityEditor.EditorUtility.SetDirty(this);
2023-09-25 02:08:58 +08:00
}
#endif
}
public enum RoleLabelType
{
A,
B,
C,
D,
2023-09-25 02:08:58 +08:00
E,
F,
G,
2023-10-05 02:31:29 +08:00
J,
L,
,
2023-10-05 17:03:37 +08:00
F,
}
}