示例#1
0
文件: Serializer.cs 项目: L4fter/Orb
    private void TryLoad()
    {
        var savedJson = PlayerPrefs.GetString(saveGameKey);

        if (string.IsNullOrEmpty(savedJson))
        {
            scs = null;
        }
        else
        {
            scs = JsonUtility.FromJson <SerializedCs>(savedJson);
        }
    }
示例#2
0
文件: Serializer.cs 项目: L4fter/Orb
    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
文件: Serializer.cs 项目: L4fter/Orb
 public void Clear()
 {
     scs = null;
     PlayerPrefs.SetString(saveGameKey, null);
     PlayerPrefs.Save();
 }