void LoadDataEditor()
        {
            PersistentDataSystem persistentData = ((PersistentDataSystem)target);

            GUILayout.BeginVertical(EditorStyles.textArea);
            GUILayout.Space(2);
            GUIStyle option = new GUIStyle();

            option.alignment = TextAnchor.MiddleCenter;
            option.fontSize  = 15;
            option.fontStyle = FontStyle.Bold;
            GUILayout.Label("LOAD", option);
            GUILayout.Space(20);

            option.fontSize = 10;
            GUILayout.Label("Player", option);
            GUILayout.Space(5);

            if (persistentData.awakeLoadMode == PersistentDataSystem.AwakeLoadMode.SPECIFIC_CLASS && GUILayout.Button("Load specific player class data"))
            {
                persistentData.LoadClass(persistentData.classToLoad);
            }

            GUILayout.Space(2);
            if (GUILayout.Button("Load all player saved data"))
            {
                persistentData.LoadAllSavedData();
            }

            GUILayout.Space(2);
            if (GUILayout.Button("Erase all player saved data"))
            {
                persistentData.EraseAllSavedData();
            }

            GUILayout.Space(10);
            GUILayout.Label("Default", option);
            GUILayout.Space(5);

            if (persistentData.awakeLoadMode == PersistentDataSystem.AwakeLoadMode.SPECIFIC_CLASS && GUILayout.Button("Load specific default class data"))
            {
                persistentData.LoadClass(persistentData.classToLoad, PersistentDataSystem.PathMode.DEFAULT);
            }

            GUILayout.Space(2);
            if (GUILayout.Button("Load all default saved data"))
            {
                persistentData.LoadAllSavedData(PersistentDataSystem.PathMode.DEFAULT);
            }

            GUILayout.Space(2);
            if (GUILayout.Button("Erase all default saved data"))
            {
                persistentData.EraseAllSavedData(PersistentDataSystem.PathMode.DEFAULT);
                AssetDatabase.Refresh(ImportAssetOptions.Default);
            }

            GUILayout.EndVertical();
            GUILayout.Space(2);
        }
Beispiel #2
0
        public override void OnEnter(StatedMono <LevelStateEnum> statedMono)
        {
            LevelSystem levelSystem = statedMono as LevelSystem;

            int currentScore = ServiceProvider.GetService <ScoreSystem>().GetScore();
            PersistentDataSystem persistentDataSystem = ServiceProvider.GetService <PersistentDataSystem>();
            ScoreSavedData       scoreSavedData       = persistentDataSystem.GetSavedData <ScoreSavedData>();
            int bestScore = scoreSavedData.bestScore;

            if (bestScore < currentScore)
            {
                scoreSavedData.bestScore = currentScore;
                persistentDataSystem.SaveData(scoreSavedData);
            }

            ServiceProvider.GetService <ResultScreenView>().Show(currentScore, scoreSavedData.bestScore);

            IPausable[] pausables = GameObjectExtensions.FindObjectsOfTypeAll <IPausable>(true);

            for (int i = 0; i < pausables.Length; i++)
            {
                pausables[i].Pause(); //Awake all entities in the level
            }

            timer = levelSystem.clock.CurrentRenderTime + 5f;
        }
Beispiel #3
0
    public void DeleteGhost()
    {
        if (index == 0)
        {
            return;
        }

        ghosts.RemoveAt(index - 1);

        PersistentDataSystem inst = PersistentDataSystem.Instance;

        inst.EraseAllSavedData();
        inst.Init();
        ghosts.ForEach(inst.AddSavedDataToDictionnary);
        inst.SaveAllData();

        ResetList();
    }
        void SaveDataEditor()
        {
            PersistentDataSystem persistentData = ((PersistentDataSystem)target);

            GUILayout.BeginVertical(EditorStyles.textArea);
            GUILayout.Space(2);
            GUIStyle option = new GUIStyle();

            option.alignment = TextAnchor.MiddleCenter;
            option.fontSize  = 15;
            option.fontStyle = FontStyle.Bold;
            GUILayout.Label("SAVE", option);
            GUILayout.Space(5);

            if (persistentData.savedDataDictionnary.Count > 0 && GUILayout.Button("Save as player Data"))
            {
                persistentData.SaveAllData();
                Debug.Log("Data Saved in the Directory : " + persistentData.automaticPlayerSavedDataDirectoryPath);
            }

            if (persistentData.savedDataDictionnary.Count > 0 && GUILayout.Button("Save as default Data"))
            {
                persistentData.SaveAllData(PersistentDataSystem.PathMode.DEFAULT);
                AssetDatabase.Refresh(ImportAssetOptions.Default);

                if (persistentData.saveMode == PersistentDataSystem.SaveMode.SINGLE_FILE)
                {
                    Debug.Log("Data Saved in the Directory : " + persistentData.singleDefaultFileDirectoryPath);
                }
                else
                {
                    Debug.Log("Data Saved in the Directory : " + persistentData.multipleDefaultFilesDirectoryPath);
                }
            }

            GUILayout.EndVertical();
            GUILayout.Space(2);
        }
    public override void OnInspectorGUI()
    {
        PersistentDataSystem persistentData = ((PersistentDataSystem)target);

        persistentData.dataVersion = EditorGUILayout.TextField("DataVersion", persistentData.dataVersion);
        persistentData.autoSave    = EditorGUILayout.Toggle("AutoSave", persistentData.autoSave);

        persistentData.saveMode = (PersistentDataSystem.SaveMode)(EditorGUILayout.EnumPopup("SaveMode", persistentData.saveMode));

        EditorGUILayout.Space();
        PersistentDataSystem.LoadMode persistentDataSystemLoadMode = ((PersistentDataSystem.LoadMode)(serializedObject.FindProperty("loadAwakeMode").enumValueIndex));

        serializedObject.FindProperty("loadAwakeMode").enumValueIndex = (int)(PersistentDataSystem.LoadMode)(EditorGUILayout.EnumPopup("LoadAwakeMode", persistentDataSystemLoadMode));

        if (persistentDataSystemLoadMode == PersistentDataSystem.LoadMode.SPECIFIC_CLASS)
        {
            persistentData.classToLoad = (string[])EditorUtils.GenericField("Class to load", persistentData.classToLoad, typeof(string[]));
        }
        EditorGUILayout.Space();

        if (!persistentData.IsInit)
        {
            persistentData.Init();
        }

        GUILayout.Space(10);

        if (persistentData.savedDataDictionnary != null)
        {
            foreach (List <SavedData> sdList in persistentData.savedDataDictionnary.Values)
            {
                if (sdList != null && sdList.Count > 0)
                {
                    GUILayout.BeginVertical(EditorStyles.textArea);
                    GUILayout.Space(2);
                    GUIStyle option = new GUIStyle();
                    option.alignment = TextAnchor.MiddleCenter;
                    option.fontSize  = 15;
                    option.fontStyle = FontStyle.Bold;
                    GUILayout.Label(sdList[0].GetType().Name, option);
                    GUILayout.Space(5);

                    foreach (SavedData sd in sdList)
                    {
                        sd.DisplayInspector();
                        GUILayout.Space(2);
                    }

                    GUILayout.EndVertical();
                    GUILayout.Space(2);
                }
            }

            if (persistentData.savedDataDictionnary.Count > 0 && GUILayout.Button("Save Data"))
            {
                persistentData.SaveAllData();
                Debug.Log("Data Saved in the Directory : " + persistentData.AutomaticSavedDataDirectoryPath);
            }
        }

        GUILayout.Space(2);
        if (persistentDataSystemLoadMode == PersistentDataSystem.LoadMode.SPECIFIC_CLASS && GUILayout.Button("Load specific class data"))
        {
            persistentData.LoadClass(persistentData.classToLoad);
        }

        GUILayout.Space(2);
        if (GUILayout.Button("Load all saved data"))
        {
            persistentData.LoadAllSavedData();
        }

        GUILayout.Space(2);
        if (GUILayout.Button("Unload saved data"))
        {
            persistentData.UnloadAllSavedData();
        }

        GUILayout.Space(2);
        if (GUILayout.Button("Erase all saved data"))
        {
            persistentData.EraseAllSavedData();
        }

        serializedObject.ApplyModifiedProperties();
    }
Beispiel #6
0
 public void MakePersistent()
 {
     PersistentDataSystem.MakePersistent(this);
 }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUI.BeginChangeCheck();
            PersistentDataSystem persistentData = ((PersistentDataSystem)target);

            EditorGUILayout.PropertyField(serializedObject.FindProperty("dataVersion"), true);

            GUILayout.Space(5);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("autoSave"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("saveMode"), true);

            EditorGUILayout.Space();

            EditorGUILayout.PropertyField(serializedObject.FindProperty("awakeLoadMode"), true);


            if (persistentData.awakeLoadMode == PersistentDataSystem.AwakeLoadMode.SPECIFIC_CLASS)
            {
                //FIND ALL SAVEDDATA BY REFLECTION
                List <string> options = new List <string>();

                foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                {
                    foreach (Type type in assembly.GetTypes())
                    {
                        if (type.IsSubclassOf(typeof(SavedData)))
                        {
                            options.Add(type.FullName);
                        }
                    }
                }

                foldout = EditorGUILayout.Foldout(foldout, "Class To Load");

                if (foldout)
                {
                    GUILayout.Space(5);
                    GUILayout.BeginVertical();

                    if (GUILayout.Button("Add Element"))
                    {
                        if (persistentData.classToLoad == null)
                        {
                            persistentData.classToLoad = new List <string>();
                        }
                        persistentData.classToLoad.Add("");
                    }

                    if (persistentData.classToLoad != null)
                    {
                        EditorGUI.indentLevel++;
                        for (var i = 0; i < persistentData.classToLoad.Count; i++)
                        {
                            GUILayout.BeginHorizontal();

                            int selectedType = 0;

                            selectedType = options.FindIndex((x) => { return(x.Equals(persistentData.classToLoad[i])); });

                            if (selectedType == -1)
                            {
                                selectedType = 0;
                            }

                            selectedType = EditorGUILayout.Popup("Type", selectedType, options.ToArray());

                            persistentData.classToLoad[i] = options[selectedType];

                            if (GUILayout.Button("X", GUILayout.Width(18)))
                            {
                                persistentData.classToLoad.RemoveAt(i);
                            }

                            GUILayout.EndHorizontal();
                        }
                    }

                    EditorGUI.indentLevel--;
                    GUILayout.EndVertical();
                }

                EditorGUILayout.Space();
            }

            persistentData.Init();

            GUILayout.Space(10);

            if (persistentData.savedDataDictionnary != null)
            {
                foreach (List <SavedData> sdList in persistentData.savedDataDictionnary.Values)
                {
                    if (sdList != null && sdList.Count > 0)
                    {
                        GUILayout.BeginVertical(EditorStyles.textArea);
                        GUILayout.Space(2);
                        GUIStyle option = new GUIStyle();
                        option.alignment = TextAnchor.MiddleCenter;
                        option.fontSize  = 15;
                        option.fontStyle = FontStyle.Bold;
                        GUILayout.Label(sdList[0].GetType().Name, option);
                        GUILayout.Space(5);

                        foreach (SavedData sd in sdList)
                        {
                            AutoClassInspectorExtension.ShowAutoEditorGUI(sd);
                            GUILayout.Space(2);
                        }

                        GUILayout.EndVertical();
                        GUILayout.Space(2);
                    }
                }

                SaveDataEditor();
            }

            GUILayout.Space(10);
            LoadDataEditor();

            GUILayout.Space(10);
            if (GUILayout.Button("Unload saved data"))
            {
                persistentData.UnloadAllSavedData();
            }

            GUILayout.Space(10);

            serializedObject.ApplyModifiedProperties();
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Persisdent Data System");
            }
        }