Beispiel #1
0
        /// <summary>
        /// Resets the value of the variable to default one.
        /// </summary>
        public void Reset()
        {
            Value = DefaultValue.Value;

            RunemarkDebug.Log("RESET: {0} is reseted from {1} to default value {2}",
                              Name, Value, DefaultValue.Value
                              );
        }
Beispiel #2
0
        void OnGUI()
        {
            RunemarkGUI.inspectorTitle.Draw("Dialogue System UI Globals", "");

            // If globals doesn't exists create new one.
            if (_globals == null)
            {
                float w = position.width;
                float h = position.height;
                Rect  r = new Rect(20, 60, w - 40, 30);

                EditorGUI.HelpBox(r, "You have to create a new Dialogue System Global asset. ", MessageType.Warning);
                r.y += r.height + 10;
                if (GUI.Button(r, "Create"))
                {
                    string path = EditorUtility.SaveFilePanelInProject(
                        "Create a new Dialogue System Global asset",
                        "Dialogue System Global.asset",
                        "asset", ""
                        );
                    // Check if the path is a Resources folder.
                    if (!path.Contains("Resources"))
                    {
                        var    pathArr  = path.Split('/').ToList();
                        string filename = pathArr[pathArr.Count - 1];
                        pathArr.RemoveAt(pathArr.Count - 1);
                        path = string.Join("/", pathArr.ToArray());

                        if (!Directory.Exists(path + "/Resources"))
                        {
                            AssetDatabase.CreateFolder(path, "Resources");
                        }

                        path = path + "/Resources";
                        path = path + "/" + filename;
                    }
                    RunemarkDebug.Log("Dialogue System Global created. Path: " + path);
                    _globals = AssetCreator.CreateAsset <DialogueSystemGlobals>(path);
                    OnEnable();
                }
                return;
            }

            Rect rectLeft  = new Rect(5, 45, 250, this.position.height - 50);
            Rect rectRight = new Rect(265, 45, position.width - 275, this.position.height - 50);

            EditorGUI.BeginChangeCheck();

            _variableList.Draw(rectLeft);

            VariableEditor.OnInspectorGUI(rectRight, _selected);

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(_globals);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Save every local and global variable value (that are marked as Saveable)
        /// </summary>
        public void Save()
        {
            if (mode == Mode.PlayerPrefs)
            {
                DialogueSystemSaveLoad.SaveToPlayerPrefs();
            }

            else if (mode == Mode.File)
            {
                string data = DialogueSystemSaveLoad.SerializeToString();
                string path = Path.Combine(Application.dataPath, FileName + ".save");
                File.WriteAllText(path, data);

                RunemarkDebug.Log("Saved to " + path);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Saves the saveable variables to the player prefs.
        /// </summary>
        public void SaveToPlayerPrefs()
        {
            string prefix = "RunemarkDialogueSystem";

            if (owner.GetType() == typeof(VisualEditorBehaviour) || owner.GetType().IsSubclassOf(typeof(VisualEditorBehaviour)))
            {
                prefix += "-" + ((VisualEditorBehaviour)owner).ID;
            }
            else if (owner.GetType() == typeof(GameObject))
            {
                var b = ((GameObject)owner).GetComponent <VisualEditorBehaviour>();
                prefix += "-" + b.ID;
            }

            foreach (var v in _variables)
            {
                if (v.Save)
                {
                    string key = prefix + "-" + v.Name;

                    RunemarkDebug.Log("{0} variable saved to player prefs", key);

                    if (v.type == typeof(int))
                    {
                        PlayerPrefs.SetInt(key, v.ConvertedValue <int>());
                    }
                    else if (v.type == typeof(float))
                    {
                        PlayerPrefs.SetFloat(key, v.ConvertedValue <float>());
                    }
                    else if (v.type == typeof(string))
                    {
                        PlayerPrefs.SetString(key, v.ConvertedValue <string>());
                    }
                    else
                    {
                        string s = SerializeToString(v.Value);
                        PlayerPrefs.SetString(key, s);
                    }
                }
            }
        }