Compare commits
8 Commits
67bac3b50d
...
174af4bf7b
Author | SHA1 | Date |
---|---|---|
|
174af4bf7b | |
|
65770cadda | |
|
12b5aacf1d | |
|
fa8d7fa312 | |
|
dc82e4074d | |
|
924550b0fc | |
|
c4e4fce26f | |
|
ab427e9b6a |
|
@ -57,7 +57,7 @@ namespace Coffee.UIExtensions
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
[Tooltip("The particles will be emitted at the ParticleSystem position.\nMove the UIParticle/ParticleSystem to move the particle.")]
|
[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>();
|
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;
|
var j = 0;
|
||||||
for (var i = 0; i < particles.Count; i++)
|
for (var i = 0; i < particles.Count; i++)
|
||||||
{
|
{
|
||||||
|
@ -308,11 +313,6 @@ namespace Coffee.UIExtensions
|
||||||
GetRenderer(j++).Set(this, particles[i], true);
|
GetRenderer(j++).Set(this, particles[i], true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; j < m_Renderers.Count; j++)
|
|
||||||
{
|
|
||||||
GetRenderer(j).Clear(j);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void UpdateTransformScale()
|
internal void UpdateTransformScale()
|
||||||
|
@ -400,7 +400,7 @@ namespace Coffee.UIExtensions
|
||||||
{
|
{
|
||||||
_tracker.Clear();
|
_tracker.Clear();
|
||||||
UIParticleUpdater.Unregister(this);
|
UIParticleUpdater.Unregister(this);
|
||||||
m_Renderers.ForEach(r => r.Clear());
|
m_Renderers.ForEach(r => r.Reset());
|
||||||
UnregisterDirtyMaterialCallback(UpdateRendererMaterial);
|
UnregisterDirtyMaterialCallback(UpdateRendererMaterial);
|
||||||
|
|
||||||
base.OnDisable();
|
base.OnDisable();
|
||||||
|
@ -451,9 +451,12 @@ namespace Coffee.UIExtensions
|
||||||
{
|
{
|
||||||
if (!canvas) return Camera.main;
|
if (!canvas) return Camera.main;
|
||||||
|
|
||||||
// World camera.
|
// Render mode is not ScreenSpaceOverlay, use world camera.
|
||||||
var root = canvas.rootCanvas;
|
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.
|
// Create ortho-camera.
|
||||||
if (!_orthoCamera)
|
if (!_orthoCamera)
|
||||||
|
|
|
@ -36,6 +36,12 @@ namespace Coffee.UIExtensions
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private UnityEvent m_OnAttracted;
|
private UnityEvent m_OnAttracted;
|
||||||
|
|
||||||
|
public float destinationRadius
|
||||||
|
{
|
||||||
|
get { return m_DestinationRadius; }
|
||||||
|
set { m_DestinationRadius = Mathf.Clamp(value, 0.1f, 10f); }
|
||||||
|
}
|
||||||
|
|
||||||
public float delay
|
public float delay
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -72,6 +78,12 @@ namespace Coffee.UIExtensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UnityEvent onAttracted
|
||||||
|
{
|
||||||
|
get { return m_OnAttracted; }
|
||||||
|
set { m_OnAttracted = value; }
|
||||||
|
}
|
||||||
|
|
||||||
public ParticleSystem particleSystem
|
public ParticleSystem particleSystem
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
@ -157,29 +169,32 @@ namespace Coffee.UIExtensions
|
||||||
var psPos = m_ParticleSystem.transform.position;
|
var psPos = m_ParticleSystem.transform.position;
|
||||||
var attractorPos = transform.position;
|
var attractorPos = transform.position;
|
||||||
var dstPos = attractorPos;
|
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);
|
dstPos = m_ParticleSystem.transform.InverseTransformPoint(dstPos);
|
||||||
if (isUI)
|
|
||||||
{
|
|
||||||
dstPos = dstPos.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
if (isUI)
|
||||||
{
|
{
|
||||||
#if UNITY_EDITOR
|
dstPos = dstPos.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
|
||||||
if (!Application.isPlaying && isUI)
|
|
||||||
|
// Relative mode
|
||||||
|
if (!_uiParticle.absoluteMode)
|
||||||
{
|
{
|
||||||
var diff = dstPos - psPos;
|
var diff = _uiParticle.transform.position - psPos;
|
||||||
diff = diff.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
|
diff.Scale(_uiParticle.scale3D - _uiParticle.transform.localScale);
|
||||||
return psPos + diff;
|
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
|
#endif
|
||||||
if (isUI)
|
|
||||||
{
|
|
||||||
dstPos.Scale(_uiParticle.transform.localScale);
|
|
||||||
dstPos.Scale(_uiParticle.scale3D.Inverse());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return dstPos;
|
return dstPos;
|
||||||
}
|
}
|
||||||
|
|
|
@ -112,7 +112,12 @@ namespace Coffee.UIExtensions
|
||||||
{
|
{
|
||||||
_currentMaterialForRendering = null;
|
_currentMaterialForRendering = null;
|
||||||
|
|
||||||
if (!IsActive()) return baseMaterial;
|
if (!IsActive() || !_parent)
|
||||||
|
{
|
||||||
|
ModifiedMaterial.Remove(_modifiedMaterial);
|
||||||
|
_modifiedMaterial = null;
|
||||||
|
return baseMaterial;
|
||||||
|
}
|
||||||
|
|
||||||
var modifiedMaterial = base.GetModifiedMaterial(baseMaterial);
|
var modifiedMaterial = base.GetModifiedMaterial(baseMaterial);
|
||||||
|
|
||||||
|
@ -134,7 +139,7 @@ namespace Coffee.UIExtensions
|
||||||
return modifiedMaterial;
|
return modifiedMaterial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clear(int index = -1)
|
public void Reset(int index = -1)
|
||||||
{
|
{
|
||||||
if (_renderer)
|
if (_renderer)
|
||||||
{
|
{
|
||||||
|
@ -157,6 +162,12 @@ namespace Coffee.UIExtensions
|
||||||
_lastBounds = new Bounds();
|
_lastBounds = new Bounds();
|
||||||
enabled = false;
|
enabled = false;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ModifiedMaterial.Remove(_modifiedMaterial);
|
||||||
|
_modifiedMaterial = null;
|
||||||
|
_currentMaterialForRendering = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Set(UIParticle parent, ParticleSystem particleSystem, bool isTrail)
|
public void Set(UIParticle parent, ParticleSystem particleSystem, bool isTrail)
|
||||||
|
@ -167,15 +178,18 @@ namespace Coffee.UIExtensions
|
||||||
gameObject.layer = parent.gameObject.layer;
|
gameObject.layer = parent.gameObject.layer;
|
||||||
|
|
||||||
_particleSystem = particleSystem;
|
_particleSystem = particleSystem;
|
||||||
|
_prewarm = _particleSystem.main.prewarm;
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
if (Application.isPlaying)
|
if (Application.isPlaying)
|
||||||
#endif
|
#endif
|
||||||
if (_particleSystem.isPlaying)
|
|
||||||
{
|
{
|
||||||
_particleSystem.Clear();
|
if (_particleSystem.isPlaying || _prewarm)
|
||||||
_particleSystem.Pause();
|
{
|
||||||
|
_particleSystem.Clear();
|
||||||
|
_particleSystem.Pause();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_prewarm = _particleSystem.main.prewarm;
|
|
||||||
|
|
||||||
_renderer = particleSystem.GetComponent<ParticleSystemRenderer>();
|
_renderer = particleSystem.GetComponent<ParticleSystemRenderer>();
|
||||||
_renderer.enabled = false;
|
_renderer.enabled = false;
|
||||||
|
@ -264,7 +278,7 @@ namespace Coffee.UIExtensions
|
||||||
|
|
||||||
// Bake mesh.
|
// Bake mesh.
|
||||||
Profiler.BeginSample("[UIParticleRenderer] 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);
|
_renderer.BakeTrailsMesh(s_CombineInstances[0].mesh, bakeCamera, true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue