예제 #1
0
        public virtual void OnDrag(PointerEventData eventData)
        {
            var rt = draggedItem.transform as RectTransform;

            Vector2 localPointerPosition;

            if (RectTransformUtility.ScreenPointToLocalPointInRectangle(mainCanvas.transform as RectTransform, eventData.position, eventData.pressEventCamera, out localPointerPosition))
            {
                rt.localPosition = localPointerPosition - startingPosition;
            }

            //we don't want to change siblings while we are still animating
            if (animationHelper.isHeightActive)
            {
                return;
            }

            if (eventData.pointerEnter != null && eventData.pointerEnter.GetComponent <SequenceDropHandler>() != null)
            {
                dropZone = eventData.pointerEnter.transform;
                placeholder.transform.SetParent(dropZone, false);
            }

            var currentSiblingIndex = placeholder.transform.GetSiblingIndex();
            var newSiblingIndex     = dropZone.childCount - 1;

            for (int i = 0; i < dropZone.childCount; i++)
            {
                var child = dropZone.GetChild(i);
                if (localPointerPosition.y > child.position.y)
                {
                    newSiblingIndex = i;

                    if (currentSiblingIndex < newSiblingIndex)
                    {
                        newSiblingIndex--;
                    }

                    break;
                }
            }

            if (newSiblingIndex != placeholder.transform.GetSiblingIndex())
            {
                placeholder.transform.SetSiblingIndex(newSiblingIndex);
                animationHelper.AnimateHeight(PLACEHOLDER_MIN_HEIGHT, startingHeight, 0.1f);
            }
        }
예제 #2
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);
        }
        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);
        }
예제 #4
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);
        }
        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);
        }