I am using this code snippet in unity 2021.3.16 to create Asset bundles:
using System.IO;
using UnityEditor;
using UnityEngine;
using System.Security.Cryptography;
public class ABEncryption
{
[MenuItem("ABD/Build AssetBundles")]
static void ABCreate()
{
string _assetNameForAB = "Assets/Prefab/Cube.prefab";
string _ABName = "MyAB";
AssetBundleBuild[] assetBundleBuilds = new AssetBundleBuild[1];
assetBundleBuilds[0].assetBundleName = _ABName;
assetBundleBuilds[0].assetBundleVariant = "";
assetBundleBuilds[0].assetNames = new string[] { _assetNameForAB };
BuildAssetBundleOptions buildAssetBundleOptions = BuildAssetBundleOptions.None;
buildAssetBundleOptions |= BuildAssetBundleOptions.DeterministicAssetBundle;
buildAssetBundleOptions |= BuildAssetBundleOptions.ChunkBasedCompression;
string outputPath = Application.streamingAssetsPath + "/EncryptedAB/";
BuildPipeline.BuildAssetBundles(outputPath,
assetBundleBuilds,
BuildAssetBundleOptions.None,
BuildTarget.StandaloneWindows64);
}
}
Something very strange is happening. Compile time is perfectly fine but when I run this I get several errors:
Assets\ABEncryption.cs(27,36): error CS0103: The name 'BuildAssetBundleOptions' does not exist in the current context
Assets\ABEncryption.cs(38,9): error CS0103: The name 'BuildPipeline' does not exist in the current context
Assets\ABEncryption.cs(40,41): error CS0103: The name 'BuildAssetBundleOptions' does not exist in the current context
Assets\ABEncryption.cs(41,41): error CS0103: The name 'BuildTarget' does not exist in the current context
Assets\ABEncryption.cs(54,9): error CS0103: The name 'BuildPipeline' does not exist in the current context
Assets\ABEncryption.cs(55,41): error CS0103: The name 'BuildAssetBundleOptions' does not exist in the current context
Assets\ABEncryption.cs(56,41): error CS0103: The name 'BuildTarget' does not exist in the current context
Error building Player because scripts had compiler errors
I am running this method in the editor (on context menu). Here is the complete details