mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-09 20:26:58 +08:00
parent
66a336e219
commit
86093e7d0d
@ -49,7 +49,6 @@ public class SkeletonAnimationInspector : Editor {
|
|||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
SkeletonAnimation component = (SkeletonAnimation)target;
|
SkeletonAnimation component = (SkeletonAnimation)target;
|
||||||
|
|
||||||
EditorGUIUtility.LookLikeInspector();
|
|
||||||
EditorGUILayout.PropertyField(skeletonDataAsset);
|
EditorGUILayout.PropertyField(skeletonDataAsset);
|
||||||
|
|
||||||
if (component.skeleton != null) {
|
if (component.skeleton != null) {
|
||||||
@ -67,7 +66,6 @@ public class SkeletonAnimationInspector : Editor {
|
|||||||
EditorGUILayout.LabelField("Initial Skin");
|
EditorGUILayout.LabelField("Initial Skin");
|
||||||
EditorGUIUtility.LookLikeControls();
|
EditorGUIUtility.LookLikeControls();
|
||||||
skinIndex = EditorGUILayout.Popup(skinIndex, skins);
|
skinIndex = EditorGUILayout.Popup(skinIndex, skins);
|
||||||
EditorGUIUtility.LookLikeInspector();
|
|
||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
|
|
||||||
initialSkinName.stringValue = skins[skinIndex];
|
initialSkinName.stringValue = skins[skinIndex];
|
||||||
@ -87,7 +85,6 @@ public class SkeletonAnimationInspector : Editor {
|
|||||||
EditorGUILayout.LabelField("Animation");
|
EditorGUILayout.LabelField("Animation");
|
||||||
EditorGUIUtility.LookLikeControls();
|
EditorGUIUtility.LookLikeControls();
|
||||||
animationIndex = EditorGUILayout.Popup(animationIndex, animations);
|
animationIndex = EditorGUILayout.Popup(animationIndex, animations);
|
||||||
EditorGUIUtility.LookLikeInspector();
|
|
||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
|
|
||||||
if (animationIndex == 0)
|
if (animationIndex == 0)
|
||||||
|
|||||||
@ -46,7 +46,6 @@ public class SkeletonComponentInspector : Editor {
|
|||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
SkeletonComponent component = (SkeletonComponent)target;
|
SkeletonComponent component = (SkeletonComponent)target;
|
||||||
|
|
||||||
EditorGUIUtility.LookLikeInspector();
|
|
||||||
EditorGUILayout.PropertyField(skeletonDataAsset);
|
EditorGUILayout.PropertyField(skeletonDataAsset);
|
||||||
|
|
||||||
if (component.skeleton != null) {
|
if (component.skeleton != null) {
|
||||||
@ -64,7 +63,6 @@ public class SkeletonComponentInspector : Editor {
|
|||||||
EditorGUILayout.LabelField("Initial Skin");
|
EditorGUILayout.LabelField("Initial Skin");
|
||||||
EditorGUIUtility.LookLikeControls();
|
EditorGUIUtility.LookLikeControls();
|
||||||
skinIndex = EditorGUILayout.Popup(skinIndex, skins);
|
skinIndex = EditorGUILayout.Popup(skinIndex, skins);
|
||||||
EditorGUIUtility.LookLikeInspector();
|
|
||||||
EditorGUILayout.EndHorizontal();
|
EditorGUILayout.EndHorizontal();
|
||||||
|
|
||||||
initialSkinName.stringValue = skins[skinIndex];
|
initialSkinName.stringValue = skins[skinIndex];
|
||||||
|
|||||||
@ -49,8 +49,6 @@ public class SkeletonDataAssetInspector : Editor {
|
|||||||
serializedObject.Update();
|
serializedObject.Update();
|
||||||
SkeletonDataAsset asset = (SkeletonDataAsset)target;
|
SkeletonDataAsset asset = (SkeletonDataAsset)target;
|
||||||
|
|
||||||
EditorGUIUtility.LookLikeInspector();
|
|
||||||
|
|
||||||
tk2dSpriteCollection sprites = EditorGUILayout.ObjectField("Sprite Collection", asset.spriteCollection, typeof(tk2dSpriteCollection), false) as tk2dSpriteCollection;
|
tk2dSpriteCollection sprites = EditorGUILayout.ObjectField("Sprite Collection", asset.spriteCollection, typeof(tk2dSpriteCollection), false) as tk2dSpriteCollection;
|
||||||
if (sprites != null)
|
if (sprites != null)
|
||||||
spriteCollection.objectReferenceValue = sprites.spriteCollection;
|
spriteCollection.objectReferenceValue = sprites.spriteCollection;
|
||||||
|
|||||||
@ -41,6 +41,7 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
public float timeScale = 1;
|
public float timeScale = 1;
|
||||||
public bool calculateNormals;
|
public bool calculateNormals;
|
||||||
public bool calculateTangents;
|
public bool calculateTangents;
|
||||||
|
public float zSpacing = 0.1f;
|
||||||
private MeshFilter meshFilter;
|
private MeshFilter meshFilter;
|
||||||
private Mesh mesh, mesh1, mesh2;
|
private Mesh mesh, mesh1, mesh2;
|
||||||
private bool useMesh1;
|
private bool useMesh1;
|
||||||
@ -161,7 +162,6 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
|
|
||||||
// Double buffer mesh.
|
// Double buffer mesh.
|
||||||
Mesh mesh = useMesh1 ? mesh1 : mesh2;
|
Mesh mesh = useMesh1 ? mesh1 : mesh2;
|
||||||
useMesh1 = !useMesh1;
|
|
||||||
meshFilter.sharedMesh = mesh;
|
meshFilter.sharedMesh = mesh;
|
||||||
|
|
||||||
// Ensure mesh data is the right size.
|
// Ensure mesh data is the right size.
|
||||||
@ -189,7 +189,7 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
Color32[] colors = this.colors;
|
Color32[] colors = this.colors;
|
||||||
int vertexIndex = 0;
|
int vertexIndex = 0;
|
||||||
Color32 color = new Color32();
|
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++) {
|
for (int i = 0, n = drawOrder.Count; i < n; i++) {
|
||||||
Slot slot = drawOrder[i];
|
Slot slot = drawOrder[i];
|
||||||
RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
|
RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
|
||||||
@ -197,11 +197,12 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
regionAttachment.ComputeWorldVertices(skeleton.X, skeleton.Y, slot.Bone, vertexPositions);
|
regionAttachment.ComputeWorldVertices(skeleton.X, skeleton.Y, slot.Bone, vertexPositions);
|
||||||
|
|
||||||
vertices[vertexIndex] = new Vector3(vertexPositions[RegionAttachment.X1], vertexPositions[RegionAttachment.Y1], 0);
|
float z = i * zSpacing;
|
||||||
vertices[vertexIndex + 1] = new Vector3(vertexPositions[RegionAttachment.X4], vertexPositions[RegionAttachment.Y4], 0);
|
vertices[vertexIndex] = new Vector3(vertexPositions[RegionAttachment.X1], vertexPositions[RegionAttachment.Y1], z);
|
||||||
vertices[vertexIndex + 2] = new Vector3(vertexPositions[RegionAttachment.X2], vertexPositions[RegionAttachment.Y2], 0);
|
vertices[vertexIndex + 1] = new Vector3(vertexPositions[RegionAttachment.X4], vertexPositions[RegionAttachment.Y4], z);
|
||||||
vertices[vertexIndex + 3] = new Vector3(vertexPositions[RegionAttachment.X3], vertexPositions[RegionAttachment.Y3], 0);
|
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.a = (byte)(a * slot.A);
|
||||||
color.r = (byte)(r * slot.R * color.a);
|
color.r = (byte)(r * slot.R * color.a);
|
||||||
@ -236,7 +237,7 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
Vector3 normal = new Vector3(0, 0, -1);
|
Vector3 normal = new Vector3(0, 0, -1);
|
||||||
for (int i = 0; i < vertexCount; i++)
|
for (int i = 0; i < vertexCount; i++)
|
||||||
normals[i] = normal;
|
normals[i] = normal;
|
||||||
(useMesh1 ? mesh1 : mesh2).vertices = vertices;
|
(useMesh1 ? mesh2 : mesh1).vertices = vertices; // Set other mesh vertices.
|
||||||
mesh1.normals = normals;
|
mesh1.normals = normals;
|
||||||
mesh2.normals = normals;
|
mesh2.normals = normals;
|
||||||
|
|
||||||
@ -249,6 +250,8 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
mesh2.tangents = tangents;
|
mesh2.tangents = tangents;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useMesh1 = !useMesh1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds a material. Adds submesh indexes if existing indexes aren't sufficient. */
|
/** Adds a material. Adds submesh indexes if existing indexes aren't sufficient. */
|
||||||
|
|||||||
@ -32,11 +32,17 @@ using Spine;
|
|||||||
using System;
|
using System;
|
||||||
|
|
||||||
public class Spineboy : MonoBehaviour {
|
public class Spineboy : MonoBehaviour {
|
||||||
private SkeletonAnimation skeleton;
|
private SkeletonAnimation skeletonAnimation;
|
||||||
|
|
||||||
void Start() {
|
void Start() {
|
||||||
skeleton = GetComponent<SkeletonAnimation>();
|
// Get the SkeletonAnimation component for the GameObject this script is attached to.
|
||||||
skeleton.state.Event += Event;
|
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) {
|
public void Event (Spine.AnimationState state, int trackIndex, Spine.Event e) {
|
||||||
@ -44,7 +50,9 @@ public class Spineboy : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseDown() {
|
void OnMouseDown() {
|
||||||
skeleton.state.SetAnimation(0, "jump", false);
|
// Set jump to be played on track 0 immediately.
|
||||||
skeleton.state.AddAnimation(0, "walk", true, 0);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@ -1,5 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 0030feb017e65e9408fb61bb0049fee9
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
userData:
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
fileFormatVersion: 2
|
|
||||||
guid: 0b313125884100344b0aee91d8822094
|
|
||||||
folderAsset: yes
|
|
||||||
DefaultImporter:
|
|
||||||
userData:
|
|
||||||
@ -41,6 +41,7 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
public float timeScale = 1;
|
public float timeScale = 1;
|
||||||
public bool calculateNormals;
|
public bool calculateNormals;
|
||||||
public bool calculateTangents;
|
public bool calculateTangents;
|
||||||
|
public float zSpacing = 0.1f;
|
||||||
private MeshFilter meshFilter;
|
private MeshFilter meshFilter;
|
||||||
private Mesh mesh, mesh1, mesh2;
|
private Mesh mesh, mesh1, mesh2;
|
||||||
private bool useMesh1;
|
private bool useMesh1;
|
||||||
@ -188,7 +189,7 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
Color32[] colors = this.colors;
|
Color32[] colors = this.colors;
|
||||||
int vertexIndex = 0;
|
int vertexIndex = 0;
|
||||||
Color32 color = new Color32();
|
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++) {
|
for (int i = 0, n = drawOrder.Count; i < n; i++) {
|
||||||
Slot slot = drawOrder[i];
|
Slot slot = drawOrder[i];
|
||||||
RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
|
RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
|
||||||
@ -197,7 +198,7 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
|
|
||||||
regionAttachment.ComputeWorldVertices(skeleton.X, skeleton.Y, slot.Bone, vertexPositions);
|
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] = new Vector3(vertexPositions[RegionAttachment.X1], vertexPositions[RegionAttachment.Y1], z);
|
||||||
vertices[vertexIndex + 1] = new Vector3(vertexPositions[RegionAttachment.X4], vertexPositions[RegionAttachment.Y4], 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 + 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);
|
Vector3 normal = new Vector3(0, 0, -1);
|
||||||
for (int i = 0; i < vertexCount; i++)
|
for (int i = 0; i < vertexCount; i++)
|
||||||
normals[i] = normal;
|
normals[i] = normal;
|
||||||
(useMesh1 ? mesh2 : mesh1).vertices = vertices;
|
(useMesh1 ? mesh2 : mesh1).vertices = vertices; // Set other mesh vertices.
|
||||||
mesh1.normals = normals;
|
mesh1.normals = normals;
|
||||||
mesh2.normals = normals;
|
mesh2.normals = normals;
|
||||||
|
|
||||||
@ -249,7 +250,7 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
mesh2.tangents = tangents;
|
mesh2.tangents = tangents;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useMesh1 = !useMesh1;
|
useMesh1 = !useMesh1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +261,7 @@ public class SkeletonComponent : MonoBehaviour {
|
|||||||
|
|
||||||
int indexCount = submeshQuadCount * 6;
|
int indexCount = submeshQuadCount * 6;
|
||||||
int vertexIndex = (endQuadCount - submeshQuadCount) * 4;
|
int vertexIndex = (endQuadCount - submeshQuadCount) * 4;
|
||||||
|
|
||||||
if (submeshes.Count <= submeshIndex) submeshes.Add(new Submesh());
|
if (submeshes.Count <= submeshIndex) submeshes.Add(new Submesh());
|
||||||
Submesh submesh = submeshes[submeshIndex];
|
Submesh submesh = submeshes[submeshIndex];
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@ -35,8 +35,14 @@ public class Spineboy : MonoBehaviour {
|
|||||||
SkeletonAnimation skeletonAnimation;
|
SkeletonAnimation skeletonAnimation;
|
||||||
|
|
||||||
public void Start () {
|
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;
|
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) {
|
public void Event (Spine.AnimationState state, int trackIndex, Spine.Event e) {
|
||||||
@ -44,7 +50,9 @@ public class Spineboy : MonoBehaviour {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OnMouseDown () {
|
public void OnMouseDown () {
|
||||||
|
// Set jump to be played on track 0 immediately.
|
||||||
skeletonAnimation.state.SetAnimation(0, "jump", false);
|
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);
|
skeletonAnimation.state.AddAnimation(0, "walk", true, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user