UI update 02
This commit is contained in:
@@ -60,6 +60,10 @@ namespace EasyChart.UGUI
|
||||
[Tooltip("If enabled, logs size/resolution changes (only when changed).")]
|
||||
[SerializeField] private bool _logResolutionChanges = false;
|
||||
|
||||
[Header("Interaction")]
|
||||
[Tooltip("If enabled, the runtime chart bridge behaves as a passive display and will not capture pointer interaction.")]
|
||||
[SerializeField] private bool _disablePointerInteraction = false;
|
||||
|
||||
private UIDocument _uiDocument;
|
||||
private ChartElement _chartElement;
|
||||
private RectTransform _rectTransform;
|
||||
@@ -159,6 +163,21 @@ namespace EasyChart.UGUI
|
||||
}
|
||||
}
|
||||
|
||||
public bool DisablePointerInteraction
|
||||
{
|
||||
get => _disablePointerInteraction;
|
||||
set
|
||||
{
|
||||
if (_disablePointerInteraction == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_disablePointerInteraction = value;
|
||||
ApplyPointerInteractionMode();
|
||||
}
|
||||
}
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_rectTransform = GetComponent<RectTransform>();
|
||||
@@ -182,22 +201,7 @@ namespace EasyChart.UGUI
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
_isInitialized = false;
|
||||
_lastScreenRect = new Rect(float.NaN, float.NaN, float.NaN, float.NaN);
|
||||
|
||||
if (UsesRenderTexturePipeline())
|
||||
{
|
||||
if (_chartElement != null)
|
||||
{
|
||||
_chartElement.RemoveFromHierarchy();
|
||||
_chartElement = null;
|
||||
}
|
||||
|
||||
_rootContainer = null;
|
||||
return;
|
||||
}
|
||||
|
||||
DetachOverlayChartContent();
|
||||
ReleaseRuntimeResources();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -218,19 +222,7 @@ namespace EasyChart.UGUI
|
||||
_lastRenderMode = _renderMode;
|
||||
|
||||
// Initialize on first LateUpdate to ensure everything is ready
|
||||
if (!_isInitialized)
|
||||
{
|
||||
_isInitialized = true;
|
||||
if (UsesRenderTexturePipeline())
|
||||
{
|
||||
CreateWorldSpaceUI();
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateUIDocument();
|
||||
}
|
||||
UpdateChartProfile();
|
||||
}
|
||||
EnsureInitialized();
|
||||
|
||||
if (_logResolutionChanges && !_loggedOnce)
|
||||
{
|
||||
@@ -266,6 +258,67 @@ namespace EasyChart.UGUI
|
||||
return _renderMode == ChartRenderMode.WorldSpace || _respectUGUILayering;
|
||||
}
|
||||
|
||||
public void ReleaseRuntimeResources()
|
||||
{
|
||||
_isInitialized = false;
|
||||
_lastScreenRect = new Rect(float.NaN, float.NaN, float.NaN, float.NaN);
|
||||
|
||||
DetachOverlayChartContent();
|
||||
|
||||
if (_uiDocument != null)
|
||||
{
|
||||
_uiDocument.visualTreeAsset = null;
|
||||
|
||||
if (_uiDocument.rootVisualElement != null)
|
||||
{
|
||||
_uiDocument.rootVisualElement.Clear();
|
||||
}
|
||||
|
||||
if (_createdPanelSettings)
|
||||
{
|
||||
_uiDocument.panelSettings = null;
|
||||
}
|
||||
}
|
||||
|
||||
ReleaseRuntimePanelSettings();
|
||||
|
||||
if (_rawImage != null)
|
||||
{
|
||||
_rawImage.texture = null;
|
||||
_rawImage.enabled = false;
|
||||
_rawImage.raycastTarget = false;
|
||||
}
|
||||
|
||||
ReleaseRenderTexture();
|
||||
}
|
||||
|
||||
public void ForceRebuild()
|
||||
{
|
||||
ReleaseRuntimeResources();
|
||||
EnsureInitialized();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void EnsureInitialized()
|
||||
{
|
||||
if (_isInitialized)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_isInitialized = true;
|
||||
if (UsesRenderTexturePipeline())
|
||||
{
|
||||
CreateWorldSpaceUI();
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateUIDocument();
|
||||
}
|
||||
|
||||
UpdateChartProfile();
|
||||
}
|
||||
|
||||
private void CreateUIDocument()
|
||||
{
|
||||
// Check if UIDocument already exists on this GameObject
|
||||
@@ -336,6 +389,7 @@ namespace EasyChart.UGUI
|
||||
|
||||
_rootContainer.Add(_chartElement);
|
||||
_uiDocument.rootVisualElement.Add(_rootContainer);
|
||||
ApplyPointerInteractionMode();
|
||||
|
||||
_lastScreenRect = new Rect(float.NaN, float.NaN, float.NaN, float.NaN);
|
||||
}
|
||||
@@ -406,6 +460,34 @@ namespace EasyChart.UGUI
|
||||
_createdPanelSettings = false;
|
||||
}
|
||||
|
||||
private void ApplyPointerInteractionMode()
|
||||
{
|
||||
var pickingMode = _disablePointerInteraction ? PickingMode.Ignore : PickingMode.Position;
|
||||
|
||||
if (_uiDocument != null && _uiDocument.rootVisualElement != null)
|
||||
{
|
||||
_uiDocument.rootVisualElement.pickingMode = pickingMode;
|
||||
_uiDocument.rootVisualElement.focusable = false;
|
||||
}
|
||||
|
||||
if (_rootContainer != null)
|
||||
{
|
||||
_rootContainer.pickingMode = pickingMode;
|
||||
_rootContainer.focusable = false;
|
||||
}
|
||||
|
||||
if (_chartElement != null)
|
||||
{
|
||||
_chartElement.pickingMode = pickingMode;
|
||||
_chartElement.focusable = false;
|
||||
}
|
||||
|
||||
if (_rawImage != null)
|
||||
{
|
||||
_rawImage.raycastTarget = !_disablePointerInteraction;
|
||||
}
|
||||
}
|
||||
|
||||
private void TryResolvePanelSettingsAsset()
|
||||
{
|
||||
if (_panelSettingsAsset != null)
|
||||
@@ -566,9 +648,11 @@ namespace EasyChart.UGUI
|
||||
/// </summary>
|
||||
public void Refresh()
|
||||
{
|
||||
EnsureInitialized();
|
||||
UpdatePosition();
|
||||
if (_chartElement != null)
|
||||
{
|
||||
ApplyPointerInteractionMode();
|
||||
_chartElement.ForceRefreshProfile();
|
||||
}
|
||||
}
|
||||
@@ -669,6 +753,7 @@ namespace EasyChart.UGUI
|
||||
_rawImage.texture = _renderTexture;
|
||||
_rawImage.raycastTarget = false;
|
||||
_rawImage.color = Color.white;
|
||||
ApplyPointerInteractionMode();
|
||||
|
||||
_lastScreenRect = new Rect(float.NaN, float.NaN, float.NaN, float.NaN);
|
||||
}
|
||||
@@ -755,26 +840,67 @@ namespace EasyChart.UGUI
|
||||
_rawImage = null;
|
||||
}
|
||||
|
||||
if (_renderTexture != null)
|
||||
ReleaseRenderTexture();
|
||||
}
|
||||
|
||||
private void ReleaseRuntimePanelSettings()
|
||||
{
|
||||
if (_runtimePanelSettings == null || !_createdPanelSettings)
|
||||
{
|
||||
_renderTexture.Release();
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
var rt = _renderTexture;
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
if (rt != null)
|
||||
DestroyImmediate(rt);
|
||||
};
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Destroy(_renderTexture);
|
||||
}
|
||||
_renderTexture = null;
|
||||
_runtimePanelSettings = _createdPanelSettings ? null : _runtimePanelSettings;
|
||||
_createdPanelSettings = false;
|
||||
return;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
var panelSettings = _runtimePanelSettings;
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
if (panelSettings != null)
|
||||
{
|
||||
DestroyImmediate(panelSettings);
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Destroy(_runtimePanelSettings);
|
||||
}
|
||||
|
||||
_runtimePanelSettings = null;
|
||||
_createdPanelSettings = false;
|
||||
}
|
||||
|
||||
private void ReleaseRenderTexture()
|
||||
{
|
||||
if (_renderTexture == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_renderTexture.Release();
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
var rt = _renderTexture;
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
if (rt != null)
|
||||
{
|
||||
DestroyImmediate(rt);
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
Destroy(_renderTexture);
|
||||
}
|
||||
|
||||
_renderTexture = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user