Exemple #1
0
        public static void RestoreGame()
        {
            QuickSaveReader saveReader = QuickSaveReader.Create(LoadSaveScript.selectedFile);

            int indexCount = saveReader.Read <int>("indexCount");

            for (int index = 0; index < indexCount; index++)
            {
                BaseBehavior.Load(ref saveReader, index);
            }

            foreach (GameObject unitObject in GameObject.FindGameObjectsWithTag("Building").Concat(GameObject.FindGameObjectsWithTag("Unit")))
            {
                BaseBehavior unitBaseBehavior = unitObject.GetComponent <BaseBehavior>();
                unitBaseBehavior.RestoreBehavior();
            }

            Vector3    cameraPosition = saveReader.Read <Vector3>("cameraPosition");
            Quaternion cameraRotation = saveReader.Read <Quaternion>("cameraRotation");

            Camera.main.transform.position = cameraPosition;
            Camera.main.transform.rotation = cameraRotation;

            CameraController cameraController = Camera.main.GetComponent <CameraController>();

            cameraController.resources[BaseBehavior.ResourceType.Gold]  = saveReader.Read <float>("gold");
            cameraController.resources[BaseBehavior.ResourceType.Wood]  = saveReader.Read <float>("wood");
            cameraController.resources[BaseBehavior.ResourceType.Food]  = saveReader.Read <float>("food");
            cameraController.resources[BaseBehavior.ResourceType.Favor] = saveReader.Read <float>("favor");

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

            Color[] colors    = terrainGenerator.blindTexture2D.GetPixels();
            int[]   blindInfo = saveReader.Read <int[]>("blindTextureData");
            Color   newColor  = Color.white;

            newColor.a = 0;
            for (int i = 0; i < colors.Length; i++)
            {
                colors[i] = blindInfo[i] == 1 ? Color.black : newColor;
            }
            terrainGenerator.blindTexture2D.SetPixels(colors);
            terrainGenerator.blindTexture2D.Apply();
            Graphics.Blit(terrainGenerator.blindTexture2D, terrainGenerator.blindTexture);
            terrainGenerator.initBlindTexture = true;

            try
            {
                // Binds
                for (int number = 1; number <= 9; number++)
                {
                    int[] binds = saveReader.Read <int[]>(new StringBuilder(15).AppendFormat("{0}_{1}", number, "bind").ToString());
                    int   i     = 0;
                    foreach (int bindObjectUniueId in binds)
                    {
                        cameraController.unitsBinds[KeyCode.Alpha0 + number].Add(BaseBehavior.GetObjectByUniqueId(bindObjectUniueId));
                        i++;
                    }
                }
            }
            catch (Exception e)
            { }

            selectedFile = "";
        }