Пример #1
0
    private void TryLoad()
    {
        var savedJson = PlayerPrefs.GetString(saveGameKey);

        if (string.IsNullOrEmpty(savedJson))
        {
            scs = null;
        }
        else
        {
            scs = JsonUtility.FromJson <SerializedCs>(savedJson);
        }
    }
Пример #2
0
    public void Serialize(CelestialSystem cs)
    {
        scs = new SerializedCs();
        var planets = cs.Planets;

        scs.playerIndex = planets.FindIndex(planet => planet.ControlledBy is InputPlanetController);
        scs.aiIndex     = planets.FindIndex(planet => planet.ControlledBy is AiPlanetController);

        scs.planets = new List <SerializedPlanet>();
        foreach (var planet in planets)
        {
            scs.planets.Add(new SerializedPlanet()
            {
                entity     = SerializedEntity.FromEntity(planet.SimulatedEntity),
                hp         = planet.Hp,
                startHp    = planet.StartHp,
                color      = planet.Appearance.color,
                weaponType = planet.Weapon?.Type.Name,
            });
        }

        scs.planets.Add(new SerializedPlanet()
        {
            entity    = SerializedEntity.FromEntity(cs.centralStar.SimulatedEntity),
            hp        = cs.centralStar.Hp,
            startHp   = cs.centralStar.StartHp,
            color     = cs.centralStar.Appearance.color,
            isCentral = true,
        });


        scs.projectiles = new List <SerializedProjectile>();
        foreach (var projectile in cs.Projectiles)
        {
            scs.projectiles.Add(new SerializedProjectile()
            {
                entity = SerializedEntity.FromEntity(projectile),
            });
        }

        var json = JsonUtility.ToJson(scs);

        PlayerPrefs.SetString(saveGameKey, json);
        PlayerPrefs.Save();
    }
Пример #3
0
 public void Clear()
 {
     scs = null;
     PlayerPrefs.SetString(saveGameKey, null);
     PlayerPrefs.Save();
 }