Exemple #1
0
        /// <summary>
        /// Draws the persistence fold out.
        /// </summary>
        virtual protected void DrawPersistenceFoldOut()
        {
            Persistable myTarget = (Persistable)target;

// TODO Add more options to allow users to edit these
            EditorGUILayout.BeginHorizontal();
//			GUILayout.Button ("Edit");
            if (GUILayout.Button("Reset"))
            {
                myTarget.ResetSaveData();
            }
//			GUILayout.Button ("Load...");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.LabelField("Loading", EditorStyles.boldLabel);
            UpdateBool(ref myTarget.loadOnAwake, "Load on Awake");
            UpdateBool(ref myTarget.loadOnStart, "Load on Start");
            UpdateBool(ref myTarget.loadOnCharacterLoad, "Load on Character Load");
            EditorGUILayout.LabelField("Saving", EditorStyles.boldLabel);
            UpdateBool(ref myTarget.saveOnDeath, "Save on Death");
            UpdateBool(ref myTarget.saveOnGameOver, "Save on Game Over");
            UpdateBool(ref myTarget.saveOnSceneExit, "Save on Scene Exit");
            UpdateBool(ref myTarget.saveOnChange, "Save on Change");
            EditorGUILayout.LabelField("Resetting", EditorStyles.boldLabel);
            UpdateBool(ref myTarget.resetOnDeath, "Reset on Death");
            UpdateBool(ref myTarget.resetOnGameOver, "Reset on Game Over");
            UpdateBool(ref myTarget.resetOnSceneExit, "Reset on Scene Exit");
        }
        /// <summary>
        /// Load the given persistable.
        /// </summary>
        /// <param name="p">Persistable to laod.</param>
        public static void Load(Persistable p)
        {
            object savedObject = LoadSavedData(p);

            if (savedObject != null)
            {
                p.ApplySaveData(savedObject);
            }
            else
            {
                p.ResetSaveData();
            }
        }
Exemple #3
0
        /// <summary>
        /// Load the given persistable.
        /// </summary>
        /// <param name="p">Persistable to laod.</param>
        public static void Load(Persistable p)
        {
            string data = PlayerPrefs.GetString(BasePlayerPrefId + p.Identifier, "");

            if (data.Length > 0)
            {
                using (StringReader reader = new StringReader(data)){
                    XmlSerializer serializer  = new XmlSerializer(p.SavedObjectType());
                    object        savedObject = serializer.Deserialize(reader);
                    p.ApplySaveData(savedObject);
                }
            }
            else
            {
                p.ResetSaveData();
            }
        }
Exemple #4
0
 /// <summary>
 /// Resets the given persistable.
 /// </summary>
 /// <param name="p">Persistable to reset.</param>
 public static void Reset(Persistable p)
 {
     PlayerPrefs.DeleteKey(BasePlayerPrefId + p.Identifier);
     p.ResetSaveData();
 }