Example #1
0
        protected void PickBlockView(BlockView blockView)
        {
            if (!blockView.enabled)
            {
                return;
            }
            if (mPickedBlockView != null)
            {
                Debug.LogError("Toolbox-PickBlockView: Already picked a block view.");
                return;
            }

            // compute the local position of the block view in coding area
            Vector3 localPos = BlocklyUI.WorkspaceView.CodingArea.InverseTransformPoint(blockView.ViewTransform.position);

            // clone a new block view for coding area
            mPickedBlockView = BlocklyUI.WorkspaceView.CloneBlockView(blockView, new Vector2(localPos.x, localPos.y));
            if (mPickedBlockView.InToolbox)
            {
                return;
            }
            mPickedBlockView.OnBeginDrag(null);
            mPickedBlockView.ActivateCountText(false);

            //if the max number of blocks have been used disable the block
            if (Block.blocksAvailable.ContainsKey(blockView.BlockType) && Block.blocksAvailable[blockView.BlockType] > 0)
            {
                Block.blocksAvailable[blockView.BlockType]--;
                if (Block.blocksAvailable[blockView.BlockType] <= 0)
                {
                    blockView.ChangeBgColor(Color.grey);
                    blockView.enabled = false;
                }
            }
            blockView.UpdateCount();

            OnPickBlockView();

            string  id   = GameManager.Instance.GetBlockId(mPickedBlockView.Block);
            XmlNode dom  = Xml.BlockToDomWithXY(mPickedBlockView.Block, false);
            string  text = UBlockly.Xml.DomToText(dom);

            text = GameManager.Instance.ChangeCodeIDs(text);


            TrackerAsset.Instance.setVar("block_type", mPickedBlockView.Block.Type);
            TrackerAsset.Instance.setVar("code", "\r\n" + text);

            TrackerAsset.Instance.setVar("action", "create");
            TrackerAsset.Instance.setVar("level", GameManager.Instance.GetCurrentLevelName().ToLower());
            TrackerAsset.Instance.GameObject.Interacted(id);
        }
Example #2
0
        public void OnPointerClick(PointerEventData eventData)
        {
            //todo: background outline
            if (eventData.button == PointerEventData.InputButton.Right && !eventData.dragging && !InToolbox && CanBeCloned(null))
            {
                BlockView newBlock = BlocklyUI.WorkspaceView.CloneBlockView(this, XY + BlockViewSettings.Get().BumpAwayOffset);
                newBlock.InitIDs();
                TrackerAsset.Instance.setVar("block_type", Block.Type);
                TrackerAsset.Instance.setVar("action", "duplicate");
                TrackerAsset.Instance.setVar("new_block_id", GameManager.Instance.GetBlockId(newBlock.Block));
                TrackerAsset.Instance.GameObject.Interacted(GameManager.Instance.GetBlockId(Block));

                TrackerAsset.Instance.setVar("block_type", Block.Type);
                TrackerAsset.Instance.setVar("action", "create_clone");

                XmlNode dom  = Xml.BlockToDomWithXY(newBlock.Block, false);
                string  text = UBlockly.Xml.DomToText(dom);
                text = GameManager.Instance.ChangeCodeIDs(text);

                TrackerAsset.Instance.setVar("code", "\r\n" + text);
                TrackerAsset.Instance.GameObject.Interacted(GameManager.Instance.GetBlockId(newBlock.Block));
            }
        }