Breaking Links intentionally at Build

Hi people !

I have finished my iOS game using Unity, and now I need to make a Lite/Free version for the AppStore. There are somes changes to make, in the projet in order to switch from Lite to Full, and it would really be a pain in the ass to do it manually every time.

I have 2 or 3 scripts in the scene which link to the current background and music and so on, depending on the level currently played. But as you would have guessed, in my Free version there is only 1 bg, 1 music, etc…

If I keep the others bgs & musics linked to that prefab, all those heavy assets will be added to the app and my Free version will be the same size as the full one, which in not kweeel :frowning:

.

Is there a way to breaks those links in some sort of pre-process so that when Unity will make my Build, it will not include the assets :wink: ?

So far, I’m reading stuff about Editor class and BuildPipeline but I’m having trouble on how to use them.

AssetBundle is what you are looking for, assuming you own a pro version of Unity.

You can download and try the official example project.

Thx for your answer Nico but I have find another way of doing what I want.

I’m using EditorWindow (doc, script).
It allows me to made all of my process in a few clicks. All I need is to be in the scene where my links are, and having those objects activated.

The script will find the prefab with the links, breaks them, and then will move the assets in the Project view, from Resources to another file. Thus, when building, those files won’t be added. Of course clicking the button again reverse the process.

Here is a sketch of what I’m doing :


Public class iOSBuilder : EditorWindow
{

[ MenuItem( "Tools/Switch iOS version" ) ]
public static void Launch()
{
// We find the object that hold the links
LevelMusicManager music = (LevelMusicManager) FindObjectOfType(typeof(LevelMusicManager)) ;
IntroManager intro = (IntroManager) FindObjectOfType(typeof(IntroManager)) ;


if (music.music2 == null) // We are currently in Free mode, switching to Premium
{
    // We put references back in place
    [...]


    // we disable intro and children
     // We need this object to be activated for
     // our script to run but to be disactivated
     // in order to build
 intro.gameObject.SetActiveRecursively(false) ;


     // prefab for intro and background
        moveAssets(freePath, resourcePath) ;
 }
 else // we switch to free mode
 {
     // saving premium music references for further switching
    [...]


     // we disable intro and children
     intro.gameObject.SetActiveRecursively(false) ;

     // prefab for intro and background
     moveAssets(resourcePath, freePath) ;
 }


 private static void moveAssets(string before, string after)
 {
     string error = "" ; 
     error = AssetDatabase.MoveAsset(before+introPath+"bg1.prefab", after+introPath+"bg1.prefab") ;
     error = AssetDatabase.MoveAsset(before+introPath+"bg2.prefab", after+introPath+"bg2.prefab") ; 
 }

moveAsset doc

Maybe this will help someone in the futur?

Content de voir que tu travailles encore avec Unity, Nico :wink: