fix: despite not using the size module, particles become smaller based on their z position

close #316
pull/336/head
mob-sakai 2024-06-20 12:51:02 +09:00
parent 4c285fde14
commit c43ba67a9b
1 changed files with 35 additions and 44 deletions

View File

@ -101,7 +101,7 @@ namespace Coffee.UIExtensions
private readonly List<UIParticleRenderer> _renderers = new List<UIParticleRenderer>(); private readonly List<UIParticleRenderer> _renderers = new List<UIParticleRenderer>();
private int _groupId; private int _groupId;
private Camera _orthoCamera; private Camera _bakeCamera;
private DrivenRectTransformTracker _tracker; private DrivenRectTransformTracker _tracker;
private Vector3 _storedScale; private Vector3 _storedScale;
private bool _isScaleStored; private bool _isScaleStored;
@ -581,56 +581,47 @@ namespace Coffee.UIExtensions
private Camera GetBakeCamera() private Camera GetBakeCamera()
{ {
if (!canvas) return Camera.main; if (!canvas) return Camera.main;
if (_bakeCamera) return _bakeCamera;
// When render mode is ScreenSpaceCamera or WorldSpace, use world camera. // Find existing baking camera.
var root = canvas.rootCanvas; var childCount = transform.childCount;
if (root.renderMode != RenderMode.ScreenSpaceOverlay) for (var i = 0; i < childCount; i++)
{ {
return root.worldCamera ? root.worldCamera : Camera.main; if (transform.GetChild(i).TryGetComponent<Camera>(out var cam)
} && cam.name == "[generated] UIParticle BakingCamera")
// When render mode is ScreenSpaceOverlay, use ortho-camera.
if (!_orthoCamera)
{
// Find existing ortho-camera.
foreach (Transform child in transform)
{ {
var cam = child.GetComponent<Camera>(); _bakeCamera = cam;
if (cam && cam.name == "[generated] UIParticleOverlayCamera") break;
{
_orthoCamera = cam;
break;
}
}
// Create ortho-camera.
if (!_orthoCamera)
{
var go = new GameObject("[generated] UIParticleOverlayCamera")
{
hideFlags = HideFlags.HideAndDontSave
};
go.SetActive(false);
go.transform.SetParent(transform, false);
_orthoCamera = go.AddComponent<Camera>();
_orthoCamera.enabled = false;
} }
} }
// // Create baking camera.
var size = ((RectTransform)root.transform).rect.size; if (!_bakeCamera)
_orthoCamera.orthographicSize = Mathf.Max(size.x, size.y) * root.scaleFactor; {
_orthoCamera.transform.SetPositionAndRotation(new Vector3(0, 0, -1000), Quaternion.identity); var go = new GameObject("[generated] UIParticle BakingCamera")
_orthoCamera.orthographic = true; {
_orthoCamera.farClipPlane = 2000f; // hideFlags = HideFlags.HideAndDontSave
_orthoCamera.clearFlags = CameraClearFlags.Nothing; hideFlags = HideFlags.DontSave
_orthoCamera.cullingMask = 0; // Nothing };
_orthoCamera.allowHDR = false; go.SetActive(false);
_orthoCamera.allowMSAA = false; go.transform.SetParent(transform, false);
_orthoCamera.renderingPath = RenderingPath.Forward; _bakeCamera = go.AddComponent<Camera>();
_orthoCamera.useOcclusionCulling = false; }
return _orthoCamera; // Setup baking camera.
_bakeCamera.enabled = false;
_bakeCamera.orthographicSize = 1000;
_bakeCamera.transform.SetPositionAndRotation(new Vector3(0, 0, -1000), Quaternion.identity);
_bakeCamera.orthographic = true;
_bakeCamera.farClipPlane = 2000f;
_bakeCamera.clearFlags = CameraClearFlags.Nothing;
_bakeCamera.cullingMask = 0; // Nothing
_bakeCamera.allowHDR = false;
_bakeCamera.allowMSAA = false;
_bakeCamera.renderingPath = RenderingPath.Forward;
_bakeCamera.useOcclusionCulling = false;
return _bakeCamera;
} }
} }
} }