Esempio n. 1
0
        protected override void OnEnter()
        {
            // Get connected variable
            Variable variable = GetVariable();

            if (variable == null)
            {
                RunemarkDebug.Error("Set Node Variable is null");
                return;
            }

            // Get the input
            Variable input = GetInput("Value");

            if (input == null)
            {
                RunemarkDebug.Error("Set Node Input is null");
                return;
            }

            //       Debug.Log(variable.Name + " set to " + input.Value);

            variable.Value = input.Value;
            StoreVariable("NewValue", input);
            IsFinished = true;
        }
Esempio n. 2
0
        public virtual Variable GetOutput(string name)
        {
            // Check if it has a stored value
            var stored = GetStoredVariable(name);

            if (stored != null)
            {
                return(stored);
            }

            var pin = PinCollection.Get(name);

            if (pin != null)
            {
                Variable defaultVariable = new Variable(pin.VariableType);

                // Double check... but better check more than none.
                if (pin.PinType != PinType.Output)
                {
                    RunemarkDebug.Error(name + " isn't output but it's used in the GetOutput method!");
                    return(defaultVariable);
                }
                return(CalculateOutput(name));
            }

            RunemarkDebug.Error(Name + "." + name + " is not an output.");
            return(null);
        }
        /// <summary>
        /// Sets the answer on the given index.
        /// </summary>
        /// <param name="index"></param>
        /// <param name="outputName"></param>
        /// <param name="text"></param>
        public void SetAnswer(int index, TextAnswerData answerData)
        {
            if (_answers.Count <= index)
            {
                if (DynamicAnswerNumber)
                {
                    var a = Instantiate(_answers[0]);
                    a.transform.SetParent(_answers[0].transform.parent, false);
                    a.Init(_controller);
                    _answers.Add(a);

                    BindKeyToAnswer(index, a);
                }
                else
                {
                    RunemarkDebug.Error("Can't show the {0}. answer, becouse the skin has less answer slots and it's not set to dynamical",
                                        index);
                }
            }

            var answer = _answers[index];

            answer.gameObject.SetActive(answerData.OutputName != "");
            answer.AnswerID = answerData.OutputName;
            answer.Set <string>(answerData.Text);
            answer.Index = index + 1;
        }
Esempio n. 4
0
        public static Type Get(Type nodeType)
        {
            if (nodeType.IsSubclassOf(typeof(Node)))
            {
                Type[] types       = System.Reflection.Assembly.GetExecutingAssembly().GetTypes();
                Type[] nodeLayouts = (from Type type in types where type.IsSubclassOf(typeof(NodeLayout)) select type).ToArray();

                foreach (var l in nodeLayouts)
                {
                    foreach (var attr in l.GetCustomAttributes(typeof(CustomNodeLayout), false))
                    {
                        var attribute = attr as CustomNodeLayout;
                        if (nodeType == attribute.InspectedType || (attribute.EditForChildClasses && nodeType.IsSubclassOf(attribute.InspectedType)))
                        {
                            return(l);
                        }
                    }
                }
            }
            else
            {
                RunemarkDebug.Error("{0} isn't subclass of the Node type.", nodeType);
            }

            return(typeof(DefaultLayout));            // return the default node layout
        }
Esempio n. 5
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
                              );
        }
Esempio n. 6
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);
            }
        }
Esempio n. 7
0
 protected T ConvertNode <T>() where T : Node
 {
     if (Node.GetType() == typeof(T) || Node.GetType().IsSubclassOf(typeof(T)))
     {
         return((T)Node);
     }
     RunemarkDebug.Error("{0} node is {1} and can't be converted to type of {2}",
                         Node.Name, Node.GetType(), typeof(T));
     return(null);
 }
Esempio n. 8
0
        /// <summary>
        /// Gets a value already converted to the given type (if possible).
        /// </summary>
        /// <returns>The value.</returns>
        /// <typeparam name="T">The 1st type parameter.</typeparam>
        public T ConvertedValue <T>()
        {
            if (Value == null)
            {
                return(default(T));
            }
            if (CanConvertTo(typeof(T)))
            {
                return((T)Value);
            }

            RunemarkDebug.Error("{0} variable is {1} that cannot be converted to {2}",
                                Name, Value.GetType(), typeof(T));
            return(default(T));
        }
Esempio n. 9
0
        public static void VariableField(Variable variable, GUIStyle style = null, bool showLabel = false)
        {
            try
            {
                string label = (showLabel) ? variable.Name : "";

                if (variable.type == typeof(string))
                {
                    if (style == null)
                    {
                        style = GUI.skin.textField;
                    }
                    variable.Value = EditorGUILayout.TextField(label, variable.ConvertedValue <string>(), style);
                }
                else if (variable.type == typeof(int))
                {
                    if (style == null)
                    {
                        style = GUI.skin.textField;
                    }
                    variable.Value = EditorGUILayout.IntField(label, variable.ConvertedValue <int>(), style);
                }
                else if (variable.type == typeof(float))
                {
                    if (style == null)
                    {
                        style = GUI.skin.textField;
                    }
                    variable.Value = EditorGUILayout.FloatField(label, variable.ConvertedValue <float>(), style);
                }
                else if (variable.type == typeof(bool))
                {
                    variable.Value = EditorGUILayout.Toggle(label, variable.ConvertedValue <bool>());
                }
                else
                {
                    if (style == null)
                    {
                        style = GUI.skin.label;
                    }
                    EditorGUILayout.LabelField(label, "[" + variable.type + "]", style);
                }
            }
            catch (System.InvalidCastException e)
            {
                RunemarkDebug.Error(e.Message);
            }
        }
Esempio n. 10
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);
            }
        }
Esempio n. 11
0
        protected override Variable CalculateOutput(string name)
        {
            if (name != "Result")
            {
                RunemarkDebug.Error(Name + " this node doesn't have " + name + " output");
                return(null);
            }

            var A = GetInput("A");
            var B = GetInput("B");

            Variable result = new Variable(typeof(bool));

            result.Value = Calc(A.ConvertedValue <bool>(), (B != null)? B.ConvertedValue <bool>() : false);
            return(result);
        }
Esempio n. 12
0
        protected override void OnEnter()
        {
            // If this is an input portal...
            if (IsInput)
            {
                // ... find the output portal
                if (OutputPortal == null)
                {
                    RunemarkDebug.Error("{0} ({1}) doesnt have output portal!", PortalName, ID);
                    return;
                }


                _calculatedNextNode = OutputPortal.PinCollection.Get("OUT");
                IsFinished          = true;
            }
        }
Esempio n. 13
0
        protected override Variable CalculateOutput(string name)
        {
            if (name != "Result")
            {
                RunemarkDebug.Error("{0} node doesn't have {1} output", Name, name);
                return(null);
            }

            var A = GetInput("A");
            var B = GetInput("B");

            Variable result = new Variable(Type);
            double   d      = Calc(Convert.ToDouble(A.Value), Convert.ToDouble(B.Value));

            result.Value = Convert.ChangeType(d, Type);
            return(result);
        }
Esempio n. 14
0
        public virtual Variable GetInput(string name)
        {
            var pin = PinCollection.Get(name);

            if (pin != null && pin.Connections.Count > 0)
            {
                Variable defaultVariable = new Variable(pin.VariableType);

                // Double check... but better check more than none.
                if (pin.PinType != PinType.Input)
                {
                    RunemarkDebug.Error(name + " isn't input but it's used in the GetInputValue method!");
                    return(defaultVariable);
                }

                // Get the connected node, if not exists, return a default value.
                var connectedNode = Root.Nodes.Find(pin.Connections[0].NodeID);
                if (connectedNode == null)
                {
                    RunemarkDebug.Error("{2} - No node is connected to {0}.{1}", Name, pin.Name, ID);
                    return(defaultVariable);
                }
                // Get the output value of the connected node.
                var variable = connectedNode.GetOutput(pin.Connections[0].PinName);
                if (variable == null)
                {
                    RunemarkDebug.Error("{0}- {1}.{2} variable is null",
                                        ID, connectedNode.Name, pin.Connections[0].PinName);
                    return(defaultVariable);
                }
                if (variable.type != pin.VariableType)
                {
                    RunemarkDebug.Error("{2} - Connected Pin ({0}) and Pin ({1}) has different types",
                                        variable.type, pin.VariableType, ID);
                    return(defaultVariable);
                }

                return(variable);
            }

            // Otherwise simply return a variable. Or null if it's not exists.
            return(Variables.GetByName(name));
        }
Esempio n. 15
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);
                    }
                }
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Gets the local variable with the given name of the loaded graph.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="variableName"></param>
        /// <returns></returns>
        public T GetLocalVariable <T>(string variableName)
        {
            var variable = Graph.LocalVariables.GetByName(variableName);

            if (variable == null)
            {
                RunemarkDebug.Error("Root variable with name of {0} doesn't exists in this dialogue graph({1})",
                                    variableName, Graph.Name);
                return(default(T));
            }

            if (variable.CanConvertTo(typeof(T)))
            {
                return(variable.ConvertedValue <T>());
            }

            RunemarkDebug.Error("You can't get root variable ({0}, {1}) as {2} becouse types are not matching",
                                variableName, variable.type, typeof(T));
            return(default(T));
        }
Esempio n. 17
0
        /// <summary>
        /// Sets the local variable with the given name of the loaded graph to the given value.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="variableName"></param>
        /// <param name="value"></param>
        public void SetLocalVariable <T>(string variableName, T value)
        {
            var variable = Graph.LocalVariables.GetByName(variableName);

            if (variable == null)
            {
                RunemarkDebug.Error("Root variable with name of {0} doesn't exists in this dialogue graph({1})",
                                    variableName, Graph.Name);
                return;
            }

            if (variable.CanConvertFrom(typeof(T)))
            {
                variable.Value = value;
            }
            else
            {
                RunemarkDebug.Error("You can't set root variable ({0}, {1}) to {2} ({3}) becouse types are not matching",
                                    variableName, variable.type, value, value.GetType());
            }
        }
Esempio n. 18
0
        public void CustomActionMenuCallback(string name, params object[] args)
        {
            switch (name)
            {
            case "Stress Test":     // TEST
                CreateMultipleTextNode();
                break;

            case "Paste": NodePaste(); break;

            default:

                string argsString = "\n [Arguments]";
                foreach (var a in args)
                {
                    argsString += "\n " + a + ",";
                }
                RunemarkDebug.Error("Action Menu Callback {0} not implemented. {1}",
                                    name, argsString);
                break;
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Set the global variable with the specified name.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public static void SetGlobalVariable <T>(string name, T value)
        {
            if (_globals == null)
            {
                return;
            }

            var v = _globals.Variables.GetByName(name);

            if (v != null)
            {
                if (v.type == typeof(T))
                {
                    v.Value = value;
                }
                else
                {
                    RunemarkDebug.Error("{0} global variable's type is {1}, and can't set it's value to {2}({3})",
                                        name, v.type, value, typeof(T));
                }
            }
        }
Esempio n. 20
0
        protected override Variable CalculateOutput(string name)
        {
            if (name != "Result")
            {
                RunemarkDebug.Error("{0} node doesn't have {1} output", Name, name);
                return(null);
            }

            Variable A      = GetInput("A");
            Variable B      = GetInput("B");
            Variable result = new Variable(typeof(bool));

            if (Type == typeof(string))
            {
                result.Value = Compare(A.ConvertedValue <string>(), A.ConvertedValue <string>());
            }
            else
            {
                result.Value = Compare(Convert.ToDouble(A.Value), Convert.ToDouble(B.Value));
            }
            return(result);
        }
Esempio n. 21
0
        public List <Node> NodeCreate(string name, System.Type type, System.Type subtype = null)
        {
            UnityEngine.Object o = _loadedGraph as FunctionGraph;
            if (o == null)
            {
                o = _loadedGraph as MacroGraph;
            }
            if (o == null)
            {
                RunemarkDebug.Error("Can't create node in the opened graph, since its not a INodeCollection");
                return(new List <Node>());
            }

            var node = (Node)AssetCreator.CreateAsset(name, type, o);

            node.EditorInit(_loadedGraph, _zoomArea.AbsolutePosition(_lastMousePosition), subtype);
            _loadedGraph.Nodes.Add(node);
            CreateLayout(node);
            Repaint();
            return(new List <Node>()
            {
                node
            });
        }
Esempio n. 22
0
 public virtual void UpdateValue <T>(T value)
 {
     RunemarkDebug.Error("{0} UpdateValue method is used but not implemented for value type of {1}",
                         GetType().ToString(), typeof(T));
 }
        public void OnTextChanged(DialogueFlow dialogue, TextData text, List <TextAnswerData> answers, SettingsData settings)
        {
            _behaviour = dialogue.Behaviour;

            // Select and open a skin
            if (settings.Skin == "")
            {
                settings.Skin = (dialogue.DefaultSkin != "") ? dialogue.DefaultSkin : DefaultSkin;
            }

            SelectSkin(settings.Skin);
            if (_activeSkin == null)
            {
                RunemarkDebug.Warning(settings.Skin + " skin doesn't exists in this canvas: " + gameObject.name);
                return;
            }

            // Stop the audio if currently playing
            if (_audioSource.isPlaying)
            {
                _audioSource.Stop();
            }

            // Set the actor's name and portrait
            string name     = text.Name;
            Sprite portrait = text.Portrait;

            _activeSkin.SetText(name, portrait, text.Text);
            _activeSkin.HideInputAnswer();

            _activeSkin.HideAnswers(0);

            // Set the answers
            int cnt = 0;

            foreach (var a in answers)
            {
                if (a.UseCustomUI)
                {
                    _activeSkin.SetCustomAnswer(a.UIElementName, a);
                }
                else if (answers.Count > cnt)
                {
                    _activeSkin.SetAnswer(cnt, a);
                    cnt++;
                }
            }
            // _activeSkin.HideAnswers(cnt);

            // Play Audio if any
            if (text.Audio != null)
            {
                _audioStopTime    = text.AudioEndTime;
                _audioSource.clip = text.Audio;
                _audioSource.time = text.AudioStartTime;

                if (text.AudioDelay > 0)
                {
                    _audioSource.PlayDelayed(text.AudioDelay);
                }
                else
                {
                    _audioSource.Play();
                }
            }

            // Set the timer
            if (_behaviour.Timer != null && cnt > 0)
            {
                _activeSkin.StartTimer(_behaviour.Timer.Seconds);
            }
            else
            {
                _activeSkin.HideTimer();
            }
        }