All Terrain Tactical Enforcer (Directional Light)
All Terrain Tactical Enforcer (Lightmapping)
1. 製作 AssetBundle
Lightmap Bake 完成之後將 Model 打包成 AssetBundle,使用指令:
BuildPipeline.BuildAssetBundle( Selection.activeObject, Selection.objects, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets );選擇的檔案除了 Prefab/GameObject 之外,Lightmap 圖片也要選擇:
選擇 Prefab 及 Lightmap
2. 載入 AssetBundle
載入 AssetBundle 時先設定 Lightmap 再載入 GameObject,此場景的 Lightmapping 參數如下:
Lightmapping 參數
按照當初 Lightmapping 之參數做對應的設定:
Listarrld = new List (); LightmapData ld = new LightmapData(); ld.lightmapFar = aa.assetBundle.Load("LightmapFar-0", typeof(Texture2D)) as Texture2D; ld.lightmapNear = aa.assetBundle.Load("LightmapNear-0", typeof(Texture2D)) as Texture2D; arrld.Add(ld); LightmapSettings.lightmapsMode = LightmapsMode.Dual; LightmapSettings.lightmaps = arrld.ToArray();
再載入 GameObject :
GameObject go = GameObject.Instantiate(aa.assetBundle.Load("StaticObj", typeof(GameObject))) as GameObject;此外慶幸的是,GameObject 之 MeshRenderer 內有關 Lightmapping 之參數在存取 AssetBundle 時皆有自動設定,不需再額外寫程式存取設定之。
程式碼可以在:https://github.com/phardera/unity3d_assetbundle_lightmap.git 取得
0 意見 :
張貼留言