From 4252f1199b8a7038a6fb447989534c512ec40283 Mon Sep 17 00:00:00 2001 From: mob-sakai <12690315+mob-sakai@users.noreply.github.com> Date: Wed, 26 Jun 2024 23:13:09 +0900 Subject: [PATCH] feat: add 'custom view' option. Use this if the particles are not displayed correctly due to min/max particle size. --- Packages/src/Editor/UIParticleEditor.cs | 19 +++++++++++ Packages/src/Runtime/UIParticle.cs | 43 +++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/Packages/src/Editor/UIParticleEditor.cs b/Packages/src/Editor/UIParticleEditor.cs index 648fcb3..39c804d 100644 --- a/Packages/src/Editor/UIParticleEditor.cs +++ b/Packages/src/Editor/UIParticleEditor.cs @@ -49,6 +49,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()); + // 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().Any(x => !x.canvas)); _ro.DoLayoutList(); EditorGUI.EndDisabledGroup(); serializedObject.ApplyModifiedProperties(); + if (EditorGUI.EndChangeCheck()) { + EditorApplication.QueuePlayerLoopUpdate(); foreach (var uip in targets.OfType()) { uip.RefreshParticles(uip.particles); diff --git a/Packages/src/Runtime/UIParticle.cs b/Packages/src/Runtime/UIParticle.cs index a547eba..08de5c7 100644 --- a/Packages/src/Runtime/UIParticle.cs +++ b/Packages/src/Runtime/UIParticle.cs @@ -103,6 +103,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; + [SerializeField] private bool m_Maskable = true; @@ -243,6 +253,26 @@ namespace Coffee.UIExtensions } } + /// + /// Use a custom view. + /// Use this if the particles are not displayed correctly due to min/max particle size. + /// + public bool useCustomView + { + get => m_UseCustomView; + set => m_UseCustomView = value; + } + + /// + /// Custom view size. + /// Change the bake view size. + /// + public float customViewSize + { + get => m_CustomViewSize; + set => m_CustomViewSize = Mathf.Max(0.1f, value); + } + internal bool useMeshSharing => m_MeshSharing != MeshSharing.None; internal bool isPrimary => @@ -673,7 +703,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; @@ -698,7 +737,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;