0
votes

I am writing an Android App which allows users to DIY their phone cases and then export them to .stl/other 3D printing format.

I have several scenes(each scene has a button for switching to next scene):

Scene 0(Start Scene): A simple start menu with an exit button and a start button(canvas with an image as a background).

Scene 1(Model Scene): 3 buttons(allows users to choose 3 kinds of models: iphone7, iphone6s, LGG6). After pressing one of the button, the corresponding phone case will be displayed to the users.

Scene 2(Color Scene): there are several colors for users to choose. After touching a color button, the material of the phone case will be changed to the corresponding color. Users can instantly preview how the case looks like.

Scene 3(Pattern Scene): there are several patterns for users to choose. After touching a pattern button, the back of the phone case will be changed to the corresponding pattern. Users can instantly preview how the case looks like.

...And there will be a few more scenes which add more things/functions to the phone case.

Scene x(exporting): Exporting the phone case to 3D printing format.

I've encountered a few problems when I am coding.

The main problem is that I need to keep the chosen phone case(a 3D object) throughout all the scenes. In details, after users have chosen the wanted phone case(lets say LGG6) in scene1, the case need to be kept and passed to the next scene(scene2:color scene) for further editting. After coloring the case in scene2, the colored phone case will then be passed to the next scene(pattern scene) for editting the pattern and so on.

I keep on surfing the net these days and I find several ways which can achieve this. I decided to use "DontDestroyOnLoad". However, there is something I dont understand:

I created a game object called "AppManager" in scene 0. There is a C# script(also called "AppManager" attached to it. Inside it, I created a lot of variables to store all kind of elements needed in all scenes, including Canvas&UI elements, 3D object(3 type of phone cases, I stored them in Render Type), cameras, directional light, and also the functions I need.

Then, I implement a "DontDestroyOnLoad" function inside the script. enter image description here

Also, I made all UI elements, 3D objects, cameras as the children of "AppManager" enter image description here

I would like to ask:

  1. Am I using "DontDestroyOnLoad" correctly? I still dont understand how can I access the variables and functions stored in "AppManager"(scene o) from other scenes.
  2. Since I have several scenes which have some unique buttons other scenes dont require, I hope I can active the function(.gameObject.SetActive (true/false)) of specific UI elements in each scene and disable those I dont need. I would like to know if I can implement this function inside my "AppManager"? Or in each scene, I need to create an unique script to enable/disable these UI elements?
  3. I would like to implement a "back" button in scene 2, 3, 4,... What does it mean? Lets say the user is now in scene 3(pattern scene). He has chosen LGG6 case model and red color(material). But he wants to modify the color, altering from red to black. Then, there is a back button in scene 3 for him to go back to scene 2 to choose the color. That means my app need to undo the color change. I would like to ask if there is a function in unity which can save all the information in a current scene and can be reloaded later?
1

1 Answers

1
votes

Am I using "DontDestroyOnLoad" correctly? I still dont understand how can I access the variables and functions stored in "AppManager"(scene o) from other scenes.

Yes you are. You can access the variables in the next scene by somehow accessing it through script, this can for example be by storing it in a static variable, or have a manager class that can be fetched and through the manager class acquire the object that wasn't destroyed.

Since I have several scenes which have some unique buttons other scenes dont require, I hope I can active the function(.gameObject.SetActive (true/false)) of specific UI elements in each scene and disable those I dont need. I would like to know if I can implement this function inside my "AppManager"? Or in each scene, I need to create an unique script to enable/disable these UI elements?

You could make a script in each scene that manages the buttons, and then in the "OnEnable()" method for the script store the script itself in a static variable.

public class ExampleScript : MonoBehaviour
{
    /// <summary>
    /// Store the ExampleScript in a static variable, then have the variable set when the scene is loaded, for example through OnEnable() or possibly Awake().
    /// ExampleScript should act as a manager script and hold the references to the buttons in each scene.
    /// </summary>
    public static ExampleScript _Instance;

    private void OnEnable()
    {
        _Instance = this;
    }

}

public class UsingExampleScript : MonoBehaviour
{

    private void Update()
    {
        if (Input.GetKeyDown("i"))
        {
            if (ExampleScript._Instance != null)
            {
                //Use variables from example script, for example the buttons.
            }
        }
    }
}

I would like to implement a "back" button in scene 2, 3, 4,... What does it mean? Lets say the user is now in scene 3(pattern scene). He has chosen LGG6 case model and red color(material). But he wants to modify the color, altering from red to black. Then, there is a back button in scene 3 for him to go back to scene 2 to choose the color. That means my app need to undo the color change. I would like to ask if there is a function in unity which can save all the information in a current scene and can be reloaded later?

You could have a script with static variables, then they should be saved between the scene changes, and then just load them in at the beginning of each scene.