mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-10 12:46:56 +08:00
commit
825259dbdb
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 8dc542c228b046648ae29be625ecd1b4
|
||||||
|
MonoImporter:
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
@ -38,7 +38,7 @@ using Spine;
|
|||||||
[ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
|
[ExecuteInEditMode, RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
|
||||||
public class SkeletonRenderer : MonoBehaviour {
|
public class SkeletonRenderer : MonoBehaviour {
|
||||||
|
|
||||||
public delegate void SkeletonRendererDelegate(SkeletonRenderer skeletonRenderer);
|
public delegate void SkeletonRendererDelegate (SkeletonRenderer skeletonRenderer);
|
||||||
|
|
||||||
public SkeletonRendererDelegate OnReset;
|
public SkeletonRendererDelegate OnReset;
|
||||||
[System.NonSerialized]
|
[System.NonSerialized]
|
||||||
@ -73,11 +73,26 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
private readonly List<Submesh> submeshes = new List<Submesh>();
|
private readonly List<Submesh> submeshes = new List<Submesh>();
|
||||||
|
|
||||||
|
|
||||||
public virtual void Reset() {
|
public virtual void Reset () {
|
||||||
if (meshFilter != null)
|
if (meshFilter != null)
|
||||||
meshFilter.sharedMesh = null;
|
meshFilter.sharedMesh = null;
|
||||||
if (renderer != null)
|
if (renderer != null)
|
||||||
renderer.sharedMaterial = null;
|
renderer.sharedMaterial = null;
|
||||||
|
|
||||||
|
if (mesh1 != null) {
|
||||||
|
if (Application.isPlaying)
|
||||||
|
Destroy(mesh1);
|
||||||
|
else
|
||||||
|
DestroyImmediate(mesh1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mesh2 != null) {
|
||||||
|
if (Application.isPlaying)
|
||||||
|
Destroy(mesh2);
|
||||||
|
else
|
||||||
|
DestroyImmediate(mesh2);
|
||||||
|
}
|
||||||
|
|
||||||
mesh1 = null;
|
mesh1 = null;
|
||||||
mesh2 = null;
|
mesh2 = null;
|
||||||
lastVertexCount = 0;
|
lastVertexCount = 0;
|
||||||
@ -115,22 +130,16 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
submeshSeparatorSlots.Add(skeleton.FindSlot(submeshSeparators[i]));
|
submeshSeparatorSlots.Add(skeleton.FindSlot(submeshSeparators[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Store flipped triangles for meshes
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (OnReset != null)
|
if (OnReset != null)
|
||||||
OnReset(this);
|
OnReset(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void OnEnable() {
|
public virtual void Awake () {
|
||||||
if (mesh1 == null || mesh2 == null)
|
Reset();
|
||||||
Reset();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void OnDisable() {
|
public virtual void OnDestroy () {
|
||||||
if (Application.isPlaying && gameObject.activeInHierarchy == false) {
|
if (Application.isPlaying) {
|
||||||
if (mesh1 != null) {
|
if (mesh1 != null) {
|
||||||
Destroy(mesh1);
|
Destroy(mesh1);
|
||||||
mesh1 = null;
|
mesh1 = null;
|
||||||
@ -140,11 +149,10 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
Destroy(mesh2);
|
Destroy(mesh2);
|
||||||
mesh2 = null;
|
mesh2 = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Mesh newMesh() {
|
private Mesh newMesh () {
|
||||||
Mesh mesh = new Mesh();
|
Mesh mesh = new Mesh();
|
||||||
mesh.name = "Skeleton Mesh";
|
mesh.name = "Skeleton Mesh";
|
||||||
mesh.hideFlags = HideFlags.HideAndDontSave;
|
mesh.hideFlags = HideFlags.HideAndDontSave;
|
||||||
@ -152,7 +160,7 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void LateUpdate() {
|
public virtual void LateUpdate () {
|
||||||
if (!valid)
|
if (!valid)
|
||||||
return;
|
return;
|
||||||
// Count vertices and submesh triangles.
|
// Count vertices and submesh triangles.
|
||||||
@ -357,7 +365,7 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Stores vertices and triangles for a single material. */
|
/** Stores vertices and triangles for a single material. */
|
||||||
private void AddSubmesh(Material material, int startSlot, int endSlot, int triangleCount, int firstVertex, bool lastSubmesh) {
|
private void AddSubmesh (Material material, int startSlot, int endSlot, int triangleCount, int firstVertex, bool lastSubmesh) {
|
||||||
int submeshIndex = submeshMaterials.Count;
|
int submeshIndex = submeshMaterials.Count;
|
||||||
submeshMaterials.Add(material);
|
submeshMaterials.Add(material);
|
||||||
|
|
||||||
@ -457,7 +465,7 @@ public class SkeletonRenderer : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_EDITOR
|
#if UNITY_EDITOR
|
||||||
void OnDrawGizmos() {
|
void OnDrawGizmos () {
|
||||||
// Make selection easier by drawing a clear gizmo over the skeleton.
|
// Make selection easier by drawing a clear gizmo over the skeleton.
|
||||||
if (vertices == null) return;
|
if (vertices == null) return;
|
||||||
Vector3 gizmosCenter = new Vector3();
|
Vector3 gizmosCenter = new Vector3();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user