Compare commits

...

8 Commits

Author SHA1 Message Date
mob-sakai 174af4bf7b fix: UIParticleAttractor attracts the particles at wrong position when in RelativeMode
close #262
2023-08-15 09:40:11 +09:00
mob-sakai 65770cadda feat: add public properties for UIParticleAttractor
close #253
2023-08-15 09:40:11 +09:00
mob-sakai 12b5aacf1d refactor 2023-08-15 09:40:11 +09:00
mob-sakai fa8d7fa312 fix: assertion 'ps->array_size()' in UpdateMesh() when using trails of type ribbon
close #241
2023-08-15 09:40:11 +09:00
mob-sakai dc82e4074d fix: change AbsoluteMode default value to true 2023-08-15 09:40:11 +09:00
mob-sakai 924550b0fc fix: scaling ParticleSystem puts prewarmed particles in wrong location
close #235
2023-08-15 09:40:11 +09:00
mob-sakai c4e4fce26f fix: nullReferenceException after copy-n-paste
close #258
2023-08-15 09:40:11 +09:00
mob-sakai ab427e9b6a fix: mesh sharing not working 2023-08-15 09:40:11 +09:00
3 changed files with 64 additions and 32 deletions

View File

@ -57,7 +57,7 @@ namespace Coffee.UIExtensions
[SerializeField]
[Tooltip("The particles will be emitted at the ParticleSystem position.\nMove the UIParticle/ParticleSystem to move the particle.")]
private bool m_AbsoluteMode = false;
private bool m_AbsoluteMode = true;
private List<UIParticleRenderer> m_Renderers = new List<UIParticleRenderer>();
@ -298,6 +298,11 @@ namespace Coffee.UIExtensions
}
}
for (var i = 0; i < m_Renderers.Count; i++)
{
m_Renderers[i].Reset(i);
}
var j = 0;
for (var i = 0; i < particles.Count; i++)
{
@ -308,11 +313,6 @@ namespace Coffee.UIExtensions
GetRenderer(j++).Set(this, particles[i], true);
}
}
for (; j < m_Renderers.Count; j++)
{
GetRenderer(j).Clear(j);
}
}
internal void UpdateTransformScale()
@ -400,7 +400,7 @@ namespace Coffee.UIExtensions
{
_tracker.Clear();
UIParticleUpdater.Unregister(this);
m_Renderers.ForEach(r => r.Clear());
m_Renderers.ForEach(r => r.Reset());
UnregisterDirtyMaterialCallback(UpdateRendererMaterial);
base.OnDisable();
@ -451,9 +451,12 @@ namespace Coffee.UIExtensions
{
if (!canvas) return Camera.main;
// World camera.
// Render mode is not ScreenSpaceOverlay, use world camera.
var root = canvas.rootCanvas;
if (root.renderMode != RenderMode.ScreenSpaceOverlay) return root.worldCamera ? root.worldCamera : Camera.main;
if (root.renderMode != RenderMode.ScreenSpaceOverlay)
{
return root.worldCamera ? root.worldCamera : Camera.main;
}
// Create ortho-camera.
if (!_orthoCamera)

View File

@ -36,6 +36,12 @@ namespace Coffee.UIExtensions
[SerializeField]
private UnityEvent m_OnAttracted;
public float destinationRadius
{
get { return m_DestinationRadius; }
set { m_DestinationRadius = Mathf.Clamp(value, 0.1f, 10f); }
}
public float delay
{
get
@ -72,6 +78,12 @@ namespace Coffee.UIExtensions
}
}
public UnityEvent onAttracted
{
get { return m_OnAttracted; }
set { m_OnAttracted = value; }
}
public ParticleSystem particleSystem
{
get
@ -157,29 +169,32 @@ namespace Coffee.UIExtensions
var psPos = m_ParticleSystem.transform.position;
var attractorPos = transform.position;
var dstPos = attractorPos;
if (m_ParticleSystem.main.simulationSpace == ParticleSystemSimulationSpace.Local)
var isLocalSpace = m_ParticleSystem.main.simulationSpace == ParticleSystemSimulationSpace.Local;
if (isLocalSpace)
{
dstPos = m_ParticleSystem.transform.InverseTransformPoint(dstPos);
if (isUI)
{
dstPos = dstPos.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
}
}
else
if (isUI)
{
#if UNITY_EDITOR
if (!Application.isPlaying && isUI)
dstPos = dstPos.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
// Relative mode
if (!_uiParticle.absoluteMode)
{
var diff = dstPos - psPos;
diff = diff.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
return psPos + diff;
var diff = _uiParticle.transform.position - psPos;
diff.Scale(_uiParticle.scale3D - _uiParticle.transform.localScale);
diff.Scale(_uiParticle.scale3D.Inverse());
dstPos += diff;
}
#if UNITY_EDITOR
if (!Application.isPlaying && !isLocalSpace)
{
dstPos += psPos - psPos.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
}
#endif
if (isUI)
{
dstPos.Scale(_uiParticle.transform.localScale);
dstPos.Scale(_uiParticle.scale3D.Inverse());
}
}
return dstPos;
}

View File

@ -112,7 +112,12 @@ namespace Coffee.UIExtensions
{
_currentMaterialForRendering = null;
if (!IsActive()) return baseMaterial;
if (!IsActive() || !_parent)
{
ModifiedMaterial.Remove(_modifiedMaterial);
_modifiedMaterial = null;
return baseMaterial;
}
var modifiedMaterial = base.GetModifiedMaterial(baseMaterial);
@ -134,7 +139,7 @@ namespace Coffee.UIExtensions
return modifiedMaterial;
}
public void Clear(int index = -1)
public void Reset(int index = -1)
{
if (_renderer)
{
@ -157,6 +162,12 @@ namespace Coffee.UIExtensions
_lastBounds = new Bounds();
enabled = false;
}
else
{
ModifiedMaterial.Remove(_modifiedMaterial);
_modifiedMaterial = null;
_currentMaterialForRendering = null;
}
}
public void Set(UIParticle parent, ParticleSystem particleSystem, bool isTrail)
@ -167,15 +178,18 @@ namespace Coffee.UIExtensions
gameObject.layer = parent.gameObject.layer;
_particleSystem = particleSystem;
_prewarm = _particleSystem.main.prewarm;
#if UNITY_EDITOR
if (Application.isPlaying)
#endif
if (_particleSystem.isPlaying)
{
_particleSystem.Clear();
_particleSystem.Pause();
if (_particleSystem.isPlaying || _prewarm)
{
_particleSystem.Clear();
_particleSystem.Pause();
}
}
_prewarm = _particleSystem.main.prewarm;
_renderer = particleSystem.GetComponent<ParticleSystemRenderer>();
_renderer.enabled = false;
@ -264,7 +278,7 @@ namespace Coffee.UIExtensions
// Bake mesh.
Profiler.BeginSample("[UIParticleRenderer] Bake Mesh");
if (_isTrail && _parent.canSimulate)
if (_isTrail && _parent.canSimulate && 0 < s_CombineInstances[0].mesh.vertices.Length)
{
_renderer.BakeTrailsMesh(s_CombineInstances[0].mesh, bakeCamera, true);
}