Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by Nin4ikP · Dec 08, 2017 at 04:05 PM · androidscripting beginnerfilebuild settingslevels

How to reset build settings from script and set new scenes from file in a certain order for android build?

Hello everyone :)

I'm new to Unity, so please excuse me, if the answer is too obvious..

I have a script, which I start with a batch file. I call it with:

 "D:\Unity3D\Editor\Unity.exe" -batchmode -nographics -quit -projectPath %~dp0 -executedMethod BuildUnityPlayer.PerformBuild
 pause

Pause, because I want to see, if there are errors, but in this case there aren't any.

The BuildUnityPlayer.PerformBuild file looks like this:

 using UnityEngine;
 using System;
 #if UNITY_EDITOR
 using UnityEditor;
 #endif
 using System.IO;
 
 public class BuildUnityPlayer : MonoBehaviour
 {
     private static string levelsFile = "LevelsToLoad.csv";
 
     public static void PerformBuild()
     {
         Debug.Log("BuildUnityPlayer active.");
         string path = GetPath();
         Debug.Log(path);
         string[] listOfLevelPaths = GetLevels(path);    //1
 
         BuildPlayerOptions resetBuildPlayerOptions = new BuildPlayerOptions()
         {
             scenes = {},    //2
             locationPathName = Application.dataPath,
             target = BuildTarget.Android,
             options = BuildOptions.None
         };
         BuildPipeline.BuildPlayer(resetBuildPlayerOptions);
 
         EditorBuildSettingsScene[] original = new EditorBuildSettingsScene[0];   //3
         EditorBuildSettings.scenes = original;
 
         foreach (var scenePath in listOfLevelPaths)
         {
             original = EditorBuildSettings.scenes;
             EditorBuildSettingsScene[] newSettings = new EditorBuildSettingsScene[original.Length + 1];
             //Array.Copy(original, newSettings, original.Length);
             var sceneToAdd = new EditorBuildSettingsScene(scenePath, true);
             newSettings[newSettings.Length - 1] = sceneToAdd;
             EditorBuildSettings.scenes = newSettings;
         }
 
         Debug.Log("starting Customized Build...");
         BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
         {
             scenes = listOfLevelPaths,    //4
             locationPathName = Application.dataPath,
             target = BuildTarget.Android,
             options = BuildOptions.None
         };
         BuildPipeline.BuildPlayer(buildPlayerOptions);
         
         Debug.Log("Customized Build performed.");
     }
 
     private static string GetPath()
     {
         return Path.GetFullPath(Application.dataPath);
     }
     
     private static string[] GetLevels(string path)
     {
         if (Directory.Exists(path))
         {
             string levelsInText = File.ReadAllText(path + "/" + levelsFile);
             if (File.Exists("Assets/" + levelsFile))
             {
                 string[] levelsInArray = levelsInText.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
                 return levelsInArray;
             }
             else
             {
                 Debug.LogError("Could not get file for levels. Check if file 'LevelsToLoad.csv' exists.");
                 return null;
             }
         }
         else
         {
             Debug.LogError("Could not get path for levels. Check path for file 'LevelsToLoad.csv'.");
             return null;
         }
     }
 }

So there is this file, which contains all paths to the right scenes, which have to be included in the build. The main reason why I want to do it so is because I want this program to be editable from people who have no idea of coding. Their main task will be copy and pasting folders and replace images and sounds as they wish. So I want the scenes to be loaded in a certain order from the file "LevelsToLoad.csv".

The content in excel looks like this:

 Assets/donetedit_scenes/Main.unity
 Assets/levels/sl_M/Sl.unity
 Assets/levels/dr_M/Dr.unity
 Assets/levels/dr_N/Dr.unity

1: This means, when "GetLevels(path)" is called, I got a list of these entries.

2: Now I want them in exactly this order. So I thought I could reset the Buildplayeroptions by emptying the scenes.

3: Then by adding to a new list the levels as they are read from the file.

4: And at last build the project with BuildPlayerOptions but now with the new ordered scenes.

The problem now is that the scenes are added, if I delete them from the build settings in Unity Editor first; BUT if I let them there, they are not changed when I modify the "LevelsToLoad.csv" file.

PS: if somebody knows, why I don't get an .apk file here, you would help me A LOT! (probably this is the problem anyway...)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Nin4ikP · Dec 09, 2017 at 12:07 PM 0
Share

Pps: changing the locationPathName to locationPathName = Application.dataPath + "/gamename.apk",

does not make a change... (if somebody was wandering)

Best, Nina

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Nin4ikP · Dec 10, 2017 at 03:27 PM

Okay guys,

The actual problem seemed to be within the command line: it must be "executeMethod" not "executedMethod". I accidently copy-pasted it from somewhere.

But I still do not get an .apk file in the end. Maybe somebody can help me with it?

Thank you.

Best, Nina

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

203 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Problems in Android build when running game 1 Answer

Running application in Android: the file mainData is corrupted 0 Answers

Unity 5.3.1f1 android switch platform 2 Answers

How to simulate a real like sky diving physics in unity 5.3? 0 Answers

Android app: IsolatedStorageException when reading from file 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges