201710032350->unity中ui窗体基本生命周期

目的:根据构建窗体时搭载的基本数据生成窗体

执行窗体的初始化,进入和刷新

关键点

1.初始化

2.进入

3.刷新

4.退出隐藏


详细代码

public class AppBasePages : IOnFormUI
    {
        protected AppBasePages() { }
        protected AppBasePages(UIType type, UIMode mode, string path = "")
        {
            this.type = type;
            this.mode = mode;
            this.path = path;
        }
        public void Show()
        {
            if (this.CacheGameObject == null && this.path.IsNonNullOrEmpty())
            {
                CreateUI();
            }
            OnEnter();
            OnRefresh();
            AdjustDeep();
            CheakPageNodes(this);
        }

        private void AdjustDeep()
        {
            UIPanel[] panels = CacheTransform.TryGetChildComponent<UIPanel>(true);
            Array.ForEach(panels, p =>
            {
                p.depth = p.depth - panels[0].depth + UIDeep;
            });
            panels[0].depth = UIDeep;
            UIDeep += 1;
        }
        private Transform SetUIParent()
        {
            switch (type)
            {
                case UIType.Normal: return AppBootStrap.Instance.NormalRoot;
                case UIType.PopUp: return AppBootStrap.Instance.PopupRoot;
            }
            return null;
        }
        private void CreateUI()
        {
            this.CacheGameObject = GameObject.Instantiate(Resources.Load(path), SetUIParent()) as GameObject;
            this.CacheTransform = this.CacheGameObject.transform;
            OnInitUI();
        }
        public void Close()
        {
            CacheGameObject.SetActiveSafe(false);
            content = null;
            OnExit();
        }
        public virtual void OnEnter()
        {
            CacheGameObject.SetVisible(true);
        }
        public virtual void OnRefresh()
        {
            CacheGameObject.SetActiveSafe(true);
        }
        public virtual void OnExit() { }
        public virtual void OnInitUI() { }

        private UIType type;
        private UIMode mode;
        private string path;
        protected object content;
        protected GameObject CacheGameObject;
        protected Transform CacheTransform;

   }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值