Skip to content

Commit

Permalink
simplify bundle build process for users
Browse files Browse the repository at this point in the history
Signed-off-by: Alptuğ Cırıt <[email protected]>
  • Loading branch information
mozhoku committed Sep 12, 2024
1 parent 61570e9 commit 84ff1c4
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using UnityEditor;

namespace AWSIM.Scripts.AssetBundleBuilder.Editor
{
public static class AWSIMBuildTargets
{
/// <summary>
/// Build targets used for building the bundles for AWSIM Labs.
/// </summary>
public enum SupportedBuildTargets
{
StandaloneLinux64 = 19,
StandaloneWindows64 = 24
}

public static readonly BuildTarget[] TargetValues =
{
BuildTarget.StandaloneLinux64,
BuildTarget.StandaloneWindows64
};
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ public class AssetBundleBuilder : EditorWindow
private bool _doBuildVehicle;
private bool _doBuildEnvironment;

private readonly BuildAssetBundleOptions[] _buildOptionsValues =
(BuildAssetBundleOptions[])System.Enum.GetValues(typeof(BuildAssetBundleOptions));
private const BuildAssetBundleOptions BuildOption =
BuildAssetBundleOptions.None | BuildAssetBundleOptions.ForceRebuildAssetBundle;

private readonly BuildTarget[] _buildTargetsValues = (BuildTarget[])System.Enum.GetValues(typeof(BuildTarget));

private string[] _buildOptionsNames;
private string[] _buildTargetsNames;

private int _selectedBuildOptionIndex;
private readonly BuildTarget[] _buildTargetValues = AWSIMBuildTargets.TargetValues;

private string[] _buildTargetNames;

private int _selectedBuildTargetIndex;

// Default locations to build the bundles
Expand All @@ -49,8 +47,7 @@ private static void ShowWindow()

private void OnEnable()
{
_buildOptionsNames = System.Enum.GetNames(typeof(BuildAssetBundleOptions));
_buildTargetsNames = System.Enum.GetNames(typeof(BuildTarget));
_buildTargetNames = System.Enum.GetNames(typeof(AWSIMBuildTargets.SupportedBuildTargets));

// Initialize bundles
_vehicleBundleInfo = InitializeBundleInfo(VehicleOutputPath);
Expand All @@ -73,11 +70,9 @@ private void OnGUI()

GUILayout.Space(5);

// Shared options for bundles
_selectedBuildOptionIndex =
EditorGUILayout.Popup("Build Options", _selectedBuildOptionIndex, _buildOptionsNames);
// Build Target
_selectedBuildTargetIndex =
EditorGUILayout.Popup("Build Target", _selectedBuildTargetIndex, _buildTargetsNames);
EditorGUILayout.Popup("Build Target", _selectedBuildTargetIndex, _buildTargetNames);

GUILayout.Space(10);

Expand All @@ -104,13 +99,12 @@ private static void DrawBundleSettings(BundleInfo bundleInfo, string label)

private void Build()
{
var selectedBuildOption = _buildOptionsValues[_selectedBuildOptionIndex];
var selectedBuildTarget = _buildTargetsValues[_selectedBuildTargetIndex];

var selectedBuildTarget = _buildTargetValues[_selectedBuildTargetIndex];

if (_doBuildVehicle && _vehicleBundleInfo.Prefab != null)
BuildAssetBundle(_vehicleBundleInfo, selectedBuildOption, selectedBuildTarget);
BuildAssetBundle(_vehicleBundleInfo, BuildOption, selectedBuildTarget);
if (_doBuildEnvironment && _environmentBundleInfo.Prefab != null)
BuildAssetBundle(_environmentBundleInfo, selectedBuildOption, selectedBuildTarget);
BuildAssetBundle(_environmentBundleInfo, BuildOption, selectedBuildTarget);
}

private static void BuildAssetBundle(BundleInfo bundleInfo, BuildAssetBundleOptions options, BuildTarget target)
Expand All @@ -128,36 +122,14 @@ private static void BuildAssetBundle(BundleInfo bundleInfo, BuildAssetBundleOpti
}

EnsureDirectoryExists(bundleInfo.OutputPath);

// Get the lightmaps for the scene/prefab
LightmapData[] lightmaps = LightmapSettings.lightmaps;
if (lightmaps != null && lightmaps.Length > 0)
{
foreach (var lightmapData in lightmaps)
{
if (lightmapData.lightmapColor != null)
{
var lightmapPath = AssetDatabase.GetAssetPath(lightmapData.lightmapColor);
var lightmapImporter = AssetImporter.GetAtPath(lightmapPath);
lightmapImporter.assetBundleName = bundleInfo.AssetBundleName;
}

if (lightmapData.lightmapDir!=null)
{
var lightmapPath = AssetDatabase.GetAssetPath(lightmapData.lightmapDir);
var lightmapImporter = AssetImporter.GetAtPath(lightmapPath);
lightmapImporter.assetBundleName = bundleInfo.AssetBundleName;
}
}
}

// Create a PrefabInfo asset with the prefab name
// var combinedPrefabName = bundleInfo.Prefab.name.Replace(" ", "_");
var prefabInfo = CreateInstance<PrefabInfo>();
Debug.Log("bundleinfo prefab name: "+ bundleInfo.Prefab.name);
Debug.Log("combined prefab name: "+ bundleInfo.Prefab.name);

Debug.Log("bundleinfo prefab name: " + bundleInfo.Prefab.name);
Debug.Log("combined prefab name: " + bundleInfo.Prefab.name);

prefabInfo.prefabName = bundleInfo.Prefab.name;
// bundleInfo.AssetBundleName = combinedPrefabName;

Expand Down Expand Up @@ -215,5 +187,10 @@ private static void EnsureDirectoryExists(string path)
Directory.CreateDirectory(path);
}
}

private BuildTarget GetBuildTarget(AWSIMBuildTargets.SupportedBuildTargets supportedBuildTargets)
{
return (BuildTarget)supportedBuildTargets;
}
}
}
}

0 comments on commit 84ff1c4

Please sign in to comment.