void OnGUI() { //if can destroy dependence asset if (GUI.Button(new Rect(0, 0, 100, 40), "Clean Common")) { AssetBundleMgr.UnLoadAssetBundle("common"); } //still can't destroy dependence asset if (GUI.Button(new Rect(0, 50, 100, 40), "Clean test")) { AssetBundleMgr.UnLoadAssetBundle("test"); } //destroy "test2", also destroy destroy dependence if (GUI.Button(new Rect(0, 100, 100, 40), "Clean test2")) { AssetBundleMgr.UnLoadAssetBundle("test2"); } if (GUI.Button(new Rect(0, 150, 100, 40), "load")) { AssetBundle t1 = AssetBundleMgr.GetAssetBundle("test"); Object cube = t1.LoadAsset("Cube"); GameObject go = Instantiate(cube) as GameObject; go.transform.position = Vector3.left; AssetBundle t2 = AssetBundleMgr.GetAssetBundle("test2"); Object sphere = t2.LoadAsset("sphere"); Instantiate(sphere); } }
/// <summary> /// Important: paramName must include extension, for example "tank.prefab" /// </summary> /// <param name="paramFolder"></param> /// <param name="paramName"></param> /// <returns></returns> public T GetObj <T>(string param) where T : UnityEngine.Object { int tempIndex = param.LastIndexOf("__"); string paramFolder = param.Substring(0, tempIndex); paramFolder = paramFolder.Replace("__", "/"); string paramName = param.Substring(tempIndex + 1); #if UNITY_EDITOR var temp = "Assets/" + paramFolder + "/" + paramName; return(AssetDatabase.LoadAssetAtPath <T>(temp)); #endif paramFolder = paramFolder.Replace("/", ""); paramFolder = paramFolder.ToLower(); paramName = paramName.Remove(paramName.LastIndexOf(".")); paramName = paramName.ToLower(); AssetBundle tempAB = AssetBundleMgr.GetAssetBundle(paramFolder); if (tempAB != null && tempAB.Contains(paramName)) { return(tempAB.LoadAsset <T>(paramName)); } Debug.LogError("the things you want to load is null"); return(null); }