[unity] Restored AtlasAsset inspector region list.

This commit is contained in:
John 2016-09-27 01:45:44 +08:00 committed by GitHub
parent 721de143d2
commit 9bb546c6d6

View File

@ -56,6 +56,13 @@ namespace Spine.Unity.Editor {
UpdateBakedList(); UpdateBakedList();
#endif #endif
} }
private List<AtlasRegion> Regions {
get {
FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.NonPublic);
return (List<AtlasRegion>)field.GetValue(atlasAsset.GetAtlas());
}
}
#if REGION_BAKING_MESH #if REGION_BAKING_MESH
private List<bool> baked; private List<bool> baked;
@ -92,8 +99,7 @@ namespace Spine.Unity.Editor {
var spriteSheet = t.spritesheet; var spriteSheet = t.spritesheet;
var sprites = new List<SpriteMetaData>(spriteSheet); var sprites = new List<SpriteMetaData>(spriteSheet);
FieldInfo field = typeof(Atlas).GetField("regions", BindingFlags.Instance | BindingFlags.NonPublic); var regions = this.Regions;
var regions = (List<AtlasRegion>)field.GetValue(atlas);
int textureHeight = texture.height; int textureHeight = texture.height;
char[] FilenameDelimiter = {'.'}; char[] FilenameDelimiter = {'.'};
int updatedCount = 0; int updatedCount = 0;
@ -168,20 +174,27 @@ namespace Spine.Unity.Editor {
} }
} }
EditorGUILayout.Space();
if (atlasFile.objectReferenceValue != null) { if (atlasFile.objectReferenceValue != null) {
if (GUILayout.Button( using (new EditorGUILayout.HorizontalScope()) {
new GUIContent( EditorGUILayout.Space();
"Apply Regions as Texture Sprite Slices", if (GUILayout.Button(
"Adds Sprite slices to atlas texture(s). " + new GUIContent(
"Updates existing slices if ones with matching names exist. \n\n" + "Apply Regions as Texture Sprite Slices",
"If your atlas was exported with Premultiply Alpha, " + SpineEditorUtilities.Icons.unityIcon,
"your SpriteRenderer should use the generated Spine _Material asset (or any Material with a PMA shader) instead of Sprites-Default.") "Adds Sprite slices to atlas texture(s). " +
, GUILayout.Height(70f))) { "Updates existing slices if ones with matching names exist. \n\n" +
var atlas = atlasAsset.GetAtlas(); "If your atlas was exported with Premultiply Alpha, " +
foreach (var m in atlasAsset.materials) "your SpriteRenderer should use the generated Spine _Material asset (or any Material with a PMA shader) instead of Sprites-Default.")
UpdateSpriteSlices(m.mainTexture, atlas); , GUILayout.Height(30f))) {
var atlas = atlasAsset.GetAtlas();
foreach (var m in atlasAsset.materials)
UpdateSpriteSlices(m.mainTexture, atlas);
}
EditorGUILayout.Space();
} }
} }
EditorGUILayout.Space();
#if REGION_BAKING_MESH #if REGION_BAKING_MESH
if (atlasFile.objectReferenceValue != null) { if (atlasFile.objectReferenceValue != null) {
@ -289,6 +302,39 @@ namespace Spine.Unity.Editor {
#endif #endif
} }
#else
if (atlasFile.objectReferenceValue != null) {
EditorGUILayout.LabelField("Atlas Regions", EditorStyles.boldLabel);
var regions = this.Regions;
AtlasPage lastPage = null;
for (int i = 0; i < regions.Count; i++) {
if (lastPage != regions[i].page) {
if (lastPage != null) {
EditorGUILayout.Separator();
EditorGUILayout.Separator();
}
lastPage = regions[i].page;
Material mat = ((Material)lastPage.rendererObject);
if (mat != null) {
GUILayout.BeginHorizontal();
{
EditorGUI.BeginDisabledGroup(true);
EditorGUILayout.ObjectField(mat, typeof(Material), false, GUILayout.Width(250));
EditorGUI.EndDisabledGroup();
EditorGUI.indentLevel++;
}
GUILayout.EndHorizontal();
} else {
EditorGUILayout.LabelField(new GUIContent("Page missing material!", SpineEditorUtilities.Icons.warning));
}
}
EditorGUILayout.LabelField(new GUIContent(regions[i].name, SpineEditorUtilities.Icons.image));
}
EditorGUI.indentLevel--;
}
#endif #endif
if (serializedObject.ApplyModifiedProperties() || if (serializedObject.ApplyModifiedProperties() ||