Пример #1
0
        public void CanSave([Values] SerializationMethodType method)
        {
            var manager = CreateManager(method);

            var testObject = new SaveLoadTestObject()
            {
                listOfStrings = new List <string> {
                    "one", "two"
                },
                count = 10,
            };

            const string filename = "Testfile";

            manager.Save(testObject, filename);

            var filepath = $"{SaveLoadUtility.GetSavePath(SaveDirectory, BaseDirectory)}/{filename}";

            Assert.IsTrue(File.Exists(filepath));

            manager.DeleteSave(filename);
            Assert.IsFalse(File.Exists(filepath));

            Object.Destroy(manager);
        }
Пример #2
0
        public override void OnInspectorGUI()
        {
            EditorGUILayout.BeginVertical("Box");
            base.OnInspectorGUI();
            EditorGUILayout.EndVertical();

            var manager = (SaveLoadManager)target;

            if (manager.IsEncrypted && (string.IsNullOrEmpty(manager.Key)))
            {
                EditorGUILayout.HelpBox("Encryption key cannot be null or empty.", MessageType.Error);
            }

            if (manager.IsEncrypted && (string.IsNullOrEmpty(manager.Salt)))
            {
                EditorGUILayout.HelpBox("Salt cannot be null or empty.", MessageType.Error);
            }

            var savePath = SaveLoadUtility.GetRuntimeSavePath(manager.DefaultFolder, manager.BaseFolder);

            EditorGUILayout.BeginVertical("Box");
            EditorGUILayout.LabelField("Default Save Path");
            EditorGUILayout.LabelField(savePath);
            EditorGUILayout.EndVertical();

            if (GUILayout.Button("Open Data Folder"))
            {
                if (!Directory.Exists(savePath))
                {
                    //Create directory if it does not exist
                    Directory.CreateDirectory(savePath);
                }
                EditorUtility.RevealInFinder(savePath);
            }
        }
Пример #3
0
    private void reassignGameObjs()
    {
        playerControllerObj = GameObject.Find("PlayerController");
        playerController    = playerControllerObj.GetComponent <PlayerController>();

        fleetCombatInfoObj = GameObject.Find("FleetCombatInfo");
        fleetCombatInfo    = fleetCombatInfoObj.GetComponent <FleetCombatInfo>();

        shipChildrenCollect = playerController.GetComponent <ShipChildrenCollect>();
        combatCalc          = playerController.GetComponent <CombatCalc>();

        buildController = buildControllerObj.GetComponent <BuildController>();

        // Load in SaveLoad Utility
        if (slu == null)
        {
            sluObj = GameObject.Find("Persistent_SaveLoad_Obj_Menu");
            slu    = sluObj.GetComponent <SaveLoadUtility>();

            if (slu == null)
            {
                Debug.Log("[SaveLoadMenu] Start(): Warning! SaveLoadUtility not assigned!");
            }
        }
    }
Пример #4
0
        public void CanSaveLoadUnityObject([Values] SerializationMethodType method)
        {
            const string filename = "Testfile";

            var manager       = CreateManager(method);
            var testObj       = ScriptableObject.CreateInstance <SaveLoadTestUnityObject>();
            var loadedTestObj = ScriptableObject.CreateInstance <SaveLoadTestUnityObject>();

            testObj.textValue = "MyValue";

            manager.SaveUnityObject(testObj, filename);

            var filepath = $"{SaveLoadUtility.GetSavePath(SaveDirectory, BaseDirectory)}/{filename}";

            Assert.IsTrue(File.Exists(filepath));

            //var loadedTestObj = manager.Load<SaveLoadTestUnityObject>(filename);
            //Assert.IsTrue(loadedTestObj != null);
            manager.LoadUnityObjectOverwrite(loadedTestObj, filename);
            Assert.IsTrue(loadedTestObj.textValue == testObj.textValue);

            manager.DeleteSave(filename);
            Assert.IsFalse(File.Exists(filepath));

            Object.Destroy(testObj);
            Object.Destroy(loadedTestObj);
            Object.Destroy(manager);
        }
        public void CanGetFiles()
        {
            var testSave = new SaveLoadTestObject()
            {
                testData = "SaveFileExists"
            };
            var serializationMethod = GetSerializationMethod(SerializationMethodType.Binary);
            var filename            = "TestSave.sav";
            var folder = "TestFolder";

            SaveLoadUtility.Save(testSave, serializationMethod, filename, folder);

            var files = SaveLoadUtility.GetSavedFiles(folder);

            Assert.IsTrue(files.Length == 1);

            //Files should contain a list of names that exactly match the file name used
            //omits the path of the file
            Assert.IsTrue(files[0] == filename);

            SaveLoadUtility.DeleteSavedFile(filename, folder);

            files = SaveLoadUtility.GetSavedFiles();
            Assert.IsTrue(files.Length == 0);
        }
Пример #6
0
    private Regex regularExpression = new Regex("^[a-zA-Z0-9_\"  *\"]*$"); // A regular expression is a pattern that could be matched against an input text.

    /*Regular expression, contains only upper and lowercase letters, numbers, and underscores.
     *
     * ^ : start of string
     *   [ : beginning of character group
     *   a-z : any lowercase letter
     *   A-Z : any uppercase letter
     *   0-9 : any digit
     *   _ : underscore
     *   ] : end of character group
     * : zero or more of the given characters
     *   $ : end of string
     *
     */

    /*!
     * \brief Runs upon gameobject spawn (at start) and initializes variables
     */
    void Start()
    {
        if (slu == null)
        {
            slu = GetComponent <SaveLoadUtility>();
            if (slu == null)
            {
                Debug.Log("[SaveLoadMenu] Start(): Warning! SaveLoadUtility not assigned!");
            }
        }
    }
Пример #7
0
        private static void CleanupFiles()
        {
            //Cleaning up some files that were made by tests
            const string filename = "Testfile";
            var          filepath = $"{SaveLoadUtility.GetSavePath(SaveDirectory, BaseDirectory)}/{filename}";

            if (File.Exists(filepath))
            {
                File.Delete(filepath);
            }
        }
Пример #8
0
    private void LoadSaveLoadUT()
    {
        // Load in SaveLoad Utility
        if (slu == null)
        {
            sluObj = GameObject.Find("Persistent_SaveLoad_Obj_Menu");
            slu    = sluObj.GetComponent <SaveLoadUtility>();

            if (slu == null)
            {
                Debug.Log("[SaveLoadMenu] Start(): Warning! SaveLoadUtility not assigned!");
            }
        }
    }
        public void TearDown()
        {
            var path = SaveLoadUtility.GetSavePath();

            string[] files = { "TestSave.sav" };

            foreach (var file in files)
            {
                var filename = path + file;
                if (File.Exists(filename))
                {
                    File.Delete(filename);
                }
            }
        }
Пример #10
0
 void Start()
 {
     audios     = GetComponents <AudioSource>();
     countSound = audios[0];
     goSound    = audios[1];
     game       = GameState.pause;
     if (gm != null)
     {
         slu = gm.GetComponent <SaveLoadUtility>();
         slu.LoadGame(ghostSave);
     }
     StartCoroutine(Countdown(rotationAngle, rotationTime));
     //for (int i = 0; i < 25; i++) {
     //    leaderBoard.Add(new Top10("test", Random.Range(0f, 100f)));
     //}
 }
Пример #11
0
    private void Start()
    {
        gameRoundSeparated = curGameRound;
        // Load in SaveLoad Utility
        if (slu == null)
        {
            sluObj = GameObject.Find("Persistent_SaveLoad_Obj_Menu");
            slu    = sluObj.GetComponent <SaveLoadUtility>();

            if (slu == null)
            {
                Debug.Log("[SaveLoadMenu] Start(): Warning! SaveLoadUtility not assigned!");
            }
        }

        curGameRound = nextTurnBTN2.GetComponent <NextTurnBTN2>().gameRound;
        tileX        = (int)transform.position.x;
        tileZ        = (int)transform.position.z;
    }
Пример #12
0
        public void CanSaveAndLoadDictionary([Values(
                                                  SerializationMethodType.Binary,
                                                  SerializationMethodType.BinaryEncrypted
#if JSON_DOT_NET
                                                  , SerializationMethodType.JsonDotNet,
                                                  SerializationMethodType.JsonDotNetEncrypted
#endif
                                                  )] SerializationMethodType method)
        {
            var manager = CreateManager(method);

            var testObject = new SaveLoadDictionaryTestObject()
            {
                dict = new Dictionary <string, int>
                {
                    { "one", 1 },
                    { "two", 2 }
                },
                name = "Test",
            };

            const string filename = "Testfile";

            manager.Save(testObject, filename);

            var filepath = $"{SaveLoadUtility.GetSavePath(SaveDirectory, BaseDirectory)}/{filename}";

            Assert.IsTrue(File.Exists(filepath));

            var loadedObject = manager.Load <SaveLoadDictionaryTestObject>(filename);

            Assert.IsTrue(loadedObject.name == testObject.name);
            Assert.IsTrue(loadedObject.dict.Count == testObject.dict.Count);
            Assert.IsTrue(loadedObject.dict.ContainsKey("one"));
            Assert.IsTrue(loadedObject.dict.ContainsKey("two"));
            Assert.IsTrue(loadedObject.dict["one"] == 1);
            Assert.IsTrue(loadedObject.dict["two"] == 2);

            manager.DeleteSave(filename);
            Assert.IsFalse(File.Exists(filepath));

            Object.Destroy(manager);
        }
        public void SaveLoadAndDelete([Values] SerializationMethodType method)
        {
            var testSave = new SaveLoadTestObject()
            {
                testData = "SaveFileExists"
            };
            var serializationMethod = GetSerializationMethod(method);
            var filename            = "TestSave.sav";

            SaveLoadUtility.Save(testSave, serializationMethod, filename);

            Assert.IsTrue(SaveLoadUtility.Exists(filename));

            var loadedSave = (SaveLoadTestObject)SaveLoadUtility.Load(typeof(SaveLoadTestObject), serializationMethod, filename);

            Assert.NotNull(loadedSave);
            Assert.IsTrue(loadedSave.testData == testSave.testData);

            SaveLoadUtility.DeleteSavedFile(filename);

            Assert.IsFalse(SaveLoadUtility.Exists(filename));
        }
Пример #14
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     SaveLoadUtility.Save(_gameSession);
 }
        public void CanGetFiles_Empty()
        {
            var files = SaveLoadUtility.GetSavedFiles();

            Assert.IsTrue(files.Length == 0);
        }