public static void Load() { Debug.Log("UNotes: Loading options from " + settingsFile); if (!System.IO.File.Exists(settingsFile) || string.IsNullOrEmpty(settingsFile)) { // Default values //instance.filePath = (Directory.GetParent (Application.dataPath)).ToString () + "/UNotesDatabase.dat"; instance.fileName = "UNotesDatabase.dat"; instance.textColor = SerializableColor.white; instance.bgColor = SerializableColor.black; instance.fontSize = 12; instance.bold = false; Debug.LogWarning(settingsFile + " file does not found."); return; } System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); System.IO.FileStream fs = new System.IO.FileStream(settingsFile, System.IO.FileMode.OpenOrCreate); UNotesOptions options = (UNotesOptions)bf.Deserialize(fs); // https://msdn.microsoft.com/en-us/library/hh158566(v=vs.110).aspx //instance.filePath = options.filePath; instance.fileName = options.fileName; instance.textColor = options.textColor; instance.bgColor = options.bgColor; instance.bold = options.bold; instance.fontSize = options.fontSize; fs.Close(); }
//public UNote() //{ //} public UNote(string _text, GameObject _gameObject, UNotesOptions options = null) { gameObject = _gameObject; text = _text; if (options != null) { bold = options.bold; fontSize = options.fontSize; ser_color = options.textColor.GetValues(); ser_bgColor = options.bgColor.GetValues(); } }
void OnGUI() { options = UNotesOptions.instance; // get the instance EditorStyles.label.wordWrap = true; EditorGUI.BeginChangeCheck(); scroll = EditorGUILayout.BeginScrollView(scroll); EditorGUILayout.LabelField("Default Style", EditorStyles.boldLabel); textColor = EditorGUILayout.ColorField("Text Color", options.textColor.GetColor()); bgColor = EditorGUILayout.ColorField("Backgr. Color", options.bgColor.GetColor()); options.fontSize = EditorGUILayout.IntField("Font Size", options.fontSize); options.bold = EditorGUILayout.Toggle("Bold", options.bold); showAdvanced = EditorGUILayout.Toggle("Show Advanced", showAdvanced); if (showAdvanced) { EditorGUILayout.Space(); Color guiCurrentColor = GUI.color; GUI.color = Color.red; EditorGUILayout.LabelField("ADVANCED OPTIONS", EditorStyles.boldLabel); GUI.color = new Color(1f, .7f, 0f); EditorGUILayout.LabelField("Backup your files!\nPlease note the following options can make you lose your work if not properly set."); GUI.color = guiCurrentColor; EditorGUILayout.BeginHorizontal(); //options.filePath = EditorGUILayout.TextField("File Location", options.filePath); options.fileName = EditorGUILayout.TextField("UNotes database file name", options.fileName); // if (GUILayout.Button("Set...", GUILayout.MaxWidth(40f))) // { // options.filePath = EditorUtility.OpenFilePanel("UNotes database file", Application.dataPath, "dat"); // //options.filePath = EditorUtility.SaveFilePanel("UNotes database file", Application.dataPath, "UNotesDatabase", "dat"); // } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginVertical(); EditorStyles.label.wordWrap = true; EditorGUILayout.LabelField("TIP: When changing file name, save your project immediately to store all notes in the new database file.", EditorStyles.helpBox); DEBUG_MODE = EditorGUILayout.Toggle("DEBUG MODE", DEBUG_MODE); EditorGUILayout.EndVertical(); } EditorGUILayout.EndScrollView(); if (EditorGUI.EndChangeCheck()) { options.textColor = new SerializableColor(textColor); options.bgColor = new SerializableColor(bgColor); } if (GUILayout.Button("Save and Close")) { UNotesOptions.Save(); Close(); } }