PKInviteNotice.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using System;
  6. using DG.Tweening;
  7. public class PKInviteNotice : MonoBehaviour
  8. {
  9. Transform item;
  10. RectTransform itemRTF;
  11. void Awake() {
  12. item = transform.Find("Item");
  13. itemRTF = item.GetComponent<RectTransform>();
  14. item.Find("BtnYes").GetComponent<Button>().onClick.AddListener(() => {
  15. AudioMgr.ins.PlayBtn();
  16. agree();
  17. });
  18. item.Find("BtnNo").GetComponent<Button>().onClick.AddListener(() => {
  19. AudioMgr.ins.PlayBtn();
  20. reject();
  21. });
  22. Sequence seq = DOTween.Sequence();
  23. seq.Append(itemRTF.DOLocalMoveX(itemRTF.localPosition.x + itemRTF.sizeDelta.x, 0.6f));
  24. seq.AppendInterval(10f);
  25. seq.AppendCallback(() => {
  26. if (this && this.gameObject) Destroy(this.gameObject);
  27. });
  28. seq.SetUpdate(true);
  29. }
  30. bool hasDoneDestroy = false;
  31. void OnDestroy() {
  32. if (!hasDoneDestroy) {
  33. eventOnAutoDestroy?.Invoke();
  34. }
  35. }
  36. void agree() {
  37. hasDoneDestroy = true;
  38. if (this && this.gameObject) Destroy(this.gameObject);
  39. eventOnAgree?.Invoke();
  40. }
  41. void reject() {
  42. hasDoneDestroy = true;
  43. if (this && this.gameObject) Destroy(this.gameObject);
  44. eventOnReject?.Invoke();
  45. }
  46. public Action eventOnAgree;
  47. public Action eventOnReject;
  48. public Action eventOnAutoDestroy;
  49. public void SetAvatarSprite(Sprite sprite) {
  50. item.Find("Avatar/Sprite").GetComponent<Image>().sprite = sprite;
  51. }
  52. public void SetNameText(string text) {
  53. item.Find("Name").GetComponent<Text>().text = text;
  54. }
  55. public void SetTipText(string text) {
  56. item.Find("Tip").GetComponent<Text>().text = text;
  57. }
  58. }