**SUMMARIZING MY MAIN QUESTION: "In my Save/Load script, how the heck can I define and initialize a class called GameSettings, to be exactly like the GameSettings (class) located in my GameControllerScript.cs**
Lets say I have my main GameControllerScript.cs
Inside of it, is a large class called GameSettings;
and inside of the class GameSettings, are a couple other classes like: AudioSettings and VideoSettings.
**GameControllerScripts.cs**
[System.Serializable]
public class GameSettings
{
[System.Serializable]
public class PlayerControls
{
public bool controlIsKeyboard = true;
public int controlNumber = 1;
}
public PlayerControls[] _playerControls = new PlayerControls[4];
[System.Serializable]
public class PlayerKeys
{
public string horizontalKey = "";
public string verticalKey = "";
public string aButton = "";
public string bButton = "";
public string xButton = "";
public string yButton = "";
}
public PlayerKeys[] _playerKeys;
[System.Serializable]
public class AudioSettings
{
public bool soundEnbaled = true;
public float soundVolume = 1f;
}
public AudioSettings _audioSettings;
public class VideoSettings
{
public bool enabledAmbientOcclusion = true;
public bool enabledMSAA = true;
}
public VideoSettings _videoSettings;
}
public GameSettings _gameSettings;
OKAY, Now I have a SAVE/LOAD script that needs to save that entire GameSettings class.
(FYI: I am following the persisting data tutorial on Unity)
**SaveSettingsScript.cs**
public GameControllerScript _controllerScript;
public class GameSettings { }
// Use this for initialization
void Start()
{
GameSettings _gameSettings = ????????????
}
AND THE SAVE FUNCTION (in the same script)
public void Save()
{
//the thing that savaes for us
BinaryFormatter bf = new BinaryFormatter();
//file creating
FileStream file = File.Create(Application.persistentDataPath + "/settingsInfo.dat");
// What data we are gonna put in here
// we need a clean class, NO MONOBEHAVIORS
GameSettings data = _gameControllerScript._gameSettings; // ??? I should be able to to make the variable data to an exact copy of class:GameSettings _gameSettings inside of _gameController??
//data.health = 10f; // or my local health
//data.experience = 0f;
bf.Serialize(file, data);
file.Close();
}
↧