public override string BEOperation(BETargetObject targetObject, BEBlock beBlock)
 {
     if (beBlock.BeInputs.isString)
     {
         if (beBlock.BeInputs.stringValues[0] == beBlock.BeInputs.stringValues[1])
         {
             result = "1";
         }
         else
         {
             result = "0";
         }
     }
     else
     {
         if (beBlock.BeInputs.numberValues[0] == beBlock.BeInputs.numberValues[1])
         {
             result = "1";
         }
         else
         {
             result = "0";
         }
     }
     
     return result;
 }
 public override void BEFunction(BETargetObject targetObject, BEBlock beBlock)
 {
     if (beBlock.BeBlockGroup.isActive)
     {
         BeController.PlayNextInside(beBlock);
     }
 }
    public override void BEFunction(BETargetObject targetObject, BEBlock beBlock)
    {
        targetObject.transform.position = new Vector3(beBlock.BeInputs.numberValues[0], beBlock.BeInputs.numberValues[1],
                                                      beBlock.BeInputs.numberValues[2]);

        BeController.PlayNextOutside(beBlock);
    }
    public void SetBlockAtGhostPos(BEBlock droppedBlock)
    {
        Transform ghostTransform = droppedBlock.BeController.ghostBlock.transform;

        droppedBlock.transform.SetParent(ghostTransform.parent);
        droppedBlock.transform.SetSiblingIndex(ghostTransform.GetSiblingIndex());

        // child block added to this object
        try
        {
            ghostTransform.parent.GetComponent <BEBlock>().beChildBlocksList.Insert(ghostTransform.GetSiblingIndex() - 2, droppedBlock);
        }
        catch
        {
            if (!ghostTransform.parent.GetComponent <BEBlock>().beChildBlocksList.Contains(droppedBlock))
            {
                ghostTransform.parent.GetComponent <BEBlock>().beChildBlocksList.Add(droppedBlock);
            }
        }

        droppedBlock.BeBlockGroup = ghostTransform.parent.GetComponent <BEBlock>().BeBlockGroup;

        // v1.3 -Bug fix: [reported] beTargetObject not being set
        droppedBlock.beTargetObject = TargetObject; //ghostTransform.parent.root.GetComponent<BETargetObject>();
    }
    public string WriteBlockInputs(BEBlock block)
    {
        string inputs = "(";

        if (block.userInputIndexes.Count > 0)
        {
            block.InitializeInputs();
            for (int i = 0; i < block.userInputIndexes.Count; i++)
            {
                if (block.BlockHeader.GetChild(block.userInputIndexes[i]).GetComponent <BEBlock>())
                {
                    BEBlock operation = block.BlockHeader.GetChild(block.userInputIndexes[i]).GetComponent <BEBlock>();
                    inputs += operation.name;
                    inputs += WriteBlockInputs(operation);
                    inputs += ",";
                }
                else
                {
                    inputs += "'" + block.BeInputs.stringValues[i] + ",";
                }
            }
            if (inputs.Length > 0)
            {
                inputs = inputs.Substring(0, inputs.Length - 1);
            }
        }
        inputs += ")";
        return(inputs);
    }
    public override string BEOperation(BETargetObject targetObject, BEBlock beBlock)
    {
        string inputString = beBlock.BeInputs.stringValues[0];

        if (inputString == "0" || inputString == "False" || inputString == "false")
        {
            result = "1";
        }
        else if (inputString == "1" || inputString == "True" || inputString == "true")
        {
            result = "0";
        }
        else if (beBlock.BeInputs.isString)
        {
            //reverse string
            char[] charArray = inputString.ToCharArray();
            System.Array.Reverse(charArray);
            result = new string( charArray );
        }
        else
        {
            //invert number
            float tempResult = beBlock.BeInputs.numberValues[0] * -1;
            result = tempResult.ToString(CultureInfo.InvariantCulture);
        }

        return(result);
    }
Esempio n. 7
0
    public override string BEOperation(BETargetObject targetObject, BEBlock beBlock)
    {
        if (beBlock.BeInputs.isString)
        {
            result = "";
            if (beBlock.BeInputs.numberValues[0] != 0)
            {
                for (int i = 0; i < beBlock.BeInputs.numberValues[0]; i++)
                {
                    result += beBlock.BeInputs.stringValues[1];
                }
            }
            else if (beBlock.BeInputs.numberValues[1] != 0)
            {
                for (int i = 0; i < beBlock.BeInputs.numberValues[1]; i++)
                {
                    result += beBlock.BeInputs.stringValues[0];
                }
            }
            else
            {
                result = beBlock.BeInputs.stringValues[0];
            }
        }
        else
        {
            float tempResult = beBlock.BeInputs.numberValues[0] * beBlock.BeInputs.numberValues[1];
            result = tempResult.ToString(CultureInfo.InvariantCulture);
        }

        return(result);
    }
    public override void BEFunction(BETargetObject targetObject, BEBlock beBlock)
    {
        Vector3 axis;

        switch (beBlock.BeInputs.stringValues[0])
        {
        case "X axis":
            axis = Vector3.right;
            break;

        case "Y axis":
            axis = Vector3.up;
            break;

        case "Z axis":
            axis = Vector3.forward;
            break;

        default:
            axis = Vector3.up;
            break;
        }

        targetObject.transform.Rotate(axis, beBlock.BeInputs.numberValues[1]);

        BeController.PlayNextOutside(beBlock);
    }
Esempio n. 9
0
    public override void BEFunction(BETargetObject targetObject, BEBlock beBlock)
    {
        soundToPlay = BeController.GetSound(beBlock.BeInputs.stringValues[0]);
        targetObject.beAudioSource.clip = soundToPlay;
        targetObject.beAudioSource.Play();

        BeController.PlayNextOutside(beBlock);
    }
Esempio n. 10
0
 public void OnDrop(PointerEventData eventData)
 {
     if (BEEventSystem.SelectedBlock != null)
     {
         BEBlock droppedBlock = BEEventSystem.SelectedBlock;
         SetBlockAtIndex(droppedBlock, CalculateIndex());
         BEEventSystem.SetSelectedBlock(null);
     }
 }
Esempio n. 11
0
    public override string BEOperation(BETargetObject targetObject, BEBlock beBlock)
    {
        string inputString0 = beBlock.BeInputs.stringValues[0];
        string inputString1 = beBlock.BeInputs.stringValues[1];

        result = (inputString0 == "1" || inputString0 == "True" || inputString0 == "true") || (inputString1 == "1" || inputString1 == "True" || inputString1 == "true")
        ? "1" : "0";

        return(result);
    }
Esempio n. 12
0
 public override void BEFunction(BETargetObject targetObject, BEBlock beBlock)
 {
     if (BEOperation(targetObject, beBlock) == "1")
     {
         BeController.PlayNextInside(beBlock);
     }
     else
     {
         BeController.PlayNextOutside(beBlock);
     }
 }
Esempio n. 13
0
 public void RemoveBlockFromParentChildList(BEBlock block)
 {
     if (block.BeBlockGroup != null)
     {
         block.BeBlockGroup.isActive      = false;
         block.BeBlockGroup.beActiveBlock = block.BeBlockGroup.GetComponent <BEBlock>();
         block.BeBlockGroup.GetComponent <Outline>().enabled = false;
         block.BeBlockGroup = null;
     }
     block.transform.parent.GetComponent <BEBlock>().beChildBlocksList.Remove(block);
 }
Esempio n. 14
0
    public override void BEFunction(BETargetObject targetObject, BEBlock beBlock)
    {
        if (targetObject.GetComponent <Collider2D>())
        {
            targetObject.transform.position += targetObject.transform.right * beBlock.BeInputs.numberValues[0];
        }
        else if (targetObject.GetComponent <Collider>())
        {
            targetObject.transform.position += targetObject.transform.forward * beBlock.BeInputs.numberValues[0];
        }

        BeController.PlayNextOutside(beBlock);
    }
Esempio n. 15
0
    public override void BEFunction(BETargetObject targetObject, BEBlock beBlock)
    {
        if (targetObject.GetComponent <Rigidbody2D>())
        {
            targetObject.GetComponent <Rigidbody2D>().AddForce(targetObject.transform.right * beBlock.BeInputs.numberValues[0]);
        }
        else if (targetObject.GetComponent <Rigidbody>())
        {
            targetObject.GetComponent <Rigidbody>().AddForce(targetObject.transform.forward * beBlock.BeInputs.numberValues[0]);
        }

        BeController.PlayNextOutside(beBlock);
    }
    public override string BEOperation(BETargetObject targetObject, BEBlock beBlock)
    {
        if (beBlock.BeInputs.isString)
        {
            result = beBlock.BeInputs.stringValues[0] + beBlock.BeInputs.stringValues[1];
        }
        else
        {
            float tempResult = beBlock.BeInputs.numberValues[0] + beBlock.BeInputs.numberValues[1];
            result = tempResult.ToString(CultureInfo.InvariantCulture);
        }

        return(result);
    }
 public static IEnumerator DelayedLayoutRebuild(BEBlock beBlock)
 {
     refreshCounter = 0;
     while (true)
     {
         if (refreshCounter < 100)
         {
             refreshCounter++;
             beBlock.rectTransform.sizeDelta = new Vector2(beBlock.BlockHeader.GetComponent <HorizontalLayoutGroup>().preferredWidth + 25, beBlock.rectTransform.sizeDelta.y);
             LayoutRebuilder.ForceRebuildLayoutImmediate(beBlock.rectTransform);
         }
         yield return(new WaitForEndOfFrame());
     }
 }
Esempio n. 18
0
    public override void BEFunction(BETargetObject targetObject, BEBlock beBlock)
    {
        if (beBlock.BeInputs.stringValues[0] == "Random")
        {
            targetObject.GetComponent <Renderer>().material.color = Random.ColorHSV(0f, 1f, 1f, 1f, 0.5f, 1f);
        }
        else
        {
            mat = BeController.GetColor(beBlock.BeInputs.stringValues[0]);
            targetObject.GetComponent <Renderer>().material.color = mat.color;
        }

        BeController.PlayNextOutside(beBlock);
    }
    public List <string> TranslateBlockGroupToVirtualCode(BEBlock block)
    {
        string hierarchyMarker = "";

        List <string> tempVirtualCode = new List <string>();

        TranslateSingleBlockToVirtualCode(block, tempVirtualCode, hierarchyMarker);

        GetChildBlocks(block, tempVirtualCode, hierarchyMarker);

        tempVirtualCode.Add(""); // write empty line after each group

        return(tempVirtualCode);
    }
Esempio n. 20
0
    public override void BEFunction(BETargetObject targetObject, BEBlock beBlock)
    {
        if (beBlock.beBlockFirstPlay)
        {
            counterForRepetitions    = (int)beBlock.BeInputs.numberValues[1];
            beBlock.beBlockFirstPlay = false;
        }

        // [0] first input (dropdown)
        // options: up-right, up-left, down-right, down-left, right-up, right-down, left-up, left-down
        string option = beBlock.BeInputs.stringValues[0];

        string[] options = option.Split('-');

        //movements
        Vector3 firstMovement  = GetDirection(options[0]);
        Vector3 secondMovement = GetDirection(options[1]);

        Vector3[] movements = new[] { firstMovement, firstMovement, secondMovement };

        if (counterForMovement == 0)
        {
            startPos = targetObject.transform.position;
        }

        if (counterForMovement <= movementDuration)
        {
            counterForMovement += Time.deltaTime;
            targetObject.transform.position = Vector3.Lerp(startPos, startPos + movements[moveSelection], counterForMovement / movementDuration);
        }
        else
        {
            moveSelection++;
            counterForMovement = 0;
        }

        if (moveSelection == 3)
        {
            moveSelection      = 0;
            counterForMovement = 0;
            counterForRepetitions--;

            if (counterForRepetitions <= 0)
            {
                beBlock.beBlockFirstPlay = true;
                BeController.PlayNextOutside(beBlock);
            }
        }
    }
    // v1.3 -Bug fix: [reported on Unity 2019] variable blocks dropdown changing to index 0 on Play pressed
    public void RepopulateDropdown()
    {
        BEBlock thisBlock = GetComponent <BEBlock>();

        int selectedValue = dropdown.value;

        dropdown.ClearOptions();
        foreach (BEVariable variable in thisBlock.BeController.BeVariableList)
        {
            dropdown.options.Add(new Dropdown.OptionData(variable.name));
        }
        dropdown.RefreshShownValue();

        dropdown.value = selectedValue;
    }
    public void GetChildBlocks(BEBlock parentBlock, List <string> tempVirtualCode, string hierarchyMarker)
    {
        hierarchyMarker += "\t";

        foreach (BEBlock block in parentBlock.beChildBlocksList)
        {
            TranslateSingleBlockToVirtualCode(block, tempVirtualCode, hierarchyMarker);

            if (block.beChildBlocksList.Count > 0)
            {
                GetChildBlocks(block, tempVirtualCode, hierarchyMarker);
            }
        }

        hierarchyMarker = hierarchyMarker.Substring(0, hierarchyMarker.Length - 1);
    }
    public override void BEFunction(BETargetObject targetObject, BEBlock beBlock)
    {
        try
        {
            float newValue = float.Parse(BeController.GetVariable(beBlock.BeInputs.stringValues[0]), CultureInfo.InvariantCulture)
                             + beBlock.BeInputs.numberValues[1];
            BeController.SetVariable(beBlock.BeInputs.stringValues[0], newValue.ToString(CultureInfo.InvariantCulture));
        }
        catch
        {
            string newValue = BeController.GetVariable(beBlock.BeInputs.stringValues[0]);
            BeController.SetVariable(beBlock.BeInputs.stringValues[0], newValue.ToString(CultureInfo.InvariantCulture));
        }

        BeController.PlayNextOutside(beBlock);
    }
    void Awake()
    {
        BEBlock thisBlock = GetComponent <BEBlock>();

        thisBlock.InitializeBlock();

        dropdown = thisBlock.BlockHeader.GetChild(thisBlock.userInputIndexes[0]).GetComponent <Dropdown>();

        //populating dropdown
        dropdown.ClearOptions();
        foreach (AudioClip audio in thisBlock.BeController.beSoundsList)
        {
            dropdown.options.Add(new Dropdown.OptionData(audio.name));
        }
        dropdown.RefreshShownValue();
    }
Esempio n. 25
0
    public void DragBlock()
    {
        BELayoutRebuild.RebuildAll();

        try
        {
            startParent = transform.parent.GetComponent <UIDrop>();
        }
        catch
        {
            startParent = null;
        }
        startIndex = transform.GetSiblingIndex();

        startPosition = transform.position;
        diffPosition  = Input.mousePosition - startPosition;

        BEBlock block = GetComponent <BEBlock>();

        BEEventSystem.SetSelectedBlock(beBlock);

        if (transform.parent.GetComponent <BEBlock>())
        {
            RemoveBlockFromParentChildList(block);
        }
        else
        {
            if (transform.parent.name == "ProgrammingEnv")
            {
                TargetObject.beBlockGroupsList.Remove(GetComponent <BEBlock>());
            }
        }

        var tempIndex = transform.GetSiblingIndex();

        if (inactiveBlockInputs.Count > 0)
        {
            InactiveBlockInput inactiveChild = inactiveBlockInputs.Find(a => a.childIndex == tempIndex);
            inactiveChild.blockInput.SetParent(transform.parent);
            inactiveChild.blockInput.SetSiblingIndex(tempIndex);
            inactiveChild.blockInput.gameObject.SetActive(true);
            inactiveBlockInputs.Remove(inactiveChild);
        }

        transform.SetParent(onDragCanvas);
        transform.SetAsLastSibling();
    }
    void Awake()
    {
        BEBlock thisBlock = GetComponent <BEBlock>();

        thisBlock.InitializeBlock();

        dropdown = thisBlock.BlockHeader.GetChild(thisBlock.userInputIndexes[0]).GetComponent <Dropdown>();

        //populating dropdown
        dropdown.ClearOptions();
        dropdown.options.Add(new Dropdown.OptionData("Random"));
        foreach (Material color in thisBlock.BeController.beColorsList)
        {
            dropdown.options.Add(new Dropdown.OptionData(color.name));
        }
        dropdown.RefreshShownValue();
    }
    public void TranslateSingleBlockToVirtualCode(BEBlock block, List <string> tempVirtualCode, string hierarchyMarker)
    {
        string inputs = "";

        inputs = WriteBlockInputs(block);

        string blockPosition = "";

        if (hierarchyMarker == "")
        {
            float x = block.transform.position.x;
            float y = block.transform.position.y;
            blockPosition = ":" + x.ToString(CultureInfo.InvariantCulture) + "," + y.ToString(CultureInfo.InvariantCulture);
        }

        tempVirtualCode.Add(hierarchyMarker + block.name + inputs + blockPosition);
    }
 public static void LayoutRebuildParents(Transform blockTransform)
 {
     if (blockTransform.parent != null)
     {
         if (blockTransform.parent.GetComponent <BEBlock>())
         {
             BEBlock       parentBlock = blockTransform.parent.GetComponent <BEBlock>();
             RectTransform parentRect  = parentBlock.GetComponent <RectTransform>();
             parentRect.sizeDelta = new Vector2(parentBlock.BlockHeader.GetComponent <HorizontalLayoutGroup>().preferredWidth + 25, parentRect.sizeDelta.y);
             LayoutRebuilder.ForceRebuildLayoutImmediate(parentRect);
         }
         else
         {
             LayoutRebuildParents(blockTransform.parent);
         }
     }
 }
    void Awake()
    {
        BEBlock thisBlock = GetComponent <BEBlock>();

        thisBlock.InitializeBlock();

        dropdown = thisBlock.BlockHeader.GetChild(thisBlock.userInputIndexes[0]).GetComponent <Dropdown>();

        //populating dropdown
        dropdown.ClearOptions();
        string[] keys = System.Enum.GetNames(typeof(KeyCode));
        foreach (string key in keys)
        {
            dropdown.options.Add(new Dropdown.OptionData(key));
        }
        dropdown.RefreshShownValue();
    }
    public override void BEFunction(BETargetObject targetObject, BEBlock beBlock)
    {
        Vector3 axis = Vector3.up;

        if (targetObject.GetComponent <Collider2D>())
        {
            axis = Vector3.forward;
        }
        else if (targetObject.GetComponent <Collider>())
        {
            axis = Vector3.up;
        }

        targetObject.transform.Rotate(axis, 90);

        BeController.PlayNextOutside(beBlock);
    }