PKInviteNotice.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. //解决移动不能完全出来问题
  25. float offscreenX = itemRTF.anchoredPosition.x + itemRTF.rect.width;
  26. seq.Append(itemRTF.DOAnchorPosX(offscreenX, 0.6f));
  27. //seq.Append(itemRTF.DOLocalMoveX(itemRTF.localPosition.x + itemRTF.sizeDelta.x, 0.6f));
  28. seq.AppendInterval(10f);
  29. seq.AppendCallback(() => {
  30. if (this && this.gameObject) Destroy(this.gameObject);
  31. });
  32. seq.SetUpdate(true);
  33. }
  34. bool hasDoneDestroy = false;
  35. void OnDestroy() {
  36. if (!hasDoneDestroy) {
  37. eventOnAutoDestroy?.Invoke();
  38. }
  39. }
  40. void agree() {
  41. hasDoneDestroy = true;
  42. if (this && this.gameObject) Destroy(this.gameObject);
  43. eventOnAgree?.Invoke();
  44. }
  45. void reject() {
  46. hasDoneDestroy = true;
  47. if (this && this.gameObject) Destroy(this.gameObject);
  48. eventOnReject?.Invoke();
  49. }
  50. public Action eventOnAgree;
  51. public Action eventOnReject;
  52. public Action eventOnAutoDestroy;
  53. public void SetAvatarSprite(int avatarID, string avatarUrl) {
  54. RoleMgr.SetAvatarToImage(
  55. item.Find("Avatar/Sprite").GetComponent<Image>(),
  56. avatarID, avatarUrl
  57. );
  58. }
  59. public void SetNameText(string text) {
  60. item.Find("Name").GetComponent<Text>().text = text;
  61. }
  62. public void SetTipText(string text) {
  63. Text textObj = item.Find("Tip").GetComponent<Text>();
  64. textObj.text = text;
  65. if (TextAutoLanguage2.GetLanguage() == LanguageEnum.Japan) {
  66. textObj.fontSize = 17;
  67. }
  68. }
  69. }