Exemplo n.º 1
0
    public void Save()
    {
        QuickSaveWriter writer = QuickSaveWriter.Create("GuardianIdleSave");
        Equipment       item;
        string          key;

        for (int i = 0; i < slots.Count; i++)
        {
            key = "equipSlot" + i;

            if (!(slots[i].IsEmpty()))
            {
                item = (Equipment)slots[i].GetItem();
                string data = JsonUtility.ToJson(item, false);

                writer.Write(key, data);
                writer.Write(key + "_icon", item.imagePath);
            }
            else
            {
                writer.Delete(key);
            }
        }

        writer.Commit();
    }
    public void QuickSaveWriterExample()
    {
        // Use a QuickSaveWriter to save content to a file, multiple items can be saved to the save file by specifying different keys

        string  one   = "Hello World!";
        double  two   = 45.6789;
        Vector2 three = new Vector2(34.0f, 78.92f);
        Color   four  = new Color(0.1f, 0.5f, 0.8f, 1.0f);

        QuickSaveWriter.Create("RootName")
        .Write("Key1", one)
        .Write("Key2", two)
        .Write("Key3", three)
        .Write("Key4", four)
        .Commit();

        // OR

        QuickSaveWriter writer = QuickSaveWriter.Create("RootName");

        writer.Write("Key1", one);
        writer.Write("Key2", two);
        writer.Write("Key3", three);
        writer.Write("Key4", four);
        writer.Commit();
    }
Exemplo n.º 3
0
    public void Save()
    {
        QuickSaveWriter writer = QuickSaveWriter.Create("GuardianIdleSave");

        writer.Write("itemIdCounter", idCounter);
        writer.Commit();
    }
Exemplo n.º 4
0
    public void Save()
    {
        QuickSaveWriter writer = QuickSaveWriter.Create("GuardianIdleSave");
        Item            item;
        string          key;

        for (int i = 0; i < slots.Count; i++)
        {
            key = "invslot" + i;

            if (!(slots[i].IsEmpty()))
            {
                item = slots[i].GetItem();
                string data = JsonUtility.ToJson(item, false);
                Debug.Log(key);
                writer.Write(key, data);
                writer.Write(key + "_icon", item.imagePath);

                if (item is Equipment)
                {
                    writer.Write(key + "_type", "equipment");
                }
                else
                {
                    writer.Write(key + "_type", "item");
                }


                Debug.Log("Wrote item in slot" + i + ": " + item);
                Debug.Log("JSON Utility: " + JsonUtility.ToJson(item, false));
            }
            else
            {
                writer.Delete(key);
            }
        }

        writer.Commit();
    }
Exemplo n.º 5
0
    public void SaveHighScores()
    {
        if (QuickSaveRoot.Exists("HighScoreFile"))
        {
            QuickSaveRoot.Delete("HighScoreFile"); //if the file exists, then delete it
        }

        string nameForScore;

        if (uiController.NameTextDisplay.text != null)
        {
            if (uiController.NameTextDisplay.text.Length > 3)
            {
                nameForScore = uiController.NameTextDisplay.text.Substring(0, 3);
            }
            else
            {
                nameForScore = uiController.NameTextDisplay.text;
            }
        }
        else
        {
            nameForScore = "AAA";
        }

        highScoreObjectList.Add(new HighScoreObject(nameForScore, Resources));
        highScoreObjectList.Sort();
        highScoreObjectList.Reverse();
        if (highScoreObjectList.Count > 10)
        {
            highScoreObjectList.RemoveAt(highScoreObjectList.Count - 1);
        }
        foreach (HighScoreObject highScoreObject in highScoreObjectList)
        {
            Debug.Log("The High score for " + highScoreObject.scoreString + " is " + highScoreObject.scoreValue);
        }

        QuickSaveWriter instWriter = QuickSaveWriter.Create("HighScoreFile"); //create an instance of the QuickSaveWriter

        instWriter.Write <List <HighScoreObject> >("HighScoreObjectList", highScoreObjectList);
        instWriter.Commit();//write the save file
    }
 public void Save()
 {
     _quickSaveWriter.Write <SaveData>("SaveData", Data).Commit();
 }
Exemplo n.º 7
0
        public static string SaveGame()
        {
            CameraController cameraController = Camera.main.GetComponent <CameraController>();

            string saveName = DateTime.Now.ToString("MM_dd_yyyy_HH_mm_ss");

            QuickSaveWriter quickSaveWriter = QuickSaveWriter.Create(saveName);

            quickSaveWriter.Write(GameInfo.MAP_SEED, GameInfo.mapSeed);
            quickSaveWriter.Write(GameInfo.MAP_SIZE, GameInfo.mapSize);
            quickSaveWriter.Write("playerTeam", GameInfo.playerTeam);
            quickSaveWriter.Write("cameraPosition", Camera.main.transform.position);
            quickSaveWriter.Write("cameraRotation", Camera.main.transform.rotation);

            quickSaveWriter.Write("gold", cameraController.resources[BaseBehavior.ResourceType.Gold]);
            quickSaveWriter.Write("wood", cameraController.resources[BaseBehavior.ResourceType.Wood]);
            quickSaveWriter.Write("food", cameraController.resources[BaseBehavior.ResourceType.Food]);
            quickSaveWriter.Write("favor", cameraController.resources[BaseBehavior.ResourceType.Favor]);

            int index = 0;

            foreach (GameObject unitObject in GameObject.FindGameObjectsWithTag("Building").Concat(GameObject.FindGameObjectsWithTag("Unit")))
            {
                BaseBehavior unitBaseBehavior = unitObject.GetComponent <BaseBehavior>();
                unitBaseBehavior.Save(ref quickSaveWriter, index);
                index++;
            }
            quickSaveWriter.Write("indexCount", index);

            TerrainGenerator terrainGenerator = Terrain.activeTerrain.GetComponent <TerrainGenerator>();

            // Blind texture
            Color[] colors    = terrainGenerator.blindTexture2D.GetPixels();
            int[]   blindInfo = new int[colors.Length];
            for (int i = 0; i < colors.Length; i++)
            {
                blindInfo[i] = colors[i] == Color.black ? 1 : 0;
            }
            quickSaveWriter.Write("blindTextureData", blindInfo);

            // Binds
            for (int number = 1; number <= 9; number++)
            {
                int[] binds = new int[cameraController.unitsBinds[KeyCode.Alpha0 + number].Count];
                int   i     = 0;
                foreach (GameObject bindObject in cameraController.unitsBinds[KeyCode.Alpha0 + number])
                {
                    BaseBehavior bindObjectBaseBehavior = bindObject.GetComponent <BaseBehavior>();
                    binds[i] = bindObjectBaseBehavior.uniqueId;
                    i++;
                }
                quickSaveWriter.Write(new StringBuilder(15).AppendFormat("{0}_{1}", number, "bind").ToString(), binds);
            }

            quickSaveWriter.Commit();

            return(saveName);
        }
Exemplo n.º 8
0
    public void SaveResourceAndUpgradeData()
    {
        QuickSaveWriter instWriter = QuickSaveWriter.Create(resourceAndUpgradeDataSaveFileName); //create an instance of the QuickSaveWriter

        instWriter.Write <int>("resources", Resources);
        instWriter.Write <int>("totalResources", TotalResources);
        instWriter.Write <int>("solarSystemNumber", SolarSystemNumber);
        instWriter.Write <int>("currentMaxLaserRange", currentMaxLaserRange);
        instWriter.Write <int>("currentMaxLaserRecharge", currentMaxLaserRecharge);
        instWriter.Write <int>("currentMaxRocketRange", currentMaxRocketRange);
        instWriter.Write <int>("currentMaxRocketReload", currentMaxRocketReload);
        instWriter.Write <int>("currentMaxRocketYield", currentMaxRocketYield);
        instWriter.Write <int>("currentMaxJumpRange", currentMaxJumpRange);
        instWriter.Write <int>("currentMaxJumpRecharge", currentMaxJumpRecharge);
        instWriter.Write <int>("currentMaxShieldBoost", currentMaxShieldBoost);
        instWriter.Write <bool>("currentShieldOverboostActive", currentShieldOverboostActive);
        instWriter.Write <int>("currentMaxShieldBoostRecharge", currentMaxShieldBoostRecharge);
        instWriter.Write <int>("currentMaxHealth", currentMaxHealth);
        instWriter.Write <int>("currentMaxShields", currentMaxShields);
        instWriter.Write <int>("currentMaxSensorRange", currentMaxSensorRange);

        instWriter.Write <bool>("rocketsInstalled", rocketsInstalled);
        instWriter.Write <bool>("jumpDriveInstalled", jumpDriveInstalled);
        instWriter.Write <bool>("shieldBoostInstalled", shieldBoostInstalled);

        instWriter.Write <int>("currentHealth", playerHealthControl.currentPlayerHealth);
        instWriter.Write <int>("currentShields", playerHealthControl.currentPlayerShields);
        instWriter.Write <int>("currentJumpCharge", abilityController.jumpRange);
        instWriter.Write <int>("currentLaserCharge", abilityController.laserRange);
        //Debug.Log("Laser range saved as " + abilityController.laserRange);
        instWriter.Write <int>("currentShieldBoostCharge", abilityController.currentShieldBoostCharge);
        instWriter.Write <int>("currentRocketReload", abilityController.currentRocketReloadAmount);

        instWriter.Write <int>("healthMaxUpgradeCost", HealthMaxUpgradeCost);
        instWriter.Write <int>("shieldMaxUpgradeCost", ShieldMaxUpgradeCost);
        instWriter.Write <int>("sensorRangeUpgradeCost", SensorRangeUpgradeCost);
        instWriter.Write <int>("rocketRangeUpgradeCost", RocketRangeUpgradeCost);
        instWriter.Write <int>("rocketReloadUpgradeCost", RocketReloadUpgradeCost);
        instWriter.Write <int>("rocketYieldUpgradeCost", RocketYieldUpgradeCost);
        instWriter.Write <int>("laserRangeUpgradeCost", LaserRangeUpgradeCost);
        instWriter.Write <int>("laserRechargeUpgradeCost", LaserRechargeUpgradeCost);
        instWriter.Write <int>("jumpRangeUpgradeCost", JumpRangeUpgradeCost);
        instWriter.Write <int>("jumpRechargeUpgradeCost", JumpRechargeUpgradeCost);
        instWriter.Write <int>("shieldBoostUpgradeCost", ShieldBoostUpgradeCost);
        instWriter.Write <int>("shieldBoostRechargeUpgradeCost", ShieldBoostRechargeUpgradeCost);
        instWriter.Write <int>("shieldOverboostUpgradeCost", ShieldOverboostUpgradeCost);

        instWriter.Write <float>("threatLevel", ThreatLevel);
        instWriter.Write <int>("maxThreatLevelCounter", MaxThreatLevelCounter);


        instWriter.Commit();//write the save file

        mapManager.Save();
    }
Exemplo n.º 9
0
    public void SaveTestFile()
    {
        QuickSaveWriter instWriter = QuickSaveWriter.Create("TestFile");

        instWriter.Write <int>("resources", 1);
    }