コード例 #1
0
        private void Start()
        {
            // for testing only
            CurrentSystem = new CodeblockSystem();

            _handle = transform.GetChild(0);
        }
コード例 #2
0
        protected override CodeblockSystem BuildSystem()
        {
            CodeblockSystem system = new CodeblockSystem();

            const int   desiredLoopCount   = 4;
            int         loopRunCount       = 0;
            ActionBlock loopCountIncrement = new ActionBlock();

            loopCountIncrement.Action = () => loopRunCount++;

            DynamicInputOperator <int> count = new DynamicInputOperator <int>();

            count.Value = desiredLoopCount;

            ForLoopBlock forLoop = new ForLoopBlock();

            forLoop.LoopCount = count;

            AssertTestBlock assert = new AssertTestBlock();

            assert.Condition = () => loopRunCount == desiredLoopCount;

            forLoop.Children.InsertItem(loopCountIncrement, null);

            system.Blocks.InsertItem(forLoop, null);
            system.Blocks.InsertItem(assert, forLoop);

            return(system);
        }
コード例 #3
0
        private IEnumerator Start()
        {
            try
            {
                CodeblockSystem system = BuildSystem();

                if (system.AnyError)
                {
                    IEnumerable <IBlockError> errors = system.Errors;
                    string[] errorMessages           = errors.Select(e => e.ToString()).ToArray();
                    Debug.LogError(string.Join("\n", errorMessages));
                }
                else
                {
                    ICodeblockExecutionContext context = new StandardContext(this);
                    yield return(StartCoroutine(system.Blocks.ExecuteCodeblocks(context)));
                }
                _isDone = true;
            }
            finally
            {
                IsTestSuccess = true;
            }
            yield break;
        }
コード例 #4
0
        protected override CodeblockSystem BuildSystem()
        {
            CodeblockSystem system = new CodeblockSystem();

            AssertTestBlock poisonedBlock = new AssertTestBlock();

            poisonedBlock.Condition = () => false;

            BreakCodeblock breakBlock = new BreakCodeblock();

            DynamicInputOperator <int> count = new DynamicInputOperator <int>();

            count.Value = 100;

            ForLoopBlock flb = new ForLoopBlock();

            flb.LoopCount = count;

            flb.Children.InsertItem(breakBlock, null);
            flb.Children.InsertItem(poisonedBlock, breakBlock);

            system.Blocks.InsertItem(flb, null);

            return(system);
        }
コード例 #5
0
        protected override CodeblockSystem BuildSystem()
        {
            CodeblockSystem system = new CodeblockSystem();

            DynamicInputOperator <int>[] inputs = new DynamicInputOperator <int> [4];
            for (int i = 0; i < 4; i++)
            {
                DynamicInputOperator <int> input = new DynamicInputOperator <int>();
                input.Value = i * 2;
                inputs[i]   = input;
            }

            ComparisonOperationCodeblock left = new ComparisonOperationCodeblock()
            {
                Left      = inputs[0],
                Right     = inputs[1],
                Operation = ComparisonOperation.SmallerOrEqual
            };
            ComparisonOperationCodeblock right = new ComparisonOperationCodeblock()
            {
                Left      = inputs[2],
                Right     = inputs[3],
                Operation = ComparisonOperation.Equal
            };

            LogicOperationCodeblock logic = new LogicOperationCodeblock()
            {
                Left      = left,
                Right     = right,
                Operation = LogicalOperation.OR
            };

            AssertTestBlock ifTrue = new AssertTestBlock();

            ifTrue.Condition = () => true;

            AssertTestBlock ifFalse = new AssertTestBlock();

            ifFalse.Condition = () => false;

            IfElseBlock ifElseBlock = new IfElseBlock();

            ifElseBlock.Condition = logic;

            ifElseBlock.Children.InsertItem(ifTrue, null);
            ifElseBlock.ElseChildren.InsertItem(ifFalse, null);

            system.Blocks.InsertItem(ifElseBlock, null);

            return(system);
        }
コード例 #6
0
        protected override CodeblockSystem BuildSystem()
        {
            CodeblockSystem system = new CodeblockSystem();

            AssertTestBlock ifTrue = new AssertTestBlock();

            ifTrue.Condition = () => true;

            AssertTestBlock ifFalse = new AssertTestBlock();

            ifFalse.Condition = () => false;

            var left = new DynamicInputOperator <float>();

            left.Value = 5;
            var right = new DynamicInputOperator <string>();

            right.Value = "1";

            ComparisonOperationCodeblock coc = new ComparisonOperationCodeblock();

            coc.Operation = ComparisonOperation.GreaterThan;
            coc.Left      = left;
            coc.Right     = right;

            IfElseBlock ifelse = new IfElseBlock();

            ifelse.Condition = coc;

            ifelse.Children.InsertItem(ifTrue, null);
            ifelse.ElseChildren.InsertItem(ifFalse, null);

            system.Blocks.InsertItem(ifelse, null);

            return(system);
        }