Could someone describe me how to make a setting panel or an window for my main menu spawned by a button click and disabled by clicking on the sides of the panrl.
pls step by step and in an easy english
public GameObject panel;
public GameObject panelParameters;
public void TogglePanel () {
//
// This will make the panel hidden if it was previously on, and vice versa.
//
// The function will be called from an X button in the panel, and on a button to show the panel, Ex: a "Settings" Button.
//
if (!panel.activeInHierarchy) {
LoadPanel ();
}
panel.SetActive (!panel.activeInHierarchy);
}
public void LoadPanel () {
//
// This function should be called in the start function, or it can be called when the settings menu is opened,
// meaning on the TogglePanel() function where panel.activeInHierarchy is false;
//
for (int i = 0; i < panelParameters.Length; i++) {
GameObject parameter = panelParameters *;*
-
if (parameter.GetComponent<InputField> () != null) {*
-
parameter.GetComponent<InputField> ().text = PlayerPrefs.GetString ("panelParameter_" + i);*
-
}*
-
if (parameter.GetComponent<Toggle> () != null) {*
-
parameter.GetComponent<Toggle> ().isOn = intToBool(PlayerPrefs.GetInt ("panelParameter_" + i));*
-
}*
-
if (parameter.GetComponent<Dropdown> () != null) {*
-
parameter.GetComponent<Dropdown> ().value = PlayerPrefs.GetInt ("panelParameter_" + i);*
-
}*
-
}*
-
}*
-
public void SavePanel () {*
-
//*
-
// This function should be called each frame, or for better performance every time you change a value in*
-
// the settings. Can be done using the OnValueChanged() on most Buttons, InputFields, Toggles, and Dropdowns.*
-
//*
-
for (int i = 0; i < panelParameters.Length; i++) {*
_ GameObject parameter = panelParameters ;_
* if (parameter.GetComponent () != null) {*
* PlayerPrefs.SetString (“panelParameter_” + i, parameter.GetComponent ().text);
_ }*_
* if (parameter.GetComponent () != null) {*
* PlayerPrefs.SetInt (“panelParameter_” + i, boolToInt(parameter.GetComponent ().isOn));
_ }*_
* if (parameter.GetComponent () != null) {*
* PlayerPrefs.SetInt (“panelParameter_” + i, parameter.GetComponent ().value);
_ }*_
* }*
* }*
* public int boolToInt (bool input) {*
* //*
* // Returns an integer (1/0) based on a bool (true/false) input; Due to the fact that there is no*
* // PlayerPrefs.Set/GetBool();*
* //*
* if (input) {*
* return 1;*
* } else {*
* return 0;*
* }*
* }*
* public bool intToBool (int input) {*
* //*
* // Returns a bool (true/false) based on an integer (1/0) input; Due to the fact that there is no*
* // PlayerPrefs.Set/GetBool();*
* //*
* if (input == 1) {*
* return true;*
* } else {*
* return false;*
* }*
* }*
Final thoughts:
-This took me WAY too long to do
-Please fix basic compiler errors if there is some…
-Use a LayoutGroup on the panel, so that all of the parameters are lined up nicely
-You can set panelParameters from panel’s children, but it is more resource intensive and takes more time in the long run.