Ejemplo n.º 1
0
        /// <summary>
        /// 加载场景
        /// </summary>
        /// <param name="asbName">Asb name.</param>
        /// <param name="sceneName">Scene name.</param>
        /// <param name="sync">If set to <c>true</c> sync.</param>
        /// <param name="add">If set to <c>true</c> add.</param>
        /// <param name="callback">Callback.</param>
        /// <param name="luaFunc">Lua func.</param>
        public void LoadScene(string asbName, string sceneName, bool sync, bool add, Action <float> callback = null, LuaFunction luaFunc = null)
        {
            if (sceneName.Equals(""))
            {
                sceneName = ".unity";
            }
            string        scenePath = Tools.GetResInAssetsName(asbName, sceneName);
            LoadSceneMode mode      = add ? LoadSceneMode.Additive : LoadSceneMode.Single;

#if UNITY_EDITOR
            if (!GameConfig.useAsb)
            {
                //Tools.RelativeTo(Tools.GetResPath(Tools.PathCombine(asbName, sceneName)), Application.dataPath, true);
                //Debug.LogWarning(scenePath);
                int index = SceneUtility.GetBuildIndexByScenePath(scenePath);
                //Debug.LogWarning(index);

                bool   hasSceneLoad = index >= 0;
                string loadName     = "";
                if (hasSceneLoad)
                {
                    loadName = SceneUtility.GetScenePathByBuildIndex(index);
                }
                loadScene(sync, mode, loadName, hasSceneLoad, callback, luaFunc);
                return;
            }
#endif
            LoadRes <UObj>(asbName, string.Empty
                           , delegate(UObj obj)
            {
                if (obj != null)
                {
                    LogFile.Log(obj.ToString());
                }
                AssetBundleInfo info = GetLoadedAssetBundle(Tools.GetAsbName(asbName));
                bool rst             = false;
                string loadName      = "";

                if (null != info)
                {
                    string[] scenes = info.m_AssetBundle.GetAllScenePaths();
                    for (int i = 0; i < scenes.Length; ++i)
                    {
                        string s = scenes[i];
                        //LogFile.Log("Scenename {0}: {1}, inputName:{2}", i, s, scenePath);
                        if (s.Equals(scenePath))
                        {
                            loadName = s;
                            //SceneManager.LoadScene(s, mode);
                            rst = true;
                            //LogFile.Log("找到名字相同的scene,break");
                            break;
                        }
                    }
                    if (!rst)
                    {
                        LogFile.Error("LoadScene加载Assetbundl:{0},查找{1}失败!!", asbName, scenePath);
                    }
                }
                else
                {
                    LogFile.Error("LoadScene找不到Assetbundle:{0}", asbName);
                }
                loadScene(sync, mode, loadName, rst, callback, luaFunc);
            });
        }
Ejemplo n.º 2
0
        IEnumerator onLoadAsset <T>(string abName) where T : UObj
        {
            AssetBundleInfo bundleInfo = GetLoadedAssetBundle(abName);

            if (bundleInfo == null)
            {
                yield return(StartCoroutine(OnLoadAssetBundle(abName, typeof(T))));

                bundleInfo = GetLoadedAssetBundle(abName);
                if (bundleInfo == null)
                {
                    m_LoadRequests.Remove(abName);
                    LogFile.Error("OnLoadAsset error --->>>" + abName);
                    yield break;
                }
            }
            List <LoadAssetRequest> list = null;

            if (!m_LoadRequests.TryGetValue(abName, out list))
            {
                m_LoadRequests.Remove(abName);
                yield break;
            }
            for (int i = 0; i < list.Count; i++)
            {
                string[]    assetNames = list[i].assetNames;
                List <UObj> result     = new List <UObj>();

                AssetBundle ab = bundleInfo.m_AssetBundle;
                for (int j = 0; j < assetNames.Length; j++)
                {
                    string assetPath = assetNames[j];
                    if (!string.IsNullOrEmpty(assetPath))
                    {
                        AssetBundleRequest request = ab.LoadAssetAsync(assetPath, list[i].assetType);
                        yield return(request);

                        result.Add(request.asset);
                    }
                    else
                    {
                        result.Add(null);
                    }
                    ////TODO:UnloadAsset
                    //Resources.UnloadAsset(request.asset);
                }
                if (list[i].sharpFunc != null)
                {
                    //LogFile.Log("call c# func of {0}, result.Count:{1}", abName, result.Count);
                    list[i].sharpFunc(result.ToArray());
                    list[i].sharpFunc = null;
                }
                if (list[i].luaFunc != null)
                {
                    list[i].luaFunc.Call((object)result.ToArray());
                    list[i].luaFunc.Dispose();
                    list[i].luaFunc = null;
                }
                bundleInfo.m_ReferencedCount++;
            }
            m_LoadRequests.Remove(abName);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 单例组件被销毁时调用,子类可派生
 /// </summary>
 public virtual bool Dispose()
 {
     LogFile.Log("clearComp:" + typeof(T));
     return(true);
 }