Пример #1
0
    public override void OnInspectorGUI()
    {
        if (SerializableManager.current != target)
        {
            GUI.color = Color.red;
            EditorGUILayout.HelpBox("You can only have one instance of Serializable Manager at the same time.", MessageType.Error, true);
            if (SerializableManager.current == null && SerializableManager.current != (SerializableManager)target)
            {
                SerializableManager.current = ((SerializableManager)target);
            }
            return;
        }

        DrawDefaultInspector();

        serializedObject.Update();

        if (serializedObject.FindProperty("Encrypt").boolValue)
        {
            EditorGUILayout.PropertyField(serializedObject.FindProperty("password"), true);
            if (passwordWarning > Time.realtimeSinceStartup || (lastpassword != "" && lastpassword != serializedObject.FindProperty("password").stringValue))
            {
                EditorGUILayout.HelpBox("Change the password will cause can not be loaded old games", MessageType.Warning, true);
                if (passwordWarning < Time.realtimeSinceStartup)
                {
                    passwordWarning = Time.realtimeSinceStartup + 20;
                }
            }
            lastpassword = serializedObject.FindProperty("password").stringValue;
        }

        if (serializedObject.FindProperty("AutoSave").boolValue)
        {
            EditorGUILayout.PropertyField(serializedObject.FindProperty("TimeBetweenSavedSeconds"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("CurrentTimeToSave"), true);
        }

        GUI.enabled = Application.isPlaying;

        if (GUILayout.Button("Save All"))
        {
            SerializableManager.SaveAll();
        }
        if (GUILayout.Button("Load All"))
        {
            SerializableManager.LoadAll();
        }
        if (!Application.isPlaying)
        {
            GUI.enabled = true;
            GUI.color   = Color.yellow;
            EditorGUILayout.HelpBox("You can only save and load in play mode", MessageType.Warning, true);
            GUI.color = Color.white;
        }


        serializedObject.ApplyModifiedProperties();
    }
Пример #2
0
    void OnGUI()
    {
        if (GUI.Button(new Rect(10, 10, 150, 20), "Save Game"))
        {
            SerializableManager.SaveAll();
        }
        if (GUI.Button(new Rect(10, 50, 150, 20), "Load Game"))
        {
            //to erase those now!
            foreach (exampleCube cubes in GameObject.FindObjectsOfType <exampleCube>())
            {
                Destroy(cubes.gameObject);
            }
            SerializableManager.LoadAll();
        }

        GUI.Label(new Rect(10, 300, 200, 20), "Time: " + (int)time);
    }
    private void FilesExplorer()
    {
        if (SerializableManager.current.Encrypt && SerializableManager.current.password != lastpassword)
        {
            this.CacheEncrytion.Clear();//old
        }

        //Back...
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.LabelField("[FOLDER]", EditorStyles.boldLabel, GUILayout.Width(90));
        EditorGUILayout.LabelField("[BACK]", GUILayout.MinWidth(20));
        if (GUILayout.Button("Open", GUILayout.Width(110)))
        {
            GUIUtility.keyboardControl = 0;
            FilesPath = Path.GetFullPath(Path.Combine(FilesPath, @"..\"));
        }
        //to aling
        EditorGUILayout.LabelField("", EditorStyles.label, GUILayout.Width(110 * 2 + 4));
        EditorGUILayout.EndHorizontal();

        try {
            foreach (string DirectoryPath in Directory.GetDirectories(FilesPath))
            {
                string FolderName = Path.GetFileName(DirectoryPath);
                EditorGUILayout.BeginHorizontal();

                EditorGUILayout.LabelField("[FOLDER]", EditorStyles.boldLabel, GUILayout.Width(90));
                EditorGUILayout.LabelField(FolderName, GUILayout.MinWidth(20));

                if (GUILayout.Button("Open", GUILayout.Width(110)))
                {
                    GUIUtility.keyboardControl = 0;
                    FilesPath = DirectoryPath;
                }
                //to aling
                EditorGUILayout.LabelField("", EditorStyles.label, GUILayout.Width(110 * 2 + 4));

                EditorGUILayout.EndHorizontal();
            }

            EditorGUILayout.Space();

            foreach (string FilePath in Directory.GetFiles(FilesPath))
            {
                string FileName = Path.GetFileName(FilePath);
                if (FileName == "Thumbs.db")
                {
                    continue;
                }

                if (lastpassword == null || SerializableManager.current.password != lastpassword || !CacheEncrytion.ContainsKey(FileName))
                {
                    //create cache
                    CacheEncrytion.Add(FileName, SerializableFiles.IsValid(FilePath));
                }

                SerializableFiles.ValidsTypes ValidSave = SerializableFiles.ValidsTypes.Error;  //SerializableFiles.IsValid(FilePath);
                CacheEncrytion.TryGetValue(FileName, out ValidSave);

                EditorGUILayout.BeginHorizontal();
                bool valid = ValidSave != SerializableFiles.ValidsTypes.Error && ValidSave != SerializableFiles.ValidsTypes.ERROR_Enc;
                //File status
                EditorGUILayout.LabelField("[" + ValidSave.ToString().Replace("_", " ").ToUpper() + "]", valid ? ValidFile : NotValidFile, GUILayout.Width(90));
                //File name
                EditorGUILayout.LabelField(FileName, GUILayout.MinWidth(200));
                //File size
                EditorGUILayout.LabelField(FileSize(FilePath), TextButtonRight, GUILayout.Width(100));
                //shows buttons?
                if (valid)
                {
                    //View Button
                    if (GUILayout.Button("View", GUILayout.Width(110)))
                    {
                        this.LoadGame(FileName);
                    }
                    //Load Button
                    GUI.enabled = SerializableManager.current != null && SerializableManager.current.enabled && Application.isPlaying;
                    if (GUILayout.Button("Load", GUILayout.Width(110)))
                    {
                        SerializableManager.LoadAll(FileName);
                    }
                    //Default Button
                    GUI.enabled = SerializableManager.current != null;
                    if (GUILayout.Button((SerializableManager.current.DefaultFileName == FileName ? "Remove Default" : "Set Default"), GUILayout.Width(110)))
                    {
                        if (SerializableManager.current.DefaultFileName == FileName)
                        {
                            FileName = SerializableManager.DefaultSaveName;
                        }
                        SerializableManager.current.DefaultFileName = FileName;
                    }
                }
                else
                {
                    if (ValidSave == SerializableFiles.ValidsTypes.Error)
                    {
                        EditorGUILayout.LabelField("This is not a valid saved", EditorStyles.label, GUILayout.Width(110 * 3 + 8));
                    }
                    else if (ValidSave == SerializableFiles.ValidsTypes.ERROR_Enc)
                    {
                        EditorGUILayout.LabelField("The saved could not be decrypted, bad password?", EditorStyles.label, GUILayout.Width(110 * 3 + 8));
                    }
                    else
                    {
                        EditorGUILayout.LabelField("INTERAL ERROR (A161)", EditorStyles.label, GUILayout.Width(110 * 3 + 8));
                    }
                }
                //Restart GUI Status
                GUI.enabled = true;
                EditorGUILayout.EndHorizontal();
            }
        } catch (FileNotFoundException e) {
            GUI.color = Color.yellow;
            EditorGUILayout.HelpBox("The route " + e.FileName + " is not a folder!", MessageType.Error);
        } catch (Exception e) {
            GUI.color = Color.yellow;
            EditorGUILayout.HelpBox("Error: " + e.Message, MessageType.Error);
        }

        lastpassword = SerializableManager.current.password;
    }