PKInviteNotice.cs 1.9 KB

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