mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
[unity] SlotTintBlackFollower module
This commit is contained in:
parent
620461494c
commit
74e688d548
@ -0,0 +1,9 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e364d7a84acb894ea3f4bde752a09e8
|
||||
folderAsset: yes
|
||||
timeCreated: 1489227060
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -0,0 +1,60 @@
|
||||
using UnityEngine;
|
||||
using Spine.Unity;
|
||||
|
||||
namespace Spine.Unity.Modules {
|
||||
|
||||
/// <summary>
|
||||
/// Add this component to a Spine GameObject to apply a specific slot's Colors as MaterialProperties.
|
||||
/// This allows you to apply the two color tint to the whole skeleton and not require the overhead of an extra vertex stream on the mesh.
|
||||
/// </summary>
|
||||
public class SlotTintBlackFollower : MonoBehaviour {
|
||||
|
||||
#region Inspector
|
||||
/// <summary>
|
||||
/// Serialized name of the slot loaded at runtime. Change the slot field instead of this if you want to change the followed slot at runtime.</summary>
|
||||
[SpineSlot]
|
||||
[SerializeField]
|
||||
protected string slotName;
|
||||
|
||||
[SerializeField]
|
||||
protected string colorPropertyName = "_Color";
|
||||
[SerializeField]
|
||||
protected string blackPropertyName = "_Black";
|
||||
#endregion
|
||||
|
||||
public Slot slot;
|
||||
MeshRenderer mr;
|
||||
MaterialPropertyBlock mb;
|
||||
int colorPropertyId, blackPropertyId;
|
||||
|
||||
void Start () {
|
||||
Initialize(false);
|
||||
}
|
||||
|
||||
public void Initialize (bool overwrite) {
|
||||
if (overwrite || mb == null) {
|
||||
mb = new MaterialPropertyBlock();
|
||||
mr = GetComponent<MeshRenderer>();
|
||||
slot = GetComponent<ISkeletonComponent>().Skeleton.FindSlot(slotName);
|
||||
|
||||
colorPropertyId = Shader.PropertyToID(colorPropertyName);
|
||||
blackPropertyId = Shader.PropertyToID(blackPropertyName);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update () {
|
||||
Slot s = slot;
|
||||
if (s == null) return;
|
||||
|
||||
mb.SetColor(colorPropertyId, new Color(s.r, s.g, s.b, s.a));
|
||||
mb.SetColor(blackPropertyId, new Color(s.r2, s.g2, s.b2, 1f));
|
||||
|
||||
mr.SetPropertyBlock(mb);
|
||||
}
|
||||
|
||||
void OnDisable () {
|
||||
mb.Clear();
|
||||
mr.SetPropertyBlock(mb);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49a62759c814e7a458b9026d504e0898
|
||||
timeCreated: 1489227143
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
x
Reference in New Issue
Block a user