コード例 #1
0
        public bool InterceptMouseEvent(IPanel panel, IMouseEvent ev)
        {
            if (!m_Context.pickElement)
            {
                return(false);
            }

            var evtBase = ev as EventBase;
            var evtType = evtBase.eventTypeId;
            var target  = evtBase.target as VisualElement;

            // Ignore events on detached elements
            if (panel == null)
            {
                return(false);
            }

            if (((BaseVisualElementPanel)panel).ownerObject is HostView hostView && hostView.actualView is PlayModeView playModeView)
            {
                // Send event to runtime panels from closest to deepest
                var panels = UIElementsRuntimeUtility.GetSortedPlayerPanels();
                for (var i = panels.Count - 1; i >= 0; i--)
                {
                    if (SendEventToRuntimePanel((BaseRuntimePanel)panels[i], evtBase, playModeView.viewPadding, playModeView.viewMouseScale))
                    {
                        return(true);
                    }
                }

                // If no RuntimePanel catches it, select GameView editor panel and let interception fall through.
                if (evtType == MouseMoveEvent.TypeId() && m_Context.selectedElement != target)
                {
                    OnPickMouseOver(target, panel);
                }
            }
コード例 #2
0
        private void TrySelectWindow()
        {
            VisualElement root = null;

            if (m_WindowToDebug is GameView)
            {
                var runtimePanels = UIElementsRuntimeUtility.GetSortedPlayerPanels();
                if (runtimePanels != null && runtimePanels.Count > 0)
                {
                    root = runtimePanels[0].visualTree;
                }
            }

            if (root == null)
            {
                root = m_WindowToDebug.rootVisualElement;
            }


            if (root == null)
            {
                return;
            }

            IPanel searchedPanel = root.panel;

            SelectPanelToDebug(searchedPanel);

            if (m_SelectedPanel != null)
            {
                m_WindowToDebug = null;
                m_ConnectWindowScheduledItem.Pause();
            }
        }
コード例 #3
0
ファイル: InternalBridge.cs プロジェクト: Fleezey/phygames
        /// <summary>
        /// Create a new panel.
        /// </summary>
        /// <param name="scriptableObject">The owner of the panel.</param>
        /// <returns>Returns the new panel.</returns>
        public static IPanel CreatePanel(ScriptableObject scriptableObject)
        {
            var panel = UIElementsRuntimeUtility.CreateRuntimePanel(scriptableObject);

#if UNITY_EDITOR
            EditorInternalBridge.CreateDebugPanel(panel);
#endif
            panel.visualTree.pseudoStates |= PseudoStates.Root;
            return(panel);
        }
コード例 #4
0
        protected override void OnEnable()
        {
            base.OnEnable();
            m_EventSystems.Add(this);

#if PACKAGE_UITOOLKIT
            if (sendUIToolkitEvents)
            {
                UIElementsRuntimeUtility.RegisterEventSystem(this);
            }
#endif
        }
コード例 #5
0
        protected override void Start()
        {
            base.Start();

#if PACKAGE_UITOOLKIT
            if (createUIToolkitPanelGameObjectsOnStart)
            {
                foreach (BaseRuntimePanel panel in UIElementsRuntimeUtility.GetSortedPlayerPanels())
                {
                    CreateUIToolkitPanelGameObject(panel);
                }
                UIElementsRuntimeUtility.onCreatePanel += CreateUIToolkitPanelGameObject;
            }
#endif
        }
コード例 #6
0
        public void ProcessKeyboardEvents(InputSystemEventSystem eventSystem)
        {
            while (Event.PopEvent(m_Event))
            {
                if (m_Event.type != EventType.KeyDown && m_Event.type != EventType.KeyUp)
                {
                    continue;
                }

                using (EventBase evt = UIElementsRuntimeUtility.CreateEvent(m_Event))
                {
                    eventSystem.focusedPanel.visualTree.SendEvent(evt);
                }
            }
        }
コード例 #7
0
        protected override void OnDisable()
        {
#if PACKAGE_UITOOLKIT
            UIElementsRuntimeUtility.UnregisterEventSystem(this);
#endif

            if (m_CurrentInputModule != null)
            {
                m_CurrentInputModule.DeactivateModule();
                m_CurrentInputModule = null;
            }

            m_EventSystems.Remove(this);

            base.OnDisable();
        }
コード例 #8
0
        public bool InterceptMouseEvent(IPanel panel, IMouseEvent ev)
        {
            if (!m_Context.pickElement)
            {
                return(false);
            }

            var evtBase = ev as EventBase;
            var evtType = evtBase.eventTypeId;
            var target  = evtBase.target as VisualElement;

            // Ignore events on detached elements
            if (panel == null)
            {
                return(false);
            }

            if (((BaseVisualElementPanel)panel).ownerObject is HostView hostView && hostView.actualView is GameView)
            {
                var innerArea       = panel.GetRootVisualElement();
                var gameViewPadding =
                    (innerArea.parent.contentRect.height - innerArea.contentRect.height) * Vector2.up +
                    innerArea.layout.position; // Measured to: gameViewPadding = new Vector2(1, 40)

                // Send event to runtime panels from closest to deepest
                var panels = UIElementsRuntimeUtility.GetSortedPlayerPanels();
                for (var i = panels.Count - 1; i >= 0; i--)
                {
                    if (SendEventToRuntimePanel((BaseRuntimePanel)panels[i], evtBase, gameViewPadding))
                    {
                        return(true);
                    }
                }

                // If no RuntimePanel catches it, select GameView editor panel and let interception fall through.
                if (evtType == MouseMoveEvent.TypeId() && m_Context.selectedElement != target)
                {
                    OnPickMouseOver(target, panel);
                }
            }
コード例 #9
0
        /// <summary>
        /// Sets how UI Toolkit runtime panels receive events and handle selection
        /// when interacting with other objects that use the EventSystem, such as components from the Unity UI package.
        /// </summary>
        /// <param name="activeEventSystem">
        /// The EventSystem used to override UI Toolkit panel events and selection.
        /// If activeEventSystem is null, UI Toolkit panels will use current enabled EventSystem
        /// or, if there is none, the default InputManager-based event system will be used.
        /// </param>
        /// <param name="sendEvents">
        /// If true, UI Toolkit events will come from this EventSystem
        /// instead of the default InputManager-based event system.
        /// </param>
        /// <param name="createPanelGameObjectsOnStart">
        /// If true, UI Toolkit panels' unassigned selectableGameObject will be automatically initialized
        /// with children GameObjects of this EventSystem on Start.
        /// </param>
        public static void SetUITookitEventSystemOverride(EventSystem activeEventSystem, bool sendEvents = true, bool createPanelGameObjectsOnStart = true)
        {
#if PACKAGE_UITOOLKIT
            UIElementsRuntimeUtility.UnregisterEventSystem(UIElementsRuntimeUtility.activeEventSystem);

            s_UIToolkitOverride = new UIToolkitOverrideConfig
            {
                activeEventSystem             = activeEventSystem,
                sendEvents                    = sendEvents,
                createPanelGameObjectsOnStart = createPanelGameObjectsOnStart,
            };

            if (sendEvents)
            {
                var eventSystem = activeEventSystem != null ? activeEventSystem : EventSystem.current;
                if (eventSystem.isActiveAndEnabled)
                {
                    UIElementsRuntimeUtility.RegisterEventSystem(activeEventSystem);
                }
            }
#endif
        }
コード例 #10
0
ファイル: InternalBridge.cs プロジェクト: Fleezey/phygames
 /// <summary>
 /// Create a UIElements event from an Event.
 /// </summary>
 /// <param name="evt">The event to use as the source event.</param>
 /// <returns>Returns a new UIElements event.</returns>
 public static EventBase CreateEvent(Event evt)
 {
     return(UIElementsRuntimeUtility.CreateEvent(evt));
 }
コード例 #11
0
ファイル: InternalBridge.cs プロジェクト: Fleezey/phygames
 public static void DisposePanel(ScriptableObject scriptableObject)
 {
     UIElementsRuntimeUtility.DisposeRuntimePanel(scriptableObject);
 }
コード例 #12
0
 /// <summary>
 /// Unregister the panel from the engine.
 /// </summary>
 /// <param name="ownerID">The id of the ScriptableObject that owns the panel.</param>
 public static void UnregisterPanel(int ownerID)
 {
     UIElementsRuntimeUtility.RemoveCachedPanel(ownerID);
 }
コード例 #13
0
        /// <summary>
        /// Register the panel in the engine.
        /// </summary>
        /// <param name="ownerID">The id of the ScriptableObject that owns the panel.</param>
        /// <param name="panel">The panel to register.</param>
        public static void RegisterPanel(int ownerID, IPanel panel)
        {
            var runtimePanel = panel as RuntimePanel;

            UIElementsRuntimeUtility.RegisterCachedPanel(ownerID, runtimePanel);
        }