private void OnAddCodeBlock(object[] eventParam) { int _index = (int)eventParam[0]; BlockItemType _type = (BlockItemType)eventParam[1]; BlockItemIdentifier _identifier = (BlockItemIdentifier)eventParam[2]; //Lay index active moi nhat int latestActiveIndex = -1; for (int i = 0; i < scrollPanelObject.transform.childCount; i++) { if (scrollPanelObject.transform.GetChild(i).gameObject.activeSelf == false) { latestActiveIndex = i - 1; break; } } GameObject currentCodeBlock = scrollPanelObject.transform.GetChild(latestActiveIndex + 1).gameObject; currentCodeBlock.SetActive(true); BlockData data = currentCodeBlock.transform.GetComponent <MovementBlockController>().data; data.blockType = _type; data.blockIdentifier = _identifier; currentCodeBlock.transform.GetComponent <MovementBlockController>().SetBlockData(); refreshIDs(); }
private void OnRemoveBottomCodeItem(object[] eventParam) { int _index = (int)eventParam[0]; BlockItemType _type = (BlockItemType)eventParam[1]; BlockItemIdentifier _identifier = (BlockItemIdentifier)eventParam[2]; // Can bo dung block code tuong ung Transform trans = scrollPanelObject.transform; if (trans.childCount > 0) { GameObject lastCodeBlock = trans.GetChild(_index - 1).gameObject; lastCodeBlock.SetActive(false); // Get all children GameObject[] _array = new GameObject[trans.childCount]; for (int i = 0; i < trans.childCount; i++) { _array[i] = trans.GetChild(i).gameObject; } // Sort all remaining block GameObject[] _sortedArray = _array.OrderByDescending(w => w.activeSelf).ToArray(); for (int i = 0; i < trans.childCount; i++) { _sortedArray[i].transform.SetSiblingIndex(i); } //Destroy(lastCodeBlock); } else { Debug.Log("No child left"); } refreshIDs(); }