Hello,
I need to iterate over all my game scenes with script and make some changes. I need this to be done before game compilation.
I’ve tried to google preprocess scripting in Unity. Did I understand correctly that I need to use something like BuildPipeline? Are there any simple examples to understand how does it work?
I would really appreciate any help.
Thanks in advance.
Well, finally I managed it myself. If someone will face same problem, here is my script:
class MyBuilder : Editor {
private static string[] FillLevels ()
{
return (from scene in EditorBuildSettings.scenes where scene.enabled select scene.path).ToArray ();
}
[MenuItem ("MyTool/BuildGame")]
public static void buildGame()
{
string[] levels = FillLevels ();
foreach (string level in levels) {
EditorApplication.OpenScene (level);
object[] allObjects = Resources.FindObjectsOfTypeAll (typeof(UnityEngine.GameObject));
foreach (object thisObject in allObjects) {
/* my gameObjects changing before compilation */
}
EditorApplication.SaveScene ();
}
BuildPipeline.BuildPlayer (levels, Path.GetFullPath (Application.dataPath + "/../game.exe"), BuildTarget.StandaloneWindows, BuildOptions.None);
}
}