Exemplo n.º 1
0
        public virtual void OnBeginDrag(PointerEventData eventData)
        {
            if (draggedItem == null)
            {
                draggedItem = this.transform.parent.parent.gameObject; //need to get the whole line as dragged item
            }
            dropZone             = draggedItem.transform.parent;
            startingSiblingIndex = draggedItem.transform.GetSiblingIndex();
            dragHandleOffset     = this.transform.position - draggedItem.transform.position;

            placeholder = new GameObject();
            placeholder.transform.SetParent(draggedItem.transform.parent);
            placeholder.transform.SetSiblingIndex(startingSiblingIndex);
            var rt = placeholder.AddComponent <RectTransform>();

            rt.pivot = Vector2.zero;

            var le = placeholder.AddComponent <LayoutElement>();

            le.preferredHeight = startingHeight = GetDraggedItemHeight();
            //le.flexibleWidth = 1;

            animationHelper             = draggedItem.AddComponent <UIAnimationHelper>();
            animationHelper.SetHeight   = SetPlaceholderHeight;
            animationHelper.SetPosition = SetDraggedItemPosition;

            animationHelper.AnimateHeight(le.preferredHeight, PLACEHOLDER_MIN_HEIGHT, 0.1f);

            var cg = draggedItem.AddComponent <CanvasGroup>();

            cg.blocksRaycasts = false;

            draggedItemBG            = draggedItem.AddComponent <Image>();
            draggedItemBG.sprite     = background;
            draggedItemBG.type       = Image.Type.Sliced;
            draggedItemBG.color      = Color.white;
            draggedItemBG.fillCenter = true;

            draggedItem.transform.SetParent(mainCanvas.transform);

            Debug.Log("OnBeginDrag: draggedItem.name = " + draggedItem.name + ", dropZone.name" + dropZone.name);
        }