public void StartLoad(string assetBundlePath, string assetBundleName, OnLoadedDelegate loadedDelegate, object param) { //编辑器模式下,直接通过Profab右下角的AssetBundle名称加载模型,不需要对模型进行打包 #if UNITY_EDITOR if (isEditor) { string[] assetPaths = AssetDatabase.GetAssetPathsFromAssetBundleAndAssetName(assetBundlePath, assetBundleName); if (assetPaths.Length == 0) { Debug.LogError("There is no asset with name \"" + assetBundlePath + "\" in " + assetBundleName); } else { Debug.Log(assetPaths[0]); } Object target = AssetDatabase.LoadMainAssetAtPath(assetPaths[0]); loadedDelegate(target, param); } else { //打包成程序后 模型必须打包后才能加载模型 StartCoroutine(Load(assetBundlePath, assetBundleName, loadedDelegate, param)); } #else //打包成程序后 模型必须打包后才能加载模型 StartCoroutine(Load(assetBundlePath, assetBundleName, loadedDelegate, param)); #endif }
public IEnumerator CheckForGame(string path, OnLoadedDelegate onLoadedDelegate = null) { Debug.Log("checking for game"); var dataTask = db.GetReference("games").OrderByChild("status").EqualTo("new").GetValueAsync(); yield return(new WaitUntil(() => dataTask.IsCompleted)); string jsonData = dataTask.Result.GetRawJsonValue(); Debug.Log("game data: " + jsonData); if (dataTask.Exception != null) { Debug.LogWarning(dataTask.Exception); } if (dataTask.Result.ChildrenCount > 0) { foreach (var item in dataTask.Result.Children) { Debug.Log("multiple data found: " + item.GetRawJsonValue()); onLoadedDelegate(item.GetRawJsonValue()); break; } } else { onLoadedDelegate(jsonData); } }
public static void LoadLevel(string sceneName, bool isAsync = false, bool isAdditive = false, OnLoadedDelegate onLoaded = null) { if (m_OnLoaded.ContainsKey (sceneName)) { Debug.LogWarning ("Loaded this scene before. Please check again."); return; } m_OnLoaded.Add(sceneName, onLoaded); if (!isAsync) { if (isAdditive) Application.LoadLevelAdditive (sceneName); else Application.LoadLevel (sceneName); } else { if (isAdditive) Application.LoadLevelAdditiveAsync (sceneName); else Application.LoadLevelAsync (sceneName); } }
public static void LoadLevelAdditive(string sceneName, bool isAsync = false, OnLoadedDelegate onLoaded = null) { m_OnLoaded = onLoaded; if (!isAsync) { Application.LoadLevelAdditive (sceneName); } else { Application.LoadLevelAdditiveAsync (sceneName); } }
public static void LoadLevelAdditive(string sceneName, bool isAsync = false, OnLoadedDelegate onLoaded = null) { m_OnLoaded = onLoaded; if (!isAsync) { Application.LoadLevelAdditive(sceneName); } else { Application.LoadLevelAdditiveAsync(sceneName); } }
//loads the data at "path" then returns json result to the delegate/callback function public IEnumerator LoadData(string path, OnLoadedDelegate onLoadedDelegate) { var dataTask = db.RootReference.Child(path).GetValueAsync(); yield return(new WaitUntil(() => dataTask.IsCompleted)); if (dataTask.Exception != null) { Debug.LogWarning(dataTask.Exception); } string jsonData = dataTask.Result.GetRawJsonValue(); onLoadedDelegate(jsonData); }
IEnumerator Load(string assetBundlePath, string assetBundleName, OnLoadedDelegate loadedDelegate, object param) { //如果模型字典中已经存在模型了,就可以直接加载 if (objectList.ContainsKey(assetBundlePath + "/" + assetBundleName)) { //返回(模型,参数) loadedDelegate(objectList[assetBundlePath + "/" + assetBundleName], param); yield break; } //在指定文件夹中加载模型,这个根据打包时指定的打包位置有关 Application.streamingAssetsPath当前文件中StreamingAssets文件夹 WWW www = new WWW("file:///" + Application.streamingAssetsPath + "/AssetBundle" + "/Windows/" + assetBundlePath); yield return(www); AssetBundle bundle = www.assetBundle; //bundle中可能包含不只一个模型 Object target = bundle.LoadAsset(assetBundleName); //在模型的字典中添加模型,方便下次加载 objectList.Add(assetBundlePath + "/" + assetBundleName, target); //返回(模型,参数) loadedDelegate(target, param); }
public static void LoadLevel(string sceneName, bool isAsync = false, bool isAdditive = false, OnLoadedDelegate onLoaded = null) { if (m_OnLoaded.ContainsKey(sceneName)) { Debug.LogWarning("Loaded this scene before. Please check again."); return; } m_OnLoaded.Add(sceneName, onLoaded); if (!isAsync) { if (isAdditive) { Application.LoadLevelAdditive(sceneName); } else { Application.LoadLevel(sceneName); } } else { if (isAdditive) { Application.LoadLevelAdditiveAsync(sceneName); } else { Application.LoadLevelAsync(sceneName); } } }
public static void LoadLevel(string sceneName, bool isAsync = false, bool isAdditive = false, OnLoadedDelegate onLoaded = null) { if (m_OnLoaded.ContainsKey(sceneName)) { Debug.LogWarning("Loaded this scene before. Please check again."); return; } m_OnLoaded.Add(sceneName, onLoaded); #if UNITY_5_2 || UNITY_5_1 || UNITY_5_0 || UNITY_4_6 if (!isAsync) { if (isAdditive) { Application.LoadLevelAdditive(sceneName); } else { Application.LoadLevel(sceneName); } } else { if (isAdditive) { Application.LoadLevelAdditiveAsync(sceneName); } else { Application.LoadLevelAsync(sceneName); } } #else if (!isAsync) { if (isAdditive) { UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName, UnityEngine.SceneManagement.LoadSceneMode.Additive); } else { UnityEngine.SceneManagement.SceneManager.LoadScene(sceneName, UnityEngine.SceneManagement.LoadSceneMode.Single); } } else { if (isAdditive) { UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName, UnityEngine.SceneManagement.LoadSceneMode.Additive); } else { UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName, UnityEngine.SceneManagement.LoadSceneMode.Single); } } #endif }