Example #1
0
    void LoadHeroes()
    {
        var heroesInScene = FindObjectsOfType <HeroSystem>();

        foreach (var heroRuntime in saveGame.heroRuntimes)
        {
            HeroRuntime foundHeroRuntime = null;
            HeroSystem  foundHeroSystem  = null;

            foreach (var heroInScene in heroesInScene)
            {
                var heroInSceneSaveGameId = heroInScene.GetComponent <SaveGameIdSystem>().SaveGameId;
                if (heroInSceneSaveGameId == heroRuntime.saveGameId)
                {
                    foundHeroRuntime = heroRuntime;
                    foundHeroSystem  = heroInScene.GetComponent <HeroSystem>();
                    break;
                }
            }

            if (foundHeroRuntime == null)
            {
                var spawnedHero = Instantiate(runtimePrefabSettings.heroPrefab, heroRuntime.position, heroRuntime.rotation);
                spawnedHero.transform.localScale = heroRuntime.scale;
                spawnedHero.GetComponent <SaveGameIdSystem>().SaveGameId = heroRuntime.saveGameId;
                spawnedHero.GetComponent <HeroSystem>().OnLoad(saveGame);
            }
            else
            {
                foundHeroSystem.OnLoad(saveGame);
            }
        }
    }
Example #2
0
    void Start()
    {
        heroRuntime = new HeroRuntime(GetComponent <SaveGameIdSystem>().SaveGameId, null, null);

        var gameSystem = FindObjectOfType <GameSystem>();

        gameSystem.heroes.Add(this);

        interactableSystem = GetComponent <InteractableSystem>();
        rewiredPlayer      = ReInput.players.GetPlayer(0);
    }
Example #3
0
    public void OnSave(MySaveGame saveGame)
    {
        Logging.LogFormat("HeroSystem OnSave: " + GetComponent <SaveGameIdSystem>().SaveGameId);

        var saveGameIdSystem = this.GetComponent <SaveGameIdSystem>();
        var abilitySystem    = GetComponent <AbilitySystem>();
        var classSystem      = GetComponent <ClassSystem>();
        var healthSystem     = GetComponent <HealthSystem>();

        heroRuntime = new HeroRuntime(saveGameIdSystem.SaveGameId, abilitySystem.abilityRuntimes, classSystem.classRuntime);

        heroRuntime.position = transform.position;
        heroRuntime.rotation = transform.rotation;
        heroRuntime.scale    = transform.localScale;

        heroRuntime.maxHealth     = healthSystem.maxHealth;
        heroRuntime.currentHealth = healthSystem.currentHealth;
        heroRuntime.isAlive       = healthSystem.IsAlive;

        saveGame.heroRuntimes.Add(heroRuntime);
    }