Пример #1
0
        public virtual void WriteCode(TemplateContext ctx, ActionNode node)
        {
            var varStatement = ctx.CurrentDeclaration._private_(node.Meta.FullName, node.VarName);

            varStatement.InitExpression = new CodeObjectCreateExpression(node.Meta.FullName);

            foreach (var item in node.GraphItems.OfType <IActionIn>())
            {
                var contextVariable = item.Item;
                if (contextVariable == null)
                {
                    continue;
                }
                ctx._("{0}.{1} = {2}", varStatement.Name, item.Name, item.VariableName);
            }


            ctx._("{0}.System = System", varStatement.Name);


            foreach (var item in node.GraphItems.OfType <ActionBranch>())
            {
                var branchOutput = item.OutputTo <SequenceItemNode>();
                if (branchOutput == null)
                {
                    continue;
                }
                if (DebugSystem.IsDebugMode)
                {
                    ctx._("{0}.{1} = ()=> {{ System.StartCoroutine({2}()); }}", varStatement.Name, item.Name, item.VariableName);
                }
                else
                {
                    ctx._("{0}.{1} = {2}", varStatement.Name, item.Name, item.VariableName);
                }
            }

            ctx._("{0}.Execute()", varStatement.Name);

            node.WriteActionOutputs(ctx);
        }
Пример #2
0
 public ActionNodeViewModel(ActionNode graphItemObject, Invert.Core.GraphDesigner.DiagramViewModel diagramViewModel) :
     base(graphItemObject, diagramViewModel)
 {
 }
Пример #3
0
        public override void WriteCode(TemplateContext ctx, ActionNode node)
        {
            var codeMethodReferenceExpression = new CodeMethodReferenceExpression(
                new CodeSnippetExpression(SystemType.FullName),
                Method.Name);

            if (this.InstanceInfo != null)
            {
                var instanceVar = node.InputVars.FirstOrDefault(p => p.ActionFieldInfo == this.InstanceInfo);
                if (instanceVar != null)
                {
                    codeMethodReferenceExpression = new CodeMethodReferenceExpression(new CodeSnippetExpression(instanceVar.VariableName), Method.Name);
                }
            }
            var _currentActionInvoker =
                new CodeMethodInvokeExpression(
                    codeMethodReferenceExpression);

            foreach (var x in Method.GetParameters())
            {
                var item  = node.GraphItems.OfType <IActionItem>().FirstOrDefault(p => p.Name == x.Name);
                var input = item as IActionIn;
                if (input != null)
                {
                    if (input.ActionFieldInfo == InstanceInfo)
                    {
                        continue;
                    }

                    if (input.ActionFieldInfo.IsGenericArgument)
                    {
                    }
                    else
                    {
                        _currentActionInvoker.Parameters.Add(
                            new CodeSnippetExpression((input.ActionFieldInfo.IsByRef ? "ref " : string.Empty) +
                                                      string.Format("{0}", input.VariableName)));
                    }
                }
                var @out = item as ActionOut;
                if (@out != null)
                {
                    if (@out.ActionFieldInfo != null && @out.ActionFieldInfo.IsReturn)
                    {
                        continue;
                    }
                    _currentActionInvoker.Parameters.Add(
                        new CodeSnippetExpression(string.Format("out {0}", @out.VariableName)));
                }
                var branch = item as ActionBranch;
                if (branch != null)
                {
                    if (DebugSystem.IsDebugMode)
                    {
                        _currentActionInvoker.Parameters.Add(
                            new CodeSnippetExpression(string.Format("()=> {{ System.StartCoroutine({0}()); }}",
                                                                    branch.VariableName)));
                    }
                    else
                    {
                        _currentActionInvoker.Parameters.Add(
                            new CodeSnippetExpression(string.Format("{0}", branch.VariableName)));
                    }
                }
            }

            var resultOut = node.GraphItems.OfType <IActionItem>().FirstOrDefault(p => p.ActionFieldInfo != null && p.ActionFieldInfo.IsReturn);

            if (resultOut == null)
            {
                ctx.CurrentStatements.Add(_currentActionInvoker);
            }
            else
            {
                var assignResult = new CodeAssignStatement(
                    new CodeSnippetExpression(resultOut.VariableName), _currentActionInvoker);
                ctx.CurrentStatements.Add(assignResult);
            }
        }