Clean up, added zSpacing.

#166
This commit is contained in:
NathanSweet 2014-02-05 18:10:07 +01:00
parent 66a336e219
commit 86093e7d0d
12 changed files with 39 additions and 36 deletions

View File

@ -49,7 +49,6 @@ public class SkeletonAnimationInspector : Editor {
serializedObject.Update();
SkeletonAnimation component = (SkeletonAnimation)target;
EditorGUIUtility.LookLikeInspector();
EditorGUILayout.PropertyField(skeletonDataAsset);
if (component.skeleton != null) {
@ -67,7 +66,6 @@ public class SkeletonAnimationInspector : Editor {
EditorGUILayout.LabelField("Initial Skin");
EditorGUIUtility.LookLikeControls();
skinIndex = EditorGUILayout.Popup(skinIndex, skins);
EditorGUIUtility.LookLikeInspector();
EditorGUILayout.EndHorizontal();
initialSkinName.stringValue = skins[skinIndex];
@ -87,7 +85,6 @@ public class SkeletonAnimationInspector : Editor {
EditorGUILayout.LabelField("Animation");
EditorGUIUtility.LookLikeControls();
animationIndex = EditorGUILayout.Popup(animationIndex, animations);
EditorGUIUtility.LookLikeInspector();
EditorGUILayout.EndHorizontal();
if (animationIndex == 0)

View File

@ -46,7 +46,6 @@ public class SkeletonComponentInspector : Editor {
serializedObject.Update();
SkeletonComponent component = (SkeletonComponent)target;
EditorGUIUtility.LookLikeInspector();
EditorGUILayout.PropertyField(skeletonDataAsset);
if (component.skeleton != null) {
@ -64,7 +63,6 @@ public class SkeletonComponentInspector : Editor {
EditorGUILayout.LabelField("Initial Skin");
EditorGUIUtility.LookLikeControls();
skinIndex = EditorGUILayout.Popup(skinIndex, skins);
EditorGUIUtility.LookLikeInspector();
EditorGUILayout.EndHorizontal();
initialSkinName.stringValue = skins[skinIndex];

View File

@ -49,8 +49,6 @@ public class SkeletonDataAssetInspector : Editor {
serializedObject.Update();
SkeletonDataAsset asset = (SkeletonDataAsset)target;
EditorGUIUtility.LookLikeInspector();
tk2dSpriteCollection sprites = EditorGUILayout.ObjectField("Sprite Collection", asset.spriteCollection, typeof(tk2dSpriteCollection), false) as tk2dSpriteCollection;
if (sprites != null)
spriteCollection.objectReferenceValue = sprites.spriteCollection;

View File

@ -41,6 +41,7 @@ public class SkeletonComponent : MonoBehaviour {
public float timeScale = 1;
public bool calculateNormals;
public bool calculateTangents;
public float zSpacing = 0.1f;
private MeshFilter meshFilter;
private Mesh mesh, mesh1, mesh2;
private bool useMesh1;
@ -161,7 +162,6 @@ public class SkeletonComponent : MonoBehaviour {
// Double buffer mesh.
Mesh mesh = useMesh1 ? mesh1 : mesh2;
useMesh1 = !useMesh1;
meshFilter.sharedMesh = mesh;
// Ensure mesh data is the right size.
@ -189,7 +189,7 @@ public class SkeletonComponent : MonoBehaviour {
Color32[] colors = this.colors;
int vertexIndex = 0;
Color32 color = new Color32();
float a = skeleton.A * 255, r = skeleton.R, g = skeleton.G, b = skeleton.B;
float a = skeleton.A * 255, r = skeleton.R, g = skeleton.G, b = skeleton.B, zSpacing = this.zSpacing;
for (int i = 0, n = drawOrder.Count; i < n; i++) {
Slot slot = drawOrder[i];
RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
@ -197,11 +197,12 @@ public class SkeletonComponent : MonoBehaviour {
continue;
regionAttachment.ComputeWorldVertices(skeleton.X, skeleton.Y, slot.Bone, vertexPositions);
vertices[vertexIndex] = new Vector3(vertexPositions[RegionAttachment.X1], vertexPositions[RegionAttachment.Y1], 0);
vertices[vertexIndex + 1] = new Vector3(vertexPositions[RegionAttachment.X4], vertexPositions[RegionAttachment.Y4], 0);
vertices[vertexIndex + 2] = new Vector3(vertexPositions[RegionAttachment.X2], vertexPositions[RegionAttachment.Y2], 0);
vertices[vertexIndex + 3] = new Vector3(vertexPositions[RegionAttachment.X3], vertexPositions[RegionAttachment.Y3], 0);
float z = i * zSpacing;
vertices[vertexIndex] = new Vector3(vertexPositions[RegionAttachment.X1], vertexPositions[RegionAttachment.Y1], z);
vertices[vertexIndex + 1] = new Vector3(vertexPositions[RegionAttachment.X4], vertexPositions[RegionAttachment.Y4], z);
vertices[vertexIndex + 2] = new Vector3(vertexPositions[RegionAttachment.X2], vertexPositions[RegionAttachment.Y2], z);
vertices[vertexIndex + 3] = new Vector3(vertexPositions[RegionAttachment.X3], vertexPositions[RegionAttachment.Y3], z);
color.a = (byte)(a * slot.A);
color.r = (byte)(r * slot.R * color.a);
@ -236,7 +237,7 @@ public class SkeletonComponent : MonoBehaviour {
Vector3 normal = new Vector3(0, 0, -1);
for (int i = 0; i < vertexCount; i++)
normals[i] = normal;
(useMesh1 ? mesh1 : mesh2).vertices = vertices;
(useMesh1 ? mesh2 : mesh1).vertices = vertices; // Set other mesh vertices.
mesh1.normals = normals;
mesh2.normals = normals;
@ -249,6 +250,8 @@ public class SkeletonComponent : MonoBehaviour {
mesh2.tangents = tangents;
}
}
useMesh1 = !useMesh1;
}
/** Adds a material. Adds submesh indexes if existing indexes aren't sufficient. */

View File

@ -32,11 +32,17 @@ using Spine;
using System;
public class Spineboy : MonoBehaviour {
private SkeletonAnimation skeleton;
private SkeletonAnimation skeletonAnimation;
void Start() {
skeleton = GetComponent<SkeletonAnimation>();
skeleton.state.Event += Event;
// Get the SkeletonAnimation component for the GameObject this script is attached to.
skeletonAnimation = GetComponent<SkeletonAnimation>();
// Call our method any time an animation fires an event.
skeletonAnimation.state.Event += Event;
// Queue jump to be played on track 0 after the starting animation.
skeletonAnimation.state.AddAnimation(0, "jump", false, 0);
// Queue walk to be looped on track 0 after the jump animation.
skeletonAnimation.state.AddAnimation(0, "walk", true, 0);
}
public void Event (Spine.AnimationState state, int trackIndex, Spine.Event e) {
@ -44,7 +50,9 @@ public class Spineboy : MonoBehaviour {
}
void OnMouseDown() {
skeleton.state.SetAnimation(0, "jump", false);
skeleton.state.AddAnimation(0, "walk", true, 0);
// Set jump to be played on track 0 immediately.
skeletonAnimation.state.SetAnimation(0, "jump", false);
// Queue walk to be looped on track 0 after the jump animation.
skeletonAnimation.state.AddAnimation(0, "walk", true, 0);
}
}

View File

@ -1,5 +0,0 @@
fileFormatVersion: 2
guid: 0030feb017e65e9408fb61bb0049fee9
folderAsset: yes
DefaultImporter:
userData:

View File

@ -1,5 +0,0 @@
fileFormatVersion: 2
guid: 0b313125884100344b0aee91d8822094
folderAsset: yes
DefaultImporter:
userData:

View File

@ -41,6 +41,7 @@ public class SkeletonComponent : MonoBehaviour {
public float timeScale = 1;
public bool calculateNormals;
public bool calculateTangents;
public float zSpacing = 0.1f;
private MeshFilter meshFilter;
private Mesh mesh, mesh1, mesh2;
private bool useMesh1;
@ -188,7 +189,7 @@ public class SkeletonComponent : MonoBehaviour {
Color32[] colors = this.colors;
int vertexIndex = 0;
Color32 color = new Color32();
float a = skeleton.A * 255, r = skeleton.R, g = skeleton.G, b = skeleton.B;
float a = skeleton.A * 255, r = skeleton.R, g = skeleton.G, b = skeleton.B, zSpacing = this.zSpacing;
for (int i = 0, n = drawOrder.Count; i < n; i++) {
Slot slot = drawOrder[i];
RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
@ -197,7 +198,7 @@ public class SkeletonComponent : MonoBehaviour {
regionAttachment.ComputeWorldVertices(skeleton.X, skeleton.Y, slot.Bone, vertexPositions);
float z = -i * 0.1f;
float z = i * zSpacing;
vertices[vertexIndex] = new Vector3(vertexPositions[RegionAttachment.X1], vertexPositions[RegionAttachment.Y1], z);
vertices[vertexIndex + 1] = new Vector3(vertexPositions[RegionAttachment.X4], vertexPositions[RegionAttachment.Y4], z);
vertices[vertexIndex + 2] = new Vector3(vertexPositions[RegionAttachment.X2], vertexPositions[RegionAttachment.Y2], z);
@ -236,7 +237,7 @@ public class SkeletonComponent : MonoBehaviour {
Vector3 normal = new Vector3(0, 0, -1);
for (int i = 0; i < vertexCount; i++)
normals[i] = normal;
(useMesh1 ? mesh2 : mesh1).vertices = vertices;
(useMesh1 ? mesh2 : mesh1).vertices = vertices; // Set other mesh vertices.
mesh1.normals = normals;
mesh2.normals = normals;
@ -249,7 +250,7 @@ public class SkeletonComponent : MonoBehaviour {
mesh2.tangents = tangents;
}
}
useMesh1 = !useMesh1;
}
@ -260,7 +261,7 @@ public class SkeletonComponent : MonoBehaviour {
int indexCount = submeshQuadCount * 6;
int vertexIndex = (endQuadCount - submeshQuadCount) * 4;
if (submeshes.Count <= submeshIndex) submeshes.Add(new Submesh());
Submesh submesh = submeshes[submeshIndex];

View File

@ -35,8 +35,14 @@ public class Spineboy : MonoBehaviour {
SkeletonAnimation skeletonAnimation;
public void Start () {
skeletonAnimation = GetComponent<SkeletonAnimation>();
// Get the SkeletonAnimation component for the GameObject this script is attached to.
skeletonAnimation = GetComponent<SkeletonAnimation>();
// Call our method any time an animation fires an event.
skeletonAnimation.state.Event += Event;
// Queue jump to be played on track 0 after the starting animation.
skeletonAnimation.state.AddAnimation(0, "jump", false, 0);
// Queue walk to be looped on track 0 after the jump animation.
skeletonAnimation.state.AddAnimation(0, "walk", true, 0);
}
public void Event (Spine.AnimationState state, int trackIndex, Spine.Event e) {
@ -44,7 +50,9 @@ public class Spineboy : MonoBehaviour {
}
public void OnMouseDown () {
// Set jump to be played on track 0 immediately.
skeletonAnimation.state.SetAnimation(0, "jump", false);
// Queue walk to be looped on track 0 after the jump animation.
skeletonAnimation.state.AddAnimation(0, "walk", true, 0);
}
}