unity3d www下载资源包

先上几种打包代码,记住 BuildTarget.iPhone 

BuildTarget.Android  别混用了。


using UnityEngine;
using UnityEditor;

public class ExportAssetBundles : MonoBehaviour {

	[MenuItem("Assets/Build AssetBundle From Selection - Track dependencies")]
	static void ExportResource () {
	// Bring up save panel
	string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
	if (path.Length != 0) {
	// Build the resource file from the active selection.
	Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
	//BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets);
	BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies, BuildTarget.iPhone);
	Selection.objects = selection;
	}
	}
	
	[MenuItem("Assets/Build AssetBundle From Selection - No dependency tracking")]
	static void ExportResourceNoTrack () {
	// Bring up save panel
	string path = EditorUtility.SaveFilePanel ("Save Resource", "", "New Resource", "unity3d");
	if (path.Length != 0) {
	// Build the resource file from the active selection.
	BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, path);
	}
	}
	
	[MenuItem ("Assets/Build AssetBundle From Selection") ]
	static void ExportBundle()
	{
     string str = EditorUtility.SaveFilePanel("Save Bundle...", Application.dataPath, Selection.activeObject.name, "unity3d");
     if (str.Length != 0){
          BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, str, BuildAssetBundleOptions.CollectDependencies, BuildTarget.Android);
     }
	}
}

场景打包

@MenuItem ("Build/BuildWebplayerStreamed")
static function MyBuild(){
	var path = EditorUtility.SaveFilePanel("Build Bundle","","*","unity3d");
    var levels : String[] = ["Assets/E.unity"];
    BuildPipeline.BuildStreamedSceneAssetBundle( levels, path, BuildTarget.iPhone);
    //BuildPipeline.BuildPlayer( levels, "StreamedWebplayer.unity3d",BuildTarget.WebPlayer, BuildOptions.BuildAdditionalStreamedScenes);
}


下面是www加载场景资源包

Application.LoadLevelAdditive(scenename); 参数是打包的场景名称,不是包名称,别搞错了

	IEnumerator loadNetScene(string url,string scenename)
	{
		// Wait for the Caching system to be ready
		while (!Caching.ready)
			yield return null;

		// Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
		using(WWW www = WWW.LoadFromCacheOrDownload (url,1))
		{
			yield return www;
			if (www.error != null)
			{
				throw new Exception("WWW download had an error:" + www.error);
				//Debug.LogError(www.error);
				//yield return false;
			}
			bundle = www.assetBundle;
			Application.LoadLevelAdditive(scenename);
			yield return new WaitForSeconds(0.5f);
			www.assetBundle.Unload(false);
			Resources.UnloadUnusedAssets();
		}
			
	}

下面是www加载prefab资源包

GameObject obj = bundle.Load("prefabname",typeof(GameObject))asGameObject; "prefabname"是包内要加载的物体名字,不是包名,别搞错了

	IEnumerator loadNetPrefab(string url)
	{
		// Wait for the Caching system to be ready
		while (!Caching.ready)
			yield return null;

		// Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
		using(WWW www = WWW.LoadFromCacheOrDownload (url,1))
		{
			yield return www;
			if (www.error != null)
			{
				throw new Exception("WWW download had an error:" + www.error);
				//Debug.LogError(www.error);
				//yield return false;
			}
			bundle = www.assetBundle;
			GameObject obj = bundle.Load("prefabname", typeof(GameObject))as GameObject;
			objPrefab =  Instantiate(obj)as GameObject;
		}
		yield return new WaitForSeconds(0.5f);
		bundle.Unload(false);
		Resources.UnloadUnusedAssets();
	}



Unity官方资源下载非常简单。首先,您需要打开Unity官方网站,网址为www.unity3d.com。在主页的顶部菜单栏上,您会看到一个"资源"选项。单击该选项,然后选择"资源"。这将带您到Unity资源下载页面。 在资源下载页面,您可以找到各种类型的资源括2D和3D艺术资源、动画资源、声音效果资源等等。您可以根据自己的需要选择下载。 一旦您找到了合适的资源,只需单击其名称或封面图像,然后就会显示它的详细信息页面。在此页面上,您可以查看有关资源的详细描述、功能、系统要求和其他详细信息。如果您确定要下载资源,只需单击页面上的"下载"按钮即可开始下载。 Unity资源通常以压缩文件的形式提供,例如.zip或.unitypackage。一旦下载完成,您可以在计算机上选择一个位置来保存这个文件。 下载完成后,您可以打开Unity编辑器。在Unity编辑器的主界面中,选择"Assets"(资源)选项卡,然后选择"Import Package"(导入资源)。这将打开一个文件浏览器,您可以在其中找到并选择您之前下载资源文件。单击"导入"按钮即可开始导入资源。 导入资源后,您就可以在Unity编辑器中使用这些资源了。您可以将它们拖动到场景或游戏对象中,使用它们创建游戏元素或进行其他操作。 总之,Unity官方资源下载非常简单。只需打开官方网站,找到适合您的资源下载,然后在Unity编辑器中导入它们即可开始使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值