Exemplo n.º 1
0
        public void BindModel(Block block)
        {
            if (mBlock == block)
            {
                return;
            }
            if (mBlock != null)
            {
                UnBindModel();
            }

            mBlock = block;
            BlocklyUI.WorkspaceView.AddBlockView(this);

            mBlockObserver = new MemorySafeBlockObserver(this);
            mBlock.AddObserver(mBlockObserver);

            //bind input and connections
            int inputIndex = 0;

            foreach (BaseView view in Childs)
            {
                if (view.Type == ViewType.Connection)
                {
                    ConnectionView conView = view as ConnectionView;
                    conView.BindModel(mBlock.GetFirstClassConnection(conView.ConnectionType));
                }
                else if (view.Type == ViewType.LineGroup)
                {
                    LineGroupView groupView = view as LineGroupView;
                    foreach (var inputView in groupView.Childs)
                    {
                        ((InputView)inputView).BindModel(mBlock.InputList[inputIndex]);
                        inputIndex++;
                    }
                }
            }

            RegisterUIEvents();

            foreach (Transform child in transform)
            {
                if (child.name.ToLower().StartsWith("block_count"))
                {
                    SetCountText(child.GetComponentInChildren <Text>());
                }
            }
        }
Exemplo n.º 2
0
        public void BindModel(Block block)
        {
            if (mBlock == block)
            {
                return;
            }
            if (mBlock != null)
            {
                UnBindModel();
            }

            mBlock = block;
            BlocklyUI.WorkspaceView.AddBlockView(this);

            mBlockObserver = new MemorySafeBlockObserver(this);
            mBlock.AddObserver(mBlockObserver);

            //bind input and connections
            int inputIndex = 0;

            foreach (BaseView view in Childs)
            {
                if (view.Type == ViewType.Connection)
                {
                    ConnectionView conView = view as ConnectionView;
                    conView.BindModel(mBlock.GetFirstClassConnection(conView.ConnectionType));
                }
                else if (view.Type == ViewType.LineGroup)
                {
                    LineGroupView groupView = view as LineGroupView;
                    foreach (var inputView in groupView.Childs)
                    {
                        ((InputView)inputView).BindModel(mBlock.InputList[inputIndex]);
                        inputIndex++;
                    }
                }
            }

            RegisterUIEvents();
        }