From 4603b7eed3bf57af25ff195d807a2bc117435446 Mon Sep 17 00:00:00 2001 From: Yonsh Date: Sat, 15 Jun 2013 13:21:45 +0900 Subject: [PATCH] Fix: Unable to select in editor when flipped http://www.esotericsoftware.com/forum/viewtopic.php?f=3&t=823 --- spine-tk2d/Code/tk2dSpineSkeleton.cs | 32 ++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/spine-tk2d/Code/tk2dSpineSkeleton.cs b/spine-tk2d/Code/tk2dSpineSkeleton.cs index 4fe3c23ae..221258aa5 100644 --- a/spine-tk2d/Code/tk2dSpineSkeleton.cs +++ b/spine-tk2d/Code/tk2dSpineSkeleton.cs @@ -24,6 +24,11 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor private int[] triangles; private int cachedQuadCount; private float[] vertexPositions; + +#if UNITY_EDITOR + Vector3 gizmosCenter = new Vector3(); + Vector3 gizmosSize = new Vector3(); +#endif void Awake() { vertexPositions = new float[8]; @@ -73,6 +78,10 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor int quadIndex = 0; int drawCount = skeleton.DrawOrder.Count; Color currentColor = new Color(); + +#if UNITY_EDITOR + Vector3 min = new Vector3(float.MaxValue, float.MaxValue, 0), max = new Vector3(float.MinValue, float.MinValue, 0); +#endif for (int i = 0; i < drawCount; i++) { Slot slot = skeleton.DrawOrder[i]; @@ -114,8 +123,23 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor triangles[index + 5] = vertexIndex + 1; quadIndex++; +#if UNITY_EDITOR + min = Vector3.Min(min, vertices[vertexIndex + 0]); + min = Vector3.Min(min, vertices[vertexIndex + 1]); + min = Vector3.Min(min, vertices[vertexIndex + 2]); + min = Vector3.Min(min, vertices[vertexIndex + 3]); + max = Vector3.Max(max, vertices[vertexIndex + 0]); + max = Vector3.Max(max, vertices[vertexIndex + 1]); + max = Vector3.Max(max, vertices[vertexIndex + 2]); + max = Vector3.Max(max, vertices[vertexIndex + 3]); +#endif } } +#if UNITY_EDITOR + float width = max.x - min.x, height = max.y - min.y; + gizmosCenter = new Vector3(min.x + width / 2, min.y + height / 2, 0); + gizmosSize = new Vector3(Mathf.Abs(width), Mathf.Abs(height), 1); +#endif mesh.Clear(); @@ -138,6 +162,14 @@ public class tk2dSpineSkeleton : MonoBehaviour, tk2dRuntime.ISpriteCollectionFor renderer.sharedMaterial = skeletonDataAsset.spritesData.inst.materials[0]; } + +#if UNITY_EDITOR + void OnDrawGizmos() { + Gizmos.color = Color.clear; + Gizmos.matrix = transform.localToWorldMatrix; + Gizmos.DrawCube(gizmosCenter, gizmosSize); + } +#endif private void UpdateCache() { int quadCount = 0;