Ejemplo n.º 1
0
        protected virtual void DoUpdate()
        {
            updateSampler.Begin();

            var targetSize = targetTexture == null
                ? GetActiveRenderTargetSize()
                : new Vector2(targetTexture.width, targetTexture.height);

            if (targetTexture != m_TargetTexture)
            {
                m_TargetTexture = targetTexture;
                InternalBridge.SetTargetTexture(panel, targetTexture);
            }

            // Temporary: clamp scale to prevent font atlas running out of space
            // won't be needed when using TextCore
            var scale = Mathf.Max(0.1f, m_PanelScaler == null ? 1 : m_PanelScaler.ComputeScalingFactor(targetSize));

            if (m_Scale != scale || m_TargetSize != targetSize)
            {
                InternalBridge.SetScale(panel, scale == 0 ? 0 : 1.0f / scale);
                visualTree.style.left   = 0;
                visualTree.style.top    = 0;
                visualTree.style.width  = targetSize.x * scale;
                visualTree.style.height = targetSize.y * scale;
                m_Scale      = scale;
                m_TargetSize = targetSize;
            }

            InternalBridge.UpdatePanel(panel);

            updateSampler.End();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Implementation of Update()
        /// </summary>
        public void Update()
        {
            if (panel == null)
            {
                return;
            }

#if UNITY_EDITOR
            if (enableLiveUpdates && m_TrackedAssetList != null && m_TrackedAssetHashes != null)
            {
                for (int i = 0; i < m_TrackedAssetList.Count; ++i)
                {
                    var asset      = m_TrackedAssetList[i];
                    var hash       = EditorUtility.GetDirtyCount(asset);
                    var cachedHash = m_TrackedAssetHashes[i];

                    if (hash == cachedHash)
                    {
                        continue;
                    }

                    // RecreateUIFromUxml();
                    return;
                }
            }
#endif

            m_UpdateSampler.Begin();

            var targetSize = targetTexture == null
                ? GetActiveRenderTargetSize()
                : new Vector2(targetTexture.width, targetTexture.height);

            if (targetTexture != m_TargetTexture)
            {
                m_TargetTexture = targetTexture;
                InternalBridge.SetTargetTexture(panel, targetTexture);
            }

            // Temporary: clamp scale to prevent font atlas running out of space
            // won't be needed when using TextCore
            var scale = Mathf.Max(0.1f, m_PanelScaler == null ? 1 : m_PanelScaler.ComputeScalingFactor(targetSize));

            if (m_Scale != scale || m_TargetSize != targetSize)
            {
                InternalBridge.SetScale(panel, scale == 0 ? 0 : 1.0f / scale);
                visualTree.style.left   = 0;
                visualTree.style.top    = 0;
                visualTree.style.width  = targetSize.x * scale;
                visualTree.style.height = targetSize.y * scale;
                m_Scale      = scale;
                m_TargetSize = targetSize;
            }

            InternalBridge.UpdatePanel(panel);

            m_UpdateSampler.End();
        }
Ejemplo n.º 3
0
 private void OnRenderObject()
 {
     // render texture based world space rendering
     if (targetTexture != null)
     {
         // when doing world space repaint has to be called explicitly
         InternalBridge.RepaintPanel(panel, m_Event);
     }
 }
Ejemplo n.º 4
0
        void Cleanup()
        {
            if (m_PanelOwner != null)
            {
                InternalBridge.DisposePanel(m_PanelOwner);
                DestroyImmediate(m_PanelOwner);
            }

            panel         = null;
            m_PanelOwner  = null;
            m_PanelScaler = null;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Implementation of OnEnable()
        /// </summary>
        public void OnEnable()
        {
            m_PanelScaler   = GetComponent <PanelScaler>();
            m_Event.type    = EventType.Repaint;
            m_Scale         = Single.NaN;
            m_TargetSize    = new Vector2(Single.NaN, Single.NaN);
            m_TargetTexture = targetTexture;
            InternalBridge.SetTargetTexture(panel, m_TargetTexture);

            OnValidate();

            InternalBridge.RegisterPanel(gameObject.GetInstanceID(), panel);
        }
Ejemplo n.º 6
0
        internal static void RegisterUserFactories()
        {
            HashSet <string> userAssemblies = new HashSet <string>(InternalBridge.GetAllUserAssemblies());
            var assemblies = AppDomain.CurrentDomain.GetAssemblies();

            foreach (Assembly assembly in assemblies)
            {
                if (!(userAssemblies.Contains(assembly.GetName().Name + ".dll")))
                {
                    continue;
                }
                var types = assembly.GetTypes();
                foreach (Type type in types)
                {
                    if (typeof(IUxmlFactory).IsAssignableFrom(type) && !type.IsInterface && !type.IsAbstract)
                    {
                        var factory = (IUxmlFactory)Activator.CreateInstance(type);
                        InternalBridge.RegisterFactory(factory);
                    }
                }
            }
        }
Ejemplo n.º 7
0
        void Initialize(string name)
        {
            m_InitializedCounter++;
            if (m_InitializedCounter != 1)
            {
                return;
            }

            m_PanelOwner = ScriptableObject.CreateInstance <PanelOwner>();
            panel        = InternalBridge.CreatePanel(m_PanelOwner);
            var root = panel.visualTree;

            root.name = name;

            visualTree = new VisualElement {
                name = "runtime-panel-container"
            };
            visualTree.style.overflow = Overflow.Hidden;

            root.Add(visualTree);

            if (unityStyleSheet != null)
            {
                InternalBridge.MarkAsDefaultStyleSheet(unityStyleSheet);
                root.styleSheets.Add(unityStyleSheet);
            }

            if (stylesheets != null)
            {
                foreach (var uss in stylesheets)
                {
                    if (uss != null)
                    {
                        root.styleSheets.Add(uss);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Implementation of OnDisable()
 /// </summary>
 public void OnDisable()
 {
     InternalBridge.UnregisterPanel(gameObject.GetInstanceID());
 }
Ejemplo n.º 9
0
        void Initialize()
        {
            if (panel != null && m_PanelOwner == null)
            {
                Debug.LogWarning("Unexpected state: panel without owner. Panel will leak.");
            }

            if (panel == null || m_PanelOwner == null)
            {
                initSampler.Begin();

                if (m_PanelOwner == null)
                {
                    m_PanelOwner = ScriptableObject.CreateInstance <PanelOwner>();
                }

                panel = InternalBridge.CreatePanel(m_PanelOwner);
                var root = panel.visualTree;
                root.name = gameObject.name;

                visualTree = new VisualElement {
                    name = "runtime-panel-container"
                };
                visualTree.style.overflow = Overflow.Hidden;

                root.Add(visualTree);

                if (unityStyleSheet != null)
                {
                    InternalBridge.MarkAsDefaultStyleSheet(unityStyleSheet);
                    root.styleSheets.Add(unityStyleSheet);
                }

                if (stylesheets != null)
                {
                    foreach (var uss in stylesheets)
                    {
                        if (uss != null)
                        {
                            root.styleSheets.Add(uss);
                        }
                    }
                }

                initSampler.End();
            }

            if (m_PanelScaler == null)
            {
                m_PanelScaler = GetComponent <PanelScaler>();
            }

            m_Event.type = EventType.Repaint;
            m_Scale      = Single.NaN;
            m_TargetSize = new Vector2(Single.NaN, Single.NaN);

            if (m_TargetTexture != targetTexture)
            {
                m_TargetTexture = targetTexture;
                InternalBridge.SetTargetTexture(panel, m_TargetTexture);
            }

            Validate();

            RecreateUIFromUxml();
        }
Ejemplo n.º 10
0
        private void ProcessMouseEvents()
        {
            Vector2 pos = new Vector2(input.mousePosition.x, Screen.height - input.mousePosition.y);

            bool isInsidePanel = ScreenToPanel(focusedPanelRenderer, ref m_Event, pos, m_LastMousePosition);

            //Setup for Mouse Down/Up
            m_Event.modifiers  = EventModifiers.None;
            m_Event.pressure   = 0;
            m_Event.clickCount = 0;
            m_Event.character  = default(char);
            m_Event.keyCode    = KeyCode.None;
            /* FIXME use camera display id */
            m_Event.displayIndex = 0;
            m_Event.commandName  = String.Empty;

            int buttonDownIndex = -1;

            for (var i = 2; i >= 0; --i)
            {
                if (input.GetMouseButtonDown(i))
                {
                    m_Event.type    = EventType.MouseDown;
                    buttonDownIndex = i;
                    if (isInsidePanel)
                    {
                        m_Event.button = i;

                        using (EventBase evt = InternalBridge.CreateEvent(m_Event))
                        {
                            focusedPanel.visualTree.SendEvent(evt);
                        }
                    }
                }

                if (input.GetMouseButtonUp(i))
                {
                    m_Event.type = EventType.MouseUp;

                    if (isInsidePanel)
                    {
                        m_Event.button = i;

                        using (EventBase evt = InternalBridge.CreateEvent(m_Event))
                        {
                            focusedPanel.visualTree.SendEvent(evt);
                        }
                    }
                }
            }


            if (pos != m_LastMousePosition)
            {
                m_LastMousePosition = pos;

                m_Event.type = EventType.MouseMove;

                if (isInsidePanel)
                {
                    m_Event.button = buttonDownIndex;
                    using (EventBase evt = InternalBridge.CreateEvent(m_Event))
                    {
                        focusedPanel.visualTree.SendEvent(evt);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        void Update()
        {
            if (focusedPanel == null)
            {
                return;
            }

            if (focusedPanel != null && !isAppFocused && ShouldIgnoreEventsOnAppNotFocused())
            {
                return;
            }

            if (sendIMGUIEvents)
            {
                while (Event.PopEvent(m_Event))
                {
                    if (m_Event.type == EventType.Repaint)
                    {
                        continue;
                    }

                    var panelPosition = Vector2.zero;
                    var panelDelta    = Vector2.zero;

                    if (ScreenToPanel(focusedPanelRenderer, m_Event.mousePosition, m_Event.delta, out panelPosition, out panelDelta))
                    {
                        m_Event.mousePosition = panelPosition;
                        m_Event.delta         = panelDelta;

                        using (EventBase evt = InternalBridge.CreateEvent(m_Event))
                        {
                            focusedPanel.visualTree.SendEvent(evt);
                        }
                    }
                }
            }

            if (sendInputEvents)
            {
                if (sendNavigationEvents)
                {
                    bool sendNavigationMove = ShouldSendMoveFromInput();

                    if (sendNavigationMove)
                    {
                        using (EventBase evt = NavigationMoveEvent.GetPooled(GetRawMoveVector()))
                        {
                            focusedPanel.visualTree.SendEvent(evt);
                        }
                    }

                    if (input.GetButtonDown(m_SubmitButton))
                    {
                        using (EventBase evt = NavigationSubmitEvent.GetPooled())
                        {
                            focusedPanel.visualTree.SendEvent(evt);
                        }
                    }

                    if (input.GetButtonDown(m_CancelButton))
                    {
                        using (EventBase evt = NavigationCancelEvent.GetPooled())
                        {
                            focusedPanel.visualTree.SendEvent(evt);
                        }
                    }
                }

                if (!ProcessTouchEvents() && input.mousePresent)
                {
                    ProcessMouseEvents();
                }
            }
        }
        private void ProcessMouseEvents()
        {
            Vector2 pos = new Vector2(input.mousePosition.x, Screen.height - input.mousePosition.y);

            if (pos != m_LastMousePosition)
            {
                m_LastMousePosition = pos;

                m_Event.type = EventType.MouseMove;

                if (ScreenToPanel(focusedPanelRenderer, ref m_Event, pos, m_LastMousePosition))
                {
                    m_Event.button = input.GetMouseButtonDown(0) ? 0 :
                                     input.GetMouseButtonDown(1) ? 1 :
                                     input.GetMouseButtonDown(2) ? 2 : 0;
                    m_Event.modifiers  = EventModifiers.None;
                    m_Event.pressure   = 0;
                    m_Event.clickCount = 0;
                    m_Event.character  = default(char);
                    m_Event.keyCode    = KeyCode.None;
                    /* FIXME use camera display id */
                    m_Event.displayIndex = 0;
                    m_Event.commandName  = String.Empty;

                    EventBase evt = InternalBridge.CreateEvent(m_Event);
                    focusedPanel.visualTree.SendEvent(evt);
                }
            }

            for (var i = 0; i < 3; i++)
            {
                if (input.GetMouseButtonDown(i))
                {
                    m_Event.type = EventType.MouseDown;

                    if (ScreenToPanel(focusedPanelRenderer, ref m_Event, pos, m_LastMousePosition))
                    {
                        m_Event.button     = i;
                        m_Event.modifiers  = EventModifiers.None;
                        m_Event.pressure   = 0;
                        m_Event.clickCount = 0;
                        m_Event.character  = default(char);
                        m_Event.keyCode    = KeyCode.None;
                        /* FIXME use camera display id */
                        m_Event.displayIndex = 0;
                        m_Event.commandName  = String.Empty;

                        EventBase evt = InternalBridge.CreateEvent(m_Event);
                        focusedPanel.visualTree.SendEvent(evt);
                    }
                }

                if (input.GetMouseButtonUp(i))
                {
                    m_Event.type = EventType.MouseUp;

                    if (ScreenToPanel(focusedPanelRenderer, ref m_Event, pos, m_LastMousePosition))
                    {
                        m_Event.button     = i;
                        m_Event.modifiers  = EventModifiers.None;
                        m_Event.pressure   = 0;
                        m_Event.clickCount = 0;
                        m_Event.character  = default(char);
                        m_Event.keyCode    = KeyCode.None;
                        /* FIXME use camera display id */
                        m_Event.displayIndex = 0;
                        m_Event.commandName  = String.Empty;

                        EventBase evt = InternalBridge.CreateEvent(m_Event);
                        focusedPanel.visualTree.SendEvent(evt);
                    }
                }
            }
        }