Exclude code from SWF


I’m new to Unity and I’m using the Flash export. I want to have 1 swf file per level of my game.

When I look at the list of exported classes in the swf, I can see a lot of classes in the packages global, System and UnityEngine. I understand that those classes are required for the game to run.

I want to load these classes only once, but they are included on every swf that I export. Is it possible to avoid this waste of file weight?

If you wish to save file-size of your bundled scenes, you can use streamed scenes with push/pop dependencies to achieve this.

  1. Build a player from your main scene.
  2. Push dependencies
  3. Build any additional streamed scenes
  4. Pop dependencies

This will result in your main scene swf being its usual size but your streamed scene swfs will be much smaller.

Here’s a quick example that you should be able to modify for your project:

public class ExportSceneBundles : Editor
	[MenuItem("Assets/Export Scene Bundles")]
	public static void Export()
		var options = BuildAssetBundleOptions.CompleteAssets;
		BuildPipeline.BuildPlayer(new string[]{"Assets/BaseScene.unity"}, "SceneAssetBundles/BaseScene.swf", BuildTarget.FlashPlayer, BuildOptions.None);	
				BuildPipeline.BuildStreamedSceneAssetBundle(new string[]{"Assets/StreamedScene.unity"}, "SceneAssetBundles/StreamedScene.swf", BuildTarget.FlashPlayer);