Instead of having to manually select which materials to export to asset, is there a way to reference/include only the ones actually used in a particular scene?
To export your scene (level) just clean, you have to go to the Project window - select there you level and right click and select: “Select dependencies” it will show you summary information about your level files which was used only in that scene, then you have to go top menu: Assets → Export Package and UNCHECK include dependencies and it the window you’ll see it’s only selected stuff from your scene and then you can click Okay and save your scene just with stuff you had in that scene.
Include Dependencies - should have to be renamed: “Include all garbage from entire unity projects”.
What do you mean “export to asset”? An asset is any individual “thing” in Unity, you can’t export to that. A prefab is a predefined hierarchy of assets, a package is a selection of assets you can export and import from the Unity editor, and an AssetBundle is a collection of assets you can export/load/stream on-the-fly during game mode and in builds.
To answer your question - as far as I understand it - just right click on your scene in the Project tab, and select “export to package”, it will automatically select all dependencies, i.e. stuff that this scene uses/references (although it will not include base classes of used scripts).
To get a selection of dependency assets via (editor) script, supply the asset path of your scene to AssetDatabase.GetDependencies().
EDIT: argh, somebody bumped this ancient question. Well, I hope at least my answer helps him…