示例#1
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;
        }
示例#3
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;
        }
示例#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
        }
示例#5
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);
 }
示例#6
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));
        }
示例#7
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);
            }
        }
示例#8
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);
        }
示例#9
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;
            }
        }
示例#10
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);
        }
示例#11
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));
        }
示例#12
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));
        }
示例#13
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());
            }
        }
示例#14
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);
        }
示例#15
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;
            }
        }
示例#16
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));
                }
            }
        }
示例#17
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
            });
        }
示例#18
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));
 }