123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- using System;
- // using DG.Tweening;
- using Unity.VisualScripting;
- using UnityEngine;
- using UnityEngine.UI;
- namespace Plugins.CxShine.page
- {
- public class PageComp : MonoBehaviour
- {
- public delegate void onPageClosingListener();
- public GameObject playAnimBackGround;
- public string pageName;
- private bool _isShowAnim;
- private Action _onClose;
- private onPageClosingListener _onPageClosing;
- public Action OnPause;
- public Action OnResume;
- // Start is called before the first frame update
- private void Start()
- {
- if (playAnimBackGround == null)
- // 如果播放动画的背景go没有设置,就是自己
- playAnimBackGround = gameObject;
- //Debug.Log("启动页面" + pageName);
- _initClickEvents();
- if (_isShowAnim) _playOpenAnim();
- }
- // Update is called once per frame
- private void Update()
- {
- }
- public void setOnPageCloseListener(Action action)
- {
- _onClose = action;
- }
- private void _initClickEvents()
- {
- // find all 'ClosePageButton' tag add closePageEvent
- var trans = gameObject.GetComponentsInChildren<Transform>();
- foreach (var t in trans)
- if ("ClosePageButton".Equals(t.gameObject.tag))
- t.gameObject.GetOrAddComponent<Button>().onClick.AddListener(A__ClosePage);
- }
- private void _playOpenAnim()
- {
- var to = playAnimBackGround.transform.localScale;
- // transform.SetPositionX(a.x - 50);
- playAnimBackGround.transform.localScale = new Vector3(to.x * 0.3f, to.y * 0.3f, to.z);
- // transform.SetLocalScaleX(to.x * 0.3f);
- // transform.SetLocalScaleY(to.y * 0.3f);
- // transform.DOMove(from, 0.5f).SetEase(Ease.Linear);
- // playAnimBackGround.transform.DOScale(new Vector3(to.x, to.y, to.z), 0.2f).SetEase(Ease.InSine);
- }
- public void A__ClosePage()
- {
- //Debug.Log("关闭页面" + pageName);
- if (_onPageClosing != null) _onPageClosing();
- _onClose?.Invoke();
- if (_isShowAnim)
- {
- // var to = playAnimBackGround.transform.localScale;
- // var t = playAnimBackGround.transform.DOScale(new Vector3(to.x * 0.3f, to.y * 0.3f, to.z), 0.2f)
- // .SetEase(Ease.InSine);
- // t.onComplete = onComplete;
- }
- else
- {
- onComplete();
- }
- }
- // public void setOnPageClosingListener(onPageClosingListener l)
- // {
- // _onPageClosing = l;
- // }
- // delegate TweenCallback onPageCloseAnimationFinish;
- private void onComplete()
- {
- var o = gameObject;
- if (o != null)
- {
- o.transform.localPosition = new Vector3(10000, 0, 0);
- Destroy(gameObject);
- }
- // Destroy(o, 0.1f);
- }
- public void showAnim(bool isShowAnim)
- {
- _isShowAnim = isShowAnim;
- }
- }
- }
|