public void RefreshAddUnit(PageModel.PageStatus _status, PageModel.Unit _unit)
 {
     BlockModel.BlockStatus statusBlock = _status.Access(BlockModel.BlockStatus.NAME) as BlockModel.BlockStatus;
     CustomElementModel.CustomElementStatus statusElement = statusBlock.Access(CustomElementModel.CustomElementStatus.NAME) as CustomElementModel.CustomElementStatus;
     BlockModel.Block block = statusBlock.blocks.Find((_item) => {
         return(_item.method.Equals(_unit.block));
     });
     addBlock(_unit.uuid, block, _unit.variants, statusElement);
 }
        private void addExpression(string _uuid, BlockModel.Block _block, Dictionary <string, string> _variants, CustomElementModel.CustomElementStatus _elementStatus,
                                   List <BlockModel.Element> _elements, BlockBuilder.Symbol _symbol)
        {
            GameObject clone = GameObject.Instantiate(uiWorkbench.templateExpression.gameObject);

            clone.transform.SetParent(uiWorkbench.templateExpression.parent);
            clone.transform.localScale = Vector3.one;
            clone.SetActive(true);
            clone.name = _uuid;
            BlockBuilder.BuildExpression(_elements, _variants, clone, _elementStatus, _symbol, _block.color);
        }
 public void RefreshAddUnits(PageModel.PageStatus _status, List <PageModel.Unit> _units)
 {
     destroyActiveChildren(uiWorkbench.templateExpression.parent.gameObject);
     BlockModel.BlockStatus statusBlock = _status.Access(BlockModel.BlockStatus.NAME) as BlockModel.BlockStatus;
     CustomElementModel.CustomElementStatus statusElement = statusBlock.Access(CustomElementModel.CustomElementStatus.NAME) as CustomElementModel.CustomElementStatus;
     foreach (PageModel.Unit unit in _units)
     {
         BlockModel.Block block = statusBlock.blocks.Find((_item) => {
             return(_item.method.Equals(unit.block));
         });
         addBlock(unit.uuid, block, unit.variants, statusElement);
     }
 }
        private void addBlock(string _uuid, BlockModel.Block _block, Dictionary <string, string> _variants, CustomElementModel.CustomElementStatus _elementStatus)
        {
            if (null == _block)
            {
                return;
            }

            BlockBuilder.Symbol symbol = BlockBuilder.LineToSymbol(_block, 0);
            addExpression(_uuid, _block, _variants, _elementStatus, _block.elements[0], symbol);
            for (int line = 1; line < _block.elements.Count; ++line)
            {
                addExpression(_uuid, _block, _variants, _elementStatus, new List <BlockModel.Element>(0), BlockBuilder.Symbol.Blank);
                symbol = BlockBuilder.LineToSymbol(_block, line);
                addExpression(_uuid, _block, _variants, _elementStatus, _block.elements[line], symbol);
            }
        }
        private void addBlock(BlockModel.Block _block, CustomElementModel.CustomElementStatus _elementStatus)
        {
            GameObject clone = GameObject.Instantiate(uiBlockly.tsTempalteBlock.gameObject);

            clone.transform.SetParent(uiBlockly.tsTempalteBlock.parent);
            clone.transform.localScale = Vector3.one;
            clone.SetActive(true);
            clone.name = _block.method;

            BlockBuilder.BuildBlock(_block, clone, _elementStatus);

            Transform tsSection = uiBlockly.tsTempalteBlock.parent.Find(_block.ns);

            if (null != tsSection)
            {
                clone.transform.SetSiblingIndex(tsSection.GetSiblingIndex());
            }
        }
        public static Symbol LineToSymbol(BlockModel.Block _block, int _line)
        {
            if (_block.elements.Count == 1)
            {
                return(Symbol.Single);
            }

            if (_line == 0)
            {
                return(Symbol.Left);
            }

            if (_line == _block.elements.Count - 1)
            {
                return(Symbol.Right);
            }

            return(Symbol.Middle);
        }
        public static void BuildBlock(BlockModel.Block _block, GameObject _obj, CustomElementModel.CustomElementStatus _elementStatus)
        {
            Transform  tsExpression    = _obj.transform.Find("expression");
            Color      color           = FacadeUtility.HexToColor(_block.color);
            GameObject expressionClone = null;

            int line = _block.elements.Count;

            expressionClone = cloneExpression(tsExpression.gameObject, color, line > 1 ? imgBlockHead : imgBlockSingle, line == 1 ? Symbol.Single : Symbol.Left);
            decorateElements(expressionClone, _block.elements[0], new Dictionary <string, string>(), _elementStatus);

            for (int i = 1; i < _block.elements.Count; ++i)
            {
                Symbol symbol = Symbol.Blank;
                Sprite sprite = imgBlockBlank;
                // blank
                cloneExpression(tsExpression.gameObject, color, sprite, symbol);

                if (i == line - 1)
                {
                    // last one
                    symbol = Symbol.Right;
                    sprite = imgBlockFoot;
                }
                else
                {
                    symbol = Symbol.Middle;
                    sprite = imgBlockMiddle;
                }

                expressionClone = cloneExpression(tsExpression.gameObject, color, sprite, symbol);
                decorateElements(expressionClone, _block.elements[i], new Dictionary <string, string>(), _elementStatus);
            }

            Transform tsDrag = _obj.transform.Find("#drag");

            tsDrag.SetAsLastSibling();

            DragBlock drag = tsDrag.GetComponent <DragBlock>();

            drag.method = _block.method;
        }