コード例 #1
0
    /*public static void saveAllPlanets(Planet[] planets) {
     *  BinaryFormatter formatter = new BinaryFormatter();
     *
     *  string path = Application.persistentDataPath + "/data/planets/all.data";
     *  FileStream stream = new FileStream(path, FileMode.Create);
     *
     *  AllPlanetData data = new AllPlanetData(planets);
     *
     *  formatter.Serialize(stream, data);
     *  stream.Close();
     * }
     *
     * public static AllPlanetData loadAllPlanets() {
     *  string path = Application.persistentDataPath + "/data/planets/all.data";
     *  if (File.Exists(path)) {
     *      BinaryFormatter formatter = new BinaryFormatter();
     *      FileStream stream = new FileStream(path, FileMode.Open);
     *
     *      AllPlanetData data = formatter.Deserialize(stream) as AllPlanetData;
     *
     *      stream.Close();
     *      return data;
     *  }
     *  else {
     *      Debug.Log("SAVE FILE NOT FOUND");
     *      return null;
     *  }
     * }*/



    public static void savePlanet(Planet planet)
    {
        BinaryFormatter formatter = new BinaryFormatter();

        Debug.Log("SAVING " + planet.getNumber());

        string     path   = Application.persistentDataPath + "/single" + planet.getNumber().ToString() + ".data";
        FileStream stream = new FileStream(path, FileMode.Create);

        DataPlanet data = new DataPlanet(planet);

        formatter.Serialize(stream, data);
        stream.Close();
    }
コード例 #2
0
    public void load(DataPlanet data, bool withLocation, Vector3 center)
    {
        if (data == null)
        {
            data = SaveSystem.loadPlanet(number);
        }
        foreach (Transform child in transform)
        {
            string childName = OverallUtility.simplify(child.gameObject.ToString());
            if (childName != "planet" && childName != "particles")
            {
                Destroy(child.gameObject);
            }
        }
        radiusAroudSun = data.radiusAroudSun;
        planetRadius   = data.planetRadius;
        speed          = data.speed;
        angle          = data.angle;
        number         = data.number;
        cratersAdded   = data.cratersAdded;
        blocking       = data.blocking;
        buildings      = new List <Building>();
        buildings.Clear();
        if (withLocation == true)
        {
            gameObject.transform.position = data.position;
            gameObject.transform.rotation = data.rotation;
        }
        Rigidbody planetRgb = gameObject.GetComponent <Rigidbody>();

        planetRgb.constraints = RigidbodyConstraints.FreezeAll;
        if (data.buildings != null)
        {
            foreach (DataBuilding datBil in data.buildings)
            {
                GameObject building = Instantiate(GameObject.Find(datBil.exactName), datBil.position + center, datBil.rotation);
                building.transform.parent = gameObject.transform;
                Rigidbody rgb = building.GetComponent <Rigidbody>();
                rgb.constraints = RigidbodyConstraints.FreezeAll;
                print(building.GetComponent <Building>());
                buildings.Add(building.GetComponent <Building>());
            }
        }

        planetRgb.constraints = RigidbodyConstraints.None;
    }
コード例 #3
0
    public static DataPlanet loadPlanet(int number)
    {
        string path = Application.persistentDataPath + "/single" + number.ToString() + ".data";

        if (File.Exists(path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(path, FileMode.Open);

            DataPlanet data = formatter.Deserialize(stream) as DataPlanet;

            stream.Close();
            return(data);
        }
        else
        {
            Debug.Log("SAVE FILE NOT FOUND");
            return(null);
        }
    }
コード例 #4
0
 public Planet(DataPlanet data)
 {
     load(data, true, Vector3.zero);
 }