Beispiel #1
0
        public static void LoadPackages()
        {
            if (Application.isPlaying || _loaded)
            {
                return;
            }

#if !UNITY_5
            EditorApplication.update -= EditorApplication_Update;
            EditorApplication.update += EditorApplication_Update;
#endif
            _loaded = true;

            UIPackage.RemoveAllPackages();
            FontManager.Clear();
            NTexture.DisposeEmpty();

            string[] ids = AssetDatabase.FindAssets("@sprites t:textAsset");
            int      cnt = ids.Length;
            for (int i = 0; i < cnt; i++)
            {
                string assetPath = AssetDatabase.GUIDToAssetPath(ids[i]);
                int    pos       = assetPath.LastIndexOf("@");
                if (pos == -1)
                {
                    continue;
                }

                assetPath = assetPath.Substring(0, pos);
                if (AssetDatabase.AssetPathToGUID(assetPath) != null)
                {
                    UIPackage.AddPackage(assetPath,
                                         (string name, string extension, System.Type type) =>
                    {
                        return(AssetDatabase.LoadAssetAtPath(name + extension, type));
                    }
                                         );
                }
            }

            List <UIPackage> pkgs = UIPackage.GetPackages();
            pkgs.Sort(CompareUIPackage);

            cnt = pkgs.Count;
            packagesPopupContents = new GUIContent[cnt + 1];
            for (int i = 0; i < cnt; i++)
            {
                packagesPopupContents[i] = new GUIContent(pkgs[i].name);
            }
            packagesPopupContents[cnt] = new GUIContent("Please Select");

            UIConfig.ClearResourceRefs();
            UIConfig[] configs = GameObject.FindObjectsOfType <UIConfig>();
            foreach (UIConfig config in configs)
            {
                config.Load();
            }

            EMRenderSupport.Reload();
        }
Beispiel #2
0
 void OnRenderObject()
 {
     //Update和OnGUI在EditMode的调用都不那么及时,OnRenderObject则比较频繁,可以保证界面及时刷新。所以使用OnRenderObject
     if (isMain && !Application.isPlaying)
     {
         EMRenderSupport.Update();
     }
 }
        public static void LoadPackages()
        {
            if (Application.isPlaying || _loaded)
            {
                return;
            }

            EditorApplication.update -= EditorApplication_Update;
            EditorApplication.update += EditorApplication_Update;

            _loaded = true;

            UIPackage.RemoveAllPackages();
            FontManager.Clear();
            NTexture.DisposeEmpty();
            UIObjectFactory.Clear();

            string[] ids = AssetDatabase.FindAssets("_fui t:textAsset");
            int      cnt = ids.Length;

            for (int i = 0; i < cnt; i++)
            {
                string assetPath = AssetDatabase.GUIDToAssetPath(ids[i]);
                int    pos       = assetPath.LastIndexOf("_fui");
                if (pos == -1)
                {
                    continue;
                }

                assetPath = assetPath.Substring(0, pos);
                if (AssetDatabase.AssetPathToGUID(assetPath) != null)
                {
                    UIPackage.AddPackage(assetPath,
                                         (string name, string extension, System.Type type, out DestroyMethod destroyMethod) =>
                    {
                        destroyMethod = DestroyMethod.Unload;
                        return(AssetDatabase.LoadAssetAtPath(name + extension, type));
                    }
                                         );
                }
            }

            List <UIPackage> pkgs = UIPackage.GetPackages();

            pkgs.Sort(CompareUIPackage);

            cnt = pkgs.Count;
            packagesPopupContents = new GUIContent[cnt + 1];
            for (int i = 0; i < cnt; i++)
            {
                packagesPopupContents[i] = new GUIContent(pkgs[i].name);
            }
            packagesPopupContents[cnt] = new GUIContent("Please Select");

            EMRenderSupport.Reload();
        }
Beispiel #4
0
        /// <summary>
        /// 界面初始化。
        /// </summary>
        /// <param name="userData">用户自定义数据。</param>
        protected override void OnInit(object userData)
        {
            base.OnInit(userData);

            if (Application.isPlaying)
            {
                if (this.m_Container == null)
                {
                    CreateContainer();

                    if (!string.IsNullOrEmpty(m_PackagePath) && UIPackage.GetByName(m_PackageName) == null)
                    {
                        GameEntry.FairyGui.AddPackage(m_PackagePath);
                    }
                }
                else
                {
                    this.m_Container._disabled = false;
                }
            }
            else
            {
                //不在播放状态时我们不在OnEnable创建,因为Prefab也会调用OnEnable,延迟到Update里创建(Prefab不调用Update)
                //每次播放前都会disable/enable一次。。。
                if (m_Container != null)//如果不为null,可能是因为Prefab revert, 而不是因为Assembly reload,
                {
                    OnDestroy();
                }

                EMRenderSupport.Add(this);
                screenSizeVer     = 0;
                uiBounds.position = m_Position;
                uiBounds.size     = m_CachedUISize;
                if (uiBounds.size == Vector2.zero)
                {
                    uiBounds.size = new Vector2(30, 30);
                }
            }

            if (!_created && Application.isPlaying)
            {
                CreateUI_PlayMode();
            }

            OriginalDepth = UI.sortingOrder;
            Transform transform = GetComponent <Transform>();

            transform.position   = Vector3.zero;
            transform.rotation   = Quaternion.identity;
            transform.localScale = Vector3.one;
        }
Beispiel #5
0
        /// <summary>
        /// 界面关闭。
        /// </summary>
        /// <param name="userData">用户自定义数据。</param>
        protected override void OnClose(object userData)
        {
            base.OnClose(userData);

            if (Application.isPlaying)
            {
                if (this.m_Container != null)
                {
                    this.m_Container._disabled = true;
                }
            }
            else
            {
                EMRenderSupport.Remove(this);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 界面销毁
        /// </summary>
        public virtual void Clear()
        {
            if (m_Container != null)
            {
                if (!Application.isPlaying)
                {
                    EMRenderSupport.Remove(this);
                }

                if (_ui != null)
                {
                    _ui.Dispose();
                    _ui = null;
                }

                GameEntry.FairyGui.RemovePackage(m_PackagePath);
                m_Container.Dispose();
                m_Container = null;
            }

            _renders = null;
        }
Beispiel #7
0
        /// <summary>
        /// 界面销毁
        /// </summary>
        protected override void OnDestroy()
        {
            base.OnDestroy();

            if (m_Container != null)
            {
                if (!Application.isPlaying)
                {
                    EMRenderSupport.Remove(this);
                }

                if (_ui != null)
                {
                    _ui.Dispose();
                    _ui = null;
                }

                GameEntry.FairyGui.RemovePackage(m_PackagePath);
                m_Container.Dispose();
                m_Container = null;
            }

            _renders = null;
        }