3.0.0-preview.21
# [3.0.0-preview.21](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.20...v3.0.0-preview.21) (2020-08-28) ### Bug Fixes * if in the mask, rendering material will be destroyed ([0db40cf](pull/120/head0db40cf160
)) * support animatable material property (again) ([cf6ca80](cf6ca80d12
))
parent
ab27f0af6f
commit
46ec957a52
|
@ -1,3 +1,11 @@
|
|||
# [3.0.0-preview.21](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.20...v3.0.0-preview.21) (2020-08-28)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* if in the mask, rendering material will be destroyed ([0db40cf](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/0db40cf160b2a5a27c83ef15d648b2771a47b51a))
|
||||
* support animatable material property (again) ([cf6ca80](https://github.com/mob-sakai/ParticleEffectForUGUI/commit/cf6ca80d1273bcf49e18d805260afa8e36e94617))
|
||||
|
||||
# [3.0.0-preview.20](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.19...v3.0.0-preview.20) (2020-08-28)
|
||||
|
||||
|
||||
|
|
|
@ -26,20 +26,30 @@ namespace Coffee.UIExtensions
|
|||
|
||||
public void UpdateMaterialProperties(Material material, MaterialPropertyBlock mpb)
|
||||
{
|
||||
if (!material.HasProperty(id)) return;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ShaderPropertyType.Color:
|
||||
material.SetColor(id, mpb.GetColor(id));
|
||||
var color = mpb.GetColor(id);
|
||||
if (color != default(Color))
|
||||
material.SetColor(id, color);
|
||||
break;
|
||||
case ShaderPropertyType.Vector:
|
||||
material.SetVector(id, mpb.GetVector(id));
|
||||
var vector = mpb.GetVector(id);
|
||||
if (vector != default(Vector4))
|
||||
material.SetVector(id, vector);
|
||||
break;
|
||||
case ShaderPropertyType.Float:
|
||||
case ShaderPropertyType.Range:
|
||||
material.SetFloat(id, mpb.GetFloat(id));
|
||||
var value = mpb.GetFloat(id);
|
||||
if (value != default(float))
|
||||
material.SetFloat(id, value);
|
||||
break;
|
||||
case ShaderPropertyType.Texture:
|
||||
material.SetTexture(id, mpb.GetTexture(id));
|
||||
var tex = mpb.GetTexture(id);
|
||||
if (tex != default(Texture))
|
||||
material.SetTexture(id, tex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,9 +34,11 @@ namespace Coffee.UIExtensions
|
|||
private DrivenRectTransformTracker _tracker;
|
||||
private Mesh _bakedMesh;
|
||||
private readonly List<Material> _modifiedMaterials = new List<Material>();
|
||||
private readonly List<Material> _maskMaterials = new List<Material>();
|
||||
private uint _activeMeshIndices;
|
||||
private Vector3 _cachedPosition;
|
||||
private static readonly List<Material> s_TempMaterials = new List<Material>(2);
|
||||
private static MaterialPropertyBlock s_Mpb;
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
@ -129,10 +131,18 @@ namespace Coffee.UIExtensions
|
|||
|
||||
protected override void UpdateMaterial()
|
||||
{
|
||||
// Clear mask materials.
|
||||
for (var i = 0; i < _maskMaterials.Count; i++)
|
||||
{
|
||||
StencilMaterial.Remove(_maskMaterials[i]);
|
||||
_maskMaterials[i] = null;
|
||||
}
|
||||
|
||||
_maskMaterials.Clear();
|
||||
|
||||
// Clear modified materials.
|
||||
for (var i = 0; i < _modifiedMaterials.Count; i++)
|
||||
{
|
||||
StencilMaterial.Remove(_modifiedMaterials[i]);
|
||||
DestroyImmediate(_modifiedMaterials[i]);
|
||||
_modifiedMaterials[i] = null;
|
||||
}
|
||||
|
@ -173,7 +183,9 @@ namespace Coffee.UIExtensions
|
|||
if (0 < (activeMeshIndices & bit) && 0 < s_TempMaterials.Count)
|
||||
{
|
||||
var mat = GetModifiedMaterial(s_TempMaterials[0], ps.GetTextureForSprite());
|
||||
canvasRenderer.SetMaterial(mat, j++);
|
||||
canvasRenderer.SetMaterial(mat, j);
|
||||
UpdateMaterialProperties(r, j);
|
||||
j++;
|
||||
}
|
||||
|
||||
// Trails
|
||||
|
@ -192,7 +204,7 @@ namespace Coffee.UIExtensions
|
|||
if (0 < m_StencilValue)
|
||||
{
|
||||
baseMaterial = StencilMaterial.Add(baseMaterial, (1 << m_StencilValue) - 1, StencilOp.Keep, CompareFunction.Equal, ColorWriteMask.All, (1 << m_StencilValue) - 1, 0);
|
||||
_modifiedMaterials.Add(baseMaterial);
|
||||
_maskMaterials.Add(baseMaterial);
|
||||
}
|
||||
|
||||
if (texture == null && m_AnimatableProperties.Length == 0) return baseMaterial;
|
||||
|
@ -205,6 +217,25 @@ namespace Coffee.UIExtensions
|
|||
return baseMaterial;
|
||||
}
|
||||
|
||||
internal void UpdateMaterialProperties(Renderer r, int index)
|
||||
{
|
||||
if (m_AnimatableProperties.Length == 0 || canvasRenderer.materialCount <= index) return;
|
||||
|
||||
r.GetPropertyBlock(s_Mpb ?? (s_Mpb = new MaterialPropertyBlock()));
|
||||
if (s_Mpb.isEmpty) return;
|
||||
|
||||
// #41: Copy the value from MaterialPropertyBlock to CanvasRenderer
|
||||
var mat = canvasRenderer.GetMaterial(index);
|
||||
if (!mat) return;
|
||||
|
||||
foreach (var ap in m_AnimatableProperties)
|
||||
{
|
||||
ap.UpdateMaterialProperties(mat, s_Mpb);
|
||||
}
|
||||
|
||||
s_Mpb.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is called when the object becomes enabled and active.
|
||||
/// </summary>
|
||||
|
|
|
@ -205,6 +205,11 @@ namespace Coffee.UIExtensions
|
|||
|
||||
if (m.vertexCount == 0)
|
||||
MeshHelper.DiscardTemporaryMesh();
|
||||
else
|
||||
{
|
||||
var index = MeshHelper.activeMeshIndices.BitCount() - 1;
|
||||
particle.UpdateMaterialProperties(r, index);
|
||||
}
|
||||
}
|
||||
|
||||
// Bake trails particles.
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"name": "com.coffee.ui-particle",
|
||||
"displayName": "UI Particle",
|
||||
"description": "This plugin provide a component to render particle effect for uGUI.\nThe particle rendering is maskable and sortable, without Camera, RenderTexture or Canvas.",
|
||||
"version": "3.0.0-preview.20",
|
||||
"version": "3.0.0-preview.21",
|
||||
"unity": "2018.2",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
|
|
Loading…
Reference in New Issue