예제 #1
0
    public void loadAllVitality()
    {
        // FIXME: implement settings manager
        return;

        NetworkUser userFromPlayer = NetworkUserList.getUserFromPlayer(base.networkView.owner);
        string      empty          = string.Empty;

        if (userFromPlayer != null)
        {
            empty = Savedata.loadLife(userFromPlayer.id);
        }
        this.loadAllVitalityFromSerial(empty);
    }
예제 #2
0
파일: Skills.cs 프로젝트: Horsuna/server
    public void loadAllKnowledge()
    {
        // FIXME: implement settings
        return;

        NetworkUser userFromPlayer = NetworkUserList.getUserFromPlayer(base.networkView.owner);
        string      empty          = string.Empty;

        if (userFromPlayer != null)
        {
            empty = Savedata.loadSkills(userFromPlayer.id);
        }
        this.loadAllKnowledgeFromSerial(empty);
    }
예제 #3
0
    public static Savedata SaveProcess()
    {
        //I. Create a new savedata object.
        Savedata sav = new Savedata();

        //II. Initialize this object by loading local file.
        sav.InitialSavedataObject();
        sav.CreateNewSaveData();

        //III. Write object to local file.
        sav.WriteSaveData();

        //IV. Return.
        return(sav);//Maybe have some lifetime problem.
    }
예제 #4
0
 public void loadAllClothing()
 {
     if (true)           // FIXME: implement config manager
     {
     }
     else
     {
         NetworkUser userFromPlayer = NetworkUserList.getUserFromPlayer(base.networkView.owner);
         string      clothString    = string.Empty;
         if (userFromPlayer != null)
         {
             clothString = Savedata.loadClothes(userFromPlayer.id);
         }
         this.loadAllClothingFromSerial(clothString);
     }
 }
예제 #5
0
    public void Load()
    {
        if (File.Exists(Application.dataPath + "/saves/SaveData.dat"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.dataPath + "/saves/SaveData.dat", FileMode.Open);

            data = (Savedata)bf.Deserialize(file);

            CopyLoadData();

            file.Close();

            SceneManager.LoadScene(SceneIndexes.WorldMap());
        }
    }
예제 #6
0
    public static Savedata GeneralLoadSave()
    {
        string path = Application.persistentDataPath + "/generalsave.mario";

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

            Savedata savedata = formatter.Deserialize(stream) as Savedata;
            stream.Close();

            return(savedata);
        }

        return(null);
    }
예제 #7
0
 public void saveAllVitality()
 {
     if (this.loaded)
     {
         string empty = string.Empty;
         if (!this.dead)
         {
             object[] objArray = new object[] { this.health, ";", this.food, ";", this.water, ";", this.sickness, ";", null, null, null, null };
             objArray[8]  = (!this.bleeding ? "f" : "t");
             objArray[9]  = ";";
             objArray[10] = (!this.bones ? "f" : "t");
             objArray[11] = ";";
             empty        = string.Concat(objArray);
         }
         Savedata.saveLife(base.GetComponent <Player>().owner.id, empty);
     }
 }
예제 #8
0
    public static void save()
    {
        string structureString = string.Empty;

        for (int i = 0; i < SpawnStructures.structures.Count; i++)
        {
            ServerStructure item = SpawnStructures.structures[i];
            structureString = string.Concat(structureString, item.id, ":");
            structureString = string.Concat(structureString, item.health, ":");
            structureString = string.Concat(structureString, item.state, ":");
            structureString = string.Concat(structureString, Mathf.Floor(item.position.x * 100f) / 100f, ":");
            structureString = string.Concat(structureString, Mathf.Floor(item.position.y * 100f) / 100f, ":");
            structureString = string.Concat(structureString, Mathf.Floor(item.position.z * 100f) / 100f, ":");
            structureString = string.Concat(structureString, item.rotation, ":;");
        }

        //Database.provider.SaveStructures(structureString);
        Savedata.saveStructures(structureString);
    }
예제 #9
0
    public static void save()
    {
        string saveData = string.Empty;

        for (int i = 0; i < SpawnVehicles.models.Count; i++)
        {
            if (SpawnVehicles.models[i] != null)
            {
                Vehicle component = SpawnVehicles.models[i].GetComponent <Vehicle>();
                if (component.transform.position.y >= Ocean.level - 1f && !component.exploded)
                {
                    saveData = string.Concat(saveData, component.name, ":");
                    saveData = string.Concat(saveData, component.health, ":");
                    saveData = string.Concat(saveData, component.fuel, ":");
                    Vector3 vector3 = component.transform.position;
                    saveData = string.Concat(saveData, Mathf.Floor(vector3.x * 100f) / 100f, ":");
                    Vector3 vector31 = component.transform.position;
                    saveData = string.Concat(saveData, Mathf.Floor(vector31.y * 100f) / 100f, ":");
                    Vector3 vector32 = component.transform.position;
                    saveData = string.Concat(saveData, Mathf.Floor(vector32.z * 100f) / 100f, ":");
                    Vector3 vector33 = component.transform.rotation.eulerAngles;
                    saveData = string.Concat(saveData, (int)vector33.x, ":");
                    Vector3 vector34 = component.transform.rotation.eulerAngles;
                    saveData = string.Concat(saveData, (int)vector34.y, ":");
                    Vector3 vector35 = component.transform.rotation.eulerAngles;
                    saveData = string.Concat(saveData, (int)vector35.z, ":");
                    if (component.GetComponent <Painter>() == null)
                    {
                        saveData = string.Concat(saveData, "0:");
                        saveData = string.Concat(saveData, "0:");
                        saveData = string.Concat(saveData, "0:;");
                    }
                    else
                    {
                        saveData = string.Concat(saveData, Mathf.Floor(component.GetComponent <Painter>().color.r * 100f) / 100f, ":");
                        saveData = string.Concat(saveData, Mathf.Floor(component.GetComponent <Painter>().color.g * 100f) / 100f, ":");
                        saveData = string.Concat(saveData, Mathf.Floor(component.GetComponent <Painter>().color.b * 100f) / 100f, ":;");
                    }
                }
            }
        }
        Savedata.saveVehicles(saveData);
    }
예제 #10
0
파일: Player.cs 프로젝트: Horsuna/server
    public void saveAllOrientation()
    {
        string positionString = string.Empty;

        if (!base.GetComponent <Life>().dead)
        {
            this.lastPosition = base.transform.position;
            if (this.vehicle != null)
            {
                this.lastPosition = this.vehicle.getPosition();
            }

            positionString = string.Concat(positionString, Mathf.Floor(this.lastPosition.x * 100f) / 100f, ";");
            positionString = string.Concat(positionString, Mathf.Floor(this.lastPosition.y * 100f) / 100f, ";");
            positionString = string.Concat(positionString, Mathf.Floor(this.lastPosition.z * 100f) / 100f, ";");
            Vector3 vector3 = base.transform.rotation.eulerAngles;
            positionString = string.Concat(positionString, (int)vector3.y, ";");
        }
        Savedata.savePosition(this.owner.id, positionString);
    }
예제 #11
0
 public static void save(int x, int y)
 {
     if (SpawnBarricades.regions[x, y].barricades.Count > 0 || SpawnBarricades.regions[x, y].edit)
     {
         string empty = string.Empty;
         for (int i = 0; i < SpawnBarricades.regions[x, y].barricades.Count; i++)
         {
             ServerBarricade item = SpawnBarricades.regions[x, y].barricades[i];
             empty = string.Concat(empty, item.id, ":");
             empty = string.Concat(empty, item.health, ":");
             empty = string.Concat(empty, item.state, ":");
             empty = string.Concat(empty, Mathf.Floor(item.position.x * 100f) / 100f, ":");
             empty = string.Concat(empty, Mathf.Floor(item.position.y * 100f) / 100f, ":");
             empty = string.Concat(empty, Mathf.Floor(item.position.z * 100f) / 100f, ":");
             empty = string.Concat(empty, Mathf.Floor(item.rotation.x * 100f) / 100f, ":");
             empty = string.Concat(empty, Mathf.Floor(item.rotation.y * 100f) / 100f, ":");
             empty = string.Concat(empty, Mathf.Floor(item.rotation.z * 100f) / 100f, ":;");
         }
         Savedata.saveBarricades(x, y, empty);
     }
 }
예제 #12
0
    public void onReady()
    {
        SpawnStructures.tool       = this;
        SpawnStructures.model      = GameObject.Find(Application.loadedLevelName).transform.FindChild("structures").gameObject;
        SpawnStructures.structures = new List <ServerStructure>();
        SpawnStructures.models     = new List <GameObject>();
        if (!Network.isServer)
        {
            base.networkView.RPC("askAllStructures", RPCMode.Server, new object[] { Network.player });
        }
        else
        {
            string str = Savedata.loadStructures();
            if (str != string.Empty)
            {
                string[] strArrays = Packer.unpack(str, ';');
                for (int i = 0; i < (int)strArrays.Length; i++)
                {
                    string[] strArrays1 = Packer.unpack(strArrays[i], ':');
                    SpawnStructures.structures.Add(
                        new ServerStructure(
                            int.Parse(strArrays1[0]),
                            int.Parse(strArrays1[1]),
                            strArrays1[2],
                            new Vector3(
                                float.Parse(strArrays1[3]),
                                float.Parse(strArrays1[4]),
                                float.Parse(strArrays1[5])),
                            int.Parse(strArrays1[6]))
                        );

                    this.createStructure(
                        SpawnStructures.structures[SpawnStructures.structures.Count - 1].id,
                        SpawnStructures.structures[SpawnStructures.structures.Count - 1].position,
                        SpawnStructures.structures[SpawnStructures.structures.Count - 1].rotation
                        );
                }
            }
        }
    }
예제 #13
0
    private Savedata LoadAndBuild()
    {
        bool failureFlag = false;

        //Load local file if it exists.
        string _path = Application.persistentDataPath + "/savedata.rua";

        if (File.Exists(_path))
        {
            BinaryFormatter bf    = new BinaryFormatter();
            FileStream      _file = File.Open(_path, FileMode.Open);// No handle for open failure.
            if (_file == null)
            {
                Debug.Log("Open files failed. The file has been removed at runtime.");
                // failureFlag = true;// Maybe can let control stream jump to create brunch.
                InitialSavedataObject();
            }
            else
            {
                Savedata _tmpSav = (Savedata)bf.Deserialize(_file);// No handle for deserialize failure.
                if (_tmpSav == null)
                {
                    _tmpSav.InitialSavedataObject();
                }
                _file.Close();
                _highScore   = _tmpSav._highScore;
                _highMove    = _tmpSav._highMove;
                _allTimeMove = _tmpSav._allTimeMove;
            }
        }
        //If not, create a new file
        else
        {
            InitialSavedataObject();
        }

        return(this);
    }
예제 #14
0
    // Savefile handler
    // This is accomplished with the help of the JSON.NET for Unity asset
    public void SaveGame(string filename = "_autosave")
    {
        // Strings for the save directory and savefile
        string savePath = Application.dataPath + "/Saves";
        string saveName = savePath + "/" + filename + ".txt";

        // Sanity check: if the filename is "", assume it's "_autosave"
        if (filename == "")
        {
            saveName = savePath + "/_autosave.txt";
        }

        // The game will save data in JSON format into a text file
        // These datavectors, plus the funding amount, are saved into a single JSON string
        Savedata s = new Savedata {
            residentialData = _resSim.DataVector,
            commercialData  = _commSim.DataVector,
            educationData   = _eduSim.DataVector,
            healthcareData  = _hlthSim.DataVector,
            financialData   = _fundingMgr.Funds,
            gameTime        = _timeCtrl.TickCount,
            gameSaved       = true
        };

        // Convert the savedata class into a JSON string
        string saveString = JsonConvert.SerializeObject(s, Formatting.Indented);

        // Create the savefile folder if it doesn't exist
        DirectoryInfo d = Directory.CreateDirectory(savePath);

        // Create the savefile if it doesn't exist either; if it exists, overwrite it
        File.WriteAllText(saveName, saveString);

        // For debugging; load the string
        Debug.Log(saveString);
        _textSavefilePreview.text = "Saved to savefile: " + filename.ToString();
    }
예제 #15
0
파일: Skills.cs 프로젝트: Horsuna/server
 public void saveAllKnowledge()
 {
     if (this.loaded)
     {
         string skillLine = string.Empty;
         if (false /*base.GetComponent<Life>().dead*/)             // Disabled skill halfing
         {
             skillLine = string.Concat(skillLine, this.experience / 2, ";");
             for (int i = 0; i < (int)this.skills.Length; i++)
             {
                 skillLine = string.Concat(skillLine, this.skills[i].level / 2, ";");
             }
         }
         else
         {
             skillLine = string.Concat(skillLine, this.experience, ";");
             for (int j = 0; j < (int)this.skills.Length; j++)
             {
                 skillLine = string.Concat(skillLine, this.skills[j].level, ";");
             }
         }
         Savedata.saveSkills(base.GetComponent <Player>().owner.id, skillLine);
     }
 }
예제 #16
0
 public void onReady()
 {
     SpawnBarricades.tool    = this;
     SpawnBarricades.model   = GameObject.Find(Application.loadedLevelName).transform.FindChild("barricades").gameObject;
     SpawnBarricades.regions = new BarricadesRegion[NetworkRegions.REGION_X, NetworkRegions.REGION_Y];
     for (int i = 0; i < NetworkRegions.REGION_X; i++)
     {
         for (int j = 0; j < NetworkRegions.REGION_Y; j++)
         {
             SpawnBarricades.regions[i, j] = new BarricadesRegion();
         }
     }
     if (Network.isServer)
     {
         for (int k = 0; k < NetworkRegions.REGION_X; k++)
         {
             for (int l = 0; l < NetworkRegions.REGION_Y; l++)
             {
                 string str = Savedata.loadBarricades(k, l);
                 if (str != string.Empty)
                 {
                     string[] strArrays = Packer.unpack(str, ';');
                     for (int m = 0; m < (int)strArrays.Length; m++)
                     {
                         string[]        strArrays1      = Packer.unpack(strArrays[m], ':');
                         int             num             = int.Parse(strArrays1[0]);
                         ServerBarricade serverBarricade = new ServerBarricade(num, int.Parse(strArrays1[1]), strArrays1[2], new Vector3(float.Parse(strArrays1[3]), float.Parse(strArrays1[4]), float.Parse(strArrays1[5])), new Vector3(float.Parse(strArrays1[6]), float.Parse(strArrays1[7]), float.Parse(strArrays1[8])));
                         SpawnBarricades.regions[k, l].barricades.Add(serverBarricade);
                         this.createBarricade(SpawnBarricades.regions[k, l].barricades[SpawnBarricades.regions[k, l].barricades.Count - 1].id, SpawnBarricades.regions[k, l].barricades[SpawnBarricades.regions[k, l].barricades.Count - 1].position, SpawnBarricades.regions[k, l].barricades[SpawnBarricades.regions[k, l].barricades.Count - 1].rotation);
                     }
                     SpawnBarricades.regions[k, l].edit = true;
                 }
             }
         }
     }
 }
예제 #17
0
    public void onReady()
    {
        SpawnVehicles.model = GameObject.Find(Application.loadedLevelName).transform.FindChild("vehicles").gameObject;

        Debug.Log("Temporary disabled car spawn");
        return;

        if (Network.isServer)
        {
            SpawnVehicles.models = new List <GameObject>();
            if (Loot.getCars() > 0)
            {
                string   str   = Savedata.loadVehicles();
                string[] empty = new string[Loot.getCars()];
                for (int i = 0; i < (int)empty.Length; i++)
                {
                    empty[i] = string.Empty;
                }
                if (str != string.Empty)
                {
                    string[] strArrays = Packer.unpack(str, ';');
                    for (int j = 0; j < (int)strArrays.Length; j++)
                    {
                        if (j < (int)empty.Length)
                        {
                            empty[j] = strArrays[j];
                        }
                    }
                }
                int num = 0;
                List <Transform> transforms = new List <Transform>();
                for (int k = 0; k < SpawnVehicles.model.transform.FindChild("spawns").childCount; k++)
                {
                    transforms.Add(SpawnVehicles.model.transform.FindChild("spawns").GetChild(k));
                }
                for (int l = 0; l < (int)empty.Length; l++)
                {
                    if (empty[l] == string.Empty)
                    {
                        int       num1 = UnityEngine.Random.Range(0, transforms.Count);
                        Transform item = transforms[num1];
                        transforms.RemoveAt(num1);
                        float single = UnityEngine.Random.@value;
                        if (item.name == "civilianCar")
                        {
                            if ((double)single > 0.66)
                            {
                                SpawnVehicles.create(string.Concat("truck_", UnityEngine.Random.Range(0, 1)), item.transform.position + new Vector3(0f, 0.1f, 0f), item.rotation * Quaternion.Euler(-90f, 0f, 0f));
                            }
                            else if ((double)single <= 0.33)
                            {
                                SpawnVehicles.create(string.Concat("van_", UnityEngine.Random.Range(0, 1)), item.transform.position + new Vector3(0f, 0.1f, 0f), item.rotation * Quaternion.Euler(-90f, 0f, 0f));
                            }
                            else
                            {
                                SpawnVehicles.create(string.Concat("car_", UnityEngine.Random.Range(0, 2)), item.transform.position + new Vector3(0f, 0.1f, 0f), item.rotation * Quaternion.Euler(-90f, 0f, 0f));
                            }
                            num++;
                        }
                        else if (item.name == "policeCar")
                        {
                            SpawnVehicles.create("policeCar_0", item.transform.position + new Vector3(0f, 0.1f, 0f), item.rotation * Quaternion.Euler(-90f, 0f, 0f));
                            num++;
                        }
                        else if (item.name == "fireCar")
                        {
                            SpawnVehicles.create("fireTruck_0", item.transform.position + new Vector3(0f, 0.1f, 0f), item.rotation * Quaternion.Euler(-90f, 0f, 0f));
                            num++;
                        }
                        else if (item.name == "militaryCar")
                        {
                            if ((double)single <= 0.9)
                            {
                                SpawnVehicles.create(string.Concat("humvee_", UnityEngine.Random.Range(0, 2)), item.transform.position + new Vector3(0f, 0.1f, 0f), item.rotation * Quaternion.Euler(-90f, 0f, 0f));
                            }
                            else
                            {
                                SpawnVehicles.create(string.Concat("apc_", UnityEngine.Random.Range(0, 2)), item.transform.position + new Vector3(0f, 0.1f, 0f), item.rotation * Quaternion.Euler(-90f, 0f, 0f));
                            }
                            num++;
                        }
                        else if (item.name == "medicalCar")
                        {
                            SpawnVehicles.create("medic_0", item.transform.position + new Vector3(0f, 0.1f, 0f), item.rotation * Quaternion.Euler(-90f, 0f, 0f));
                            num++;
                        }
                    }
                    else
                    {
                        string[]   strArrays1 = Packer.unpack(empty[l], ':');
                        Vector3    vector3    = new Vector3(float.Parse(strArrays1[3]), float.Parse(strArrays1[4]) + 0.1f, float.Parse(strArrays1[5]));
                        Quaternion quaternion = Quaternion.Euler(float.Parse(strArrays1[6]), float.Parse(strArrays1[7]), float.Parse(strArrays1[8]));
                        Color      color      = new Color(float.Parse(strArrays1[9]), float.Parse(strArrays1[10]), float.Parse(strArrays1[11]));
                        SpawnVehicles.create(strArrays1[0], int.Parse(strArrays1[1]), int.Parse(strArrays1[2]), vector3, quaternion, color);
                    }
                }
                SpawnVehicles.save();
            }
        }
    }
예제 #18
0
    private Savedata CreateNewSaveData()
    {
        bool failureFlag = false;

        //I. Building Savedata object.
        //Load local file if it exists.
        string _path = Application.persistentDataPath + "/savedata.rua";

        if (File.Exists(_path))
        {
            BinaryFormatter bf    = new BinaryFormatter();
            FileStream      _file = File.Open(_path, FileMode.Open);// No handle for open failure.
            if (_file == null)
            {
                Debug.Log("Open files failed. The file has been removed at runtime.");
                // failureFlag = true;// Maybe can let control stream jump to create brunch.
                InitialSavedataObject();
            }
            else
            {
                Savedata _tmpSav = (Savedata)bf.Deserialize(_file);// No handle for deserialize failure.
                if (_tmpSav == null)
                {
                    _tmpSav.InitialSavedataObject();
                }
                _file.Close();
                _highScore   = _tmpSav._highScore;
                _highMove    = _tmpSav._highMove;
                _allTimeMove = _tmpSav._allTimeMove;

                //_highItems = _tmpSav._highItems;// Uncertain
                //_allTimeItems = _tmpSav._allTimeItems;
            }
        }
        //If not, create a new file
        else
        {
            InitialSavedataObject();
        }

        //II. Update some values of savedata object.
        GameObject _gcon   = GameObject.FindWithTag("GameController");
        GameObject _player = GameObject.FindWithTag("Player");

        Score[] _score = _gcon.GetComponents <Score>();
        for (int i = 0; i < _score.Length; ++i)//To find the highscore, but not exactly.
        {
            if (_score[i].getScore() > _highScore)
            {
                _isHighScore = 1;
                _highScore   = _score[i].getScore();
                _highMove    = _player.transform.position.x;
                Debug.Log("New record!");
            }
        }
        _allTimeMove += _player.transform.position.x;

        if (failureFlag)
        {
            Debug.Log("Savedata object creation is failed.");
        }
        else
        {
            Debug.Log("Savedata creation is completed successfully.");
        }

        _isCreated = 1;
        return(this);
    }
예제 #19
0
    //セーブ関数
    public void Main_Save()
    {
        if (EventSystem.current == null)
        {
            return;
        }
        PointerEventData eventDataCurrent = new PointerEventData(EventSystem.current);

        eventDataCurrent.position = Input.mousePosition;
        List <RaycastResult> raycast = new List <RaycastResult>();

        EventSystem.current.RaycastAll(eventDataCurrent, raycast);
        if (Input.GetMouseButtonDown(1))
        {
            BattleVal.status = STATUS.PLAYER_UNIT_SELECT;
            savemanager.save_BackGround.gameObject.SetActive(false);
            for (int page = 0; page < savemanager.save_load_page; page++)
            {
                for (int j = 0; j < savemanager.save_load; j++)
                {
                    savemanager.save_object[page][j].gameObject.SetActive(true);
                    Destroy(savemanager.save_object[page][j]);
                }
            }
            savemanager.nextpagebutton.gameObject.SetActive(false);
            savemanager.prevpagebutton.gameObject.SetActive(false);
            savemanager.page_number.gameObject.SetActive(false);
            Destroy(save_canvas.GetComponent <CanvasScaler>());
            Destroy(save_canvas.GetComponent <GraphicRaycaster>());
            Destroy(save_canvas.gameObject);
            Destroy(save_canvas);
        }
        for (int page = 0; page < savemanager.save_load_page; page++)
        {
            for (int i = 0; i < savemanager.save_load; i++)
            {
                savemanager.save_object[page][i].gameObject.SetActive(savemanager.now_page == page);
            }
        }
        Debug.Log(savemanager.now_page);
        for (int i = 0; i < savemanager.save_load; i++)
        {
            savemanager.save_object[savemanager.now_page][i].GetComponent <Image>().color = Color.white;
        }
        foreach (RaycastResult tmp in raycast)
        {
            for (int i = 0; i < savemanager.save_load; i++)
            {
                if (tmp.gameObject.name == savemanager.save_object[savemanager.now_page][i].gameObject.name)
                {
                    savemanager.save_object[savemanager.now_page][i].GetComponent <Image>().color = Color.red;
                    if (Input.GetMouseButtonDown(0))
                    {
                        Savedata SD = new Savedata();
                        SD.Save();
                        SD.nameScene = SceneManager.GetActiveScene().name;
                        SD.nameTitle = "夢現の旅籠";

                        //--------------------------------------------------------------------------------------
                        SD.current_message = string.Format("夢現の旅籠\n{0}/{1}/{2}/{3}:{4}", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute);
                        //---------------------------------------------------------------------------------------

                        FileStream   fs = new FileStream(Application.streamingAssetsPath + "/SaveData/" + tmp.gameObject.name + ".json", FileMode.Create, FileAccess.Write);
                        StreamWriter sw = new StreamWriter(fs);
                        //**注意**--------------------------------------------------------------------------------------------------------------------------------------------------------------
                        Encryption_Config ec = Resources.Load <Encryption_Config>("Prefab/Encryption");
                        //sw.WriteLine(ec.EncryptionSystem(JsonUtility.ToJson(SD),false));
                        sw.WriteLine(ec.EncryptionSystem(JsonUtility.ToJson(SD), true));

                        //**--------------------------------------------------------------------------------------------------------------------------------------------------------------------
                        //sw.WriteLine(JsonUtility.ToJson(SD));
                        sw.Flush();
                        sw.Close();
                        fs.Close();
                        byte[] bytes = picture.EncodeToPNG();
                        File.WriteAllBytes(Application.streamingAssetsPath + "/SaveData/" + tmp.gameObject.name + ".png", bytes);
                        state = EXTRAMENUSTATE.MENU;
                        savemanager.save_BackGround.gameObject.SetActive(false);
                        savemanager.nextpagebutton.gameObject.SetActive(false);
                        savemanager.prevpagebutton.gameObject.SetActive(false);
                        savemanager.page_number.gameObject.SetActive(false);

                        for (int k = 0; k < savemanager.save_load_page; k++)
                        {
                            for (int j = 0; j < savemanager.save_load; j++)
                            {
                                Destroy(savemanager.save_object[k][j]);
                            }
                        }
                        Destroy(save_canvas.GetComponent <CanvasScaler>());
                        Destroy(save_canvas.GetComponent <GraphicRaycaster>());
                        Destroy(save_canvas.gameObject);
                        Destroy(save_canvas);
                        return;
                    }
                }
            }
        }
    }
예제 #20
0
    //Save画面を描画する関数
    public void SaveWindowOpen()
    {
        page_number.gameObject.SetActive(true);
        nextpagebutton.gameObject.SetActive(true);
        prevpagebutton.gameObject.SetActive(true);
        save_BackGround.gameObject.SetActive(true);
        save_menu_text.gameObject.SetActive(true);
        page_number.text = string.Format("{0}/{1}", now_page + 1, save_load_page);
        FileStream   fs;
        StreamReader sr;
        string       filename = "";

        save_object = new GameObject[save_load_page][];
        sd          = new Savedata[save_load_page][];
        float y = save_box.GetComponent <RectTransform>().sizeDelta.y + 5;

        for (int page = 0; page < save_load_page; page++)
        {
            save_object[page] = new GameObject[save_load];
            sd[page]          = new Savedata[save_load];
            for (int i = 1; i <= save_load; i++)
            {
                filename = Application.streamingAssetsPath + string.Format("/SaveData/{0}{1}.json", page, i);
                save_object[page][i - 1]      = Instantiate <GameObject>(save_box, Vector3.zero, Quaternion.identity, canvas.transform);
                save_object[page][i - 1].name = string.Format("{0}{1}", page, i);
                save_object[page][i - 1].transform.position = new Vector3(100, canvas.GetComponent <RectTransform>().sizeDelta.y - 5 - y * (i - 1) - 120, 0);
                if (!System.IO.File.Exists(filename))
                {
                    save_object[page][i - 1].GetComponentInChildren <Text>().text = " NO DATA";
                    save_object[page][i - 1].gameObject.SetActive(false);
                    continue;
                }
                fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
                sr = new StreamReader(fs);

                //**注意**------------------------------------------------------------------------------------------------------------------------------------------------------
                Encryption_Config ec = Resources.Load <Encryption_Config>("Prefab/Encryption");

                //sd[page][i - 1] = JsonUtility.FromJson<Savedata>(ec.DecryptionSystem(sr.ReadToEnd(),false));
                sd[page][i - 1] = JsonUtility.FromJson <Savedata>(ec.DecryptionSystem(sr.ReadToEnd(), true));  //debug
                FileStream filestream = new FileStream(Application.streamingAssetsPath + string.Format("/SaveData/{0}{1}.png", page, i), FileMode.Open, FileAccess.Read);

                //**------------------------------------------------------------------------------------------------------------------------------------------------------------
                BinaryReader bin        = new BinaryReader(filestream);
                byte[]       readBinary = bin.ReadBytes((int)bin.BaseStream.Length);
                bin.Close();
                filestream.Dispose();
                filestream = null;
                Rect      rect    = save_object[page][i - 1].GetComponent <Image>().GetComponent <RectTransform>().rect;
                Texture2D texture = new Texture2D((int)rect.width, (int)rect.height);
                if (readBinary != null)
                {
                    //横サイズ
                    int pos   = 16;
                    int width = 0;
                    for (int k = 0; k < 4; k++)
                    {
                        width = width * 256 + readBinary[pos++];
                    }
                    //縦サイズ
                    int height = 0;
                    for (int k = 0; k < 4; k++)
                    {
                        height = height * 256 + readBinary[pos++];
                    }
                    //byteからTexture2D作成
                    texture = new Texture2D(width, height);
                    texture.LoadImage(readBinary);
                }
                readBinary = null;
                save_object[page][i - 1].GetComponentInChildren <Image>().sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), Vector2.zero);
                save_object[page][i - 1].GetComponentInChildren <Text>().text    = sd[page][i - 1].current_message;
                save_object[page][i - 1].gameObject.SetActive(false);
                sr.Close();
                fs.Close();
            }
        }
    }
예제 #21
0
    private static void Load()
    {
        Debug.Log("Loading settings...");

        if (!File.Exists(settingsFilePath))
        {
            return;
        }

        Savedata savedata = JsonUtility.FromJson <Savedata>(File.ReadAllText(settingsFilePath, System.Text.Encoding.ASCII));

        isFirstRun     = savedata.isFirstRun;
        language       = savedata.language;
        soundOn        = savedata.soundOn;
        musicOn        = savedata.musicOn;
        soundVolume    = savedata.soundVolume;
        musicVolume    = savedata.musicVolume;
        UItransparency = savedata.UItransparency;
        modelQuality   = savedata.modelQuality;
        textureQuality = savedata.textureQuality;

        for (int i = 0; i < savedata.controllersSavedata.Length; i++)
        {
            Savedata.ControllerSavedata controllerSavedata = JsonUtility.FromJson <Savedata.ControllerSavedata>(savedata.controllersSavedata[i]);

            bool used = false;

            foreach (Controller controller in allPlayers)
            {
                if (controllerSavedata.name != controller.name)
                {
                    continue;
                }

                controller.isAvailable     = controllerSavedata.isAvailable;
                controller.up              = controllerSavedata.up;
                controller.down            = controllerSavedata.down;
                controller.left            = controllerSavedata.left;
                controller.right           = controllerSavedata.right;
                controller.jump            = controllerSavedata.jump;
                controller.tool1           = controllerSavedata.tool1;
                controller.tool2           = controllerSavedata.tool2;
                controller.tool3           = controllerSavedata.tool3;
                controller.pick            = controllerSavedata.pick;
                controller.menu            = controllerSavedata.menu;
                controller.timesBeenUnused = controllerSavedata.timesBeenUnused;
                controller.axis1x          = controllerSavedata.axis1x;
                controller.axis1y          = controllerSavedata.axis1y;
                controller.axis2x          = controllerSavedata.axis2x;
                controller.axis2y          = controllerSavedata.axis2y;
                controller.axis1Scale      = controllerSavedata.axis1Scale;
                controller.axis2Scale      = controllerSavedata.axis2Scale;
                controller.visual          = controllerVisuals.Find(visual => visual.name == controllerSavedata.visualName);
                controller.layout          = controllerSavedata.layout;

                used = true;

                if (controller.visual)
                {
                    controllerVisuals.Remove(controller.visual);
                }
                else
                {
                    TakeVisualScheme(controller.controlType, ref controller.visual);
                    Debug.Assert(controller.visual, "Found no visual scheme for " + controller.name);
                }

                break;
            }

            if (!used)
            {
                Debug.Log("");
                //todo, instantiate new controller based on its type
                //and reduce its unused counter by 1 if the counter
                //is not 0. otherwise just ignore that object and it
                //will not be saved next time
            }
        }

        Debug.Log("Settings successfully loaded");
    }