mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
34 lines
749 B
C#
34 lines
749 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
namespace Spine.Unity.Examples {
|
|
public class MaterialPropertyBlockExample : MonoBehaviour {
|
|
|
|
public float timeInterval = 1f;
|
|
public Gradient randomColors = new Gradient();
|
|
public string colorPropertyName = "_FillColor";
|
|
|
|
MaterialPropertyBlock mpb;
|
|
float timeToNextColor = 0;
|
|
|
|
void Start () {
|
|
mpb = new MaterialPropertyBlock();
|
|
}
|
|
|
|
void Update () {
|
|
if (timeToNextColor <= 0) {
|
|
timeToNextColor = timeInterval;
|
|
|
|
Color newColor = randomColors.Evaluate(UnityEngine.Random.value);
|
|
mpb.SetColor(colorPropertyName, newColor);
|
|
GetComponent<MeshRenderer>().SetPropertyBlock(mpb);
|
|
}
|
|
|
|
timeToNextColor -= Time.deltaTime;
|
|
}
|
|
|
|
}
|
|
|
|
}
|