Exemplo n.º 1
0
        /// <summary>
        /// 界面打开。
        /// </summary>
        /// <param name="userData">用户自定义数据。</param>
        protected override void OnOpen(object userData)
        {
            base.OnOpen(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;
                }
            }

            UI.alpha = 0f;
            StopAllCoroutines();
            StartCoroutine(UI.FadeToAlpha(1f, m_FadeTime));
        }
Exemplo n.º 2
0
        public void RemovePackage(string type)
        {
            if (RemovePackageRef(type))
            {
                var p = UIPackage.GetByName(type);

                if (p != null)
                {
                    UIPackage.RemovePackage(type);
                }
            }

            /*UIPackage package;
             *
             * if(packages.TryGetValue(type, out package))
             * {
             *  var p = UIPackage.GetByName(package.name);
             *
             *  if (p != null)
             *  {
             *      UIPackage.RemovePackage(package.name);
             *  }
             *
             *  packages.Remove(package.name);
             * }*/

            if (!Define.IsEditorMode)
            {
                string uiBundleDesName = AssetBundleHelper.StringToAB($"{type}_fui");
                string uiBundleResName = AssetBundleHelper.StringToAB(type);
                Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle(uiBundleDesName);
                Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle(uiBundleResName);
            }
        }
        public override void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }

            base.Dispose();

            if (this.checkForResUpdatelPackage != null)
            {
                var p = UIPackage.GetByName(checkForResUpdatelPackage.name);

                if (p != null)
                {
                    UIPackage.RemovePackage(checkForResUpdatelPackage.name);
                }

                checkForResUpdatelPackage = null;
            }

            if (this.loadingPackage != null)
            {
                var p = UIPackage.GetByName(loadingPackage.name);

                if (p != null)
                {
                    UIPackage.RemovePackage(loadingPackage.name);
                }

                loadingPackage = null;
            }
        }
Exemplo n.º 4
0
    /// <summary>
    /// FGUI获取
    /// </summary>
    /// <param name="strPkgName"></param>
    /// <param name="resName"></param>
    /// <returns></returns>
    public object Get(string strPkgName, string resName)
    {
        GObject go = null;

        if (objPool.ContainsKey(resName))
        {
            List <object> objList = objPool[resName];
            if (objList.Count > 0)
            {
                go = objList[0] as GObject;
                objList.Remove(go);
            }
        }
        if (go == null)
        {
            if (UIPackage.GetByName(strPkgName) == null)
            {
                Debug.LogError(strPkgName + "包未加载");
                return(null);
            }
            go      = UIPackage.CreateObject(strPkgName, resName);
            go.name = resName;
        }
        if (go == null)
        {
            Debug.LogError(resName + "资源不存在");
        }
        return(go);
    }
Exemplo n.º 5
0
        public void AddPackage(string packageName)
        {
            if (string.IsNullOrEmpty(packageName))
            {
                throw new GameFrameworkException("packageName is null");
            }

            UIPackage uiPackage = UIPackage.GetByName(packageName);

            if (uiPackage == null)
            {
                if (GameEntry.Base.EditorResourceMode)
                {
                    string packagePath =
                        Utility.Text.Format("Assets/GameMain/FGuiResource/{0}/{0}", packageName);

                    uiPackage = UIPackage.AddPackage(packagePath);
                }
                else
                {
                    AssetBundle ab = AssetBundle.LoadFromFile(Utility.Text.Format("{0}/fgui/{1}.dat",
                                                                                  Application.streamingAssetsPath, packageName.ToLower()));

                    UIPackage.AddPackage(ab);
                }
            }

            AddRef(packageName);
        }
Exemplo n.º 6
0
        public static void UnLoadUI(string uipath, bool destroyRes)
        {
            UIPackage pkg = UIPackage.GetByName(uipath);

            if (null != pkg)
            {
                pkg.UnloadAssets();
            }
        }
    /// <summary>
    /// load package
    /// </summary>
    public void LoadPackage(string packageName)
    {
        if (UIPackage.GetByName(packageName) == null)
        {
            // TODO 这里需要判断是否是ab加载(更新)

            UIPackage.AddPackage("UI/" + packageName);
        }
    }
Exemplo n.º 8
0
        public static void RemovePackage(string pkgName)
        {
            UIPackage pkg = UIPackage.GetByName(pkgName);

            if (pkg != null)
            {
                pkg.UnloadAssets();
                UIPackage.RemovePackage(pkgName);
            }
        }
Exemplo n.º 9
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;
        }
Exemplo n.º 10
0
 /// <summary>
 /// 重新加载包的资源进入内存。
 /// </summary>
 /// <param name="packageName">包名</param>
 public void ReloadAssets(string packageName)
 {
     try
     {
         UIPackage package = UIPackage.GetByName(packageName);
         package.ReloadAssets();
     }
     catch (Exception e)
     {
         Debug.LogError("资源加载错误,请检查是否在调用了DestroyAllWindow方法后又调用了OpenWindow方法:" + e);
         #if UNITY_EDITOR
         UnityEditor.EditorApplication.isPlaying = false;
         #endif
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// 移除一个包,并清理其asset
        /// </summary>
        /// <param name="type"></param>
        public void RemovePackage(string type)
        {
            UIPackage package;

            if (packages.TryGetValue(type, out package))
            {
                var p = UIPackage.GetByName(package.name);
                if (p != null)
                {
                    UIPackage.RemovePackage(package.name);
                }

                packages.Remove(package.name);
            }
        }
Exemplo n.º 12
0
 public void ReloadAssets(string packageName)
 {
     try
     {
         UIPackage package = UIPackage.GetByName(packageName);
         package.ReloadAssets();
     }
     catch (Exception e)
     {
         Debug.LogError("资源加载错误,请检查是否在调用了UIWindowManager.Instance.DestoryAllWindow()方法后又调用了UIWindowManager.Instance.OpenWindow()方法,错误代码:AA0012");
         #if UNITY_EDITOR
         UnityEditor.EditorApplication.isPlaying = false;
         #endif
         return;
     }
 }
Exemplo n.º 13
0
 public void UnloadAssets(string packageName)
 {
     try
     {
         UIPackage package = UIPackage.GetByName(packageName);
         package.UnloadAssets();
     }
     catch (Exception e)
     {
         Debug.LogError(e);
     }
     #if UNITY_EDITOR
     UnityEditor.EditorApplication.isPlaying = false;
     #endif
     return;
 }
    public IEnumerator DownLoadData <T>(BundleComplete completeCallBack) where T : AssetBundleResName, new()
    {
        if (!this.LoadBundle())
        {
            yield return(AssetFromBundle(BundleConst.WindowframeBundleName, this));

            T         instance      = new T();
            UIPackage bundlePackage = UIPackage.GetByName(instance.ResName);
            if (null == bundlePackage)
            {
                //bundlePackage = UIPackage.AddPackage(assetBundle);
                this.SetBundlePackageOfPoolInstance(bundlePackage);
            }
            //completeCallBack.OnComplete(assetBundle);
        }
    }
Exemplo n.º 15
0
        /// <summary>
        /// 移除一个包,并清理其asset
        /// </summary>
        /// <param name="type"></param>
        public void RemovePackage(string type)
        {
            UIPackage package;

            if (s_Packages.TryGetValue(type, out package))
            {
                var p = UIPackage.GetByName(package.name);
                if (p != null)
                {
                    UIPackage.RemovePackage(package.name);
                    XAssetLoader.UnLoadAsset(XAssetPathUtilities.GetFGUIDesPath($"{type}_fui"));
                    XAssetLoader.UnLoadAsset(XAssetPathUtilities.GetFGUIResPath($"{type}_atlas0", ".png"));
                }

                s_Packages.Remove(package.name);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// fgui独立管理ab,接口单独拎出来!
        /// </summary>
        public static void LoadUI(string uipath)
        {
            AssetBundle ab = null;

            // 检测是否存在ab
            if (null != ABVersion.CurVersionInfo && ABVersion.CurVersionInfo.IsValid)
            {
                string abname     = ABHelper.GetFileFolderPath(uipath) + ".ab";
                string uiFullPath = ABVersion.CurVersionInfo.GetABFullPath(abname);

                if (!string.IsNullOrEmpty(uiFullPath))
                {
                    ab = AssetBundle.LoadFromFile(uiFullPath);
                }
            }

            UIPackage pkg = UIPackage.GetByName(uipath);

            if (null == pkg)
            {
                if (null == ab)
                {
                    pkg = UIPackage.AddPackage(uipath);
                }
                else
                {
                    pkg = UIPackage.AddPackage(ab);
                }
            }
            else
            {
                if (null == ab)
                {
                    pkg.ReloadAssets();
                }
                else
                {
                    pkg.ReloadAssets(ab);
                }
            }
        }
Exemplo n.º 17
0
        public override void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }

            base.Dispose();

            if (modelPackage != null)
            {
                var p = UIPackage.GetByName(modelPackage.name);

                if (p != null)
                {
                    UIPackage.RemovePackage(modelPackage.name);
                }

                modelPackage = null;
            }
        }
Exemplo n.º 18
0
        void CreateUI_EditMode()
        {
            if (!EMRenderSupport.packageListReady || UIPackage.GetByName(m_PackageName) == null)
            {
                return;
            }

#if (UNITY_5 || UNITY_5_3_OR_NEWER)
            DisplayOptions.SetEditModeHideFlags();
            _ui = (GComponent)UIPackage.CreateObject(m_PackageName, m_ComponentName);

            if (_ui != null)
            {
                _ui.displayObject.gameObject.hideFlags |= HideFlags.HideInHierarchy;
                _ui.gameObjectName = "UI(AutoGenerated)";

                _ui.position = m_Position;
                if (m_Scale.x != 0 && m_Scale.y != 0)
                {
                    _ui.scale = m_Scale;
                }
                _ui.rotationX = m_Rotation.x;
                _ui.rotationY = m_Rotation.y;
                _ui.rotation  = m_Rotation.z;
                this.m_Container.AddChildAt(_ui.displayObject, 0);

                m_CachedUISize = _ui.size;
                uiBounds.size  = m_CachedUISize;
                HandleScreenSizeChanged();
            }
#else
            PackageItem pi = UIPackage.GetByName(packageName).GetItemByName(componentName);
            if (pi != null)
            {
                cachedUISize  = new Vector2(pi.width, pi.height);
                uiBounds.size = cachedUISize;
                HandleScreenSizeChanged();
            }
#endif
        }
Exemplo n.º 19
0
    public bool CheckAndAddFGUIPackge(string pkgDirectory, string pkgName, bool isBundle = true)
    {
        if (string.IsNullOrEmpty(pkgDirectory) || string.IsNullOrEmpty(pkgName))
        {
            Debug.LogError("AssetManager load pkgName is null or len=0 !!!");
            return(false);
        }
        if (UIPackage.GetByName(pkgName) == null)
        {
            if (!isBundle)
            {
                ////////////////////////////////////下面是resource方式的加载/////////////////////////////////////
                string path = Path.Combine("UIPackage", pkgDirectory, pkgName);
                path = path.Replace("\\", "/");
                UIPackage.AddPackage(path);
            }
            else
            {
                ////////////////////////////////////下面是bundle方式的加载/////////////////////////////////////

                string pkgLowerName = pkgName.ToLower();//unity 5.5打包的bundle 包名全为小写
                string path         = FormatBundlePath(pkgLowerName, pkgDirectory);
                //AssetBundle manifestBundle = AssetBundle.LoadFromFile(AddBundleSuffix(path));
                AssetBundle manifestBundle = LoadMyAssetBundle(AddBundleSuffix(path));
                if (manifestBundle == null)
                {
                    return(false);
                }
                //AssetBundle bundle = AssetBundle.LoadFromFile(path);
                AssetBundle bundle = LoadMyAssetBundle(path);
                if (bundle == null)
                {
                    return(false);
                }
                pkgName = string.Format("{0}_fui", pkgName);
                UIPackage.AddPackage(manifestBundle, bundle, pkgName);
            }
        }
        return(true);
    }
Exemplo n.º 20
0
        public void RemovePackage(string type)
        {
            UIPackage package;

            if (packages.TryGetValue(type, out package))
            {
                var p = UIPackage.GetByName(package.name);

                if (p != null)
                {
                    UIPackage.RemovePackage(package.name);
                }

                packages.Remove(package.name);
            }

            if (!Define.ResModeIsEditor)
            {
                Game.Scene.GetComponent <ResourcesComponent>().UnLoadAsset(ABPathUtilities.GetFGUIDesPath($"{type}_fui"));
                Game.Scene.GetComponent <ResourcesComponent>().UnLoadAsset(ABPathUtilities.GetFGUIResPath($"{type}_atlas0"));
            }
        }
Exemplo n.º 21
0
        public void RemovePackage(string type)
        {
            UIPackage package;

            if (packages.TryGetValue(type, out package))
            {
                var p = UIPackage.GetByName(package.name);

                if (p != null)
                {
                    UIPackage.RemovePackage(package.name);
                }

                packages.Remove(package.name);
            }

#if !UNITY_EDITOR
            string uiBundleDesName = $"{type}_fui".StringToAB();
            string uiBundleResName = type.StringToAB();
            ETModel.Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle(uiBundleDesName);
            ETModel.Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle(uiBundleResName);
#endif
        }
Exemplo n.º 22
0
        public void RemovePackage(string type)
        {
            UIPackage package;

            if (packages.TryGetValue(type, out package))
            {
                var p = UIPackage.GetByName(package.name);

                if (p != null)
                {
                    UIPackage.RemovePackage(package.name);
                }

                packages.Remove(package.name);
            }

            if (Define.IsAsync)
            {
                string uiBundleDesName = AssetBundleHelper.StringToAB($"{type}_fui");
                string uiBundleResName = AssetBundleHelper.StringToAB(type);
                Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle(uiBundleDesName);
                Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle(uiBundleResName);
            }
        }