Beispiel #1
0
        public void SetContent(object[] references, PointerEventData draggingPointer)
        {
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
            if (InstanceItem)
            {
                InstanceItem.DestroySelf();
            }

            InstanceItem = this;

            draggingPointer = new PointerEventData(EventSystem.current)
            {
                pressPosition = draggingPointer.pressPosition,
                position      = draggingPointer.position,
                delta         = draggingPointer.delta
            };
#endif

            m_references = references;
            label.text   = (references.Length == 1) ? references[0].GetNameWithType() : string.Concat(references[0].GetNameWithType(), " (and ", (references.Length - 1).ToString(RuntimeInspectorUtils.numberFormat), " more)");

            draggingPointer.pointerDrag = gameObject;
            draggingPointer.dragging    = true;

            SetPointer(draggingPointer);
        }
        public void SetContent(Object reference, PointerEventData draggingPointer)
        {
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
            if (InstanceItem)
            {
                InstanceItem.DestroySelf();
            }

            InstanceItem = this;

            draggingPointer = new PointerEventData(EventSystem.current)
            {
                pressPosition = draggingPointer.pressPosition,
                position      = draggingPointer.position,
                delta         = draggingPointer.delta
            };
#endif

            m_reference = reference;
            label.text  = reference.GetNameWithType();

            draggingPointer.pointerDrag = gameObject;
            draggingPointer.dragging    = true;

            SetPointer(draggingPointer);
        }
Beispiel #3
0
        public static DraggedReferenceItem CreateDraggedReferenceItem(Object reference, PointerEventData draggingPointer, UISkin skin = null)
        {
            DraggedReferenceItem referenceItem = Object.Instantiate(Resources.Load <DraggedReferenceItem>("RuntimeInspector/DraggedReferenceItem"), DraggedReferenceItemsCanvas.transform, false);

            referenceItem.Initialize(DraggedReferenceItemsCanvas, reference, draggingPointer, skin);

            return(referenceItem);
        }
Beispiel #4
0
 public static void PoolDraggedReferenceItem(DraggedReferenceItem item)
 {
     if (item.gameObject.activeSelf)
     {
         item.gameObject.SetActive(false);
         draggedReferenceItemsPool.Push(item);
     }
 }
Beispiel #5
0
        public static DraggedReferenceItem CreateDraggedReferenceItem(Object reference, PointerEventData draggingPointer, UISkin skin = null)
        {
            DraggedReferenceItem dri           = GameObject.Find("BTDebugInspector").GetComponent <BTDebugInspector>().draggedReferenceItemPrefab;
            DraggedReferenceItem referenceItem = (DraggedReferenceItem)Object.Instantiate(dri, DraggedReferenceItemsCanvas.transform, false);

            referenceItem.Initialize(DraggedReferenceItemsCanvas, reference, draggingPointer, skin);

            return(referenceItem);
        }
        protected override void DestroySelf()
        {
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
            if (InstanceItem == this)
            {
                InstanceItem = null;
            }
#endif

            RuntimeInspectorUtils.PoolDraggedReferenceItem(this);
        }
Beispiel #7
0
        public static Object GetAssignableObjectFromDraggedReferenceItem(PointerEventData draggingPointer, Type assignableType)
        {
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
            // In new Input System, DraggedReferenceItems aren't tracked by the PointerEventData that initiated them. They are tracked manually by DraggedReferenceItem itself
            DraggedReferenceItem draggedReference = DraggedReferenceItem.InstanceItem;
#else
            if (!draggingPointer.pointerDrag)
            {
                return(null);
            }

            DraggedReferenceItem draggedReference = draggingPointer.pointerDrag.GetComponent <DraggedReferenceItem>();
#endif
            if (draggedReference && draggedReference.Reference)
            {
                if (assignableType.IsAssignableFrom(draggedReference.Reference.GetType()))
                {
                    return(draggedReference.Reference);
                }
                else if (typeof(Component).IsAssignableFrom(assignableType))
                {
                    Object component = null;
                    if (draggedReference.Reference is Component)
                    {
                        component = ((Component)draggedReference.Reference).GetComponent(assignableType);
                    }
                    else if (draggedReference.Reference is GameObject)
                    {
                        component = ((GameObject)draggedReference.Reference).GetComponent(assignableType);
                    }

                    if (component)
                    {
                        return(component);
                    }
                }
                else if (typeof(GameObject).IsAssignableFrom(assignableType))
                {
                    if (draggedReference.Reference is Component)
                    {
                        return(((Component)draggedReference.Reference).gameObject);
                    }
                }
            }

            return(null);
        }
        public static Object GetAssignableObjectFromDraggedReferenceItem(PointerEventData draggingPointer, Type assignableType)
        {
            if (!draggingPointer.pointerDrag)
            {
                return(null);
            }

            DraggedReferenceItem draggedReference = draggingPointer.pointerDrag.GetComponent <DraggedReferenceItem>();

            if (draggedReference && draggedReference.Reference)
            {
                if (assignableType.IsAssignableFrom(draggedReference.Reference.GetType()))
                {
                    return(draggedReference.Reference);
                }
                else if (typeof(Component).IsAssignableFrom(assignableType))
                {
                    Object component = null;
                    if (draggedReference.Reference is Component)
                    {
                        component = ((Component)draggedReference.Reference).GetComponent(assignableType);
                    }
                    else if (draggedReference.Reference is GameObject)
                    {
                        component = ((GameObject)draggedReference.Reference).GetComponent(assignableType);
                    }

                    if (component)
                    {
                        return(component);
                    }
                }
                else if (typeof(GameObject).IsAssignableFrom(assignableType))
                {
                    if (draggedReference.Reference is Component)
                    {
                        return(((Component)draggedReference.Reference).gameObject);
                    }
                }
            }

            return(null);
        }
        internal static DraggedReferenceItem GetDraggedReferenceItem(AssetBundle assetBundle = null)
        {
            if (!cacheDraggedReferenceItem)
            {
                GameObject go;
                if (!assetBundle)
                {
                    assetBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "runtimeinspector_colorpicker.bundle"));

                    go = Instantiate(assetBundle.LoadAsset <GameObject>("DraggedReferenceItem")).gameObject;
                    go.SetActive(false);
                    assetBundle.Unload(false);
                    return(cacheDraggedReferenceItem = go.GetComponent <DraggedReferenceItem>());
                }
                go = Instantiate(assetBundle.LoadAsset <GameObject>("DraggedReferenceItem")).gameObject;
                go.SetActive(false);
                return(cacheDraggedReferenceItem = go.GetComponent <DraggedReferenceItem>());
            }
            return(cacheDraggedReferenceItem);
        }
        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;
                    }
                }
            }
        }
Beispiel #11
0
        private static object GetAssignableObjectsFromDraggedReferenceItemInternal(PointerEventData draggingPointer, Type assignableType, bool returnFirstObject)
        {
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
            // In new Input System, DraggedReferenceItems aren't tracked by the PointerEventData that initiated them. They are tracked manually by DraggedReferenceItem itself
            DraggedReferenceItem draggedReference = DraggedReferenceItem.InstanceItem;
#else
            if (!draggingPointer.pointerDrag)
            {
                return(null);
            }

            DraggedReferenceItem draggedReference = draggingPointer.pointerDrag.GetComponent <DraggedReferenceItem>();
#endif
            if (draggedReference && draggedReference.References != null && draggedReference.References.Length > 0)
            {
                object[] references = draggedReference.References;
                bool     allReferencesAreAlreadyOfAssignableType = true;
                for (int i = 0; i < references.Length; i++)
                {
                    if (references[i].IsNull() || !assignableType.IsAssignableFrom(references[i].GetType()))
                    {
                        allReferencesAreAlreadyOfAssignableType = false;
                        break;
                    }
                    else if (returnFirstObject)
                    {
                        break;
                    }
                }

                if (allReferencesAreAlreadyOfAssignableType)
                {
                    if (returnFirstObject)
                    {
                        return(references[0]);
                    }
                    else
                    {
                        return(references);
                    }
                }

                Array result       = returnFirstObject ? null : Array.CreateInstance(assignableType, references.Length);
                int   resultLength = 0;

                for (int i = 0; i < references.Length; i++)
                {
                    object reference = references[i];
                    if (reference.IsNull())
                    {
                        continue;
                    }

                    object validReference = null;
                    if (assignableType.IsAssignableFrom(reference.GetType()))
                    {
                        validReference = reference;
                    }
                    else if (typeof(Component).IsAssignableFrom(assignableType))
                    {
                        if (reference is Component)
                        {
                            validReference = ((Component)reference).GetComponent(assignableType);
                        }
                        else if (reference is GameObject)
                        {
                            validReference = ((GameObject)reference).GetComponent(assignableType);
                        }
                    }
                    else if (typeof(GameObject).IsAssignableFrom(assignableType))
                    {
                        if (reference is Component)
                        {
                            validReference = ((Component)reference).gameObject;
                        }
                    }

                    if (!validReference.IsNull())
                    {
                        if (returnFirstObject)
                        {
                            return(validReference);
                        }
                        else
                        {
                            result.SetValue(validReference, resultLength++);
                        }
                    }
                }

                if (resultLength > 0)
                {
                    if (resultLength != result.Length)
                    {
                        Array _result = Array.CreateInstance(assignableType, resultLength);
                        Array.Copy(result, _result, resultLength);
                        return(_result);
                    }

                    return(result);
                }
            }

            return(null);
        }
        private void Update()
        {
#if !ENABLE_INPUT_SYSTEM || ENABLE_LEGACY_INPUT_MANAGER
            // On new Input System, DraggedReferenceItem's PointerEventData is tracked by DraggedReferenceItem itself, not this component
            if (draggingPointer != null)
            {
                if (!draggedReference || !draggedReference.gameObject.activeSelf)
                {
                    draggingPointer = null;
                }
                else if (IsPointerHeld())
                {
                    draggingPointer.position = GetPointerPosition();
                    ExecuteEvents.Execute(draggedReference.gameObject, draggingPointer, ExecuteEvents.dragHandler);
                }
                else
                {
                    ExecuteEvents.Execute(draggedReference.gameObject, draggingPointer, ExecuteEvents.endDragHandler);
                    if (EventSystem.current != null)
                    {
                        hoveredUIElements.Clear();
                        EventSystem.current.RaycastAll(draggingPointer, hoveredUIElements);

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

                    draggingPointer = null;
                }
            }
            else
#endif
            {
                if (!pointerDown)
                {
                    if (IsPointerDown() && EventSystem.current && !EventSystem.current.IsPointerOverGameObject())
                    {
                        RaycastHit hit;
                        if (Physics.Raycast(_camera.ScreenPointToRay(GetPointerPosition()), out hit, raycastRange, interactableObjectsMask))
                        {
                            hitObject = (ProcessRaycastHit != null) ? ProcessRaycastHit(hit) : hit.collider.gameObject;
                            if (hitObject)
                            {
                                pointerDown     = true;
                                pointerDownTime = Time.realtimeSinceStartup;
                                pointerDownPos  = GetPointerPosition();
                            }
                        }
                    }
                }
                else
                {
                    if (IsPointerHeld())
                    {
                        if ((GetPointerPosition() - pointerDownPos).sqrMagnitude >= 100f)
                        {
                            pointerDown = false;
                        }
                        else if (Time.realtimeSinceStartup - pointerDownTime >= holdTime)
                        {
                            pointerDown = false;

                            if (hitObject && EventSystem.current)
                            {
                                draggingPointer = new PointerEventData(EventSystem.current)
                                {
#if !ENABLE_INPUT_SYSTEM || ENABLE_LEGACY_INPUT_MANAGER
                                    pointerId = Input.touchCount > 0 ? Input.GetTouch(0).fingerId : -1,
#endif
                                    pressPosition = GetPointerPosition(),
                                    position      = GetPointerPosition(),
                                    button        = PointerEventData.InputButton.Left
                                };

                                draggedReference = RuntimeInspectorUtils.CreateDraggedReferenceItem(hitObject, draggingPointer, draggedReferenceSkin, draggedReferenceCanvas);
                                if (!draggedReference)
                                {
                                    pointerDown     = false;
                                    draggingPointer = null;
                                }
                            }
                        }
                    }
                    else
                    {
                        pointerDown = false;
                    }
                }
            }
        }