feat: 'AutoScaling' option will be imported from 'IgnoreCanvasScale' (for v3.x)
parent
67eff61073
commit
410304125f
|
@ -60,11 +60,6 @@ namespace Coffee.UIExtensions
|
||||||
private static readonly GUIContent s_Content3D = new GUIContent("3D");
|
private static readonly GUIContent s_Content3D = new GUIContent("3D");
|
||||||
private static readonly GUIContent s_ContentRandom = new GUIContent("Random");
|
private static readonly GUIContent s_ContentRandom = new GUIContent("Random");
|
||||||
private static readonly GUIContent s_ContentScale = new GUIContent("Scale");
|
private static readonly GUIContent s_ContentScale = new GUIContent("Scale");
|
||||||
|
|
||||||
private static readonly GUIContent s_ContentAutoScaling = new GUIContent("Auto Scaling",
|
|
||||||
"Transform.lossyScale (=world scale) is automatically set to (1, 1, 1)," +
|
|
||||||
" to prevent the root-Canvas scale from affecting the hierarchy-scaled ParticleSystem.");
|
|
||||||
|
|
||||||
private static SerializedObject s_SerializedObject;
|
private static SerializedObject s_SerializedObject;
|
||||||
private static bool s_XYZMode;
|
private static bool s_XYZMode;
|
||||||
|
|
||||||
|
@ -74,8 +69,8 @@ namespace Coffee.UIExtensions
|
||||||
private SerializedProperty _meshSharing;
|
private SerializedProperty _meshSharing;
|
||||||
private SerializedProperty _groupId;
|
private SerializedProperty _groupId;
|
||||||
private SerializedProperty _groupMaxId;
|
private SerializedProperty _groupMaxId;
|
||||||
private SerializedProperty _ignoreCanvasScaler;
|
|
||||||
private SerializedProperty _positionMode;
|
private SerializedProperty _positionMode;
|
||||||
|
private SerializedProperty _autoScaling;
|
||||||
private ReorderableList _ro;
|
private ReorderableList _ro;
|
||||||
private bool _showMax;
|
private bool _showMax;
|
||||||
|
|
||||||
|
@ -157,8 +152,8 @@ namespace Coffee.UIExtensions
|
||||||
_meshSharing = serializedObject.FindProperty("m_MeshSharing");
|
_meshSharing = serializedObject.FindProperty("m_MeshSharing");
|
||||||
_groupId = serializedObject.FindProperty("m_GroupId");
|
_groupId = serializedObject.FindProperty("m_GroupId");
|
||||||
_groupMaxId = serializedObject.FindProperty("m_GroupMaxId");
|
_groupMaxId = serializedObject.FindProperty("m_GroupMaxId");
|
||||||
_ignoreCanvasScaler = serializedObject.FindProperty("m_IgnoreCanvasScaler");
|
|
||||||
_positionMode = serializedObject.FindProperty("m_PositionMode");
|
_positionMode = serializedObject.FindProperty("m_PositionMode");
|
||||||
|
_autoScaling = serializedObject.FindProperty("m_AutoScaling");
|
||||||
|
|
||||||
var sp = serializedObject.FindProperty("m_Particles");
|
var sp = serializedObject.FindProperty("m_Particles");
|
||||||
_ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true)
|
_ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true)
|
||||||
|
@ -276,16 +271,7 @@ namespace Coffee.UIExtensions
|
||||||
EditorGUILayout.PropertyField(_positionMode);
|
EditorGUILayout.PropertyField(_positionMode);
|
||||||
|
|
||||||
// Auto Scaling
|
// Auto Scaling
|
||||||
DrawInversedToggle(_ignoreCanvasScaler, s_ContentAutoScaling, () =>
|
DrawAutoScaling(_autoScaling, targets.OfType<UIParticle>());
|
||||||
{
|
|
||||||
foreach (var uip in targets.OfType<UIParticle>())
|
|
||||||
{
|
|
||||||
if (uip && !uip.autoScaling)
|
|
||||||
{
|
|
||||||
uip.transform.localScale = Vector3.one;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Target ParticleSystems.
|
// Target ParticleSystems.
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
|
@ -490,22 +476,21 @@ namespace Coffee.UIExtensions
|
||||||
return showMax;
|
return showMax;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void DrawInversedToggle(SerializedProperty sp, GUIContent label, Action onChanged)
|
private static void DrawAutoScaling(SerializedProperty prop, IEnumerable<UIParticle> uiParticles)
|
||||||
{
|
{
|
||||||
EditorGUI.showMixedValue = sp.hasMultipleDifferentValues;
|
|
||||||
var autoScaling = !sp.boolValue;
|
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
if (autoScaling != EditorGUILayout.Toggle(label, autoScaling))
|
EditorGUILayout.PropertyField(prop);
|
||||||
{
|
if (!EditorGUI.EndChangeCheck()) return;
|
||||||
sp.boolValue = autoScaling;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (EditorGUI.EndChangeCheck())
|
// on changed true->false, reset scale.
|
||||||
|
EditorApplication.delayCall += () =>
|
||||||
{
|
{
|
||||||
EditorApplication.delayCall += onChanged.Invoke;
|
foreach (var uip in uiParticles)
|
||||||
|
{
|
||||||
|
if (!uip || uip.autoScaling) continue;
|
||||||
|
uip.transform.localScale = Vector3.one;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
EditorGUI.showMixedValue = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void WindowFunction(Object target, SceneView sceneView)
|
private static void WindowFunction(Object target, SceneView sceneView)
|
||||||
|
@ -513,7 +498,8 @@ namespace Coffee.UIExtensions
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (s_SerializedObject == null || !s_SerializedObject.targetObject) return;
|
if (s_SerializedObject == null || !s_SerializedObject.targetObject) return;
|
||||||
if (s_SerializedObject.targetObjects.OfType<UIParticle>().Any(x => !x || !x.canvas)) return;
|
var uiParticles = s_SerializedObject.targetObjects.OfType<UIParticle>();
|
||||||
|
if (uiParticles.Any(x => !x || !x.canvas)) return;
|
||||||
|
|
||||||
s_SerializedObject.Update();
|
s_SerializedObject.Update();
|
||||||
using (new EditorGUILayout.VerticalScope(GUILayout.Width(220f)))
|
using (new EditorGUILayout.VerticalScope(GUILayout.Width(220f)))
|
||||||
|
@ -522,17 +508,8 @@ namespace Coffee.UIExtensions
|
||||||
EditorGUIUtility.labelWidth = 100;
|
EditorGUIUtility.labelWidth = 100;
|
||||||
EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_Enabled"));
|
EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_Enabled"));
|
||||||
s_XYZMode = DrawFloatOrVector3Field(s_SerializedObject.FindProperty("m_Scale3D"), s_XYZMode);
|
s_XYZMode = DrawFloatOrVector3Field(s_SerializedObject.FindProperty("m_Scale3D"), s_XYZMode);
|
||||||
DrawInversedToggle(s_SerializedObject.FindProperty("m_IgnoreCanvasScaler"),
|
|
||||||
s_ContentAutoScaling,
|
|
||||||
() =>
|
|
||||||
{
|
|
||||||
s_SerializedObject.targetObjects
|
|
||||||
.OfType<UIParticle>()
|
|
||||||
.Where(x => x && !x.autoScaling)
|
|
||||||
.ToList()
|
|
||||||
.ForEach(x => x.transform.localScale = Vector3.one);
|
|
||||||
});
|
|
||||||
EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_PositionMode"));
|
EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_PositionMode"));
|
||||||
|
DrawAutoScaling(s_SerializedObject.FindProperty("m_AutoScaling"), uiParticles);
|
||||||
EditorGUIUtility.labelWidth = labelWidth;
|
EditorGUIUtility.labelWidth = labelWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,11 @@ namespace Coffee.UIExtensions
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
internal bool m_IsTrail;
|
internal bool m_IsTrail;
|
||||||
|
|
||||||
|
[HideInInspector]
|
||||||
|
[FormerlySerializedAs("m_IgnoreParent")]
|
||||||
|
[SerializeField]
|
||||||
|
private bool m_IgnoreCanvasScaler;
|
||||||
|
|
||||||
[HideInInspector]
|
[HideInInspector]
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private bool m_AbsoluteMode;
|
private bool m_AbsoluteMode;
|
||||||
|
@ -79,12 +84,10 @@ namespace Coffee.UIExtensions
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private PositionMode m_PositionMode = PositionMode.Relative;
|
private PositionMode m_PositionMode = PositionMode.Relative;
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This field uses the inverted value as "AutoScaling".
|
|
||||||
/// </summary>
|
|
||||||
[FormerlySerializedAs("m_IgnoreParent")]
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private bool m_IgnoreCanvasScaler;
|
[Tooltip("Transform.lossyScale (=world scale) is automatically set to (1, 1, 1), " +
|
||||||
|
"to prevent the root-Canvas scale from affecting the hierarchy-scaled ParticleSystem.")]
|
||||||
|
private bool m_AutoScaling = true;
|
||||||
|
|
||||||
#if !SERIALIZE_FIELD_MASKABLE
|
#if !SERIALIZE_FIELD_MASKABLE
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
|
@ -170,17 +173,16 @@ namespace Coffee.UIExtensions
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Transform.lossyScale (=world scale) is automatically set to (1, 1, 1).
|
/// Transform.lossyScale (=world scale) will be set to (1, 1, 1) on update.
|
||||||
/// It prevents the root-Canvas scale from affecting the hierarchy-scaled ParticleSystem.
|
/// It prevents the root-Canvas scale from affecting the hierarchy-scaled ParticleSystem.
|
||||||
/// Note: This option works in reverse of ’IgnoreCanvasScaler’ option in v3.x.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool autoScaling
|
public bool autoScaling
|
||||||
{
|
{
|
||||||
get { return !m_IgnoreCanvasScaler; }
|
get { return m_AutoScaling; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (m_IgnoreCanvasScaler != value) return;
|
if (m_AutoScaling == value) return;
|
||||||
m_IgnoreCanvasScaler = !value;
|
m_AutoScaling = value;
|
||||||
UpdateTracker();
|
UpdateTracker();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -324,11 +326,17 @@ namespace Coffee.UIExtensions
|
||||||
|
|
||||||
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
void ISerializationCallbackReceiver.OnBeforeSerialize()
|
||||||
{
|
{
|
||||||
|
m_IgnoreCanvasScaler = !m_AutoScaling;
|
||||||
m_AbsoluteMode = m_PositionMode == PositionMode.Absolute;
|
m_AbsoluteMode = m_PositionMode == PositionMode.Absolute;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
void ISerializationCallbackReceiver.OnAfterDeserialize()
|
||||||
{
|
{
|
||||||
|
if (m_IgnoreCanvasScaler)
|
||||||
|
{
|
||||||
|
m_AutoScaling = false;
|
||||||
|
}
|
||||||
|
|
||||||
if (m_AbsoluteMode)
|
if (m_AbsoluteMode)
|
||||||
{
|
{
|
||||||
m_PositionMode = PositionMode.Absolute;
|
m_PositionMode = PositionMode.Absolute;
|
||||||
|
|
Loading…
Reference in New Issue