zoukankan      html  css  js  c++  java
  • 3

    using System;
    using System.Collections.Generic;
    using UnityEngine;

    namespace Game.UI
    {
        public class View : UIItemWidget
        {
            //[SerializeField]
            //bool CloseReleaseResource = false;
            public event DelegateT<View> OnClose;
            bool hasClose = false;
            Window mWindow;
            Canvas mPannel;
            //List<UIPanel> mSubPanels = new List<UIPanel>();

            public Window window { get { return mWindow; } }
            public Canvas panel { get { return mPannel; } }

            public const string EventSetPos = "SetPos";
            public const string EventSetPosX = "SetPosX";
            public const string EventSetPosY = "SetPosY";

            //public IEnumerable<UIPanel> subPanels { get { return mSubPanels; } }

            //public void AddSubPanel( UIPanel panel )
            //{
            //    if (panel == null)
            //        return;

            //    mSubPanels.Add(panel);
            //}
            //public void RemoveSubPanel(UIPanel panel)
            //{
            //    mSubPanels.Remove(panel);
            //}
            void _Close()
            {
                if (!hasClose)
                {
                    hasClose = true;
                    if (OnClose != null)
                    {
                        OnClose(this);
                    }
                }
            }
            public virtual void Close()
            {
                _Close();
                if (mWindow != null)
                    mWindow.Close();
            }

            public bool Create(Window win, object val)
            {
                //try
                //{
                mWindow = win;
                CreateImp(val);
                mPannel = GetComponentInChildren<Canvas>();
                return true;
                //}
                //catch(Exception e)
                //{
                //    MyLog.LogError("[{0}] create error!msg:{1}", window.name, e);
                //    return false;
                //}
            }

            public void Show(bool bShow)
            {
                gameObject.SetActive(bShow);
            }

            public virtual void UpdateView(FrameTimer ft)
            {

            }

            //[Flags]
            //public enum eEnabelFlag
            //{
            //    ContainChild = 1,
            //    ContainBox = 2,
            //}
            //static Color c_DisableColor = new Color(0.3f, 0.3f, 0.3f, 1);
            //public static EnableClass EnableUI(bool _enable, GameObject uiRoot, eEnabelFlag flag = eEnabelFlag.ContainChild | eEnabelFlag.ContainBox,List<string> list=null)
            //{
            //    EnableClass enable = new EnableClass();
            //    //UISprite[] sprites = null;
            //    //Collider[] colliders = null;
            //    if ( (int)(flag & eEnabelFlag.ContainChild) > 0 )
            //    {
            //        enable.sprites = uiRoot.GetComponentsInChildren<UISprite>();
            //        enable.textures = uiRoot.GetComponentsInChildren<UITexture>();
            //        if ((int)(flag & eEnabelFlag.ContainBox) > 0)
            //        {
            //            enable.colliders = uiRoot.GetComponentsInChildren<Collider>();
            //        }
            //    }
            //    else
            //    {
            //        enable.sprites = uiRoot.GetComponents<UISprite>();
            //        enable.textures = uiRoot.GetComponents<UITexture>();
            //        if ((int)(flag & eEnabelFlag.ContainBox) > 0)
            //        {
            //            enable.colliders = uiRoot.GetComponentsInChildren<Collider>();
            //        }
            //    }
            //    if (list != null)
            //    {
            //        List<Collider> coliList = new List<Collider>();
            //        foreach (var item in enable.colliders)
            //        {
            //            if (!list.Contains(item.name))
            //            {
            //                coliList.Add(item);
            //            }
            //        }
            //        enable.colliders = coliList.ToArray();

            //        List<UISprite> spriList = new List<UISprite>();
            //        foreach (var item in enable.sprites)
            //        {
            //            if (!list.Contains(item.name))
            //            {
            //                spriList.Add(item);
            //            }
            //        }
            //        enable.sprites = spriList.ToArray();

            //        List<UITexture> texList = new List<UITexture>();
            //        foreach (var item in enable.textures)
            //        {
            //            if (!list.Contains(item.name))
            //            {
            //                texList.Add(item);
            //            }
            //        }
            //        enable.textures = texList.ToArray();
            //    }
            //    if (enable.colliders != null)
            //    {
            //        foreach (var col in enable.colliders)
            //        {
            //            col.enabled = _enable;
            //        }
            //    }
            //    foreach (UISprite sprite in enable.sprites)
            //    {
            //        if(sprite.enabled != false)
            //        {
            //            if (!_enable)
            //            {
            //                sprite.color = new Color(0, 0, 0, sprite.color.a);
            //            }
            //            else
            //            {
            //                sprite.color = new Color(1, 1, 1, sprite.color.a);
            //            }
            //        }
            //    }
            //    if (enable.textures != null)
            //    {
            //        foreach (var sprite in enable.textures)
            //        {
            //            if (sprite.enabled != false)
            //            {
            //                if (!_enable)
            //                {
            //                    sprite.color = new Color(0, 0, 0, sprite.color.a);
            //                }
            //                else
            //                {
            //                    sprite.color = new Color(1, 1, 1, sprite.color.a);
            //                }
            //            }
            //        }
            //    }
            //    return enable;
            //}
            public virtual void BecomeTopView()
            {
                //GuideMgr.singleton.StartGuideEvent(GuideStartType.Open_UI, window.name);
            }

            public virtual void LoseTopView()
            {

            }

            public virtual void OnEvent(string sevent, object obj)
            {
                //switch (sevent)
                //{
                //    case EventSetPos:
                //        {
                //            var newPos = (Vector2)obj;
                //            var pos = transform.localPosition;
                //            pos.x = newPos.x;
                //            pos.y = newPos.y;
                //            transform.localPosition = pos;
                //        }break;
                //    case EventSetPosX:
                //        {
                //            float newPos = (float)obj;
                //            var pos = transform.localPosition;
                //            pos.x = newPos;
                //            transform.localPosition = pos;
                //        }break;
                //    case EventSetPosY:
                //        {
                //            float newPos = (float)obj;
                //            var pos = transform.localPosition;
                //            pos.y = newPos;
                //            transform.localPosition = pos;
                //        } break;
                //}
            }
            public override void Destroy()
            {
                try
                {
                    base.Destroy();
                    DestroyImp();
                    _Close();
                    return;
                }
                catch (Exception e)
                {
                    if (window != null)
                        MyLog.LogWarning("[{0}] Destroy error!msg:{1}", window.name, e);
                    return;
                }
            }
            protected virtual void CreateImp(object val)
            {

            }

            protected virtual void DestroyImp()
            {
            }

            protected override void OnDestroy()
            {
                if (!hasDestroy)
                {
                    //if (CloseReleaseResource && GameMain.singleton)
                    //    GameMain.singleton.UnloadUnusedAssets();
                    if (window != null)
                    {
                        MyLog.LogWarning("please close {0} view", window.name);
                    }
                    Close();
                    //UIMgr.singleton.Close(this);
                }
                base.OnDestroy();
            }
            protected virtual void PlayAnimation(Animation ani, string name, bool forward = true)
            {
                if (ani == null)
                {
                    return;
                }
                var clip = ani[name];
                if (forward)
                {
                    clip.time = 0;
                    clip.speed = 1;
                }
                else
                {
                    clip.time = clip.length;
                    clip.speed = -1;
                }
                ani.Play(name);
            }
        }
        //public class EnableClass 
        //{
        //    public UISprite[] sprites = null;
        //    public Collider[] colliders = null;
        //    public UITexture[] textures = null;

        //    public void Reset()
        //    {
        //        if(sprites != null)
        //        {
        //            foreach (UISprite item in sprites)
        //            {
        //                item.color = Color.white;
        //            }
        //        }
        //        if (colliders != null)
        //        {
        //            foreach(Collider item in colliders)
        //            {
        //                item.enabled = true;
        //            }
        //        }
        //        if (textures != null)
        //        {
        //            foreach (var item in textures)
        //            {
        //                item.color = Color.white;
        //            }
        //        }
        //    }
        //}
    }

  • 相关阅读:
    [设计模式]之依赖倒置
    CSS的三种使用方式
    CSS的语法结构
    学习 jQueryMobile 第一个程序
    初识 GoogleMap
    程序员考试
    程序员考试
    CSS学习
    认识CSS
    开始忙一段时间
  • 原文地址:https://www.cnblogs.com/rexzhao/p/7278959.html
Copyright © 2011-2022 走看看