feat: add 'custom view' option.
Use this if the particles are not displayed correctly due to min/max particle size.pull/318/head
parent
de35cba34c
commit
a703c2921c
|
@ -47,6 +47,8 @@ namespace Coffee.UIExtensions
|
|||
private SerializedProperty _groupMaxId;
|
||||
private SerializedProperty _positionMode;
|
||||
private SerializedProperty _autoScalingMode;
|
||||
private SerializedProperty _useCustomView;
|
||||
private SerializedProperty _customViewSize;
|
||||
private ReorderableList _ro;
|
||||
private bool _showMax;
|
||||
|
||||
|
@ -82,6 +84,8 @@ namespace Coffee.UIExtensions
|
|||
_groupMaxId = serializedObject.FindProperty("m_GroupMaxId");
|
||||
_positionMode = serializedObject.FindProperty("m_PositionMode");
|
||||
_autoScalingMode = serializedObject.FindProperty("m_AutoScalingMode");
|
||||
_useCustomView = serializedObject.FindProperty("m_UseCustomView");
|
||||
_customViewSize = serializedObject.FindProperty("m_CustomViewSize");
|
||||
|
||||
var sp = serializedObject.FindProperty("m_Particles");
|
||||
_ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true)
|
||||
|
@ -201,14 +205,29 @@ namespace Coffee.UIExtensions
|
|||
// Auto Scaling
|
||||
DrawAutoScaling(_autoScalingMode, targets.OfType<UIParticle>());
|
||||
|
||||
// Custom View Size
|
||||
EditorGUILayout.PropertyField(_useCustomView);
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.BeginDisabledGroup(!_useCustomView.boolValue);
|
||||
EditorGUI.indentLevel++;
|
||||
EditorGUILayout.PropertyField(_customViewSize);
|
||||
EditorGUI.indentLevel--;
|
||||
EditorGUI.EndDisabledGroup();
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
_customViewSize.floatValue = Mathf.Max(0.1f, _customViewSize.floatValue);
|
||||
}
|
||||
|
||||
// Target ParticleSystems.
|
||||
EditorGUI.BeginChangeCheck();
|
||||
EditorGUI.BeginDisabledGroup(targets.OfType<UIParticle>().Any(x => !x.canvas));
|
||||
_ro.DoLayoutList();
|
||||
EditorGUI.EndDisabledGroup();
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
EditorApplication.QueuePlayerLoopUpdate();
|
||||
foreach (var uip in targets.OfType<UIParticle>())
|
||||
{
|
||||
uip.RefreshParticles(uip.particles);
|
||||
|
|
|
@ -99,6 +99,16 @@ namespace Coffee.UIExtensions
|
|||
"UIParticle: UIParticle.scale will be adjusted.")]
|
||||
private AutoScalingMode m_AutoScalingMode = AutoScalingMode.Transform;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Use a custom view.\n" +
|
||||
"Use this if the particles are not displayed correctly due to min/max particle size.")]
|
||||
private bool m_UseCustomView;
|
||||
|
||||
[SerializeField]
|
||||
[Tooltip("Custom view size.\n" +
|
||||
"Change the bake view size.")]
|
||||
private float m_CustomViewSize = 10;
|
||||
|
||||
private readonly List<UIParticleRenderer> _renderers = new List<UIParticleRenderer>();
|
||||
private int _groupId;
|
||||
private Camera _bakeCamera;
|
||||
|
@ -211,6 +221,26 @@ namespace Coffee.UIExtensions
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use a custom view.
|
||||
/// Use this if the particles are not displayed correctly due to min/max particle size.
|
||||
/// </summary>
|
||||
public bool useCustomView
|
||||
{
|
||||
get => m_UseCustomView;
|
||||
set => m_UseCustomView = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Custom view size.
|
||||
/// Change the bake view size.
|
||||
/// </summary>
|
||||
public float customViewSize
|
||||
{
|
||||
get => m_CustomViewSize;
|
||||
set => m_CustomViewSize = Mathf.Max(0.1f, value);
|
||||
}
|
||||
|
||||
internal bool useMeshSharing => m_MeshSharing != MeshSharing.None;
|
||||
|
||||
internal bool isPrimary =>
|
||||
|
@ -585,7 +615,16 @@ namespace Coffee.UIExtensions
|
|||
private Camera GetBakeCamera()
|
||||
{
|
||||
if (!canvas) return Camera.main;
|
||||
if (_bakeCamera) return _bakeCamera;
|
||||
if (!useCustomView && canvas.renderMode != RenderMode.ScreenSpaceOverlay && canvas.rootCanvas.worldCamera)
|
||||
{
|
||||
return canvas.rootCanvas.worldCamera;
|
||||
}
|
||||
|
||||
if (_bakeCamera)
|
||||
{
|
||||
_bakeCamera.orthographicSize = useCustomView ? customViewSize : 10;
|
||||
return _bakeCamera;
|
||||
}
|
||||
|
||||
// Find existing baking camera.
|
||||
var childCount = transform.childCount;
|
||||
|
@ -610,7 +649,7 @@ namespace Coffee.UIExtensions
|
|||
|
||||
// Setup baking camera.
|
||||
_bakeCamera.enabled = false;
|
||||
_bakeCamera.orthographicSize = 1000;
|
||||
_bakeCamera.orthographicSize = useCustomView ? customViewSize : 10;
|
||||
_bakeCamera.transform.SetPositionAndRotation(new Vector3(0, 0, -1000), Quaternion.identity);
|
||||
_bakeCamera.orthographic = true;
|
||||
_bakeCamera.farClipPlane = 2000f;
|
||||
|
|
Loading…
Reference in New Issue