將本地資源打包,,然后放到資源服務(wù)器上供游戲客戶端下載或更新。服務(wù)器上包含以下資源列表: <VersionNum> <File FileName="Assets.Resources.BigLevelTexture.TestLevel.assetbundle" Num="1" /> <File FileName="Assets.Resources.EquipmentTexture.Test001.assetbundle" Num="1" /> <File FileName="Assets.Resources.EquipmentTexture.Test002.assetbundle" Num="1" /> <File FileName="Assets.Resources.EquipmentTexture.Test003.assetbundle" Num="1" /> <File FileName="Assets.Resources.EquipmentTexture.Test004.assetbundle" Num="1" /> <File FileName="Assets.Resources.PetTexture.Empty.assetbundle" Num="1" /> </VersionNum>
那么本地客戶端的資源打包編輯器就需要完成以下工作:將資源打包,、生成版本號(hào)。 各個(gè)平臺(tái)使用的資源包時(shí)各自獨(dú)立的,打包資源代碼時(shí)的選項(xiàng)不一樣,,編輯器界面如下,,圖2中的4個(gè)按鈕每個(gè)對(duì)應(yīng)上述的一步操作:
最終生成的資源目錄結(jié)構(gòu)如下所示: 編輯器代碼如下所示(包括菜單項(xiàng)和窗口): using UnityEditor; using UnityEngine; using System.IO; using System.Collections; using System.Collections.Generic; public class AssetBundleController : EditorWindow { public static AssetBundleController window; public static UnityEditor.BuildTarget buildTarget = BuildTarget.StandaloneWindows; [MenuItem("XiYouEditor/AssetBundle/AssetBundle For Windows32", false, 1)] public static void ExecuteWindows32() { if (window == null) { window = (AssetBundleController)GetWindow(typeof(AssetBundleController)); } buildTarget = UnityEditor.BuildTarget.StandaloneWindows; window.Show(); } [MenuItem("XiYouEditor/AssetBundle/AssetBundle For IPhone", false, 2)] public static void ExecuteIPhone() { if (window == null) { window = (AssetBundleController)GetWindow(typeof(AssetBundleController)); } buildTarget = UnityEditor.BuildTarget.iPhone; window.Show(); } [MenuItem("XiYouEditor/AssetBundle/AssetBundle For Mac", false, 3)] public static void ExecuteMac() { if (window == null) { window = (AssetBundleController)GetWindow(typeof(AssetBundleController)); } buildTarget = UnityEditor.BuildTarget.StandaloneOSXUniversal; window.Show(); } [MenuItem("XiYouEditor/AssetBundle/AssetBundle For Android", false, 4)] public static void ExecuteAndroid() { if (window == null) { window = (AssetBundleController)GetWindow(typeof(AssetBundleController)); } buildTarget = UnityEditor.BuildTarget.Android; window.Show(); } [MenuItem("XiYouEditor/AssetBundle/AssetBundle For WebPlayer", false, 5)] public static void ExecuteWebPlayer() { if (window == null) { window = (AssetBundleController)GetWindow(typeof(AssetBundleController)); } buildTarget = UnityEditor.BuildTarget.WebPlayer; window.Show(); } void OnGUI() { if (GUI.Button(new Rect(10f, 10f, 200f, 50f), "(1)CreateAssetBundle")) { CreateAssetBundle.Execute(buildTarget); EditorUtility.DisplayDialog("", "Step (1) Completed", "OK"); } if (GUI.Button(new Rect(10f, 80f, 200f, 50f), "(2)Generate MD5")) { CreateMD5List.Execute(buildTarget); EditorUtility.DisplayDialog("", "Step (2) Completed", "OK"); } if (GUI.Button(new Rect(10f, 150f, 200f, 50f), "(3)Compare MD5")) { CampareMD5ToGenerateVersionNum.Execute(buildTarget); EditorUtility.DisplayDialog("", "Step (3) Completed", "OK"); } if (GUI.Button(new Rect(10f, 220f, 200f, 50f), "(4)Build VersionNum.xml")) { CreateAssetBundleForXmlVersion.Execute(buildTarget); EditorUtility.DisplayDialog("", "Step (4) Completed", "OK"); } } public static string GetPlatformPath(UnityEditor.BuildTarget target) { string SavePath = ""; switch (target) { case BuildTarget.StandaloneWindows: SavePath = "Assets/AssetBundle/Windows32/"; break; case BuildTarget.StandaloneWindows64: SavePath = "Assets/AssetBundle/Windows64/"; break; case BuildTarget.iPhone: SavePath = "Assets/AssetBundle/IOS/"; break; case BuildTarget.StandaloneOSXUniversal: SavePath = "Assets/AssetBundle/Mac/"; break; case BuildTarget.Android: SavePath = "Assets/AssetBundle/Android/"; break; case BuildTarget.WebPlayer: SavePath = "Assets/AssetBundle/WebPlayer/"; break; default: SavePath = "Assets/AssetBundle/"; break; } if (Directory.Exists(SavePath) == false) Directory.CreateDirectory(SavePath); return SavePath; } public static string GetPlatformName(UnityEditor.BuildTarget target) { string platform = "Windows32"; switch (target) { case BuildTarget.StandaloneWindows: platform = "Windows32"; break; case BuildTarget.StandaloneWindows64: platform = "Windows64"; break; case BuildTarget.iPhone: platform = "IOS"; break; case BuildTarget.StandaloneOSXUniversal: platform = "Mac"; break; case BuildTarget.Android: platform = "Android"; break; case BuildTarget.WebPlayer: platform = "WebPlayer"; break; default: break; } return platform; } } PS:每個(gè)操作的具體實(shí)現(xiàn),見下一篇講解... |
|