1.创建AssetBudle 通过脚本将一个prefab创建为AssetBudle,将下面代码放入Editor文件夹下面
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class ExportAssetBundles : EditorWindow
{
[MenuItem("Assets/Build AssetBundle From Selection")]
static void ExportResourceRespective()
{ // 打开保存面板,获得用户选择的路径
string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "assetbundle");
if (path.Length != 0)
{
// 选择的要保存的对象
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
//打包
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, BuildTarget.StandaloneWindows);
}
}
[MenuItem("Assets/Save Scene")]
static void ExportScene()
{
// 打开保存面板,获得用户选择的路径
string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "unity3d");
if (path.Length != 0)
{
// 选择的要保存的对象
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
string[] scenes = { "Assets/scene1.unity" };
//打包
BuildPipeline.BuildPlayer(scenes, path, BuildTarget.StandaloneWindows, BuildOptions.BuildAdditionalStreamedScenes);
}
}
}
2.本地资源文件以及服务器文件的MD5配置文件生成
public void CreatConfiga(string resPath)
{
string[] files = Directory.GetFiles(resPath, "*", SearchOption.AllDirectories);
System.Text.StringBuilder versions = new System.Text.StringBuilder();
for (int i = 0; i < files.Length; i++)
{
string filePath = files[i];
string extension = filePath.Substring(files[i].LastIndexOf("."));
if (extension == ".assetbundle")
{
string relativePath = filePath.Replace(resPath, "").Replace("\\", "/");
string md5 = MD5File(filePath);
versions.Append(relativePath).Append(",").Append(md5).Append(&