Пример #1
0
        public virtual void OnBeginDrag(PointerEventData eventData)
        {
            if (draggedItem == null)
            {
                draggedItem = this.transform.parent.gameObject;
            }

            if (SequencerGUI.Instance.openSequence.isActive)
            {
                SequencerGUI.Instance.openSequence.Pause();
                SequencerGUI.Instance.openSequence.Reset();
                SequencerGUI.Instance.ResetOpenSequenceCommandProgress();
            }

            //don't forget to remove Repeat placeholders from dropzone
            dropZone = draggedItem.transform.parent;
            var repeatPlaceholder = dropZone.gameObject.GetChild("RepeatCommandPlaceholder");

            if (repeatPlaceholder)
            {
                repeatPlaceholder.transform.SetAsLastSibling();
                repeatPlaceholder.SetActive(false);
            }

            startingSiblingIndex = draggedItem.transform.GetSiblingIndex();

            RectTransformUtility.ScreenPointToLocalPointInRectangle(draggedItem.transform as RectTransform, eventData.position, eventData.pressEventCamera, out startingPosition);

            placeholder = new GameObject();
            placeholder.transform.SetParent(draggedItem.transform.parent, false);
            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;

            draggedItem.transform.SetParent(mainCanvas.transform, false);
        }
Пример #2
0
        public virtual void OnBeginDrag(PointerEventData eventData)
        {
            if (draggedItem == null)
            {
                draggedItem = this.transform.parent.gameObject;
            }
            dropZone             = draggedItem.transform.parent;
            startingSiblingIndex = draggedItem.transform.GetSiblingIndex();

            RectTransformUtility.ScreenPointToLocalPointInRectangle(draggedItem.transform as RectTransform, eventData.position, eventData.pressEventCamera, out startingPosition);

            placeholder = new GameObject();
            placeholder.transform.SetParent(draggedItem.transform.parent, false);
            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, false);
        }