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(); }
/// <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(); }
/// <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); }
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(); }