| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 | using FairyGUI;using System.Collections;using UnityEngine;namespace GFGGame{    /// <summary>    /// 视图基类,界面不可以直接继承    /// </summary>    public class UIView : IUIView    {        private string _descFilePath;        private EnumViewAnimationType _viewAnimationType = EnumViewAnimationType.None;        /// <summary>        /// 打开视图传递的参数        /// </summary>        public object viewData { get; set; }        /// <summary>        /// 设置视图组件        /// </summary>        public virtual GComponent viewCom { get; set; }        /// <summary>        /// 设置是否全屏自适应        /// </summary>        public bool isfullScreen { get; set; }        /// <summary>        /// FairyGUI包名        /// </summary>        protected string packageName        {            set            {                _descFilePath = ResPathUtil.GetUIPackagePath(value);                GFGUIPackage.AddPackage(_descFilePath);            }        }        /// <summary>        /// 是否显示中        /// </summary>        public bool isShowing        {            get { return viewCom != null && viewCom.onStage; }        }        /// <summary>        /// 设置视图显示和隐藏的动画类型        /// </summary>        protected EnumViewAnimationType viewAnimationType        {            set            {                _viewAnimationType = value;            }        }        public UIView()        {            //            Init();            OnInit();            if (viewCom != null)            {                viewCom.onAddedToStage.Add(__addedToStage);                viewCom.onRemovedFromStage.Add(__removeFromStage);            }        }        public virtual void Dispose()        {            if (viewCom != null)            {                viewCom.RemoveFromParent();                viewCom.Dispose();                viewCom = null;            }            if (_descFilePath != null)            {                GFGUIPackage.RemovePackage(_descFilePath);            }            _descFilePath = null;            viewData = null;        }        virtual protected void Init()        {        }        virtual protected void OnInit()        {        }        /// <summary>        /// 界面打开状态刷新界面        /// </summary>        virtual public void Refresh()        {            object temp = viewData;            this.OnHide();            this.viewData = temp;            this.OnShown();        }        public virtual void Show()        {        }        public virtual void Hide()        {            DoHideAnimation();        }        virtual protected void OnShown()        {            if (isfullScreen)            {                MakeFullScreen(viewCom);            }            if (GuideController.IsGuide())            {                Timers.inst.AddUpdate(UpdateToCheckGuide);            }        }        virtual protected void OnHide()        {            viewData = null;            Timers.inst.Remove(UpdateToCheckGuide);            TryCompleteGuide();        }        virtual protected void UpdateToCheckGuide(object param)        {        }        virtual protected void TryCompleteGuide()        {        }        protected virtual void DoShowAnimation()        {            OnShown();            switch (_viewAnimationType)            {                case EnumViewAnimationType.ZOOM_CENTER:                    ViewAnimationFactory.ZoomInCenter(this.viewCom);                    break;                default:                    break;            }        }        protected virtual void DoHideAnimation()        {            switch (_viewAnimationType)            {                case EnumViewAnimationType.ZOOM_CENTER:                    ViewAnimationFactory.ZoomOutCenter(this.viewCom, this.OnDoHideAnimationCompleted);                    break;                default:                    this.OnDoHideAnimationCompleted();                    break;            }        }        protected virtual void OnDoHideAnimationCompleted()        {            if (this.viewCom != null)            {                this.viewCom.RemoveFromParent();            }        }        private void MakeFullScreen(GObject ui)        {            ui.MakeFullScreen();            ui.AddRelation(GRoot.inst, RelationType.Size);        }        void __addedToStage()        {            DoShowAnimation();        }        void __removeFromStage()        {            OnHide();        }    }}
 |