feat: restore `Transform.localScale` when setting `autoScalingMode` to something other than `Transform`
# Conflicts: # Packages/src/Editor/UIParticleEditor.cs # Packages/src/Runtime/UIParticle.cs
parent
f96604ffc9
commit
f08809772a
|
@ -401,25 +401,7 @@ namespace Coffee.UIExtensions
|
|||
|
||||
private static void DrawAutoScaling(SerializedProperty prop, IEnumerable<UIParticle> uiParticles)
|
||||
{
|
||||
var isTransformMode = prop.intValue == (int)UIParticle.AutoScalingMode.Transform;
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUILayout.PropertyField(prop);
|
||||
if (!EditorGUI.EndChangeCheck() || !isTransformMode) return;
|
||||
|
||||
// on changed true->false, reset scale.
|
||||
ResetScale(uiParticles);
|
||||
}
|
||||
|
||||
private static void ResetScale(IEnumerable<UIParticle> uiParticles)
|
||||
{
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
foreach (var uip in uiParticles)
|
||||
{
|
||||
if (!uip) continue;
|
||||
uip.transform.localScale = Vector3.one;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void DestroyUIParticle(UIParticle p, bool ignoreCurrent = false)
|
||||
|
|
|
@ -111,6 +111,8 @@ namespace Coffee.UIExtensions
|
|||
private int _groupId;
|
||||
private Camera _orthographicCamera;
|
||||
private DrivenRectTransformTracker _tracker;
|
||||
private Vector3 _storedScale;
|
||||
private bool _isScaleStored;
|
||||
|
||||
public RectTransform rectTransform => transform as RectTransform;
|
||||
|
||||
|
@ -232,7 +234,12 @@ namespace Coffee.UIExtensions
|
|||
{
|
||||
if (m_AutoScalingMode == value) return;
|
||||
m_AutoScalingMode = value;
|
||||
UpdateTracker();
|
||||
|
||||
if (autoScalingMode != AutoScalingMode.Transform && _isScaleStored)
|
||||
{
|
||||
transform.localScale = _storedScale;
|
||||
_isScaleStored = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -308,8 +315,8 @@ namespace Coffee.UIExtensions
|
|||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
_isScaleStored = false;
|
||||
ResetGroupId();
|
||||
UpdateTracker();
|
||||
UIParticleUpdater.Register(this);
|
||||
|
||||
//
|
||||
|
@ -330,7 +337,13 @@ namespace Coffee.UIExtensions
|
|||
/// </summary>
|
||||
protected override void OnDisable()
|
||||
{
|
||||
UpdateTracker();
|
||||
_tracker.Clear();
|
||||
if (autoScalingMode == AutoScalingMode.Transform && _isScaleStored)
|
||||
{
|
||||
transform.localScale = _storedScale;
|
||||
}
|
||||
|
||||
_isScaleStored = false;
|
||||
UIParticleUpdater.Unregister(this);
|
||||
_renderers.ForEach(r => r.Reset());
|
||||
_canvas = null;
|
||||
|
@ -359,15 +372,6 @@ namespace Coffee.UIExtensions
|
|||
_canvas = null;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
protected override void OnValidate()
|
||||
{
|
||||
base.OnValidate();
|
||||
UpdateTracker();
|
||||
UpdateRendererMaterial();
|
||||
}
|
||||
#endif
|
||||
|
||||
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
||||
{
|
||||
}
|
||||
|
@ -583,12 +587,26 @@ namespace Coffee.UIExtensions
|
|||
|
||||
internal void UpdateTransformScale()
|
||||
{
|
||||
_tracker.Clear();
|
||||
canvasScale = canvas.rootCanvas.transform.localScale.Inverse();
|
||||
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();
|
||||
if (transform.localScale != newScale)
|
||||
if (currentScale != newScale)
|
||||
{
|
||||
transform.localScale = newScale;
|
||||
}
|
||||
|
@ -704,19 +722,5 @@ namespace Coffee.UIExtensions
|
|||
|
||||
return _orthographicCamera;
|
||||
}
|
||||
|
||||
private void UpdateTracker()
|
||||
{
|
||||
#pragma warning disable CS0618 // Type or member is obsolete
|
||||
if (!enabled || 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