fix #23; In overlay, particle size is too small
parent
79217d0100
commit
e6e227c7e8
|
@ -229,6 +229,7 @@ namespace Coffee.UIExtensions
|
||||||
|
|
||||||
if (m_ParticleSystem && canvas)
|
if (m_ParticleSystem && canvas)
|
||||||
{
|
{
|
||||||
|
var rootCanvas = canvas.rootCanvas;
|
||||||
Profiler.BeginSample ("Disable ParticleSystemRenderer");
|
Profiler.BeginSample ("Disable ParticleSystemRenderer");
|
||||||
if (Application.isPlaying)
|
if (Application.isPlaying)
|
||||||
{
|
{
|
||||||
|
@ -239,7 +240,7 @@ namespace Coffee.UIExtensions
|
||||||
Profiler.BeginSample ("Make Matrix");
|
Profiler.BeginSample ("Make Matrix");
|
||||||
scaleaMatrix = m_ParticleSystem.main.scalingMode == ParticleSystemScalingMode.Hierarchy
|
scaleaMatrix = m_ParticleSystem.main.scalingMode == ParticleSystemScalingMode.Hierarchy
|
||||||
? Matrix4x4.Scale (scale * Vector3.one)
|
? Matrix4x4.Scale (scale * Vector3.one)
|
||||||
: Matrix4x4.Scale (scale * canvas.rootCanvas.transform.localScale);
|
: Matrix4x4.Scale (scale * rootCanvas.transform.localScale);
|
||||||
Matrix4x4 matrix = default (Matrix4x4);
|
Matrix4x4 matrix = default (Matrix4x4);
|
||||||
switch (m_ParticleSystem.main.simulationSpace)
|
switch (m_ParticleSystem.main.simulationSpace)
|
||||||
{
|
{
|
||||||
|
@ -263,13 +264,21 @@ namespace Coffee.UIExtensions
|
||||||
if (0 < m_ParticleSystem.particleCount)
|
if (0 < m_ParticleSystem.particleCount)
|
||||||
{
|
{
|
||||||
Profiler.BeginSample ("Bake Mesh");
|
Profiler.BeginSample ("Bake Mesh");
|
||||||
|
var cam = rootCanvas.renderMode == RenderMode.ScreenSpaceOverlay
|
||||||
|
? UIParticleOverlayCamera.GetCameraForOvrelay (rootCanvas)
|
||||||
|
: canvas.worldCamera ?? Camera.main;
|
||||||
|
|
||||||
|
if (!cam)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (m_IsTrail)
|
if (m_IsTrail)
|
||||||
{
|
{
|
||||||
_renderer.BakeTrailsMesh (_mesh, true);
|
_renderer.BakeTrailsMesh (_mesh, cam, true);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_renderer.BakeMesh (_mesh, true);
|
_renderer.BakeMesh (_mesh, cam, true);
|
||||||
}
|
}
|
||||||
Profiler.EndSample ();
|
Profiler.EndSample ();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace Coffee.UIExtensions
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// </summary>
|
||||||
|
[ExecuteInEditMode]
|
||||||
|
public class UIParticleOverlayCamera : MonoBehaviour
|
||||||
|
{
|
||||||
|
//################################
|
||||||
|
// Public/Protected Members.
|
||||||
|
//################################
|
||||||
|
/// <summary>
|
||||||
|
/// Get instance object.
|
||||||
|
/// If instance does not exist, Find instance in scene, or create new one.
|
||||||
|
/// </summary>
|
||||||
|
public static UIParticleOverlayCamera instance
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
// Find instance in scene, or create new one.
|
||||||
|
if (object.ReferenceEquals (s_Instance, null))
|
||||||
|
{
|
||||||
|
s_Instance = FindObjectOfType<UIParticleOverlayCamera> () ?? new GameObject (typeof (UIParticleOverlayCamera).Name, typeof (UIParticleOverlayCamera)).GetComponent<UIParticleOverlayCamera> ();
|
||||||
|
s_Instance.gameObject.SetActive (true);
|
||||||
|
s_Instance.enabled = true;
|
||||||
|
}
|
||||||
|
return s_Instance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Camera GetCameraForOvrelay (Canvas canvas)
|
||||||
|
{
|
||||||
|
var i = instance;
|
||||||
|
var rt = canvas.rootCanvas.transform as RectTransform;
|
||||||
|
var cam = i.cameraForOvrelay;
|
||||||
|
var trans = i.transform;
|
||||||
|
cam.enabled = false;
|
||||||
|
|
||||||
|
var pos = rt.localPosition;
|
||||||
|
cam.orthographic = true;
|
||||||
|
cam.orthographicSize = Mathf.Max (pos.x, pos.y);
|
||||||
|
cam.nearClipPlane = 0.3f;
|
||||||
|
cam.farClipPlane = 1000f;
|
||||||
|
pos.z -= 100;
|
||||||
|
trans.localPosition = pos;
|
||||||
|
|
||||||
|
return cam;
|
||||||
|
}
|
||||||
|
|
||||||
|
//################################
|
||||||
|
// Private Members.
|
||||||
|
//################################
|
||||||
|
Camera cameraForOvrelay { get { return m_Camera ? m_Camera : (m_Camera = GetComponent<Camera> ()) ? m_Camera : (m_Camera = gameObject.AddComponent<Camera> ()); } }
|
||||||
|
Camera m_Camera;
|
||||||
|
static UIParticleOverlayCamera s_Instance;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Awake is called when the script instance is being loaded.
|
||||||
|
/// </summary>
|
||||||
|
void Awake ()
|
||||||
|
{
|
||||||
|
// Hold the instance.
|
||||||
|
if (s_Instance == null)
|
||||||
|
{
|
||||||
|
s_Instance = GetComponent<UIParticleOverlayCamera> ();
|
||||||
|
}
|
||||||
|
// If the instance is duplicated, destroy itself.
|
||||||
|
else if (s_Instance != this)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogWarning ("Multiple " + typeof (UIParticleOverlayCamera).Name + " in scene.", this.gameObject);
|
||||||
|
enabled = false;
|
||||||
|
#if UNITY_EDITOR
|
||||||
|
|
||||||
|
if (!Application.isPlaying)
|
||||||
|
{
|
||||||
|
DestroyImmediate (gameObject);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
Destroy (gameObject);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cameraForOvrelay.enabled = false;
|
||||||
|
|
||||||
|
// Singleton has DontDestroy flag.
|
||||||
|
if (Application.isPlaying)
|
||||||
|
{
|
||||||
|
DontDestroyOnLoad (gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This function is called when the MonoBehaviour will be destroyed.
|
||||||
|
/// </summary>
|
||||||
|
void OnDestroy ()
|
||||||
|
{
|
||||||
|
// Clear instance on destroy.
|
||||||
|
if (s_Instance == this)
|
||||||
|
{
|
||||||
|
s_Instance = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f69dfb25b53b14addbd71dbebdbaa132
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in New Issue