| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using DG.Tweening;
- /* 弹窗-PK邀请通知提示 */
- public class PKInviteNotice : MonoBehaviour
- {
- Transform item;
- RectTransform itemRTF;
- void Awake() {
- item = transform.Find("Item");
- itemRTF = item.GetComponent<RectTransform>();
- item.Find("BtnYes").GetComponent<Button>().onClick.AddListener(() => {
- AudioMgr.ins.PlayBtn();
- agree();
- });
- item.Find("BtnNo").GetComponent<Button>().onClick.AddListener(() => {
- AudioMgr.ins.PlayBtn();
- reject();
- });
- Sequence seq = DOTween.Sequence();
- //解决移动不能完全出来问题
- float offscreenX = itemRTF.anchoredPosition.x + itemRTF.rect.width;
- seq.Append(itemRTF.DOAnchorPosX(offscreenX, 0.6f));
- //seq.Append(itemRTF.DOLocalMoveX(itemRTF.localPosition.x + itemRTF.sizeDelta.x, 0.6f));
- seq.AppendInterval(10f);
- seq.AppendCallback(() => {
- if (this && this.gameObject) Destroy(this.gameObject);
- });
- seq.SetUpdate(true);
- }
- bool hasDoneDestroy = false;
- void OnDestroy() {
- if (!hasDoneDestroy) {
- eventOnAutoDestroy?.Invoke();
- }
- }
- void agree() {
- hasDoneDestroy = true;
- if (this && this.gameObject) Destroy(this.gameObject);
- eventOnAgree?.Invoke();
- }
- void reject() {
- hasDoneDestroy = true;
- if (this && this.gameObject) Destroy(this.gameObject);
- eventOnReject?.Invoke();
- }
- public Action eventOnAgree;
- public Action eventOnReject;
- public Action eventOnAutoDestroy;
- public void SetAvatarSprite(int avatarID, string avatarUrl) {
- RoleMgr.SetAvatarToImage(
- item.Find("Avatar/Sprite").GetComponent<Image>(),
- avatarID, avatarUrl
- );
- }
- public void SetNameText(string text) {
- item.Find("Name").GetComponent<Text>().text = text;
- }
- public void SetTipText(string text) {
- Text textObj = item.Find("Tip").GetComponent<Text>();
- textObj.text = text;
- if (TextAutoLanguage2.GetLanguage() == LanguageEnum.Japan) {
- textObj.fontSize = 17;
- }
- }
- }
|