您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

49 行
1.0 KiB

  1. using System;
  2. using SUISSEngine;
  3. using UnityEngine;
  4. [RequireComponent(typeof(BoxCollider2D), typeof(Rigidbody2D), typeof(AudioSource))]
  5. [RequireComponent(typeof(Clickable))]
  6. public class CIGPlayOnClick : MonoBehaviour
  7. {
  8. private void Awake()
  9. {
  10. this._audioSource = base.GetComponent<AudioSource>();
  11. }
  12. private void Start()
  13. {
  14. base.GetComponent<Rigidbody2D>().isKinematic = true;
  15. base.GetComponent<Collider2D>().isTrigger = true;
  16. if (this.clickable != null)
  17. {
  18. this.clickable.OnClickEvent += this.OnClickEvent;
  19. }
  20. }
  21. private void OnDestroy()
  22. {
  23. if (this.clickable != null)
  24. {
  25. this.clickable.OnClickEvent -= this.OnClickEvent;
  26. }
  27. }
  28. private void OnClickEvent(GameObject target)
  29. {
  30. if (Singleton<CIGSettings>.Instance.SoundEffectsEnabled && this.SoundFx != null)
  31. {
  32. this._audioSource.PlayOneShot(this.SoundFx);
  33. }
  34. }
  35. [SerializeField]
  36. private AudioClip SoundFx;
  37. [SerializeField]
  38. [SelfReference]
  39. private Clickable clickable;
  40. private AudioSource _audioSource;
  41. }