You've already forked ParticleEffectForUGUI
mirror of
https://github.com/mob-sakai/ParticleEffectForUGUI.git
synced 2026-05-14 20:20:06 +00:00
Refactor
This commit is contained in:
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
using UnityEngine.UI;
|
||||
using ShaderPropertyType = Coffee.UIExtensions.UIParticle.AnimatableProperty.ShaderPropertyType;
|
||||
|
||||
|
||||
namespace Coffee.UIExtensions
|
||||
@@ -41,7 +42,7 @@ namespace Coffee.UIExtensions
|
||||
static MaterialPropertyBlock s_Mpb;
|
||||
|
||||
[System.Serializable]
|
||||
public class AnimatableProperty
|
||||
public class AnimatableProperty : ISerializationCallbackReceiver
|
||||
{
|
||||
public enum ShaderPropertyType
|
||||
{
|
||||
@@ -49,11 +50,25 @@ namespace Coffee.UIExtensions
|
||||
Vector,
|
||||
Float,
|
||||
Range,
|
||||
TexEnv,
|
||||
Texture,
|
||||
};
|
||||
|
||||
public string name;
|
||||
public ShaderPropertyType type;
|
||||
[SerializeField]
|
||||
string m_Name;
|
||||
[SerializeField]
|
||||
ShaderPropertyType m_Type;
|
||||
public int id { get; private set; }
|
||||
public ShaderPropertyType type { get { return m_Type; } }
|
||||
|
||||
|
||||
public void OnBeforeSerialize ()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnAfterDeserialize ()
|
||||
{
|
||||
id = Shader.PropertyToID (m_Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -429,18 +444,7 @@ namespace Coffee.UIExtensions
|
||||
canvasRenderer.SetTexture (mainTexture);
|
||||
|
||||
// Copy the value from MaterialPropertyBlock to CanvasRenderer (#41)
|
||||
if (Application.isPlaying && 0 < m_AnimatableProperties.Length)
|
||||
{
|
||||
_renderer.GetPropertyBlock (s_Mpb);
|
||||
for (int i = 0; i < canvasRenderer.materialCount; i++)
|
||||
{
|
||||
var mat = canvasRenderer.GetMaterial (i);
|
||||
foreach (var ap in m_AnimatableProperties)
|
||||
{
|
||||
mat.SetVector (ap.name, s_Mpb.GetVector (ap.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdateAnimatableMaterialProperties ();
|
||||
|
||||
Profiler.EndSample ();
|
||||
}
|
||||
@@ -500,5 +504,43 @@ namespace Coffee.UIExtensions
|
||||
_parent._children.Add (this);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy the value from MaterialPropertyBlock to CanvasRenderer (#41)
|
||||
/// </summary>
|
||||
void UpdateAnimatableMaterialProperties ()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
if (0 == m_AnimatableProperties.Length)
|
||||
return;
|
||||
|
||||
_renderer.GetPropertyBlock (s_Mpb);
|
||||
for (int i = 0; i < canvasRenderer.materialCount; i++)
|
||||
{
|
||||
var mat = canvasRenderer.GetMaterial (i);
|
||||
foreach (var ap in m_AnimatableProperties)
|
||||
{
|
||||
switch (ap.type)
|
||||
{
|
||||
case ShaderPropertyType.Color:
|
||||
mat.SetColor (ap.id, s_Mpb.GetColor (ap.id));
|
||||
break;
|
||||
case ShaderPropertyType.Vector:
|
||||
mat.SetVector (ap.id, s_Mpb.GetVector (ap.id));
|
||||
break;
|
||||
case ShaderPropertyType.Float:
|
||||
case ShaderPropertyType.Range:
|
||||
mat.SetFloat (ap.id, s_Mpb.GetFloat (ap.id));
|
||||
break;
|
||||
case ShaderPropertyType.Texture:
|
||||
mat.SetTexture (ap.id, s_Mpb.GetTexture (ap.id));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user