From acd50548d5ee09ea11637525970142d332d20cf7 Mon Sep 17 00:00:00 2001 From: pharan Date: Fri, 23 Dec 2016 10:16:39 +0800 Subject: [PATCH] [unity] Updated editors. --- .../Editor/SkeletonDataAssetInspector.cs | 20 +-- .../spine-unity/Editor/GUI/icon-path.png | Bin 0 -> 519 bytes .../spine-unity/Editor/GUI/icon-path.png.meta | 59 +++++++++ .../Editor/SpineEditorUtilities.cs | 116 ++++++++++++------ .../Editor/SkeletonUtilityBoneInspector.cs | 10 +- .../Editor/SkeletonUtilityInspector.cs | 2 +- .../SkeletonUtility/SkeletonUtility.cs | 1 - 7 files changed, 149 insertions(+), 59 deletions(-) create mode 100644 spine-unity/Assets/spine-unity/Editor/GUI/icon-path.png create mode 100644 spine-unity/Assets/spine-unity/Editor/GUI/icon-path.png.meta diff --git a/spine-unity/Assets/spine-unity/Asset Types/Editor/SkeletonDataAssetInspector.cs b/spine-unity/Assets/spine-unity/Asset Types/Editor/SkeletonDataAssetInspector.cs index 48f698ff5..8431caa96 100644 --- a/spine-unity/Assets/spine-unity/Asset Types/Editor/SkeletonDataAssetInspector.cs +++ b/spine-unity/Assets/spine-unity/Asset Types/Editor/SkeletonDataAssetInspector.cs @@ -482,24 +482,8 @@ namespace Spine.Unity.Editor { for (int a = 0; a < slotAttachments.Count; a++) { Attachment attachment = slotAttachments[a]; string attachmentName = slotAttachmentNames[a]; - - Texture2D icon = null; - var type = attachment.GetType(); - - if (type == typeof(RegionAttachment)) - icon = Icons.image; - else if (type == typeof(MeshAttachment)) - icon = Icons.mesh; - else if (type == typeof(BoundingBoxAttachment)) - icon = Icons.boundingBox; - else if (type == typeof(PathAttachment)) - icon = Icons.boundingBox; - else - icon = Icons.warning; - //JOHN: left todo: Icon for paths. Generic icon for unidentified attachments. - + Texture2D icon = Icons.GetAttachmentIcon(attachment); bool initialState = slot.Attachment == attachment; - bool toggled = EditorGUILayout.ToggleLeft(new GUIContent(attachmentName, icon), slot.Attachment == attachment); if (!defaultSkinAttachmentNames.Contains(attachmentName)) { @@ -526,7 +510,7 @@ namespace Spine.Unity.Editor { if (skeletonJSON.objectReferenceValue == null) { warnings.Add("Missing Skeleton JSON"); } else { - if (SpineEditorUtilities.IsValidSpineData((TextAsset)skeletonJSON.objectReferenceValue) == false) { + if (SpineEditorUtilities.IsSpineData((TextAsset)skeletonJSON.objectReferenceValue) == false) { warnings.Add("Skeleton data file is not a valid JSON or binary file."); } else { #if !SPINE_TK2D diff --git a/spine-unity/Assets/spine-unity/Editor/GUI/icon-path.png b/spine-unity/Assets/spine-unity/Editor/GUI/icon-path.png new file mode 100644 index 0000000000000000000000000000000000000000..604ae0d6140aad67f8259cfd2c7fcc19c1a39c69 GIT binary patch literal 519 zcmV+i0{H!jP)LMhu7rkoX^f z_!T|_*q|D?VEpB|vNvIpk&_>*<1>Ii(3H>6O_wK`n}f*)$o~(-jK~TExS5$heErJ` zWc~*6nRO)LavV|C0@l7pyptFi8CYI^{JZwS>t7q*eExexLV(2|rpQW_i{tX+A9p`} z|Mwc*1p@Y(+!;T9{lA+w=V>O8{{?Cb4-kW#&5-3Pq+_AV)tBldbh&Qz%LhQA&rC=L zaB#9Q>OTMQdpA_0I1tM~!vhp>x2ElWcjW7je@Ddln5|%8gzN&4e}8@X`R^l06PAGc z4hm3K7DkaTKmOf-g#mgX{%2xj#E2O$172}M1rA4LarQ(OW(L8%SH83Zg+F1q;2+Qp z-0Vzz=mvyY@=pP}@8{Q_|1NI3@Okmp^PevPh5ulB;XlJSeoiI@ke{K>X3&ym=VAsr z3mEcmfZQL@@c50M4nV1m^ZmEKhxs^|^r7OnKoZxU{)7eeKYU3UCD2kF1&!zIfBzQ9 z{E15=3@~96JbVAgGh}CyY{2;k-#-(w8Qlx;KtsxLL;-*R0|27=l}V@`-1z_i002ov JPDHLkV1ku8?SudT literal 0 HcmV?d00001 diff --git a/spine-unity/Assets/spine-unity/Editor/GUI/icon-path.png.meta b/spine-unity/Assets/spine-unity/Editor/GUI/icon-path.png.meta new file mode 100644 index 000000000..8aebfb760 --- /dev/null +++ b/spine-unity/Assets/spine-unity/Editor/GUI/icon-path.png.meta @@ -0,0 +1,59 @@ +fileFormatVersion: 2 +guid: dbc817a6c9e9c5747b7f6261bf5d1d09 +timeCreated: 1482240904 +licenseType: Free +TextureImporter: + fileIDToRecycleName: {} + serializedVersion: 2 + mipmaps: + mipMapMode: 0 + enableMipMap: 0 + linearTexture: 1 + correctGamma: 0 + fadeOut: 0 + borderMipMap: 0 + mipMapFadeDistanceStart: 1 + mipMapFadeDistanceEnd: 3 + bumpmap: + convertToNormalMap: 0 + externalNormalMap: 0 + heightScale: 0.25 + normalMapFilter: 0 + isReadable: 0 + grayScaleToAlpha: 0 + generateCubemap: 0 + cubemapConvolution: 0 + cubemapConvolutionSteps: 7 + cubemapConvolutionExponent: 1.5 + seamlessCubemap: 0 + textureFormat: -3 + maxTextureSize: 1024 + textureSettings: + filterMode: -1 + aniso: 1 + mipBias: -1 + wrapMode: 1 + nPOTScale: 0 + lightmap: 0 + rGBM: 0 + compressionQuality: 50 + allowsAlphaSplitting: 0 + spriteMode: 0 + spriteExtrude: 1 + spriteMeshType: 1 + alignment: 0 + spritePivot: {x: 0.5, y: 0.5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} + spritePixelsToUnits: 100 + alphaIsTransparency: 1 + spriteTessellationDetail: -1 + textureType: 2 + buildTargetSettings: [] + spriteSheet: + serializedVersion: 2 + sprites: [] + outline: [] + spritePackingTag: + userData: + assetBundleName: + assetBundleVariant: diff --git a/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs b/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs index 7db3a9304..8c0f2d24d 100644 --- a/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs +++ b/spine-unity/Assets/spine-unity/Editor/SpineEditorUtilities.cs @@ -62,6 +62,7 @@ namespace Spine.Unity.Editor { public static Texture2D boundingBox; public static Texture2D mesh; public static Texture2D weights; + public static Texture2D path; public static Texture2D skin; public static Texture2D skinsRoot; public static Texture2D animation; @@ -100,10 +101,25 @@ namespace Spine.Unity.Editor { skeletonUtility = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-skeletonUtility.png"); hingeChain = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-hingeChain.png"); subMeshRenderer = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-subMeshRenderer.png"); + path = (Texture2D)AssetDatabase.LoadMainAssetAtPath(SpineEditorUtilities.editorGUIPath + "/icon-path.png"); unityIcon = EditorGUIUtility.FindTexture("SceneAsset Icon"); controllerIcon = EditorGUIUtility.FindTexture("AnimatorController Icon"); } + + public static Texture2D GetAttachmentIcon (Attachment attachment) { + if (attachment is RegionAttachment) + return Icons.image; + // Analysis disable once CanBeReplacedWithTryCastAndCheckForNull + else if (attachment is MeshAttachment) + return ((MeshAttachment)attachment).IsWeighted() ? Icons.weights : Icons.mesh; + else if (attachment is BoundingBoxAttachment) + return Icons.boundingBox; + else if (attachment is PathAttachment) + return Icons.path; + else + return Icons.warning; + } } public static string editorPath = ""; @@ -551,12 +567,12 @@ namespace Spine.Unity.Editor { imagePaths.Add(str); break; case ".json": - if (IsValidSpineData((TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset)))) + if (IsSpineData((TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset)))) skeletonPaths.Add(str); break; case ".bytes": if (str.ToLower().EndsWith(".skel.bytes", System.StringComparison.Ordinal)) { - if (IsValidSpineData((TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset)))) + if (IsSpineData((TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset)))) skeletonPaths.Add(str); } break; @@ -602,7 +618,7 @@ namespace Spine.Unity.Editor { switch (result) { case -1: - Debug.Log("Select Atlas"); + //Debug.Log("Select Atlas"); AtlasAsset selectedAtlas = GetAtlasDialog(Path.GetDirectoryName(sp)); if (selectedAtlas != null) { localAtlases.Clear(); @@ -1167,37 +1183,52 @@ namespace Spine.Unity.Editor { return false; } - public static bool IsValidSpineData (TextAsset asset) { - if (asset.name.Contains(".skel")) return true; + public static bool IsSpineData (TextAsset asset) { + bool isSpineData = false; + string rawVersion = null; - object obj = null; - obj = Json.Deserialize(new StringReader(asset.text)); + if (asset.name.Contains(".skel")) { + try { + rawVersion = SkeletonBinary.GetVersionString(new MemoryStream(asset.bytes)); + //Debug.Log(rawVersion); + } catch (System.Exception e) { + Debug.LogErrorFormat("Failed to read '{0}'. It is likely not a binary Spine SkeletonData file.\n{1}", asset.name, e); + return false; + } + } else { + var obj = Json.Deserialize(new StringReader(asset.text)); + if (obj == null) { + Debug.LogErrorFormat("'{0}' is not valid JSON.", asset.name); + return false; + } - if (obj == null) { - Debug.LogError("Is not valid JSON."); - return false; + var root = obj as Dictionary; + if (root == null) { + Debug.LogError("Parser returned an incorrect type."); + return false; + } + + isSpineData = root.ContainsKey("skeleton"); + if (isSpineData) { + var skeletonInfo = (Dictionary)root["skeleton"]; + object jv; + skeletonInfo.TryGetValue("spine", out jv); + rawVersion = jv as string; + } } - var root = obj as Dictionary; - if (root == null) { - Debug.LogError("Parser returned an incorrect type."); - return false; - } - - bool isSpineJson = root.ContainsKey("skeleton"); - // Version warning - if (isSpineJson) { - var skeletonInfo = (Dictionary)root["skeleton"]; - object jv; - skeletonInfo.TryGetValue("spine", out jv); - string jsonVersion = jv as string; - if (!string.IsNullOrEmpty(jsonVersion)) { - string[] jsonVersionSplit = jsonVersion.Split('.'); + { + string runtimeVersion = compatibleVersions[0][0] + "." + compatibleVersions[0][1]; + + if (string.IsNullOrEmpty(rawVersion)) { + Debug.LogWarningFormat("Skeleton '{0}' has no version information. It may be incompatible with your runtime version: spine-unity v{1}", asset.name, runtimeVersion); + } else { + string[] versionSplit = rawVersion.Split('.'); bool match = false; foreach (var version in compatibleVersions) { - bool primaryMatch = version[0] == int.Parse(jsonVersionSplit[0]); - bool secondaryMatch = version[1] == int.Parse(jsonVersionSplit[1]); + bool primaryMatch = version[0] == int.Parse(versionSplit[0]); + bool secondaryMatch = version[1] == int.Parse(versionSplit[1]); // if (isFixVersionRequired) secondaryMatch &= version[2] <= int.Parse(jsonVersionSplit[2]); @@ -1207,16 +1238,12 @@ namespace Spine.Unity.Editor { } } - if (!match) { - string runtimeVersion = compatibleVersions[0][0] + "." + compatibleVersions[0][1]; - Debug.LogWarning(string.Format("Skeleton '{0}' (exported with Spine {1}) may be incompatible with your runtime version: spine-unity v{2}", asset.name, jsonVersion, runtimeVersion)); - } - } else { - isSpineJson = false; + if (!match) + Debug.LogWarningFormat("Skeleton '{0}' (exported with Spine {1}) may be incompatible with your runtime version: spine-unity v{2}", asset.name, rawVersion, runtimeVersion); } } - - return isSpineJson; + + return isSpineData; } #endregion @@ -1434,6 +1461,25 @@ namespace Spine.Unity.Editor { public static string GetPathSafeRegionName (AtlasRegion region) { return region.name.Replace("/", "_"); } + + internal static int ReadVarint (Stream input, bool optimizePositive) { + int b = input.ReadByte(); + int result = b & 0x7F; + if ((b & 0x80) != 0) { + b = input.ReadByte(); + result |= (b & 0x7F) << 7; + if ((b & 0x80) != 0) { + b = input.ReadByte(); + result |= (b & 0x7F) << 14; + if ((b & 0x80) != 0) { + b = input.ReadByte(); + result |= (b & 0x7F) << 21; + if ((b & 0x80) != 0) result |= (input.ReadByte() & 0x7F) << 28; + } + } + } + return optimizePositive ? result : ((result >> 1) ^ -(result & 1)); + } } public static class SpineHandles { diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs index 22a290666..e6acd6227 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs @@ -36,6 +36,8 @@ using System.Collections.Generic; using Spine; namespace Spine.Unity.Editor { + using Icons = SpineEditorUtilities.Icons; + [CustomEditor(typeof(SkeletonUtilityBone)), CanEditMultipleObjects] public class SkeletonUtilityBoneInspector : UnityEditor.Editor { SerializedProperty mode, boneName, zPosition, position, rotation, scale, overrideAlpha, parentReference; @@ -162,11 +164,11 @@ namespace Spine.Unity.Editor { using (new GUILayout.HorizontalScope()) { EditorGUILayout.Space(); using (new EditorGUI.DisabledGroupScope(multiObject || !utilityBone.valid || utilityBone.bone == null || utilityBone.bone.Children.Count == 0)) { - if (GUILayout.Button(new GUIContent("Add Child", SpineEditorUtilities.Icons.bone), GUILayout.MinWidth(120), GUILayout.Height(24))) + if (GUILayout.Button(new GUIContent("Add Child", Icons.bone), GUILayout.MinWidth(120), GUILayout.Height(24))) BoneSelectorContextMenu("", utilityBone.bone.Children, "", SpawnChildBoneSelected); } using (new EditorGUI.DisabledGroupScope(multiObject || !utilityBone.valid || utilityBone.bone == null || containsOverrides)) { - if (GUILayout.Button(new GUIContent("Add Override", SpineEditorUtilities.Icons.poseBones), GUILayout.MinWidth(120), GUILayout.Height(24))) + if (GUILayout.Button(new GUIContent("Add Override", Icons.poseBones), GUILayout.MinWidth(120), GUILayout.Height(24))) SpawnOverride(); } EditorGUILayout.Space(); @@ -175,14 +177,14 @@ namespace Spine.Unity.Editor { using (new GUILayout.HorizontalScope()) { EditorGUILayout.Space(); using (new EditorGUI.DisabledGroupScope(multiObject || !utilityBone.valid || !canCreateHingeChain)) { - if (GUILayout.Button(new GUIContent("Create Hinge Chain", SpineEditorUtilities.Icons.hingeChain), GUILayout.Width(150), GUILayout.Height(24))) + if (GUILayout.Button(new GUIContent("Create Hinge Chain", Icons.hingeChain), GUILayout.Width(150), GUILayout.Height(24))) CreateHingeChain(); } EditorGUILayout.Space(); } using (new EditorGUI.DisabledGroupScope(multiObject || boundingBoxTable.Count == 0)) { - EditorGUILayout.LabelField(new GUIContent("Bounding Boxes", SpineEditorUtilities.Icons.boundingBox), EditorStyles.boldLabel); + EditorGUILayout.LabelField(new GUIContent("Bounding Boxes", Icons.boundingBox), EditorStyles.boldLabel); foreach (var entry in boundingBoxTable){ Slot slot = entry.Key; diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityInspector.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityInspector.cs index b20baf2ed..216bc3c01 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityInspector.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityInspector.cs @@ -130,7 +130,7 @@ namespace Spine.Unity.Editor { foreach (var attachment in pair.Value) { GUI.contentColor = slot.Attachment == attachment ? Color.white : Color.grey; EditorGUI.indentLevel = baseIndent + 2; - var icon = (attachment is MeshAttachment) ? Icons.mesh : Icons.image; + var icon = Icons.GetAttachmentIcon(attachment); bool isAttached = (attachment == slot.Attachment); bool swap = EditorGUILayout.ToggleLeft(new GUIContent(attachment.Name, icon), attachment == slot.Attachment); if (isAttached != swap) { diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs index c53d1fb49..916d410ec 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtility.cs @@ -194,7 +194,6 @@ namespace Spine.Unity { } public void RegisterConstraint (SkeletonUtilityConstraint constraint) { - if (utilityConstraints.Contains(constraint)) return; else {