You've already forked ParticleEffectForUGUI
mirror of
https://github.com/mob-sakai/ParticleEffectForUGUI.git
synced 2026-06-26 08:23:45 +00:00
feat: add fields located outside the Properties block in the shader as Animatable Properties
close #399
This commit is contained in:
32
Samples~/Demo/Animations/ColorArrayInjection.cs
Normal file
32
Samples~/Demo/Animations/ColorArrayInjection.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
[RequireComponent(typeof(ParticleSystemRenderer))]
|
||||
public class ColorArrayInjection : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private string m_PropertyName = "_Color2";
|
||||
|
||||
[SerializeField] private Color[] m_Colors = new Color[4]
|
||||
{
|
||||
Color.red,
|
||||
Color.green,
|
||||
Color.blue,
|
||||
Color.yellow
|
||||
};
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (TryGetComponent<ParticleSystemRenderer>(out var psr))
|
||||
{
|
||||
var mpb = new MaterialPropertyBlock();
|
||||
psr.GetPropertyBlock(mpb);
|
||||
mpb.SetVectorArray(m_PropertyName, m_Colors.Select(x => new Vector4(x.r, x.g, x.b, 1.0f)).ToArray());
|
||||
psr.SetPropertyBlock(mpb);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnValidate()
|
||||
{
|
||||
OnEnable();
|
||||
}
|
||||
}
|
||||
11
Samples~/Demo/Animations/ColorArrayInjection.cs.meta
Normal file
11
Samples~/Demo/Animations/ColorArrayInjection.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da4c2e90ecd3d4dd4a520099c08cf493
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user