Compare commits

..

No commits in common. "174af4bf7b33cca317130cdecd23bd5854817d69" and "a499f0c04670e6e52893799f02a30aa7b5b4db05" have entirely different histories.

3 changed files with 53 additions and 134 deletions

View File

@ -27,7 +27,7 @@ namespace Coffee.UIExtensions
Auto,
Primary,
PrimarySimulator,
Replica,
Reprica,
}
[HideInInspector][SerializeField] internal bool m_IsTrail = false;
@ -44,7 +44,7 @@ namespace Coffee.UIExtensions
[SerializeField]
private List<ParticleSystem> m_Particles = new List<ParticleSystem>();
[Tooltip("Mesh sharing.None: disable mesh sharing.\nAuto: automatically select Primary/Replica.\nPrimary: provides particle simulation results to the same group.\nPrimary Simulator: Primary, but do not render the particle (simulation only).\nReplica: render simulation results provided by the primary.")]
[Tooltip("Mesh sharing.None: disable mesh sharing.\nAuto: automatically select Primary/Reprica.\nPrimary: provides particle simulation results to the same group.\nPrimary Simulator: Primary, but do not render the particle (simulation only).\nReprica: render simulation results provided by the primary.")]
[SerializeField]
private MeshSharing m_MeshSharing = MeshSharing.None;
@ -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 = true;
private bool m_AbsoluteMode = false;
private List<UIParticleRenderer> m_Renderers = new List<UIParticleRenderer>();
@ -80,10 +80,10 @@ namespace Coffee.UIExtensions
/// <summary>
/// Mesh sharing.None: disable mesh sharing.
/// Auto: automatically select Primary/Replica.
/// Auto: automatically select Primary/Reprica.
/// Primary: provides particle simulation results to the same group.
/// Primary Simulator: Primary, but do not render the particle (simulation only).
/// Replica: render simulation results provided by the primary.
/// Reprica: render simulation results provided by the primary.
/// </summary>
public MeshSharing meshSharing
{
@ -145,7 +145,7 @@ namespace Coffee.UIExtensions
internal bool canRender
{
get { return m_MeshSharing == MeshSharing.None || m_MeshSharing == MeshSharing.Auto || m_MeshSharing == MeshSharing.Primary || m_MeshSharing == MeshSharing.Replica; }
get { return m_MeshSharing == MeshSharing.None || m_MeshSharing == MeshSharing.Auto || m_MeshSharing == MeshSharing.Primary || m_MeshSharing == MeshSharing.Reprica; }
}
/// <summary>
@ -286,22 +286,7 @@ namespace Coffee.UIExtensions
public void RefreshParticles(List<ParticleSystem> particles)
{
// #246: Nullptr exceptions when using nested UIParticle components in hierarchy
m_Renderers.Clear();
foreach (Transform child in transform)
{
var uiParticleRenderer = child.GetComponent<UIParticleRenderer>();
if (uiParticleRenderer != null)
{
m_Renderers.Add(uiParticleRenderer);
}
}
for (var i = 0; i < m_Renderers.Count; i++)
{
m_Renderers[i].Reset(i);
}
GetComponentsInChildren(m_Renderers);
var j = 0;
for (var i = 0; i < particles.Count; i++)
@ -313,6 +298,11 @@ namespace Coffee.UIExtensions
GetRenderer(j++).Set(this, particles[i], true);
}
}
for (; j < m_Renderers.Count; j++)
{
GetRenderer(j).Clear(j);
}
}
internal void UpdateTransformScale()
@ -333,13 +323,9 @@ namespace Coffee.UIExtensions
{
if (!isActiveAndEnabled) return;
foreach (var rend in m_Renderers)
if (m_Renderers.Any(x => !x))
{
if (!rend)
{
RefreshParticles(particles);
break;
}
RefreshParticles(particles);
}
var bakeCamera = GetBakeCamera();
@ -400,7 +386,7 @@ namespace Coffee.UIExtensions
{
_tracker.Clear();
UIParticleUpdater.Unregister(this);
m_Renderers.ForEach(r => r.Reset());
m_Renderers.ForEach(r => r.Clear());
UnregisterDirtyMaterialCallback(UpdateRendererMaterial);
base.OnDisable();
@ -451,12 +437,9 @@ namespace Coffee.UIExtensions
{
if (!canvas) return Camera.main;
// Render mode is not ScreenSpaceOverlay, use world camera.
// 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,12 +36,6 @@ 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
@ -78,31 +72,22 @@ namespace Coffee.UIExtensions
}
}
public UnityEvent onAttracted
{
get { return m_OnAttracted; }
set { m_OnAttracted = value; }
}
public ParticleSystem particleSystem
{
get
{
return m_ParticleSystem;
}
set
{
m_ParticleSystem = value;
if (!ApplyParticleSystem()) return;
enabled = true;
}
}
private UIParticle _uiParticle;
private void OnEnable()
{
if (!ApplyParticleSystem()) return;
if (m_ParticleSystem == null)
{
Debug.LogError("No particle system attached to particle attractor script", this);
enabled = false;
return;
}
_uiParticle = m_ParticleSystem.GetComponentInParent<UIParticle>();
if (_uiParticle && !_uiParticle.particles.Contains(m_ParticleSystem))
{
_uiParticle = null;
}
UIParticleUpdater.Register(this);
}
@ -169,32 +154,29 @@ namespace Coffee.UIExtensions
var psPos = m_ParticleSystem.transform.position;
var attractorPos = transform.position;
var dstPos = attractorPos;
var isLocalSpace = m_ParticleSystem.main.simulationSpace == ParticleSystemSimulationSpace.Local;
if (isLocalSpace)
if (m_ParticleSystem.main.simulationSpace == ParticleSystemSimulationSpace.Local)
{
dstPos = m_ParticleSystem.transform.InverseTransformPoint(dstPos);
}
if (isUI)
{
dstPos = dstPos.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
// Relative mode
if (!_uiParticle.absoluteMode)
if (isUI)
{
var diff = _uiParticle.transform.position - psPos;
diff.Scale(_uiParticle.scale3D - _uiParticle.transform.localScale);
diff.Scale(_uiParticle.scale3D.Inverse());
dstPos += diff;
dstPos = dstPos.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
}
}
else
{
#if UNITY_EDITOR
if (!Application.isPlaying && !isLocalSpace)
if (!Application.isPlaying && isUI)
{
dstPos += psPos - psPos.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
var diff = dstPos - psPos;
diff = diff.GetScaled(_uiParticle.transform.localScale, _uiParticle.scale3D.Inverse());
return psPos + diff;
}
#endif
if (isUI)
{
dstPos.Scale(_uiParticle.transform.localScale);
dstPos.Scale(_uiParticle.scale3D.Inverse());
}
}
return dstPos;
}
@ -218,22 +200,5 @@ namespace Coffee.UIExtensions
return Vector3.MoveTowards(current, target, speed);
}
private bool ApplyParticleSystem()
{
if (m_ParticleSystem == null)
{
Debug.LogError("No particle system attached to particle attractor script", this);
enabled = false;
return false;
}
_uiParticle = m_ParticleSystem.GetComponentInParent<UIParticle>();
if (_uiParticle && !_uiParticle.particles.Contains(m_ParticleSystem))
{
_uiParticle = null;
}
return true;
}
}
}

View File

@ -112,12 +112,7 @@ namespace Coffee.UIExtensions
{
_currentMaterialForRendering = null;
if (!IsActive() || !_parent)
{
ModifiedMaterial.Remove(_modifiedMaterial);
_modifiedMaterial = null;
return baseMaterial;
}
if (!IsActive()) return baseMaterial;
var modifiedMaterial = base.GetModifiedMaterial(baseMaterial);
@ -139,7 +134,7 @@ namespace Coffee.UIExtensions
return modifiedMaterial;
}
public void Reset(int index = -1)
public void Clear(int index = -1)
{
if (_renderer)
{
@ -162,12 +157,6 @@ 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)
@ -178,18 +167,15 @@ namespace Coffee.UIExtensions
gameObject.layer = parent.gameObject.layer;
_particleSystem = particleSystem;
_prewarm = _particleSystem.main.prewarm;
#if UNITY_EDITOR
if (Application.isPlaying)
#endif
if (_particleSystem.isPlaying)
{
if (_particleSystem.isPlaying || _prewarm)
{
_particleSystem.Clear();
_particleSystem.Pause();
}
_particleSystem.Clear();
_particleSystem.Pause();
}
_prewarm = _particleSystem.main.prewarm;
_renderer = particleSystem.GetComponent<ParticleSystemRenderer>();
_renderer.enabled = false;
@ -222,7 +208,7 @@ namespace Coffee.UIExtensions
// No particle to render: Clear mesh.
if (
!isActiveAndEnabled || !_particleSystem || !_parent || !canvasRenderer || !canvas || !bakeCamera
|| _parent.meshSharing == UIParticle.MeshSharing.Replica
|| _parent.meshSharing == UIParticle.MeshSharing.Reprica
|| !transform.lossyScale.GetScaled(_parent.scale3D).IsVisible() // Scale is not visible.
|| (!_particleSystem.IsAlive() && !_particleSystem.isPlaying) // No particle.
|| (_isTrail && !_particleSystem.trails.enabled) // Trail, but it is not enabled.
@ -278,7 +264,7 @@ namespace Coffee.UIExtensions
// Bake mesh.
Profiler.BeginSample("[UIParticleRenderer] Bake Mesh");
if (_isTrail && _parent.canSimulate && 0 < s_CombineInstances[0].mesh.vertices.Length)
if (_isTrail && _parent.canSimulate)
{
_renderer.BakeTrailsMesh(s_CombineInstances[0].mesh, bakeCamera, true);
}
@ -290,18 +276,6 @@ namespace Coffee.UIExtensions
{
s_CombineInstances[0].mesh.Clear(false);
}
// Too many vertices to render.
if (65535 <= s_CombineInstances[0].mesh.vertexCount)
{
s_CombineInstances[0].mesh.Clear(false);
UnityEngine.Debug.LogErrorFormat(this,
"Too many vertices to render. index={0}, isTrail={1}, vertexCount={2}(>=65535)",
_index,
_isTrail,
s_CombineInstances[0].mesh.vertexCount
);
}
Profiler.EndSample();
// Combine mesh to transform. ([ParticleSystem local ->] world -> renderer local)
@ -533,9 +507,7 @@ namespace Coffee.UIExtensions
_prewarm = false;
}
// (COMMENT OUT) #231: Sub Emitters option is not work in editor playing
/*
// Emitted particles found.
// Emitted particles found.
if (_prevParticleCount != _particleSystem.particleCount)
{
var size = _particleSystem.particleCount;
@ -550,7 +522,6 @@ namespace Coffee.UIExtensions
_particleSystem.SetParticles(particles, size);
}
*/
// get world position.
var psTransform = _particleSystem.transform;