You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.2 KiB
58 lines
1.2 KiB
using Ui.Screens; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
|
|
public class SoundEvent : MonoBehaviour |
|
{ |
|
[SerializeField] string m_soundName; |
|
[SerializeField, HideInInspector] private Button _button; |
|
|
|
private bool _subscribed; |
|
private bool _status = true; |
|
|
|
public bool Status |
|
{ |
|
get { return _status; } |
|
set { _status = value; } |
|
} |
|
|
|
public void PlaySound() |
|
{ |
|
if (m_soundName == "") |
|
return; |
|
|
|
if (!SoundsManager.Instance) |
|
return; |
|
|
|
SoundsManager.Instance.PlaySound(m_soundName, 0, false, 1f); |
|
} |
|
|
|
private void Awake() |
|
{ |
|
if (_button == null) |
|
_button = GetComponent<Button>(); |
|
|
|
if (_button != null) |
|
{ |
|
ScreenContainer.DragEvent += OnDragEvent; |
|
_subscribed = true; |
|
} |
|
} |
|
|
|
private void OnDisable() |
|
{ |
|
if (_subscribed) |
|
ScreenContainer.DragEvent -= OnDragEvent; |
|
} |
|
|
|
private void OnDragEvent(bool obj) |
|
{ |
|
_button.interactable = !obj && Status; |
|
} |
|
|
|
private void OnValidate() |
|
{ |
|
if (_button == null) |
|
_button = GetComponent<Button>(); |
|
} |
|
}
|
|
|