Esempio n. 1
0
        private IEnumerator CreateReferenceItemCoroutine(PointerEventData eventData)
        {
            yield return(new WaitForSecondsRealtime(Hierarchy.DraggedReferenceHoldTime));

            if (!BoundTransform.IsNull())
            {
                RuntimeInspectorUtils.CreateDraggedReferenceItem(BoundTransform, eventData, Skin);
            }
        }
Esempio n. 2
0
        private IEnumerator CreateReferenceItemCoroutine(PointerEventData eventData)
        {
            float dragThreshold = EventSystem.current.pixelDragThreshold;

            yield return(new WaitForSecondsRealtime(holdTime));

            if (!m_reference.IsNull() && Vector2.Distance(eventData.position, eventData.pressPosition) < dragThreshold)
            {
                RuntimeInspectorUtils.CreateDraggedReferenceItem(m_reference, eventData, draggedReferenceSkin);
            }
        }
        private void Update()
        {
            if (draggingPointer != null)
            {
                if (draggedReference.IsNull())
                {
                    draggingPointer = null;
                }
                else if (Input.GetMouseButtonUp(0))
                {
                    ExecuteEvents.Execute(draggedReference.gameObject, draggingPointer, ExecuteEvents.endDragHandler);
                    if (EventSystem.current != null)
                    {
                        List <RaycastResult> hoveredUIElements = new List <RaycastResult>();
                        EventSystem.current.RaycastAll(draggingPointer, hoveredUIElements);

                        int i = 0;
                        while (i < hoveredUIElements.Count && ExecuteEvents.ExecuteHierarchy(hoveredUIElements[i].gameObject, draggingPointer, ExecuteEvents.dropHandler) == null)
                        {
                            i++;
                        }
                    }

                    draggingPointer = null;
                }
                else
                {
                    draggingPointer.position = Input.mousePosition;
                    ExecuteEvents.Execute(draggedReference.gameObject, draggingPointer, ExecuteEvents.dragHandler);
                }
            }
            else
            {
                if (!pointerDown)
                {
                    if (Input.GetMouseButtonDown(0) && EventSystem.current != null && !EventSystem.current.IsPointerOverGameObject())
                    {
                        RaycastHit hit;
                        if (Physics.Raycast(_camera.ScreenPointToRay(Input.mousePosition), out hit, raycastRange, interactableObjectsMask))
                        {
                            hitObject = (ProcessRaycastHit != null) ? ProcessRaycastHit(hit) : hit.collider.gameObject;
                            if (!hitObject.IsNull())
                            {
                                pointerDown     = true;
                                pointerDownTime = Time.realtimeSinceStartup;
                                pointerDownPos  = Input.mousePosition;
                            }
                        }
                    }
                }
                else
                {
                    if (Input.GetMouseButton(0))
                    {
                        if (((Vector2)Input.mousePosition - pointerDownPos).sqrMagnitude >= 100f)
                        {
                            pointerDown = false;
                        }
                        else if (Time.realtimeSinceStartup - pointerDownTime >= holdTime)
                        {
                            pointerDown = false;

                            if (!hitObject.IsNull() && EventSystem.current != null)
                            {
                                draggingPointer = new PointerEventData(EventSystem.current)
                                {
                                    pointerId     = -111,
                                    pressPosition = Input.mousePosition,
                                    position      = Input.mousePosition,
                                    button        = PointerEventData.InputButton.Left
                                };

                                draggedReference = RuntimeInspectorUtils.CreateDraggedReferenceItem(hitObject, draggingPointer, draggedReferenceSkin);
                                if (draggedReference == null)
                                {
                                    pointerDown     = false;
                                    draggingPointer = null;
                                }
                            }
                        }
                    }
                    else if (Input.GetMouseButtonUp(0))
                    {
                        pointerDown = false;
                    }
                }
            }
        }