/// <summary>
        /// Places a <see cref="UICodeblock"/> under another one.
        /// </summary>
        private void PlaceUnderCodeblock(UICodeblock item, UICodeblock parent)
        {
            float yPos = -parent.GetComponent <RectTransform>().sizeDelta.y;

            item.transform.SetParent(parent.transform);
            item.PositionController.TargetLocalPosition = new Vector3(0, yPos);
        }
示例#2
0
        private void GenerateEntryBlock()
        {
            Transform transform = UICodeblock.GenerateEntryBlock().transform;

            transform.SetParent(Parent, false);
            transform.position = new Vector3(Screen.width * Random.value, Screen.height * Random.value);
        }
示例#3
0
        private T TestBlockCreation <T>() where T : CodeblockItem
        {
            CodeblockItem x         = System.Activator.CreateInstance <T>();
            Transform     transform = UICodeblock.Generate(x).transform;

            transform.SetParent(Parent, false);
            transform.position = new Vector3(Screen.width * Random.value, Screen.height * Random.value);

            return(x as T);
        }
        public void RemoveFromContent(UICodeblock item)
        {
            item.transform.SetParent(_handle);
            item.PositionController.TargetLocalPosition = item.PositionController.LocalPosition;

            RectTransform rt = item.GetComponent <RectTransform>();

            foreach (InputContent content in FindObjectsOfType <InputContent>())
            {
                content.UpdateEvaluateableProperty();
            }
        }
        public void InsertIntoInputContent(UICodeblock item, InputContent content)
        {
            item.transform.SetParent(content.DropArea);
            item.PositionController.TargetLocalPosition = new Vector3(0, 0);

            RectTransform rt = item.GetComponent <RectTransform>();

            rt.anchorMin = Vector2.zero;
            rt.anchorMax = Vector2.one;
            rt.sizeDelta = Vector2.zero;

            content.UpdateEvaluateableProperty();
        }
        /// <summary>
        /// Detaches an item from its parent, inside the collection and in the UI.
        /// </summary>
        public void DetachItem(UICodeblock item)
        {
            // Update the codeblock collection
            List <UICodeblock> blocks = new List <UICodeblock>()
            {
                item
            };

            blocks.AddRange(item.GetComponentsInChildren <UICodeblock>().Where(b => b.Type == UICodeblock.UIBlockType.Executable));
            CurrentSystem.Blocks.DetachItemRange(blocks.Select(b => b.Source).ToArray());

            // Update the transform hierarchy
            item.transform.SetParent(_handle);
            item.PositionController.TargetLocalPosition = item.PositionController.LocalPosition;
        }
        /// <summary>
        /// Inserts an item into the codeblock collection, given a previous sibling as a parent. Pass null to set the item as the entry block.
        /// </summary>
        public void InsertItem(UICodeblock item, UICodeblock previousSibling)
        {
            // Check if the previous sibling has a next sibling
            var         nextSiblings = previousSibling.GetComponentsInChildren <UICodeblock>().Where(b => b.Type == UICodeblock.UIBlockType.Executable);
            UICodeblock nextSibling  = nextSiblings.Count() > 1 ? nextSiblings.ElementAt(1) : null;

            // Update the codeblock collection
            List <UICodeblock> blocks = new List <UICodeblock>();

            blocks.AddRange(item.GetComponentsInChildren <UICodeblock>().Where(b => b.Type == UICodeblock.UIBlockType.Executable));
            CurrentSystem.Blocks.InsertItemRange(blocks.Select(b => b.Source).ToArray(), previousSibling.Source);

            // Update the transform hierarchy
            PlaceUnderCodeblock(item, previousSibling);

            // If there is a next sibling, place it after the last child of the new item
            if (nextSibling != null)
            {
                PlaceUnderCodeblock(nextSibling, blocks.Last());
            }
        }
示例#8
0
        /// <summary>
        /// Dynamically generates a UI codeblock.
        /// </summary>
        public static UICodeblock Generate(CodeblockItem source)
        {
            UIBlockType type = GetBlockType(source);
            string      name =
                source != null
                ? $"Dynamic UI Codeblock [{ type.ToString() }] ({ source.Identity.ID })"
                : $"Entry Codeblock";

            string     requiredPrefab = System.Enum.GetName(typeof(UIBlockType), (int)type);
            GameObject prefab         = Resources.Load <GameObject>($"Codeblock_{requiredPrefab}");

            GameObject blockObject = Instantiate(prefab);

            blockObject.name = name;

            UICodeblock codeblock = blockObject.GetComponent <UICodeblock>();

            codeblock.Source = source;

            return(codeblock);
        }
示例#9
0
        public virtual void OnPointerUp(PointerEventData eventData)
        {
            if (eventData.button == PointerEventData.InputButton.Left)
            {
                if (Type != UIBlockType.Entry)
                {
                    if (Type == UIBlockType.Executable)
                    {
                        UICodeblock[] blocksInDropArea     = CodeblockInspectionStructure.Instance.GetBlocksInDropArea(_transform.GetWorldRect());
                        UICodeblock   validPreviousSibling = blocksInDropArea.FirstOrDefault(b => b.Type == UIBlockType.Executable || b.Type == UIBlockType.Entry || b.Type == UIBlockType.ControlFlow);

                        if (validPreviousSibling != null)
                        {
                            if (validPreviousSibling != this)
                            {
                                CodeblockInspectionStructure.Instance.InsertItem(this, validPreviousSibling);
                            }
                        }
                        else
                        {
                            CodeblockInspectionStructure.Instance.DetachItem(this);
                        }
                    }
                    if (Type == UIBlockType.Evaluateable)
                    {
                        InputContent[] contentsInDropArea = CodeblockInspectionStructure.Instance.GetContentsInDropArea(_transform.GetWorldRect());
                        InputContent   leftmostInput      = contentsInDropArea.OrderBy(c => c.transform.position.x).FirstOrDefault();

                        if (leftmostInput != null)
                        {
                            CodeblockInspectionStructure.Instance.InsertIntoInputContent(this, leftmostInput);
                        }
                    }
                }
            }
        }