Пример #1
0
        /// <summary>
        /// 有资源依赖的情况
        /// </summary>
        /// <returns></returns>
        public Object GetPrefabDepend(string assetPath, string extension = IcConfig.EXTENSION_PREFAB)
        {
            string      m_loaderPath = null;
            Object      obj          = null;
            AssetBundle ab           = null;

            if (string.IsNullOrEmpty(assetPath))
            {
                return(null);
            }


            string dir;
            string name;

            CUtil.SplitPath(assetPath, out dir, out name);
            stResourcePath resourcePath = AssetBundleManager.GetResources().GetResourcePath(dir, name, extension);

            if (!AssetBundleManager.Instance.m_isLocaAsset)
            {
                if (resourcePath.asset != null)
                {
                    //(assetbundle 已经异步load好了)
                    obj = resourcePath.asset;
                }
                else if (resourcePath.bAssetbundle)
                {
                    string path = resourcePath.path;
                    AssetBundleManager.GetAssetBundleManager().LoadAssetSynchronization(path, resourcePath.ver, name, typeof(Object), out obj, out ab);
                    if (!m_loadAb.Contains(resourcePath.path) && ab != null)
                    {
                        m_loadAb.Add(resourcePath.path);
                    }
                }
                else
                {
                    string path = resourcePath.AssetPath;
                    AssetBundleManager.GetAssetBundleManager().LoadAssetSynchronization(path, resourcePath.ver, name, typeof(Object), out obj, out ab);
                    if (!m_loadAb.Contains(resourcePath.path) && ab != null)
                    {
                        m_loadAb.Add(resourcePath.path);
                    }
                }
            }
            else
            {
                string path = IcResources.GetEditorAssetResourcePath(dir, name, extension);
                #if UNITY_EDITOR
                obj = AssetDatabase.LoadAssetAtPath(path, typeof(Object));
                #endif

                if (obj == null)
                {
                    //同步
                    path = IcResources.GetEditorResourcePath(dir, name, extension);
                    obj  = Resources.Load(path, typeof(Object));
                }
            }
            return(obj);
        }
Пример #2
0
        //bSpecial : 非编辑器模式, alaways load from resources
        private T Load <T>(string relativePath, string fileExtention, bool bSpecial = false) where T : UnityEngine.Object
        {
            T asset = default(T);

            //#if UNITY_EDITOR
            //        if (AssetBundleManager.GetResources().IsLoadAssetBundle())
            //        {
            //#endif
            if (bSpecial)
            {   //只从Resources里读取, 用于gameConfig
                //load from resource
                asset = Resources.Load(relativePath, typeof(T)) as T;
            }
            else
            {
                string dir;
                string name;
                CUtil.SplitPath(relativePath, out dir, out name);

                stResourcePath resourcePath = GetResourcePath(dir, name, fileExtention);

                if (!AssetBundleManager.Instance.m_isLocaAsset)
                {
                    if (resourcePath.asset != null)
                    {
                        //(assetbundle 已经异步load好了)
                        asset = resourcePath.asset as T;
                    }
                    else if (resourcePath.bAssetbundle)
                    {
                        //load assetbundle
                        //同步load的, 不支持异步assetbundleload, 应该提前load好, 由resourcePath.asset返回

                        //使用CreateFromMemoryImmediate和createFromFile都会引起crash (unity3d, 5.0.4)
                        //Unity5.4以上使用AssetBundle.LoadFromFile
                        asset = LoadAssetbundle <T>(resourcePath.path, resourcePath.ver, name);
                    }
                    else
                    {
                        //load from resource
                        asset = Resources.Load(resourcePath.path, typeof(T)) as T;
                    }
                }
                else
                {
                    #if UNITY_EDITOR
                    if (asset == null)
                    {
                        string path = IcResources.GetEditorAssetResourcePath(dir, name, fileExtention);
                        asset = AssetDatabase.LoadAssetAtPath(path, typeof(T)) as T;
                    }
                    #endif
                }
            }

            return(asset);
        }
Пример #3
0
        public IEnumerator LoadNormalTxt()
        {
            //#if UNITY_EDITOR
            //        if (AssetBundleManager.GetResources().IsLoadAssetBundle())
            //        {
            //#endif
            UnloadNormalTxt();//LoadNormalTxt() 可能会多次调用, 先清空再load

            stResourcePath path = GetResourcePath(string.Empty, IcConfig.NORMAL_TXT, string.Empty, false, string.Empty);

            yield return(StartCoroutine(AssetBundleManager.GetAssetBundleManager().LoadAllAssetsAsync(path.path, path.ver, OnNormalTxtLoaded)));

            // Unload assetBundles.
            AssetBundleManager.GetAssetBundleManager().UnloadAssetBundle(path.path, false);
        }
Пример #4
0
        public IEnumerator LoadSyncLoadAssets()
        {
            //#if UNITY_EDITOR
            //        if (AssetBundleManager.GetResources().IsLoadAssetBundle())
            //        {
            //#endif
            stResourcePath path = GetResourcePath(string.Empty, IcConfig.SYNCLOAD_ASSETS, string.Empty, false, string.Empty);

            if (path.bAssetbundle)
            {
                yield return(StartCoroutine(AssetBundleManager.GetAssetBundleManager().LoadAllAssetsAsync(path.path, path.ver, OnAssetsLoaded)));

                // Unload assetBundles.
                AssetBundleManager.GetAssetBundleManager().UnloadAssetBundle(path.path, false);
            }

            //#if UNITY_EDITOR
            //        }
            //#endif
        }
Пример #5
0
        public override void DoStartLoad()//public override void StartLoad()
        {
            if (m_loadedCallback == null)
            {
                return;
            }

            /*
             * if (m_name == "fmz2jx_atk0")
             * {
             *   int iu = 0;
             *   iu++;
             * }*/
            string strNewFile = string.Empty;

            //if (MyTxtResources.GetTmpActorsFile(m_name, out strNewFile))//m_bTestRole)
            //{
            //    string pathOk = IcResources.GetPersistentDataPath_FileStream() + "actors/" + strNewFile;//IcResources.GetPersistentDataPath_WWW() + assetbundlePath;
            //    m_path = pathOk;
            //    LoadAssetbundleDirectly(pathOk, strNewFile, typeof(Object));

            //    return;
            //}
            //IcChangeFiles pChangeFile = MyTxtResources.GetChangeFile(m_name);
            //if (pChangeFile != null)
            //{
            //    m_name = pChangeFile.fileName;
            //    m_dir = pChangeFile.path;
            //}
            stResourcePath resourcePath = AssetBundleManager.GetResources().GetResourcePath(m_dir, m_name, m_extension);

            if (!AssetBundleManager.Instance.m_isLocaAsset)
            {
                if (resourcePath.asset != null)
                {
                    //(assetbundle 已经异步load好了)
                    Loaded(resourcePath.asset, resourcePath.path);
                }
                else if (resourcePath.bAssetbundle)
                {
                    StartCoroutine(LoadAssetBundle(resourcePath.path, resourcePath.ver, !loadLowPriority));
                }
                else
                {
                    if (loadLowPriority)
                    {
                        StartCoroutine(LoadResourceAssetAsync(resourcePath.path));
                    }
                    else
                    {
                        AssetBundleManifest m_AssetBundleManifest = AssetBundleManager.GetAssetBundleManager().m_AssetBundleManifest;
                        if (m_AssetBundleManifest == null)
                        {
                            Object asset = null;
                            string path  = resourcePath.path;
                            asset = Resources.Load(path, typeof(Object));
                            if (asset == null)
                            {
                                Debug.LogError("ResourceLoad Error:" + path);
                            }
                            Loaded(asset, path);
                        }
                        else
                        {
                            StartCoroutine(LoadAssetBundle(resourcePath.AssetPath, resourcePath.ver, !loadLowPriority));
                        }
                    }
                }
            }
            else
            {
                Object obj = null;

                string path = IcResources.GetEditorAssetResourcePath(m_dir, m_name, m_extension);
#if UNITY_EDITOR
                obj = AssetDatabase.LoadAssetAtPath(path, typeof(Object));
#endif

                if (obj == null)
                {
                    //同步
                    path = IcResources.GetEditorResourcePath(m_dir, m_name, m_extension);
                    obj  = Resources.Load(path, typeof(Object));
                }

                Loaded(obj, path);
            }
        }