feat: restore `Transform.localScale` when setting `autoScalingMode` to something other than `Transform`
parent
f26920f982
commit
5505247a94
|
@ -475,20 +475,7 @@ namespace Coffee.UIExtensions
|
||||||
|
|
||||||
private static void DrawAutoScaling(SerializedProperty prop, IEnumerable<UIParticle> uiParticles)
|
private static void DrawAutoScaling(SerializedProperty prop, IEnumerable<UIParticle> uiParticles)
|
||||||
{
|
{
|
||||||
var isTransformMode = prop.intValue == (int)UIParticle.AutoScalingMode.Transform;
|
|
||||||
EditorGUI.BeginChangeCheck();
|
|
||||||
EditorGUILayout.PropertyField(prop);
|
EditorGUILayout.PropertyField(prop);
|
||||||
if (!EditorGUI.EndChangeCheck() || !isTransformMode) return;
|
|
||||||
|
|
||||||
// on changed true->false, reset scale.
|
|
||||||
EditorApplication.delayCall += () =>
|
|
||||||
{
|
|
||||||
foreach (var uip in uiParticles)
|
|
||||||
{
|
|
||||||
if (!uip) continue;
|
|
||||||
uip.transform.localScale = Vector3.one;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_2021_2_OR_NEWER
|
#if UNITY_2021_2_OR_NEWER
|
||||||
|
|
|
@ -2,7 +2,6 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using Coffee.UIParticleExtensions;
|
using Coffee.UIParticleExtensions;
|
||||||
using UnityEditor;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Rendering;
|
using UnityEngine.Rendering;
|
||||||
using UnityEngine.Serialization;
|
using UnityEngine.Serialization;
|
||||||
|
@ -104,6 +103,8 @@ namespace Coffee.UIExtensions
|
||||||
private int _groupId;
|
private int _groupId;
|
||||||
private Camera _orthoCamera;
|
private Camera _orthoCamera;
|
||||||
private DrivenRectTransformTracker _tracker;
|
private DrivenRectTransformTracker _tracker;
|
||||||
|
private Vector3 _storedScale;
|
||||||
|
private bool _isScaleStored;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Should this graphic be considered a target for ray-casting?
|
/// Should this graphic be considered a target for ray-casting?
|
||||||
|
@ -201,7 +202,12 @@ namespace Coffee.UIExtensions
|
||||||
{
|
{
|
||||||
if (m_AutoScalingMode == value) return;
|
if (m_AutoScalingMode == value) return;
|
||||||
m_AutoScalingMode = value;
|
m_AutoScalingMode = value;
|
||||||
UpdateTracker();
|
|
||||||
|
if (autoScalingMode != AutoScalingMode.Transform && _isScaleStored)
|
||||||
|
{
|
||||||
|
transform.localScale = _storedScale;
|
||||||
|
_isScaleStored = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,8 +285,8 @@ namespace Coffee.UIExtensions
|
||||||
|
|
||||||
protected override void OnEnable()
|
protected override void OnEnable()
|
||||||
{
|
{
|
||||||
|
_isScaleStored = false;
|
||||||
ResetGroupId();
|
ResetGroupId();
|
||||||
UpdateTracker();
|
|
||||||
UIParticleUpdater.Register(this);
|
UIParticleUpdater.Register(this);
|
||||||
RegisterDirtyMaterialCallback(UpdateRendererMaterial);
|
RegisterDirtyMaterialCallback(UpdateRendererMaterial);
|
||||||
|
|
||||||
|
@ -301,7 +307,13 @@ namespace Coffee.UIExtensions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void OnDisable()
|
protected override void OnDisable()
|
||||||
{
|
{
|
||||||
UpdateTracker();
|
_tracker.Clear();
|
||||||
|
if (autoScalingMode == AutoScalingMode.Transform && _isScaleStored)
|
||||||
|
{
|
||||||
|
transform.localScale = _storedScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
_isScaleStored = false;
|
||||||
UIParticleUpdater.Unregister(this);
|
UIParticleUpdater.Unregister(this);
|
||||||
_renderers.ForEach(r => r.Reset());
|
_renderers.ForEach(r => r.Reset());
|
||||||
UnregisterDirtyMaterialCallback(UpdateRendererMaterial);
|
UnregisterDirtyMaterialCallback(UpdateRendererMaterial);
|
||||||
|
@ -316,14 +328,6 @@ namespace Coffee.UIExtensions
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
|
||||||
protected override void OnValidate()
|
|
||||||
{
|
|
||||||
base.OnValidate();
|
|
||||||
UpdateTracker();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -482,12 +486,26 @@ namespace Coffee.UIExtensions
|
||||||
|
|
||||||
internal void UpdateTransformScale()
|
internal void UpdateTransformScale()
|
||||||
{
|
{
|
||||||
|
_tracker.Clear();
|
||||||
canvasScale = canvas.rootCanvas.transform.localScale.Inverse();
|
canvasScale = canvas.rootCanvas.transform.localScale.Inverse();
|
||||||
parentScale = transform.parent.lossyScale;
|
parentScale = transform.parent.lossyScale;
|
||||||
if (autoScalingMode != AutoScalingMode.Transform) return;
|
if (autoScalingMode != AutoScalingMode.Transform)
|
||||||
|
{
|
||||||
|
if (_isScaleStored)
|
||||||
|
{
|
||||||
|
transform.localScale = _storedScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
_isScaleStored = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var currentScale = transform.localScale;
|
||||||
|
_storedScale = currentScale;
|
||||||
|
_isScaleStored = true;
|
||||||
|
_tracker.Add(this, rectTransform, DrivenTransformProperties.Scale);
|
||||||
var newScale = parentScale.Inverse();
|
var newScale = parentScale.Inverse();
|
||||||
if (transform.localScale != newScale)
|
if (currentScale != newScale)
|
||||||
{
|
{
|
||||||
transform.localScale = newScale;
|
transform.localScale = newScale;
|
||||||
}
|
}
|
||||||
|
@ -614,19 +632,5 @@ namespace Coffee.UIExtensions
|
||||||
|
|
||||||
return _orthoCamera;
|
return _orthoCamera;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateTracker()
|
|
||||||
{
|
|
||||||
#pragma warning disable CS0618 // Type or member is obsolete
|
|
||||||
if (!enabled || !autoScaling || autoScalingMode != AutoScalingMode.Transform)
|
|
||||||
#pragma warning restore CS0618 // Type or member is obsolete
|
|
||||||
{
|
|
||||||
_tracker.Clear();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_tracker.Add(this, rectTransform, DrivenTransformProperties.Scale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue