public static void Load( string name, bool placeInSceneWhenLoaded = true, bool destroyAllAssets = true ) { LoadContentInfo info = new LoadContentInfo(); info.pathOrUrlToAsset = name; info.placeInSceneWhenLoaded = placeInSceneWhenLoaded; info.destroyAssetsInCurrentScene = destroyAllAssets; Load( info ); }
public static void Load(string name, bool placeInSceneWhenLoaded = true, bool destroyAllAssets = true) { LoadContentInfo info = new LoadContentInfo(); info.pathOrUrlToAsset = name; info.placeInSceneWhenLoaded = placeInSceneWhenLoaded; info.destroyAssetsInCurrentScene = destroyAllAssets; Load(info); }
public static void Load( LoadContentInfo info ) { if( !instance ) { Error("VirgoLoader::>>Error: There's no a instance of Loader in scene!"); return; } if( info == null || info.pathOrUrlToAsset == null || info.pathOrUrlToAsset == "" ) { Error("VirgoLoader::>> Path to asset null or empty"); return; } string currentPath = info.pathOrUrlToAsset; bool isUrl = isURL( currentPath ); bool isScene = isSceneFile( currentPath ); if( !isUrl && !isScene ) { currentPath = "file://" + info.pathOrUrlToAsset; } /* if( isUrl && isScene ) Debug.Log("VirgoLoader::>> Trying to load a scene in web"); else if( isUrl && !isScene ) Debug.Log("VirgoLoader::>> Trying to load a bundle in web"); else if( !isUrl && isScene ) Debug.Log("VirgoLoader::>> Trying to load a local scene"); else if( !isUrl && !isScene ) Debug.Log("VirgoLoader::>> Trying to load a local bundle"); */ instance.OnLoadedAssetsBegin(new EventArgs()); instance.StartCoroutine( _Load( currentPath, isScene, info) ); }
public static void Load(LoadContentInfo info) { if (!instance) { Error("VirgoLoader::>>Error: There's no a instance of Loader in scene!"); return; } if (info == null || info.pathOrUrlToAsset == null || info.pathOrUrlToAsset == "") { Error("VirgoLoader::>> Path to asset null or empty"); return; } string currentPath = info.pathOrUrlToAsset; bool isUrl = isURL(currentPath); bool isScene = isSceneFile(currentPath); if (!isUrl && !isScene) { currentPath = "file://" + info.pathOrUrlToAsset; } /* * if( isUrl && isScene ) * Debug.Log("VirgoLoader::>> Trying to load a scene in web"); * else * if( isUrl && !isScene ) * Debug.Log("VirgoLoader::>> Trying to load a bundle in web"); * else * if( !isUrl && isScene ) * Debug.Log("VirgoLoader::>> Trying to load a local scene"); * else * if( !isUrl && !isScene ) * Debug.Log("VirgoLoader::>> Trying to load a local bundle"); */ instance.OnLoadedAssetsBegin(new EventArgs()); instance.StartCoroutine(_Load(currentPath, isScene, info)); }
static IEnumerator _Load( string path, bool isScene, LoadContentInfo info ) { AssetBundle bundle = new AssetBundle(); if( !isScene ) { #if !UNITY_WEBPLAYER if( !FileExistLocally( path ) ) { Debug.Log("VirgoLoader::>>Downloading : " + path); WWW www = new WWW( path ); while( www.isDone == false ) { instance.percent = www.progress * 100; yield return null; } instance.percent = 100f; if( www.error != null ) { instance.OnLoadedAssetsError(new EventArgs()); Error("VirgoLoader::>>Error: " + www.error ); } else bundle = www.assetBundle; if(info.saveLocallyWhenBundle ) _SaveLocally( www ); } else { instance.StartCoroutine(LoadLocalFile( path )); } #endif #if UNITY_WEBPLAYER Debug.Log("Loader (WebPlayer)::>>Downloading : " + path); WWW www = new WWW( path ); while( www.isDone == false ) { instance.percent = www.progress * 100; yield return null; } instance.percent = 100f; if( www.error != null ) { instance.OnLoadedAssetsError(new EventArgs()); Error("VirgoLoader::>>Error: " + www.error ); } else bundle = www.assetBundle; #endif } else { Debug.Log("VirgoLoader::>>Loading scene locally : " + path ); AsyncOperation operation; if(!info.destroyAssetsInCurrentScene ) { operation = Application.LoadLevelAdditiveAsync( path ); } else { operation = Application.LoadLevelAsync( path ); } operation.allowSceneActivation = info.placeInSceneWhenLoaded; while( operation.progress < 1 ) { instance.percent = operation.progress * 100; yield return null; } instance.percent = 100f; } if( info.placeInSceneWhenLoaded && bundle != null) { if(!isScene) { Instantiate( bundle.mainAsset ); bundle.Unload(false); } } instance.OnLoadedAssetsComplete( new EventArgs()); }
static IEnumerator _Load(string path, bool isScene, LoadContentInfo info) { AssetBundle bundle = new AssetBundle(); if (!isScene) { #if !UNITY_WEBPLAYER if (!FileExistLocally(path)) { Debug.Log("VirgoLoader::>>Downloading : " + path); WWW www = new WWW(path); while (www.isDone == false) { instance.percent = www.progress * 100; yield return(null); } instance.percent = 100f; if (www.error != null) { instance.OnLoadedAssetsError(new EventArgs()); Error("VirgoLoader::>>Error: " + www.error); } else { bundle = www.assetBundle; } if (info.saveLocallyWhenBundle) { _SaveLocally(www); } } else { instance.StartCoroutine(LoadLocalFile(path)); } #endif #if UNITY_WEBPLAYER Debug.Log("Loader (WebPlayer)::>>Downloading : " + path); WWW www = new WWW(path); while (www.isDone == false) { instance.percent = www.progress * 100; yield return(null); } instance.percent = 100f; if (www.error != null) { instance.OnLoadedAssetsError(new EventArgs()); Error("VirgoLoader::>>Error: " + www.error); } else { bundle = www.assetBundle; } #endif } else { Debug.Log("VirgoLoader::>>Loading scene locally : " + path); AsyncOperation operation; if (!info.destroyAssetsInCurrentScene) { operation = Application.LoadLevelAdditiveAsync(path); } else { operation = Application.LoadLevelAsync(path); } operation.allowSceneActivation = info.placeInSceneWhenLoaded; while (operation.progress < 1) { instance.percent = operation.progress * 100; yield return(null); } instance.percent = 100f; } if (info.placeInSceneWhenLoaded && bundle != null) { if (!isScene) { Instantiate(bundle.mainAsset); bundle.Unload(false); } } instance.OnLoadedAssetsComplete(new EventArgs()); }