Ejemplo n.º 1
0
        /// <summary>
        /// Called when the underlying block has been updated.
        /// </summary>
        protected void OnBlockUpdated(Block.UpdateState updateState)
        {
            switch (updateState)
            {
            case Block.UpdateState.Inputs:
            {
                //rebuild block view's input views
                BlockViewBuilder.BuildInputViews(mBlock, this);

                //reupdate layout
                BuildLayout();

                //call this once to update the connection DB
                this.OnXYUpdated();

                //call this again to change new input views
                this.ChangeBgColor(m_BgImages[0].color);

                break;
            }
            }
        }
Ejemplo n.º 2
0
        public static BlockView CreateView(Block block)
        {
            BlockView blockView;

            GameObject blockPrefab = BlockResMgr.Get().LoadBlockViewPrefab(block.Type);

            if (blockPrefab != null)
            {
                // has been builded beforehand
                GameObject blockObj = GameObject.Instantiate(blockPrefab);
                blockObj.name = blockPrefab.name;

                blockView = blockObj.GetComponent <BlockView>();
                blockView.BindModel(block);

                // rebuild inputs for mutation blocks
                if (block.Mutator != null)
                {
                    BlockViewBuilder.BuildInputViews(block, blockView);
                }

                blockView.BuildLayout();
            }
            else
            {
                blockPrefab = BlockViewBuilder.BuildBlockView(block);

                blockView = blockPrefab.GetComponent <BlockView>();
                blockView.BindModel(block);

                // BlockViewBuilder.BuildBlockView will do both "BuildInputViews" and "BuildLayout"
            }

            blockView.ChangeBgColor(BlocklyUI.WorkspaceView.Toolbox.GetColorOfBlockView(blockView));

            return(blockView);
        }