Fix: Unable to select in editor when flipped

http://www.esotericsoftware.com/forum/viewtopic.php?f=3&t=823
This commit is contained in:
Yonsh 2013-06-15 13:17:12 +09:00
parent baa70fa810
commit c2a79c43ed

View File

@ -43,6 +43,11 @@ public class SkeletonComponent : MonoBehaviour {
private int[] triangles;
private float[] vertexPositions = new float[8];
#if UNITY_EDITOR
Vector3 gizmosCenter = new Vector3();
Vector3 gizmosSize = new Vector3();
#endif
public virtual void Clear () {
GetComponent<MeshFilter>().mesh = null;
DestroyImmediate(mesh);
@ -132,6 +137,9 @@ public class SkeletonComponent : MonoBehaviour {
float[] vertexPositions = this.vertexPositions;
int vertexIndex = 0;
Color32 color = new Color32();
#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, n = drawOrder.Count; i < n; i++) {
Slot slot = drawOrder[i];
RegionAttachment regionAttachment = slot.Attachment as RegionAttachment;
@ -143,6 +151,16 @@ public class SkeletonComponent : MonoBehaviour {
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);
#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
color.a = (byte)(skeleton.A * slot.A * 255);
color.r = (byte)(skeleton.R * slot.R * color.a);
@ -165,8 +183,21 @@ public class SkeletonComponent : MonoBehaviour {
mesh.colors32 = colors;
mesh.uv = uvs;
if (newTriangles) mesh.triangles = triangles;
#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
}
#if UNITY_EDITOR
void OnDrawGizmos() {
Gizmos.color = Color.clear;
Gizmos.matrix = transform.localToWorldMatrix;
Gizmos.DrawCube(gizmosCenter, gizmosSize);
}
#endif
public virtual void OnEnable () {
Update();
}