项目简介:
这个是内部项目,有保密协议的,所以口述了。
这是个精密机械拆装的项目,使用unity2017.1.0f3开发,纯单机,没有后台服务器。
项目改造方向:
最近领导要求进行改造,改成前后端分离的,并且把服务器部署到云端。
解决思路:
将项目中所有场景打包成assetbundle,放到服务器上,然后本地客户端从云端下载和加载。
开始:
1,场景资源打成ab包;
一共11个场景
从A到E是进入软件的一套场景,F是过度场景,其他的是拆装场景。
直接上代码:
using UnityEngine;
using UnityEditor;
using System.IO;
/// <summary>
/// 场景资源打包ab
/// </summary>
public class BuildAssetBundle{
//菜单 添加场景名称
[MenuItem("build/1.create All Scene AssetBundleName")]
static void clearAssetBundleName()
{
string[] files=Directory.GetFiles (Application.dataPath, "*.unity", SearchOption.AllDirectories);
for (int i = 0; i < files.Length; i++)
{
string currentFile=files [i].Replace ("\\", "/");
int startIndex = currentFile.IndexOf ("Assets");
string assetFile = currentFile.Substring (startIndex,currentFile.Length-startIndex);
string sceneName = Path.GetFileNameWithoutExtension (assetFile);
AssetImporter ai=AssetImporter.GetAtPath (assetFile);
ai.assetBundleName = sceneName;
ai.assetBundleVariant = "assetbundle";
}
}
//打包所有AssetBundle
[MenuItem("build/2.Build All AssetBundle")]
static void buildAssetBundle()
{
string outPath=Application.str