Beispiel #1
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);
                    }
                }
            }
        }
Beispiel #2
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();
        }