コード例 #1
0
        public void Compile(CodeBuilder builder)
        {
            string varName      = builder.PortToVariableName(GetOutputPort(""));
            var    constVal     = builder.Constant(value);
            string type         = builder.HoistNamespace(typeof(T));
            string constKeyword = constVal.isConstant ? "const " : "";

            // If we're declaring something that can be optimized for future operations, track it.
            if (constVal.isConstant)
            {
                builder.AddConstToScope(varName);
            }

            builder.AppendLine($"{constKeyword}{type} {varName} = {constVal};");
        }
コード例 #2
0
        public void Compile(CodeBuilder builder)
        {
            var aVar = builder.PortToValue(GetInputPort("A"), a);
            var bVar = builder.PortToValue(GetInputPort("B"), b);

            string varName      = builder.PortToVariableName(GetOutputPort(""));
            string constKeyword = (aVar.isConst && bVar.isConst) ? "const " : "";
            string returnType   = builder.HoistNamespace(typeof(R));
            string operation    = CompileOperation(aVar.value, bVar.value);

            // If the operation executes on two constants, also make the operation constant.
            if (aVar.isConst && bVar.isConst)
            {
                builder.AddConstToScope(varName);
            }

            builder.AppendLine($"{constKeyword}{returnType} {varName} = {operation};");
        }
コード例 #3
0
        public void Compile(CodeBuilder builder)
        {
            string prefabVar        = ConstantOrVariable <GameObject>(builder, "Prefab", null);
            string parentVar        = null;
            string localPositionVar = ConstantOrVariable(builder, "Local Position", localPosition);
            string localRotationVar = ConstantOrVariable(builder, "Local Rotation", localRotation);

            NodePort port = GetInputPort("Parent");

            if (port.IsConnected)
            {
                NodePort outputPort = port.GetConnection(0);
                builder.CompileInputs(port);

                parentVar = builder.PortToVariableName(outputPort);
            }

            if (parentVar != null)
            {
                builder.AppendLine($"GameObject TODO = Instantiate(" +
                                   $"{prefabVar}, {localPositionVar}, {localRotationVar}, {parentVar}.transform" +
                                   $");"
                                   );
            }
            else // Shorter version without a parent transform
            {
                builder.AppendLine($"GameObject TODO = Instantiate(" +
                                   $"{prefabVar}, {localPositionVar}, {localRotationVar}" +
                                   $");"
                                   );
            }

            // Continue to next executable node
            // TODO: This would be duplicated for every ExecNode.
            // Put it in ExecNode or something as the base behavior
            var next = GetNextExec();

            if (next is ICanCompile nextNode)
            {
                nextNode.Compile(builder);
            }
        }