/// <summary> /// 刷新shader /// </summary> /// <param name="assetBundle"></param> public static void RefreshShader(AssetBundle assetBundle) { #if UNITY_5 UnityEngine.Material[] materials = assetBundle.LoadAllAssets<Material>(); #else UnityEngine.Object[] materials = assetBundle.LoadAll(typeof(Material)); //LoadAll<Material>(); #endif foreach (UnityEngine.Object m in materials) { Material mat = m as Material; string shaderName = mat.shader.name; Shader newShader = Shader.Find(shaderName); if (newShader != null) { mat.shader = newShader; } else { Debug.LogWarning("unable to refresh shader: " + shaderName + " in material " + m.name); } } }
/// <summary> /// Load vehicle bundles and return vehicles prefabs /// </summary> /// <param name="bundles">Bundles required to be loaded</param> /// <returns>Loaded vehicles prefabs</returns> /// <exception cref="Exception">Could not load vehicle from the asset bundle</exception> private GameObject[] LoadVehicleBundles(List <string> bundles) { return(bundles.Select(bundle => { using (ZipFile zip = new ZipFile(bundle)) { Manifest manifest; ZipEntry entry = zip.GetEntry("manifest"); using (var ms = zip.GetInputStream(entry)) { int streamSize = (int)entry.Size; byte[] buffer = new byte[streamSize]; streamSize = ms.Read(buffer, 0, streamSize); manifest = new Deserializer().Deserialize <Manifest>( Encoding.UTF8.GetString(buffer, 0, streamSize)); } AssetBundle textureBundle = null; if (zip.FindEntry($"{manifest.assetGuid}_vehicle_textures", true) != -1) { var texStream = zip.GetInputStream(zip.GetEntry($"{manifest.assetGuid}_vehicle_textures")); textureBundle = AssetBundle.LoadFromStream(texStream, 0, 1 << 20); } string platform = SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows ? "windows" : "linux"; var mapStream = zip.GetInputStream(zip.GetEntry($"{manifest.assetGuid}_vehicle_main_{platform}")); var vehicleBundle = AssetBundle.LoadFromStream(mapStream, 0, 1 << 20); if (vehicleBundle == null) { throw new Exception($"Failed to load '{bundle}' vehicle asset bundle"); } try { var vehicleAssets = vehicleBundle.GetAllAssetNames(); if (vehicleAssets.Length != 1) { throw new Exception($"Unsupported '{bundle}' vehicle asset bundle, only 1 asset expected"); } textureBundle?.LoadAllAssets(); return vehicleBundle.LoadAsset <GameObject>(vehicleAssets[0]); } finally { textureBundle?.Unload(false); vehicleBundle.Unload(false); } } }).ToArray()); }
public List <TAsset> LoadAll <TAsset>() where TAsset : Object { var assets = _assetBundle.LoadAllAssets <TAsset>().ToList(); ////#if UNITY_EDITOR //// AnalyzeProfiler?.AddAssetToBundleRef(BundleId, BundleId); ////#endif return(assets); }
void LoadFullSprites() { sprites = assetBundle.LoadAllAssets <Sprite>(); fullSpriteDict = new Dictionary <string, Sprite>(); for (int i = 0; i < sprites.Length; i++) { fullSpriteDict.Add(sprites[i].name, sprites[i]); } }
static void OnSharedComplete(CRequest req, AssetBundle ab) // repaire IOS crash bug when scene assetbundle denpendency sprite atlas assetbundle { #if HUGULA_ASSETBUNDLE_LOG || UNITY_EDITOR //AddUpLogInfo(string.Format("{0}\t{1}\t{2}", req.key, System.DateTime.Now.ToString(), Time.frameCount)); #endif if (ab && req.isShared && !specialAssetbundles.Contains(req.key)) { ab.LoadAllAssets(); } }
public T[] LoadAllAssets <T>(string url) where T : Object { AssetBundle bundle = _assetDownLoader.GetAssetBundle(url); if (bundle != null) { return(bundle.LoadAllAssets <T>()); } return(null); }
private void Start() { AssetBundle ab = AssetBundle.LoadFromFile("AssetBundles/scene/cubewall.unity3d"); GameObject[] gos = ab.LoadAllAssets <GameObject>(); foreach (var item in gos) { Instantiate(item); } }
/// <summary> /// 同步-加载所有asset资源 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="assetPath"></param> /// <returns></returns> public static List <T> SyncLoadAllAsset <T>(string assetPath) where T : Object { assetPath = assetPath.ToLower(); assetPath = PathURL + assetPath; AssetBundle assetBundle = AssetBundle.LoadFromFile(assetPath); T[] dataArray = assetBundle.LoadAllAssets <T>(); assetBundle.Unload(false); return(dataArray.ToList()); }
IEnumerator LoadAssetBundle(bool isAdditive) { /* Debug.Log("file://" + Application.streamingAssetsPath.Replace("/Load/", "/Lighting/") + "/Android/test/light"); * * WWW lightwww = new WWW("file://" + Application.streamingAssetsPath.Replace("/Load/", "/Lighting/") + "/Android/test/light"); * * yield return lightwww; * * AssetBundle bundle = lightwww.assetBundle; * * Object[] objects = bundle.LoadAllAssets(); * * * objs.AddRange(objects);*/ List <Object> objs = new List <Object>(); Debug.Log("file://" + Application.streamingAssetsPath.Replace("/Load/", "/Lighting/") + "/Android/test/skybox"); WWW skyboxwww = new WWW("file://" + Application.streamingAssetsPath.Replace("/Load/", "/Lighting/") + "/Android/test/skybox"); yield return(skyboxwww); AssetBundle skyboxbundle = skyboxwww.assetBundle; Object[] skyboxes = skyboxbundle.LoadAllAssets(); objs.AddRange(skyboxes); publicObjects = objs.ToArray(); Debug.Log(skyboxes.Length); foreach (Object obj in publicObjects) { Debug.Log("obj=" + obj.name); Debug.Log("objtype=" + obj.GetType().ToString()); } Debug.Log("file://" + Application.streamingAssetsPath.Replace("/Load/", "/Lighting/") + "/Android/test/scene"); WWW scenewww = new WWW("file://" + Application.streamingAssetsPath.Replace("/Load/", "/Lighting/") + "/Android/test/scene"); yield return(scenewww); AssetBundle scenebundle = scenewww.assetBundle; Debug.Log("LoadScene"); if (isAdditive) { yield return(SceneManager.LoadSceneAsync("LightingScene", LoadSceneMode.Additive)); } else { SceneManager.LoadSceneAsync("LightingScene"); } }
private void LoadShaders() { string kethane_bundle = "kethane-linux.ksp"; switch (Environment.OSVersion.Platform) { case PlatformID.Win32NT: kethane_bundle = "kethane-windows.ksp"; break; case PlatformID.MacOSX: kethane_bundle = "kethane-macosx.ksp"; break; case PlatformID.Unix: kethane_bundle = "kethane-linux.ksp"; break; default: Debug.LogFormat("[Kethane] unknown platform: {0}", Environment.OSVersion.Platform); break; } if (shaderDictionary == null) { shaderDictionary = new Dictionary <string, Shader>(); string root = KSPUtil.ApplicationRootPath; string url = "file://" + root + gamedata + kethane_bundle; using (WWW www = new WWW(url)) { if (www.error != null) { Debug.LogFormat("[Kethane] {0} not found!", kethane_bundle); return; } AssetBundle bundle = www.assetBundle; Shader[] shaders = bundle.LoadAllAssets <Shader>(); foreach (Shader shader in shaders) { Debug.LogFormat("[Kethane] Shader {0} loaded", shader.name); shaderDictionary[shader.name] = shader; } bundle.Unload(false); www.Dispose(); } loaded = true; } }
static void CheckBundle() { BundleConfiguration configuration = (BundleConfiguration)Resources.Load("BundleConfig"); if (configuration.bundleName.Contains(".unity3d")) { configuration.bundleName = configuration.bundleName.Substring(0, configuration.bundleName.IndexOf(".unity3d")); } string file = configuration.bundlePlatform == TargetPlatform.Android ? configuration.bundleName + "_android.unity3d" : configuration.bundleName + "_ios.unity3d"; string filePath = Path.Combine(characterOutputPath, configuration.bundleName + "/" + file); if (!File.Exists(filePath)) { Debug.LogError("Failed to find bundle: " + filePath); return; } AssetBundle assetBundle = AssetBundle.LoadFromFile(filePath); if (assetBundle == null) { Debug.Log("Failed to load AssetBundle!"); return; } string[] assetNameList = assetBundle.GetAllAssetNames(); foreach (string name in assetNameList) { Debug.Log(name); } TextAsset[] configurationFiles = assetBundle.LoadAllAssets <TextAsset>(); if (configurationFiles.Length == 1) { Debug.Log("YOUR BUNDLE IS VALID !"); } else { if (configurationFiles.Length == 0) { Debug.LogError("Configuration file not found. Please create a configuration file name_config.json"); } else { Debug.LogError("Too much configuration files found... Just one supported actually"); foreach (TextAsset txt in configurationFiles) { Debug.Log("File: " + txt.name); } } } assetBundle.Unload(false); }
void LoadedAB(AssetBundle ab, string name) { if (ab != null) { objArray = ab.LoadAllAssets(); } else { Debug.Log("<color=red>Need Parser AssetBundle is null</color>"); } }
public void LoadAllAsset() { state = ESourceState.Loading; bundle = AssetBundle.LoadFromFile(assetPath); allAssets = bundle.LoadAllAssets(); if (allAssets.Length > 0) { mainAsset = allAssets[0]; } state = ESourceState.Loaded; }
private void LoadBundleAssets() { Debug.Log("[BDArmory] Loading bundle data"); AssetBundle shaderBundle = AssetBundle.LoadFromFile(BundlePath); if (shaderBundle != null) { Shader[] shaders = shaderBundle.LoadAllAssets <Shader>(); IEnumerator <Shader> shader = shaders.AsEnumerable().GetEnumerator(); while (shader.MoveNext()) { if (shader.Current == null) { continue; } Debug.Log($"[BDArmory] Shader \"{shader.Current.name}\" loaded. Shader supported? {shader.Current.isSupported}"); switch (shader.Current.name) { case "BDArmory/Particles/Bullet": BulletShader = shader.Current; break; case "Custom/Unlit Black": UnlitBlackShader = shader.Current; break; case "Hidden/Grayscale Effect": GrayscaleEffectShader = shader.Current; break; case "Custom/rcsShader": RCSShader = shader.Current; break; default: Debug.Log($"[BDArmory] Not expected shader : {shader.Current.name}"); break; } } shader.Dispose(); //yield return null; Debug.Log("[BDArmory] unloading bundles"); shaderBundle.Unload(false); // unload the raw asset bundle } else { Debug.Log("[BDArmory] Error: Found no asset bundle to load"); } //yield return null; }
///////////////////////////////////////////////////////////////////////////////////////////////////////// public UnityEngine.Object LoadAsset(string strObjName, AssetBundle ab) { if (ab == null) { return(null); } //临时做法 GameObject[] gos = ab.LoadAllAssets <GameObject>(); return(gos[0]); // return ab.LoadAsset(strObjName); }
public void LoadOneBundle(string assetBundleName) { ABInfo abInfo; if (this.bundles.TryGetValue(assetBundleName, out abInfo)) { ++abInfo.RefCount; return; } if (this.cacheDictionary.ContainsKey(assetBundleName)) { abInfo = this.cacheDictionary[assetBundleName]; ++abInfo.RefCount; this.bundles[assetBundleName] = abInfo; this.cacheDictionary.Remove(assetBundleName); return; } if (!Define.IsAsync) { string[] realPath = null; #if UNITY_EDITOR realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName); foreach (string s in realPath) { string assetName = Path.GetFileNameWithoutExtension(s); string path = $"{assetBundleName}/{assetName}".ToLower(); UnityEngine.Object resource = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s); this.resourceCache[path] = resource; } this.bundles[assetBundleName] = new ABInfo(assetBundleName, null); #endif return; } AssetBundle assetBundle = AssetBundle.LoadFromFile(Path.Combine(PathHelper.AppHotfixResPath, assetBundleName)); if (!assetBundle.isStreamedSceneAssetBundle) { // 异步load资源到内存cache住 UnityEngine.Object[] assets = assetBundle.LoadAllAssets(); foreach (UnityEngine.Object asset in assets) { string path = $"{assetBundleName}/{asset.name}".ToLower(); this.resourceCache[path] = asset; } } this.bundles[assetBundleName] = new ABInfo(assetBundleName, assetBundle); }
public void LoadOneBundle(string assetBundleName) { ABInfo abInfo; if (bundles.TryGetValue(assetBundleName, out abInfo)) { ++abInfo.RefCount; return; } if (!Define.IsAsync) { string[] realPath = null; #if UNITY_EDITOR realPath = AssetDatabase.GetAssetPathsFromAssetBundle(assetBundleName); foreach (string s in realPath) { string assetName = Path.GetFileNameWithoutExtension(s); UnityEngine.Object resource = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(s); AddResource(assetBundleName, assetName, resource); } abInfo = ComponentFactory.CreateWithParent <ABInfo, string, AssetBundle>(this, assetBundleName, null); abInfo.Parent = this; bundles[assetBundleName] = abInfo; #endif return; } string p = Path.Combine(PathHelper.AppResPath, assetBundleName); AssetBundle assetBundle = null; if (File.Exists(p)) { assetBundle = AssetBundle.LoadFromFile(p); } else { p = Path.Combine(PathHelper.AppResPath, assetBundleName); assetBundle = AssetBundle.LoadFromFile(p); } if (assetBundle == null) { throw new Exception($"assets bundle not found : {assetBundleName}"); } if (!assetBundle.isStreamedSceneAssetBundle) { UnityEngine.Object[] assets = assetBundle.LoadAllAssets(); foreach (UnityEngine.Object asset in assets) { AddResource(assetBundleName, asset.name, asset); } } }
public static void Open() { Object[] objs = Selection.objects; if (objs != null && objs.Length != 0) { for (int i = 0; i < objs.Length; i++) { Object obj = objs[i]; string path = AssetDatabase.GetAssetPath(obj); //if (path.EndsWith(".assetbundle") == false && path.EndsWith(".unity3d") == false&& path.EndsWith(""))//.unity3d //{ // Debug.Log(path + " 不是.AssetBundle .unity3d"); // continue; //} //else //{ FileStream fs = File.OpenRead(Application.absoluteURL + path); byte[] bytes = new byte[fs.Length]; fs.Read(bytes, 0, (int)fs.Length); string name = Path.GetFileNameWithoutExtension(path); AssetBundle ab = AssetBundle.LoadFromMemory(bytes); Object[] gameObj = ab.LoadAllAssets(); if (gameObj == null) { Debug.LogError(path + " 不是AssetBundle"); ab.Unload(false); continue; } Object go = null; for (int k = 0; k < gameObj.Length; k++) { if (gameObj[k].GetType() == typeof(GameObject)) { go = gameObj[k]; } } if (go == null) { Debug.LogError(path + " AssetBundle不是GameObject"); ab.Unload(false); return; } GameObject instatObj = GameObject.Instantiate(go) as GameObject; ab.Unload(false); } //} } else { Debug.Log("未选中assetBundle"); } }
public static void Init(string resourceNamespace) { if (_initCalled) { return; } _initCalled = true; Resource.Namespace = resourceNamespace; AssetBundle bundle = AssetBundle.LoadFromMemory(Resource.DefaultResourceKOI); var sprites = bundle.LoadAllAssets <Sprite>(); for (var i = 0; i < sprites.Length; i++) { Sprite sprite = sprites[i]; switch (sprite.name) { case "Background": backgroundSprite = sprite; break; case "UISprite": standardSprite = sprite; break; case "InputFieldBackground": inputFieldBackground = sprite; break; case "Knob": knob = sprite; break; case "Checkmark": checkMark = sprite; break; case "DropdownArrow": dropdownArrow = sprite; break; case "UIMask": mask = sprite; break; } } defaultFont = Resources.GetBuiltinResource <Font>("Arial.ttf"); resources = new DefaultControls.Resources { background = backgroundSprite, checkmark = checkMark, dropdown = dropdownArrow, inputField = inputFieldBackground, knob = knob, mask = mask, standard = standardSprite }; defaultFontSize = 16; bundle.Unload(false); }
public void InitMap(AssetBundle assetbundle) { Object[] ts = assetbundle.LoadAllAssets <Object>(); GameObject obj = ts[0] as GameObject; this.dispatcher.Set("tileMap", obj); this.dispatcher.Set("camera3d", camera3d); Model.Scriptable.MapAsset mapAsset = ts[1] as Model.Scriptable.MapAsset; this.dispatcher.Set("map", mapAsset.map.tiles); assetbundle.Unload(false); }
GameObject LoadPrefabFromAssetBundle(AssetBundle bundle) { Debug.Log("bundle!"); var prefab = bundle.LoadAllAssets <GameObject>()[0]; Debug.Log("bundle2:" + prefab.name); var go = GameObject.Instantiate(prefab.gameObject); return(go); }
//void OnEnable() //{ // SpriteAtlasManager.atlasRequested += RequestAtlas; //} //void OnDisable() //{ // SpriteAtlasManager.atlasRequested -= RequestAtlas; //} void Start() { AssetBundle currentSelectedBundle = AssetBundle.LoadFromFile(Application.dataPath + "/../AssetBundles_Standalone/abtag20"); Object[] objs = currentSelectedBundle.LoadAllAssets(); foreach (var x in objs) { Object.Instantiate(x); } }
IEnumerator LoadBundles() { while (!Caching.ready) { yield return(null); } using (WWW www = WWW.LoadFromCacheOrDownload(BundleURL, version)) { Debug.Log("Sound Bundle URL => " + BundleURL); yield return(www); if (www.error != null) { Debug.Log("WWW 다운로드에 에러가 생겼습니다.:" + www.error); } AssetBundle bundle = www.assetBundle; Object[] SoundLoad = bundle.LoadAllAssets(); Dictionary <SoundManager.SoundName, AudioClip> Audio = new Dictionary <SoundManager.SoundName, AudioClip>(); for (int i = 0; i < SoundLoad.Length; i++) { AudioClip audio = (AudioClip)SoundLoad[i]; SoundManager.SoundName name = SoundManager.SoundName.MAX; if (Utils.IsEnumParseName(typeof(SoundManager.SoundName), audio.name)) { name = (SoundManager.SoundName)System.Enum.Parse(typeof(SoundManager.SoundName), audio.name); } else { name = SoundManager.SoundName.MAX; } if (name != SoundManager.SoundName.MAX) { Audio.Add(name, audio); } else { Debug.LogError("SoundName Error! => " + audio.name); } } SoundManager.instance.m_AudioClip = Audio; bundle.Unload(false); www.Dispose(); GameDefine.IsLoadAssetBundleOK = true; Debug.Log("sound sucess"); } }
public static void LoadAnimations() { AssetBundle ab = AssetBundle.LoadFromFile(ASSET_BUNDLE_LOCATION); if (ab == null) { Log.Error("Custom Player Animations asset bundle not found."); } AnimationControllers = new List <RuntimeAnimatorController>(ab.LoadAllAssets <RuntimeAnimatorController>()); }
public override T[] GetAssets <T>() { if (m_Request != null && m_Request.isDone) { return(m_AssetBundle.LoadAllAssets <T>()); } else { return(null); } }
public void LoadLevelBundleFromFile(string levelName, string url) { AssetBundle assetBundle = AssetBundle.CreateFromFile(url); if (assetBundle.LoadAllAssets() != null) { Application.LoadLevel(levelName); } assetBundle.Unload(false); }
void Extract() { AssetRefs.Clear(); ab = AssetBundle.LoadFromFile(SourcePath + BundleName); Debug.Log(string.Join(", ", ab.GetAllAssetNames())); var assets = ab.LoadAllAssets(); AssetRefs.AddRange(assets); }
private void SetupPrefabsAndPortraitsList(string bundleName) { WWW www = WWW.LoadFromCacheOrDownload("file://" + CharacterEditor.charactersModelsPath + bundleName, 1); if (www == null || www.assetBundle == null) { return; } AssetBundle bundle = www.assetBundle; // Load all prefabs to filter game objects with animations prefabs = bundle.LoadAllAssets <GameObject>(); List <string> prefabNames = new List <string>(prefabs.Length); foreach (GameObject prefab in prefabs) { if (prefab.GetComponent <Animator>() != null) { prefabNames.Add(prefab.name); } } // Load resources bundleSprites = new List <Sprite>(bundle.LoadAllAssets <Sprite>()); List <string> spriteNames = new List <string>(prefabs.Length); foreach (Sprite sprite in bundleSprites) { spriteNames.Add(sprite.name); } _prefabsList.Options = prefabNames; _portraitDropdown.ClearOptions(); _portraitDropdown.AddOptions(spriteNames); if (prefabNames.Count == 0) { _addButton.interactable = false; } www.assetBundle.Unload(false); }
public void LoadAllAsset() { AssetBundle bundle = _www.assetBundle; GameObject[] assetsObjs = bundle.LoadAllAssets <GameObject>(); for (int i = 0; i < assetsObjs.Length; ++i) { GameObject obj = assetsObjs[i]; _dicAssets.Add(obj.name, obj); } }
void Start() { espColor.normal.textColor = Color.red; AssetBundle bundle = AssetBundle.LoadFromFile(Path.Combine(AssemblyDirectory, "shaders")); bundle.LoadAllAssets <Shader>(); silBumpedDiffuseMat = bundle.LoadAsset <Material>("SBD"); bumpedDiffuseMat = bundle.LoadAsset <Material>("BD"); bundle = AssetBundle.LoadFromFile(Path.Combine(AssemblyDirectory, "metalgui")); this.skin = bundle.LoadAsset <GUISkin>("MetalGUISkin"); }
// 加载指定路径下的文本 private static string LoadAsset(string assetName) { string configPath = AssetBundleConst.GetAbResDirectory() + assetName; AssetBundle ab = AssetBundle.LoadFromFile(configPath); Object obj = ab.LoadAllAssets()[0]; TextAsset textasset = obj as TextAsset; string result = textasset.text; ab.Unload(true); ab = null; return(result); }
private IEnumerator Download(string url) { // Start a download of the given URL //Random argument added to the back of the URL to prevent caching string randomValue = "?t=" + Random.value; url += randomValue; www = new WWW(url); isDownloading = true; downloadStatus.color = Color.black; // Wait for download to complete yield return www; isDownloading = false; if (www.error != null) { Debug.Log(www.error); downloadStatus.text = www.error; } // Load and retrieve the AssetBundle bundle = www.assetBundle; if (bundle == null) { downloadStatus.color = Color.red; downloadStatus.text = DOWNLOAD_FAIL_MESSAGE; } // Load all the objects Object[] assetbundlesObject = bundle.LoadAllAssets(); foreach (Object o in assetbundlesObject) { objectCollection.AddGameObjects((GameObject)o); } objectCollection.PrepareUserObjects(); // Unload the AssetBundles compressed contents to conserve memory bundle.Unload(false); // Frees the memory from the web stream www.Dispose(); downloadStatus.color = Color.blue; downloadStatus.text = DOWNLOAD_PASS_MESSAGE; }
public void LoadExtraInstruments(AssetBundle bundle) { AudioClip[] extraInstrumentsClips = bundle.LoadAllAssets<AudioClip>(); LoadExtraInstruments(extraInstrumentsClips); }
private void HandleAssetBundle(RPCSerializer rpcData) { int index = (int) rpcData.args[0]; if (index == -1) { sceneBundle = AssetBundle.LoadFromMemory (data); sceneBundle.LoadAllAssets (); string[] scenes = sceneBundle.GetAllScenePaths (); string mySceneName = scenes[0]; mySceneName = mySceneName.Substring(0, mySceneName.Length - 6); //remove .unity mySceneName = mySceneName.Substring(mySceneName.LastIndexOf("/") + 1); //remove path SceneManager.LoadScene (mySceneName); } else if (index == 0) { data = new byte[ (int) rpcData.args[1] ] ; if (sceneBundle != null) { SceneManager.LoadScene (1); sceneBundle.Unload (true); } } else { int start = (int)rpcData.args [1]; byte[] bData = (byte[] )rpcData.args [2]; for (int i = 0; i < bData.Length; i++) { data [i + start] = bData [i]; } } }
public override void OnXGUI() { //TODO List if(Selection.objects != null && Selection.objects.Length > 0){ selectedObject = Selection.objects[0]; } if(CreateSpaceButton("Packing Selected Objects")){ Object[] objects = Selection.objects; string path = EditorUtility.SaveFilePanel("Create A Bundle", AssetDatabase.GetAssetPath(objects[0]), "newbundle.assetbundle", "assetbundle"); if (path == "") return; CreateXMLWithDependencies(objects, path); BuildPipeline.BuildAssetBundle( null, objects, path , BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.UncompressedAssetBundle | BuildAssetBundleOptions.DeterministicAssetBundle, BuildTarget.Android); } if(CreateSpaceButton("GetObject")){ string path = EditorUtility.OpenFilePanel("Open A Bundle", Application.streamingAssetsPath, "" ); if (path == "") return; _bundlepath = "file://" + path; LoadingConfig = true; asset = null; // AssetDatabase.Refresh(); if(currBundle != null){ currBundle.Unload(true); } } if(CreateSpaceButton("Clean Cache")){ currentBundleObjects = null; Caching.CleanCache(); } if( LoadingConfig ){ XLogger.Log("start loading"); if( null == asset ) asset = new WWW(_bundlepath); LoadingConfig = false; } // Logger.Log(string.Format("asset == null is {0}" , asset == null)); if(asset != null ){ // Logger.Log("asset.isDone is " + asset.isDone); // if(asset.isDone){ XLogger.Log("end loading"); currBundle = asset.assetBundle; if(currBundle == null){ CreateNotification("Selected the asset bundle 's format is error."); LoadingConfig = false; asset = null; return; } #if UNITY_5_0 currentBundleObjects = currBundle.LoadAllAssets(); #endif #if UNITY_4_6 currentBundleObjects = currBundle.LoadAll(); #endif LoadingConfig = false; asset = null; // } } if( null != currentBundleObjects ){ for (int pos = 0; pos < currentBundleObjects.Length; pos++) { CreateObjectField(currentBundleObjects[pos].GetType().ToString(),currentBundleObjects[pos]); } } if(CreateSpaceButton("Add A AssetBundle")){ allAssets.Add(new AssetBundleModel()); } if(CreateSpaceButton("Clean All AssetBundle")){ allAssets.Clear(); } if(CreateSpaceButton("Collect") && allAssets.Count > 0){ List<AssetBundleModel> AllChilds = new List<AssetBundleModel>(); sortAssets.Clear(); BundlePath = EditorUtility.SaveFolderPanel("Save Bundles", Application.streamingAssetsPath, "" ); if(BundlePath == null){ return; } BundlePath += "/"; XmlDocument xmlDoc = new XmlDocument(); XmlElement root = xmlDoc.CreateElement("root"); for(int pos = 0; pos < allAssets.Count; pos++){ if(allAssets[pos].ParentName.Equals("")){ sortAssets.Add(allAssets[pos].ModelName, allAssets[pos]); XmlElement child = xmlDoc.CreateElement(allAssets[pos].ModelName); root.AppendChild(child); }else{ AllChilds.Add(allAssets[pos]); } // allAssets.Remove(allAssets[pos]); } for(int pos = 0; pos < AllChilds.Count; pos++){ sortAssets[AllChilds[pos].ParentName].Childs.Add(AllChilds[pos]); XmlElement child = xmlDoc.CreateElement(AllChilds[pos].ModelName); root.SelectSingleNode(AllChilds[pos].ParentName).AppendChild(child); // allAssets.Remove(allAssets[pos]); } xmlDoc.AppendChild(root); xmlDoc.Save(BundlePath + "bundle.xml"); foreach(var bundle in sortAssets){ bundle.Value.PackingSelf(); } // allAssets.Clear(); AssetDatabase.Refresh(); CreateNotification("Create asset bundle success!"); } for(int pos = 0; pos < allAssets.Count; pos++){ AssetBundleModel Item = allAssets[pos]; BeginHorizontal(); Item.ModelName = CreateStringField("Name", allAssets[pos].ModelName); Item.ParentName = CreateStringField("Dependencies", allAssets[pos].ParentName); if( CreateSpaceButton("Add Asset") && null != selectedObject ){ Item.Assets.AddRange(Selection.objects); } if( CreateSpaceButton("Remove Bundle") ){ allAssets.RemoveAt(pos); } EndHorizontal(); CreateSpaceBox(); for(int idx = 0; idx < Item.Assets.Count; idx++){ BeginHorizontal(); CreateObjectField("child_" + idx, Item.Assets[idx]); if(CreateSpaceButton("Remove")){ Item.Assets.RemoveAt(idx); } EndHorizontal(); } CreateSpaceBox(); } }
private void ApplyLoadedVegetationBundle( AssetBundle bundle, string bundleName ){ Object[] objects = bundle.LoadAllAssets (typeof(Texture2D)); for ( int i = 0; i < objects.Length; i++ ){ Texture2D tex = (Texture2D)objects[i]; GameObject.Find ("AGF_TerrainManager").GetComponent<AGF_TerrainManager>().AddVegetationTextureToList( tex, bundleName ); } }
private void ApplyLoadedWarehouseBundle( AssetBundle bundle, string bundleName ){ // grab every element of the bundle, and add it to the tileList. AGF_TileListManager tileListManager = GameObject.Find ("AGF_TileListManager").GetComponent<AGF_TileListManager>(); AGF_GibManager gibManager = GameObject.Find ("AGF_GibManager").GetComponent<AGF_GibManager>(); Object[] objects = bundle.LoadAllAssets(typeof(GameObject)); for ( int i = 0; i < objects.Length; i++ ){ GameObject obj = (GameObject)objects[i]; if ( obj.GetComponent<GibProperties>() != null ){ gibManager.AddGibTolist( obj.GetComponent<GibProperties>().category, obj.GetComponent<GibProperties>().bundle, obj.transform ); } else if ( obj.GetComponent<GibSettings>() != null ){ gibManager.AddGibSettingsToList( obj.GetComponent<GibSettings>().category, obj.GetComponent<GibSettings>().bundle, obj.transform ); } else if ( obj.GetComponent<TileProperties>() != null ){ obj.GetComponent<TileProperties>().tileID += "/" + bundleName; tileListManager.AddToList( obj.GetComponent<TileProperties>().tileID, obj.transform ); } } }
/// <summary> /// /// </summary> /// <param name="ab"></param> /// <param name="luaFn"></param> public static void UnpackConfigAssetBundleFn(AssetBundle ab, LuaFunction luaFn) { callBackFn = luaFn; #if UNITY_5 UnityEngine.Object[] all = ab.LoadAllAssets(); #else UnityEngine.Object[] all = ab.LoadAll(); #endif foreach (UnityEngine.Object i in all) { if (i is TextAsset) { TextAsset a = (TextAsset)i; if (callBackFn != null) callBackFn.call(a.name, a.text); } } }