public void OnDrawerPointerEvent(HierarchyField drawer, PointerEventData eventData, bool isPointerDown)
        {
            if (!isPointerDown)
            {
                currentlyPressedDrawer     = null;
                pressedDrawerActivePointer = null;

#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
                // On new Input System, DraggedReferenceItems aren't tracked by the PointerEventDatas that initiated them. However, when a DraggedReferenceItem is
                // created by holding a HierarchyField, the PointerEventData's dragged object will be set as the RuntimeHierarchy's ScrollRect. When it happens,
                // trying to scroll the RuntimeHierarchy by holding the DraggedReferenceItem at top/bottom edge of the ScrollRect doesn't work because scrollbar's
                // value is overwritten by the original PointerEventData. We can prevent this issue by stopping original PointerEventData's drag operation here
                if (eventData.dragging && eventData.pointerDrag == scrollView.gameObject && DraggedReferenceItem.InstanceItem)
                {
                    eventData.dragging    = false;
                    eventData.pointerDrag = null;
                }
#endif
            }
            else if (m_createDraggedReferenceOnHold)
            {
                currentlyPressedDrawer     = drawer;
                pressedDrawerActivePointer = eventData;
                pressedDrawerDraggedReferenceCreateTime = Time.realtimeSinceStartup + m_draggedReferenceHoldTime;
            }
        }
示例#2
0
        RecycledListItem IListViewAdapter.CreateItem(Transform parent)
        {
            HierarchyField result = (HierarchyField)Instantiate(drawerPrefab, parent, false);

            result.Initialize(this);
            result.Skin = Skin;

            drawers.Add(result);
            return(result);
        }
示例#3
0
 public void OnDrawerPointerEvent(HierarchyField drawer, PointerEventData eventData, bool isPointerDown)
 {
     if (!isPointerDown)
     {
         currentlyPressedDrawer     = null;
         pressedDrawerActivePointer = null;
     }
     else if (m_createDraggedReferenceOnHold)
     {
         currentlyPressedDrawer     = drawer;
         pressedDrawerActivePointer = eventData;
         pressedDrawerDraggedReferenceCreateTime = Time.realtimeSinceStartup + m_draggedReferenceHoldTime;
     }
 }
示例#4
0
        void IListViewAdapter.SetItemContent(RecycledListItem item)
        {
            if (isListViewDirty)
            {
                RefreshListView();
            }

            HierarchyField drawer = (HierarchyField)item;
            HierarchyData  data   = GetDataAt(drawer.Position);

            if (data != null)
            {
                drawer.Skin = Skin;
                drawer.SetContent(data);
                drawer.IsSelected = m_currentSelection && m_currentSelection == data.BoundTransform;
                drawer.Refresh();

                shouldRecalculateContentWidth = true;
            }
        }
示例#5
0
        void IListViewAdapter.OnItemClicked(RecycledListItem item)
        {
            HierarchyField drawer = (HierarchyField)item;

            if (!drawer)
            {
                if (m_currentSelection)
                {
                    for (int i = drawers.Count - 1; i >= 0; i--)
                    {
                        if (drawers[i].gameObject.activeSelf && drawers[i].Data.BoundTransform == m_currentSelection)
                        {
                            drawers[i].IsSelected = false;
                        }
                    }

                    CurrentSelection = null;
                }
            }
            else if (m_currentSelection == drawer.Data.BoundTransform)
            {
                if (OnItemDoubleClicked != null)
                {
                    if (Time.realtimeSinceStartup - lastClickTime <= m_doubleClickThreshold)
                    {
                        lastClickTime = 0f;

                        if (m_currentSelection)
                        {
                            OnItemDoubleClicked(m_currentSelection);
                        }
                    }
                    else
                    {
                        lastClickTime = Time.realtimeSinceStartup;
                    }
                }
            }
            else
            {
                Transform clickedTransform = drawer.Data.BoundTransform;
                for (int i = drawers.Count - 1; i >= 0; i--)
                {
                    if (drawers[i].gameObject.activeSelf)
                    {
                        Transform drawerTransform = drawers[i].Data.BoundTransform;
                        if (drawerTransform == m_currentSelection)
                        {
                            drawers[i].IsSelected = false;
                        }
                        else if (drawerTransform == clickedTransform && clickedTransform)
                        {
                            drawers[i].IsSelected = true;
                        }
                    }
                }

                lastClickTime    = Time.realtimeSinceStartup;
                CurrentSelection = clickedTransform;

                if (m_isInSearchMode && clickedTransform)
                {
                    // Fetch the object's path and show it in Hierarchy
                    System.Text.StringBuilder sb = RuntimeInspectorUtils.stringBuilder;
                    sb.Length = 0;

                    sb.AppendLine("Path:");
                    while (clickedTransform)
                    {
                        sb.Append("  ").AppendLine(clickedTransform.name);
                        clickedTransform = clickedTransform.parent;
                    }

                    selectedPathText.text = sb.Append("  ").Append(drawer.Data.Root.Name).ToString();
                    selectedPathBackground.gameObject.SetActive(true);
                }
            }
        }
示例#6
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);
            }
        }