コード例 #1
0
    public void onEditSimpleCodeField()
    {
        if (!canEditTarget)
        {
            return;
        }

        List <string>    args           = new List <string>(simpleCodeInputField.text.Split(' '));
        List <InputType> finalArgsTypes = new List <InputType>();
        List <object>    finalArgs      = new List <object>();
        List <string>    finalArgsStr   = new List <string>();

        if (args.Count > parameters.Count)
        {
            Debug.LogError("More arguments than there are node parameters");
            simpleCodeInputField.text = oldAcceptedText;
        }
        else //argumets passed the first row of tests
        {
            for (int i = 0; i < args.Count; i++)
            {
                //check to see if entered text matches the parameter contraints
                bool   isPass = true;
                object result = null;
                if (parameters[i] == InputType.nodeType)
                {
                    try
                    {
                        if (args[i] == "")
                        {
                            result = Enum.Parse(typeof(NodeType), "none");
                        }
                        else
                        {
                            result = Enum.Parse(typeof(NodeType), args[i]);
                        }
                    }
                    catch
                    {
                        isPass = false;
                    }
                }
                else if (parameters[i] == InputType.dataType)
                {
                    try
                    {
                        if (args[i] == "")
                        {
                            result = Enum.Parse(typeof(DataType), "noneT");
                        }
                        else
                        {
                            result = Enum.Parse(typeof(DataType), args[i] + "T");
                        }
                    }
                    catch // (ArgumentException e)
                    {
                        isPass = false;
                    }
                }
                else if (parameters[i] == InputType.name)
                {
                    try
                    {
                        if (args[i] == "")
                        {
                            isPass = false;
                        }
                        else
                        {
                            result = (object)args[i];
                        }
                    }
                    catch
                    {
                        isPass = false;
                    }
                }
                else if (parameters[i] == InputType.value)
                {
                    try
                    {
                        if (args[i] == "")
                        {
                            isPass = false;
                        }
                        else
                        {
                            result = (object)args[i];
                        }
                    }
                    catch
                    {
                        isPass = false;
                    }
                }
                else
                {
                    isPass = false;
                }

                //If current argument passed then put into argunment list
                if (isPass && result != null)
                {
                    finalArgsTypes.Add(parameters[i]);
                    finalArgs.Add(result);
                    finalArgsStr.Add(args[i]);
                }
            }
        }

        oldAcceptedText = simpleCodeInputField.text;
        targetNode.updateNodeState(finalArgsTypes, finalArgs, finalArgsStr);
    }