private void LoadSaveManager_OnConfigLoaded(AdventurerConfig loadedConfig) { Debug.Log("AdventurerManager heard about Load request."); /// change our config to match loadedConfig _config = loadedConfig; gameObject.BroadcastMessage("ApplyAdventurerConfig", _config); }
// You could have several overloads of the Save function taking different types of config file. // Keeps the callers from having to know lots of function names public bool Save(AdventurerConfig config) { // save Debug.Log("LoadSave trying to save AdventurerConfig"); string configJson = JsonConvert.SerializeObject(config); // Convert (serialize) our objects to a JSon string File.WriteAllText(_savePath, configJson); // Save file return(true); }
void Awake() { _config = new AdventurerConfig(); // Get listener set up for any loading or other changes. Don't want to miss out. //LoadButton.OnLoadRequested += LoadButton_OnLoadRequested; // Actually we should be listening for the load/save manager NextButton.OnNextRequested += NextButton_OnNextRequested; LoadSaveManager.OnConfigLoaded += LoadSaveManager_OnConfigLoaded; SaveButton.OnSaveRequested += SaveButton_OnSaveRequested; }
public void ApplyAdventurerConfig(AdventurerConfig config) { Debug.Log("Change to sprite: adventurer_" + config.pictureId); Sprite adventurerSprite = AtlasManager.Instance.GetSprite("adventurer", config.pictureId); if (adventurerSprite != null) { _spriteRenderer.sprite = adventurerSprite; } else { Debug.Log("Couldn't get a sprite man."); } }
private void LoadButton_OnLoadRequested() { // load Debug.Log(" LoadSaveManager heard about a load click"); if (File.Exists(_savePath)) // Don't try to load a file that isn't there { string loadedJson = File.ReadAllText(_savePath); // read existing file AdventurerConfig loadedConfig = JsonConvert.DeserializeObject <AdventurerConfig>(loadedJson); // string back to sprite config object // Throw event out to the world with the new config attached OnConfigLoaded(loadedConfig); } }
// Use this for initialization public void ApplyAdventurerConfig(AdventurerConfig config) { // apply it Debug.Log("name text field heard about change: " + config.name); }