コード例 #1
0
        void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
        {
            if (!hierarchy.CanReorganizeItems || hierarchy.IsInSearchMode)
            {
                return;
            }

            if (!RuntimeInspectorUtils.GetAssignableObjectFromDraggedReferenceItem <Transform>(eventData))
            {
                return;
            }

            pointer               = eventData;
            pointerLastYPos       = -1f;
            nextPointerValidation = POINTER_VALIDATE_INTERVAL;

            if (canvas.renderMode == RenderMode.ScreenSpaceOverlay || (canvas.renderMode == RenderMode.ScreenSpaceCamera && !canvas.worldCamera))
            {
                worldCamera = null;
            }
            else
            {
                worldCamera = canvas.worldCamera ? canvas.worldCamera : Camera.main;
            }

            Update();
        }
コード例 #2
0
        void IDropHandler.OnDrop(PointerEventData eventData)
        {
            Object assignableObject = RuntimeInspectorUtils.GetAssignableObjectFromDraggedReferenceItem(eventData, elementType);

            if (assignableObject != null)
            {
                if (!OnSizeChanged(null, (Length + 1).ToString(RuntimeInspectorUtils.numberFormat)))
                {
                    return;
                }

                if (isArray)
                {
                    Array _array = (Array)Value;
                    _array.SetValue(assignableObject, Length - 1);
                    Value = _array;
                }
                else
                {
                    IList _list = (IList)Value;
                    _list[Length - 1] = assignableObject;
                    Value             = _list;
                }

                if (!IsExpanded)
                {
                    IsExpanded = true;
                }
            }
        }
コード例 #3
0
        public void OnDrop(PointerEventData eventData)
        {
            Object assignableObject = RuntimeInspectorUtils.GetAssignableObjectFromDraggedReferenceItem(eventData, BoundVariableType);

            if (assignableObject != null)
            {
                OnReferenceChanged(assignableObject);
            }
        }
コード例 #4
0
        private IEnumerator CreateReferenceItemCoroutine(PointerEventData eventData)
        {
            yield return(new WaitForSecondsRealtime(Hierarchy.DraggedReferenceHoldTime));

            if (!BoundTransform.IsNull())
            {
                RuntimeInspectorUtils.CreateDraggedReferenceItem(BoundTransform, eventData, Skin);
            }
        }
        protected override void Update()
        {
            base.Update();

            if (IsBound)
            {
                float time = Time.realtimeSinceStartup;
                if (isDirty)
                {
                    // Rebind to refresh the exposed variables in Inspector
                    object inspectedObject = m_inspectedObject;
                    StopInspect();
                    Inspect(inspectedObject);

                    isDirty         = false;
                    nextRefreshTime = time + refreshInterval;
                }
                else
                {
                    if (time > nextRefreshTime)
                    {
                        nextRefreshTime = time + refreshInterval;
                        Refresh();
                    }
                }

                // Check if a pointer has remained static over a drawer for a while; if so, show a tooltip
                if (hoveringPointer != null)
                {
                    Vector2 pointerDelta = hoveringPointer.delta;
                    if (pointerDelta.x != 0f || pointerDelta.y != 0f)
                    {
                        hoveredDrawerTooltipShowTime = time + m_tooltipDelay;
                    }
                    else if (time > hoveredDrawerTooltipShowTime)
                    {
                        // Make sure that everything is OK
                        if (!hoveredDrawer || !hoveredDrawer.gameObject.activeSelf)
                        {
                            hoveredDrawer   = null;
                            hoveringPointer = null;
                        }
                        else
                        {
                            RuntimeInspectorUtils.ShowTooltip(hoveredDrawer.NameRaw, hoveringPointer, Skin, m_canvas);

                            // Don't show the tooltip again until the pointer moves
                            hoveredDrawerTooltipShowTime = float.PositiveInfinity;
                        }
                    }
                }
            }
            else if (currentDrawer != null)
            {
                StopInspect();
            }
        }
コード例 #6
0
        protected override void DestroySelf()
        {
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
            if (InstanceItem == this)
            {
                InstanceItem = null;
            }
#endif

            RuntimeInspectorUtils.PoolDraggedReferenceItem(this);
        }
コード例 #7
0
        private IEnumerator CreateReferenceItemCoroutine(PointerEventData eventData)
        {
            float dragThreshold = EventSystem.current.pixelDragThreshold;

            yield return(new WaitForSecondsRealtime(holdTime));

            if (m_reference && (eventData.position - eventData.pressPosition).sqrMagnitude < dragThreshold * dragThreshold)
            {
                RuntimeInspectorUtils.CreateDraggedReferenceItem(m_reference, eventData, draggedReferenceSkin, GetComponentInParent <Canvas>());
            }
        }
コード例 #8
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);
            }
        }
コード例 #9
0
        internal void OnDrawerHovered(InspectorField drawer, PointerEventData pointer, bool isHovering)
        {
            // Hide tooltip if it is currently visible
            RuntimeInspectorUtils.HideTooltip();

            if (isHovering)
            {
                hoveredDrawer   = drawer;
                hoveringPointer = pointer;
                hoveredDrawerTooltipShowTime = Time.realtimeSinceStartup + m_tooltipDelay;
            }
            else if (hoveredDrawer == drawer)
            {
                hoveredDrawer   = null;
                hoveringPointer = null;
            }
        }
コード例 #10
0
        protected override void GenerateElements()
        {
            if (Value.IsNull())
            {
                initializeObjectButton.gameObject.SetActive(CanInitializeNewObject());
                return;
            }

            initializeObjectButton.gameObject.SetActive(false);

            if ((customEditor = RuntimeInspectorUtils.GetCustomEditor(Value.GetType())) != null)
            {
                customEditor.GenerateElements(this);
            }
            else
            {
                CreateDrawersForVariables();
            }
        }
コード例 #11
0
        void IDropHandler.OnDrop(PointerEventData eventData)
        {
            object[] assignableObjects = RuntimeInspectorUtils.GetAssignableObjectsFromDraggedReferenceItem(eventData, elementType);
            if (assignableObjects != null && assignableObjects.Length > 0)
            {
                int prevLength = Length;
                if (!OnSizeChanged(null, (prevLength + assignableObjects.Length).ToString(RuntimeInspectorUtils.numberFormat)))
                {
                    return;
                }

                if (isArray)
                {
                    Array _array = (Array)Value;
                    for (int i = 0; i < assignableObjects.Length; i++)
                    {
                        _array.SetValue(assignableObjects[i], prevLength + i);
                    }

                    Value = _array;
                }
                else
                {
                    IList _list = (IList)Value;
                    for (int i = 0; i < assignableObjects.Length; i++)
                    {
                        _list[prevLength + i] = assignableObjects[i];
                    }

                    Value = _list;
                }

                if (!IsExpanded)
                {
                    IsExpanded = true;
                }
            }
        }
コード例 #12
0
        private void Update()
        {
            // Check if a pointer has remained static over a drawer for a while; if so, show a tooltip
            float time = Time.realtimeSinceStartup;

            if (hoveringPointer != null)
            {
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
                // PointerEventData.delta isn't set to (0,0) for static pointers in the new Input System, so we use the active Pointer's delta instead
                // The default value isn't Vector2.zero but Vector2.one because we don't want to show tooltip if there is no pointer
                Vector2 pointerDelta = Pointer.current != null?Pointer.current.delta.ReadValue() : Vector2.one;
#else
                Vector2 pointerDelta = hoveringPointer.delta;
#endif
                if (pointerDelta.x != 0f || pointerDelta.y != 0f)
                {
                    hoveredDrawerTooltipShowTime = time + manager.TooltipDelay;
                }
                else if (time > hoveredDrawerTooltipShowTime)
                {
                    // Make sure that everything is OK
                    if (!hoveredDrawer.IsActive)
                    {
                        hoveredDrawer   = null;
                        hoveringPointer = null;
                    }
                    else
                    {
                        RuntimeInspectorUtils.ShowTooltip(hoveredDrawer.TooltipText, hoveringPointer, manager.Skin, manager.Canvas);

                        // Don't show the tooltip again until the pointer moves
                        hoveredDrawerTooltipShowTime = float.PositiveInfinity;
                    }
                }
            }
        }
コード例 #13
0
ファイル: VariableSet.cs プロジェクト: CWolfs/BTDebug-Library
        public bool Init()
        {
            type = RuntimeInspectorUtils.GetType(m_type);
            if (type == null)
            {
                return(false);
            }

            variables = new HashSet <string>();
            for (int i = 0; i < m_variables.Length; i++)
            {
                if (m_variables[i] != INCLUDE_ALL_VARIABLES)
                {
                    variables.Add(m_variables[i]);
                }
                else
                {
                    AddAllVariablesToSet();
                    break;
                }
            }

            return(true);
        }
コード例 #14
0
 protected override void DestroySelf()
 {
     RuntimeInspectorUtils.PoolDraggedReferenceItem(this);
 }
コード例 #15
0
        public void OnDrop(PointerEventData eventData)
        {
            RuntimeHierarchy hierarchy = Hierarchy;

            if (hierarchy == null || !hierarchy.CanReorganizeItems)
            {
                return;
            }

            Transform droppedTransform = RuntimeInspectorUtils.GetAssignableObjectFromDraggedReferenceItem(eventData, typeof(Transform)) as Transform;

            if (droppedTransform == null)
            {
                return;
            }

            if (hierarchyItem == null)
            {
                if (droppedTransform.parent == null)
                {
                    return;
                }

                droppedTransform.SetParent(null, true);
            }
            else if (hierarchyItem is HierarchyItemTransform)
            {
                Transform newParent = ((HierarchyItemTransform)hierarchyItem).BoundTransform;
                if (droppedTransform.parent == newParent || droppedTransform == newParent)
                {
                    return;
                }

                // Avoid setting child object as parent of the parent object
                Transform curr = newParent;
                while (curr.parent != null && curr.parent != droppedTransform)
                {
                    curr = curr.parent;
                }

                if (curr.parent == droppedTransform)
                {
                    curr.SetParent(droppedTransform.parent, true);
                }

                droppedTransform.SetParent(newParent, true);
            }
            else
            {
                IHierarchyRootContent rootContent = ((HierarchyItemRoot)hierarchyItem).Content;
                if (rootContent is HierarchyRootPseudoScene)
                {
                    //( (HierarchyRootPseudoScene) rootContent ).AddChild( droppedTransform ); // Add object to pseudo-scene
                    return;
                }
                else if (rootContent is HierarchyRootScene)
                {
                    bool parentChanged = false;
                    if (droppedTransform.parent != null)
                    {
                        droppedTransform.SetParent(null, true);
                        parentChanged = true;
                    }

                    Scene scene = ((HierarchyRootScene)rootContent).Scene;
                    if (droppedTransform.gameObject.scene != scene)
                    {
                        SceneManager.MoveGameObjectToScene(droppedTransform.gameObject, scene);
                        parentChanged = true;
                    }

                    if (!parentChanged)
                    {
                        return;
                    }
                }
            }

            if (hierarchyItem != null && !hierarchyItem.IsExpanded)
            {
                hierarchyItem.IsExpanded = true;
            }

            hierarchy.Refresh();
        }
コード例 #16
0
        protected override void Update()
        {
            base.Update();

            if (IsBound)
            {
                float time = Time.realtimeSinceStartup;
                if (isDirty)
                {
                    // Rebind to refresh the exposed variables in Inspector
                    object inspectedObject = m_inspectedObject;
                    StopInspect();
                    Inspect(inspectedObject);

                    isDirty         = false;
                    nextRefreshTime = time + refreshInterval;
                }
                else
                {
                    if (time > nextRefreshTime)
                    {
                        nextRefreshTime = time + refreshInterval;
                        Refresh();
                    }
                }

                // Check if a pointer has remained static over a drawer for a while; if so, show a tooltip
                if (hoveringPointer != null)
                {
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
                    // PointerEventData.delta isn't set to (0,0) for static pointers in the new Input System, so we use the active Pointer's delta instead
                    // The default value isn't Vector2.zero but Vector2.one because we don't want to show tooltip if there is no pointer
                    Vector2 pointerDelta = Pointer.current != null?Pointer.current.delta.ReadValue() : Vector2.one;
#else
                    Vector2 pointerDelta = hoveringPointer.delta;
#endif
                    if (pointerDelta.x != 0f || pointerDelta.y != 0f)
                    {
                        hoveredDrawerTooltipShowTime = time + m_tooltipDelay;
                    }
                    else if (time > hoveredDrawerTooltipShowTime)
                    {
                        // Make sure that everything is OK
                        if (!hoveredDrawer || !hoveredDrawer.gameObject.activeSelf)
                        {
                            hoveredDrawer   = null;
                            hoveringPointer = null;
                        }
                        else
                        {
                            RuntimeInspectorUtils.ShowTooltip(hoveredDrawer.NameRaw, hoveringPointer, Skin, m_canvas);

                            // Don't show the tooltip again until the pointer moves
                            hoveredDrawerTooltipShowTime = float.PositiveInfinity;
                        }
                    }
                }
            }
            else if (currentDrawer != null)
            {
                StopInspect();
            }
        }
コード例 #17
0
 public void OnEndDrag(PointerEventData eventData)
 {
     RuntimeInspectorUtils.PoolDraggedReferenceItem(this);
 }
コード例 #18
0
        void IDropHandler.OnDrop(PointerEventData eventData)
        {
            ((IPointerExitHandler)this).OnPointerExit(eventData);

            if (!hierarchy.CanReorganizeItems || hierarchy.IsInSearchMode)
            {
                return;
            }

            Transform droppedTransform = RuntimeInspectorUtils.GetAssignableObjectFromDraggedReferenceItem(eventData, typeof(Transform)) as Transform;

            if (!droppedTransform)
            {
                return;
            }

            int  newSiblingIndex = -1;
            bool shouldFocusObjectInHierarchy = false;

            float         contentYPos = pointerLastYPos + content.anchoredPosition.y;
            int           dataIndex   = (int)contentYPos / hierarchy.Skin.LineHeight;
            HierarchyData target      = hierarchy.GetDataAt(dataIndex);

            if (target == null)
            {
                // Dropped object onto the blank space at the bottom of the Hierarchy
                if (droppedTransform.parent == null)
                {
                    return;
                }

                droppedTransform.SetParent(null, true);
                shouldFocusObjectInHierarchy = true;
            }
            else
            {
                int   insertDirection;
                float relativePosition = contentYPos % hierarchy.Skin.LineHeight;
                if (relativePosition < siblingIndexModificationArea)
                {
                    insertDirection = -1;
                }
                else if (relativePosition > hierarchy.Skin.LineHeight - siblingIndexModificationArea)
                {
                    insertDirection = 1;
                }
                else
                {
                    insertDirection = 0;
                }

                // Inserting above/below a scene or pseudo-scene is a special case
                if (insertDirection != 0 && !(target is HierarchyDataTransform))
                {
                    if (insertDirection < 0 && dataIndex > 0)
                    {
                        // In Hierarchy AB, if inserting above B, then instead insert below A; it is easier for calculations
                        HierarchyData _target = hierarchy.GetDataAt(dataIndex - 1);
                        if (_target != null)
                        {
                            target          = _target;
                            insertDirection = 1;
                        }
                    }
                    else if (insertDirection > 0 && dataIndex < hierarchy.ItemCount - 1)
                    {
                        // In Hierarchy AB, if inserting below A, then instead insert above B if B is a Transform; it is easier for calculations
                        HierarchyData _target = hierarchy.GetDataAt(dataIndex + 1);
                        if (_target != null && _target is HierarchyDataTransform)
                        {
                            target          = _target;
                            insertDirection = -1;
                        }
                    }
                }

                HierarchyDataRoot newScene = null;
                if (!(target is HierarchyDataTransform))
                {
                    // Dropped onto a scene or pseudo-scene
                    newScene = (HierarchyDataRoot)target;
                }
                else
                {
                    // Dropped onto a Transform
                    Transform newParent = ((HierarchyDataTransform)target).BoundTransform;

                    // Dropped onto itself, ignore
                    if (!newParent || droppedTransform == newParent)
                    {
                        return;
                    }

                    if (insertDirection != 0)
                    {
                        if (insertDirection > 0 && target.Height > 1)
                        {
                            // Dropped below an expanded Transform, make dropped object a child of it
                            newSiblingIndex = 0;
                        }
                        else if (target.Depth == 1 && target.Root is HierarchyDataRootPseudoScene)
                        {
                            // Dropped above or below a root pseudo-scene object, don't actually change the parent
                            if (insertDirection < 0)
                            {
                                newSiblingIndex = ((HierarchyDataRootPseudoScene)target.Root).IndexOf(newParent);
                            }
                            else
                            {
                                newSiblingIndex = ((HierarchyDataRootPseudoScene)target.Root).IndexOf(newParent) + 1;
                            }

                            newParent = null;
                        }
                        else
                        {
                            // Dropped above or below a regular Transform, calculate target sibling index
                            if (insertDirection < 0)
                            {
                                newSiblingIndex = newParent.GetSiblingIndex();
                            }
                            else
                            {
                                newSiblingIndex = newParent.GetSiblingIndex() + 1;
                            }

                            // To be able to drop the object at that sibling index, object's parent must also be changed
                            newParent = newParent.parent;

                            // If we are only changing the sibling index of the dropped Transform and not the parent, then make sure
                            // that the target sibling index won't be affected when the dropped Transform is shifted in the Hierarchy
                            if (newParent == droppedTransform.parent && (newParent || (target.Root is HierarchyDataRootScene && ((HierarchyDataRootScene)target.Root).Scene == droppedTransform.gameObject.scene)))
                            {
                                if (newSiblingIndex > droppedTransform.GetSiblingIndex())
                                {
                                    newSiblingIndex--;
                                }
                            }
                        }
                    }

                    if (!newParent)
                    {
                        newScene = target.Root;
                    }
                    else
                    {
                        if (!canDropParentOnChild)
                        {
                            // Avoid setting child object as parent of the parent object
                            if (newParent.IsChildOf(droppedTransform))
                            {
                                return;
                            }
                        }
                        else
                        {
                            // First, set the child object's parent as dropped object's current parent so that
                            // the dropped object can then become a child of the former child object
                            Transform curr = newParent;
                            while (curr.parent != null && curr.parent != droppedTransform)
                            {
                                curr = curr.parent;
                            }

                            if (curr.parent == droppedTransform)
                            {
                                if (droppedTransform.parent == null && target.Root is HierarchyDataRootPseudoScene)
                                {
                                    // Dropped object was a root pseudo-scene object, swap the child and parent objects in the pseudo-scene, as well
                                    if (!canAddObjectsToPseudoScenes)
                                    {
                                        return;
                                    }

                                    HierarchyDataRootPseudoScene pseudoScene = (HierarchyDataRootPseudoScene)target.Root;
                                    pseudoScene.InsertChild(pseudoScene.IndexOf(newParent), curr);
                                    pseudoScene.RemoveChild(newParent);
                                }

                                int siblingIndex = droppedTransform.GetSiblingIndex();
                                curr.SetParent(droppedTransform.parent, true);
                                curr.SetSiblingIndex(siblingIndex);

                                shouldFocusObjectInHierarchy = true;
                            }
                        }

                        droppedTransform.SetParent(newParent, true);
                    }
                }

                if (newScene != null)
                {
                    if (newScene is HierarchyDataRootPseudoScene)
                    {
                        if (!canAddObjectsToPseudoScenes)
                        {
                            return;
                        }

                        // Add object to pseudo-scene
                        if (newSiblingIndex < 0)
                        {
                            ((HierarchyDataRootPseudoScene)newScene).AddChild(droppedTransform);
                        }
                        else
                        {
                            ((HierarchyDataRootPseudoScene)newScene).InsertChild(newSiblingIndex, droppedTransform);

                            // Don't try to change the actual sibling index of the Transform
                            newSiblingIndex = -1;
                            target          = newScene;
                        }
                    }
                    else if (newScene is HierarchyDataRootScene)
                    {
                        if (droppedTransform.parent != null)
                        {
                            droppedTransform.SetParent(null, true);
                        }

                        // Change dropped object's scene
                        Scene scene = ((HierarchyDataRootScene)newScene).Scene;
                        if (droppedTransform.gameObject.scene != scene)
                        {
                            SceneManager.MoveGameObjectToScene(droppedTransform.gameObject, scene);
                        }

                        if (newSiblingIndex < 0)
                        {
                            // If object was dropped onto the scene, add it to the bottom of the scene
                            newSiblingIndex = scene.rootCount + 1;
                            shouldFocusObjectInHierarchy = true;
                        }
                    }
                }

                if (newSiblingIndex >= 0)
                {
                    droppedTransform.SetSiblingIndex(newSiblingIndex);
                }
            }

            // Selecting the object in Hierarchy automatically expands collapsed parent entries and snaps the scroll view to the
            // selected object. However, this snapping can be distracting, so don't select the object unless it is necessary
            if (shouldFocusObjectInHierarchy || (newSiblingIndex < 0 && !target.IsExpanded))
            {
                hierarchy.Select(droppedTransform, true);
            }
            else
            {
                hierarchy.Refresh();
            }
        }
コード例 #19
0
        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;
                    }
                }
            }
        }
コード例 #20
0
        void IDropHandler.OnDrop(PointerEventData eventData)
        {
            ((IPointerExitHandler)this).OnPointerExit(eventData);

            if (!hierarchy.CanReorganizeItems || hierarchy.IsInSearchMode)
            {
                return;
            }

            Transform[] droppedTransforms = RuntimeInspectorUtils.GetAssignableObjectsFromDraggedReferenceItem <Transform>(eventData);
            if (droppedTransforms == null || droppedTransforms.Length == 0)
            {
                return;
            }

            // Sorting the selection is necessary to preserve the sibling index order of the dragged Transforms
            if (droppedTransforms.Length > 1)
            {
                System.Array.Sort(droppedTransforms, (transform1, transform2) => CompareHierarchySiblingIndices(transform1, transform2));
            }

            bool shouldFocusObjectInHierarchy = false;

            float         contentYPos = pointerLastYPos + content.anchoredPosition.y;
            int           dataIndex   = (int)contentYPos / hierarchy.Skin.LineHeight;
            HierarchyData target      = hierarchy.GetDataAt(dataIndex);

            if (target == null)
            {
                // Dropped Transform(s) onto the blank space at the bottom of the Hierarchy
                for (int i = 0; i < droppedTransforms.Length; i++)
                {
                    if (droppedTransforms[i].parent != null)
                    {
                        droppedTransforms[i].SetParent(null, true);
                        shouldFocusObjectInHierarchy = true;
                    }
                }

                if (!shouldFocusObjectInHierarchy)
                {
                    return;
                }
            }
            else
            {
                int   insertDirection;
                float relativePosition = contentYPos % hierarchy.Skin.LineHeight;
                if (relativePosition < siblingIndexModificationArea)
                {
                    insertDirection = -1;
                }
                else if (relativePosition > hierarchy.Skin.LineHeight - siblingIndexModificationArea)
                {
                    insertDirection = 1;
                }
                else
                {
                    insertDirection = 0;
                }

                // Inserting above/below a scene or pseudo-scene is a special case
                if (insertDirection != 0 && !(target is HierarchyDataTransform))
                {
                    if (insertDirection < 0 && dataIndex > 0)
                    {
                        // In an hierarchy with consecutive items A and B, insert below A instead of inserting above B because it makes calculations easier
                        HierarchyData _target = hierarchy.GetDataAt(dataIndex - 1);
                        if (_target != null)
                        {
                            target          = _target;
                            insertDirection = 1;
                        }
                    }
                    else if (insertDirection > 0 && dataIndex < hierarchy.ItemCount - 1)
                    {
                        // In an hierarchy with consecutive items A and B where B is a Transform, insert above B instead of inserting below A because it makes calculations easier
                        HierarchyData _target = hierarchy.GetDataAt(dataIndex + 1);
                        if (_target != null && _target is HierarchyDataTransform)
                        {
                            target          = _target;
                            insertDirection = -1;
                        }
                    }
                }

                HierarchyDataRoot newScene  = null;
                Transform         newParent = null;
                int newSiblingIndex         = -1;
                if (!(target is HierarchyDataTransform))
                {
                    // Dropped onto a scene or pseudo-scene
                    newScene = (HierarchyDataRoot)target;
                }
                else
                {
                    // Dropped onto a Transform
                    newParent = ((HierarchyDataTransform)target).BoundTransform;
                    if (!newParent)
                    {
                        return;
                    }

                    if (insertDirection != 0)
                    {
                        if (insertDirection > 0 && target.Height > 1)
                        {
                            // Dropped below an expanded Transform, make dropped object a child of it
                            newSiblingIndex = 0;
                        }
                        else if (target.Depth == 1 && target.Root is HierarchyDataRootPseudoScene)
                        {
                            // Dropped above or below a root pseudo-scene object, don't actually change the parent
                            if (insertDirection < 0)
                            {
                                newSiblingIndex = ((HierarchyDataRootPseudoScene)target.Root).IndexOf(newParent);
                            }
                            else
                            {
                                newSiblingIndex = ((HierarchyDataRootPseudoScene)target.Root).IndexOf(newParent) + 1;
                            }

                            newParent = null;
                        }
                        else
                        {
                            // Dropped above or below a regular Transform, calculate target sibling index
                            if (insertDirection < 0)
                            {
                                newSiblingIndex = newParent.GetSiblingIndex();
                            }
                            else
                            {
                                newSiblingIndex = newParent.GetSiblingIndex() + 1;
                            }

                            // To be able to drop the object at that sibling index, object's parent must also be changed
                            newParent = newParent.parent;
                        }
                    }

                    if (!newParent)
                    {
                        newScene = target.Root;
                    }
                }

                int successfullyDroppedTransformCount = 0;
                for (int i = 0; i < droppedTransforms.Length; i++)
                {
                    bool _shouldFocusObjectInHierarchy, decrementSiblingIndex;
                    if (DropTransformOnto(droppedTransforms[i], target, newScene, newParent, (newSiblingIndex >= 0) ? (newSiblingIndex + successfullyDroppedTransformCount) : newSiblingIndex, out decrementSiblingIndex, out _shouldFocusObjectInHierarchy))
                    {
                        successfullyDroppedTransformCount++;
                        shouldFocusObjectInHierarchy |= _shouldFocusObjectInHierarchy;

                        if (decrementSiblingIndex)
                        {
                            newSiblingIndex--;
                        }
                    }
                }

                if (successfullyDroppedTransformCount == 0)
                {
                    return;
                }
            }

            // Don't reveal the selection unless it's necessary (i.e. selection is already fully visible)
            if (shouldFocusObjectInHierarchy)
            {
                hierarchy.SelectInternal(droppedTransforms, RuntimeHierarchy.SelectOptions.FocusOnSelection | RuntimeHierarchy.SelectOptions.ForceRevealSelection);
            }
            else
            {
                hierarchy.Refresh();
            }
        }
コード例 #21
0
        protected override void Update()
        {
            base.Update();

            float time = Time.realtimeSinceStartup;

            if (!m_isInSearchMode)
            {
                if (time > nextHierarchyRefreshTime)
                {
                    Refresh();
                }
            }
            else if (time > nextSearchRefreshTime)
            {
                RefreshSearchResults();
            }

            if (isListViewDirty)
            {
                RefreshListView();
            }

            if (time > nextObjectNamesRefreshTime)
            {
                nextObjectNamesRefreshTime = time + m_objectNamesRefreshInterval;

                for (int i = sceneData.Count - 1; i >= 0; i--)
                {
                    sceneData[i].ResetCachedNames();
                }

                for (int i = searchSceneData.Count - 1; i >= 0; i--)
                {
                    searchSceneData[i].ResetCachedNames();
                }

                for (int i = drawers.Count - 1; i >= 0; i--)
                {
                    if (drawers[i].gameObject.activeSelf)
                    {
                        drawers[i].RefreshName();
                    }
                }

                shouldRecalculateContentWidth = true;
            }

            if (m_showHorizontalScrollbar && shouldRecalculateContentWidth)
            {
                shouldRecalculateContentWidth = false;

                float preferredWidth = 0f;
                for (int i = drawers.Count - 1; i >= 0; i--)
                {
                    if (drawers[i].gameObject.activeSelf)
                    {
                        float drawerWidth = drawers[i].PreferredWidth;
                        if (drawerWidth > preferredWidth)
                        {
                            preferredWidth = drawerWidth;
                        }
                    }
                }

                float contentMinWidth = listView.ViewportWidth + scrollView.verticalScrollbarSpacing;
                if (preferredWidth > contentMinWidth)
                {
                    scrollView.content.sizeDelta = new Vector2(preferredWidth - contentMinWidth, scrollView.content.sizeDelta.y);
                }
                else
                {
                    scrollView.content.sizeDelta = new Vector2(0f, scrollView.content.sizeDelta.y);
                }
            }

            if (m_createDraggedReferenceOnHold && currentlyPressedDrawer && time > pressedDrawerDraggedReferenceCreateTime)
            {
                if (currentlyPressedDrawer.gameObject.activeSelf && currentlyPressedDrawer.Data.BoundTransform)
                {
                    if (RuntimeInspectorUtils.CreateDraggedReferenceItem(currentlyPressedDrawer.Data.BoundTransform, pressedDrawerActivePointer, Skin, m_canvas))
                    {
                        ((IPointerEnterHandler)dragDropListener).OnPointerEnter(pressedDrawerActivePointer);
                    }
                }

                currentlyPressedDrawer     = null;
                pressedDrawerActivePointer = null;
            }

            if (m_autoScrollSpeed != 0f)
            {
                scrollView.verticalNormalizedPosition = Mathf.Clamp01(scrollView.verticalNormalizedPosition + m_autoScrollSpeed * Time.unscaledDeltaTime / totalItemCount);
            }
        }
コード例 #22
0
        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;
                    }
                }
            }
        }