Exemple #1
0
        public void Init(Label label, Divider myDivider, CodeList codeList)
        {
            base.Init(myDivider, codeList);
            this.label = label;

            string labelText = label.name + " (" + label.val + ")";

            GetComponentInChildren <TextMeshProUGUI>().text = labelText;

            Draggable draggable = GetComponent <Draggable>();

            draggable.onDragSuccess = Move;
            draggable.onDragTrash   = (Draggable.Slot slot) =>
            {
                codeList.Program.RemoveLabel(label);
                Destroy(gameObject);
            };
        }
Exemple #2
0
        private Token CreateToken(Argument arg, Transform parent, Token originalToken = null)
        {
            Token     token   = Instantiate(tokenPrefab, parent, false).GetComponent <Token>();
            Renamable tokenRN = token.GetComponent <Renamable>();

            token.Init(arg.ShallowCopy(), codeList);
            tokenRN.enabled = true;

            if (originalToken != null)
            {
                token.transform.SetSiblingIndex(originalToken.transform.GetSiblingIndex());
            }

            Draggable draggable      = token.GetComponent <Draggable>();
            Action    oldOnDragStart = draggable.onDragStart;

            draggable.onDragStart = () =>
            {
                Token clone = CreateToken(arg, parent, token);
                oldOnDragStart?.Invoke();

                draggable.onDragCancel = () => Destroy(clone.gameObject);
            };
            Action <Draggable.Slot> oldOnDragSuccess = draggable.onDragSuccess;

            draggable.onDragSuccess = (Draggable.Slot slot) =>
            {
                tokenRN.enabled         = false;
                draggable.onDragStart   = oldOnDragStart;
                draggable.onDragSuccess = oldOnDragSuccess;
                draggable.onDragCancel  = null;
                oldOnDragSuccess?.Invoke(slot);
            };

            return(token);
        }