mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
[unity] SkeletonGhost fixes and cleanup.
This commit is contained in:
parent
e296ef7c30
commit
2e086ff11c
@ -37,6 +37,10 @@ namespace Spine.Unity.Modules {
|
|||||||
|
|
||||||
[RequireComponent(typeof(SkeletonRenderer))]
|
[RequireComponent(typeof(SkeletonRenderer))]
|
||||||
public class SkeletonGhost : MonoBehaviour {
|
public class SkeletonGhost : MonoBehaviour {
|
||||||
|
// Internal Settings
|
||||||
|
const HideFlags GhostHideFlags = HideFlags.HideInHierarchy;
|
||||||
|
const string GhostingShaderName = "Spine/Special/SkeletonGhost";
|
||||||
|
|
||||||
public bool ghostingEnabled = true;
|
public bool ghostingEnabled = true;
|
||||||
public float spawnRate = 0.05f;
|
public float spawnRate = 0.05f;
|
||||||
public Color32 color = new Color32(0xFF, 0xFF, 0xFF, 0x00); // default for additive.
|
public Color32 color = new Color32(0xFF, 0xFF, 0xFF, 0x00); // default for additive.
|
||||||
@ -60,12 +64,11 @@ namespace Spine.Unity.Modules {
|
|||||||
MeshRenderer meshRenderer;
|
MeshRenderer meshRenderer;
|
||||||
MeshFilter meshFilter;
|
MeshFilter meshFilter;
|
||||||
|
|
||||||
|
readonly Dictionary<Material, Material> materialTable = new Dictionary<Material, Material>();
|
||||||
Dictionary<Material, Material> materialTable = new Dictionary<Material, Material>();
|
|
||||||
|
|
||||||
void Start () {
|
void Start () {
|
||||||
if (ghostShader == null)
|
if (ghostShader == null)
|
||||||
ghostShader = Shader.Find("Spine/Special/SkeletonGhost");
|
ghostShader = Shader.Find(GhostingShaderName);
|
||||||
|
|
||||||
skeletonRenderer = GetComponent<SkeletonRenderer>();
|
skeletonRenderer = GetComponent<SkeletonRenderer>();
|
||||||
meshFilter = GetComponent<MeshFilter>();
|
meshFilter = GetComponent<MeshFilter>();
|
||||||
@ -76,12 +79,11 @@ namespace Spine.Unity.Modules {
|
|||||||
GameObject go = new GameObject(gameObject.name + " Ghost", typeof(SkeletonGhostRenderer));
|
GameObject go = new GameObject(gameObject.name + " Ghost", typeof(SkeletonGhostRenderer));
|
||||||
pool[i] = go.GetComponent<SkeletonGhostRenderer>();
|
pool[i] = go.GetComponent<SkeletonGhostRenderer>();
|
||||||
go.SetActive(false);
|
go.SetActive(false);
|
||||||
go.hideFlags = HideFlags.HideInHierarchy;
|
go.hideFlags = GhostHideFlags;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (skeletonRenderer is SkeletonAnimation)
|
var skeletonAnimation = skeletonRenderer as Spine.Unity.IAnimationStateComponent;
|
||||||
((SkeletonAnimation)skeletonRenderer).state.Event += OnEvent;
|
if (skeletonAnimation != null) skeletonAnimation.AnimationState.Event += OnEvent;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//SkeletonAnimation
|
//SkeletonAnimation
|
||||||
@ -91,13 +93,13 @@ namespace Spine.Unity.Modules {
|
|||||||
* String Value: Pass RGBA hex color values in to set the color property. IE: "A0FF8BFF"
|
* String Value: Pass RGBA hex color values in to set the color property. IE: "A0FF8BFF"
|
||||||
*/
|
*/
|
||||||
void OnEvent (Spine.TrackEntry trackEntry, Spine.Event e) {
|
void OnEvent (Spine.TrackEntry trackEntry, Spine.Event e) {
|
||||||
if (e.Data.Name == "Ghosting") {
|
if (e.Data.Name.Equals("Ghosting", System.StringComparison.Ordinal)) {
|
||||||
ghostingEnabled = e.Int > 0;
|
ghostingEnabled = e.Int > 0;
|
||||||
if (e.Float > 0)
|
if (e.Float > 0)
|
||||||
spawnRate = e.Float;
|
spawnRate = e.Float;
|
||||||
if (e.String != null) {
|
|
||||||
|
if (!string.IsNullOrEmpty(e.stringValue))
|
||||||
this.color = HexToColor(e.String);
|
this.color = HexToColor(e.String);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,16 +155,13 @@ namespace Spine.Unity.Modules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnDestroy () {
|
void OnDestroy () {
|
||||||
for (int i = 0; i < maximumGhosts; i++) {
|
for (int i = 0; i < maximumGhosts; i++)
|
||||||
if (pool[i] != null)
|
if (pool[i] != null) pool[i].Cleanup();
|
||||||
pool[i].Cleanup();
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var mat in materialTable.Values)
|
foreach (var mat in materialTable.Values)
|
||||||
Destroy(mat);
|
Destroy(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//based on UnifyWiki http://wiki.unity3d.com/index.php?title=HexConverter
|
//based on UnifyWiki http://wiki.unity3d.com/index.php?title=HexConverter
|
||||||
static Color32 HexToColor (string hex) {
|
static Color32 HexToColor (string hex) {
|
||||||
if (hex.Length < 6)
|
if (hex.Length < 6)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user