diff --git a/Assets/UnitySpineImporter/Scripts/Editor/SpineImporterWizard.cs b/Assets/UnitySpineImporter/Scripts/Editor/SpineImporterWizard.cs index bad17f8..5d3efa2 100644 --- a/Assets/UnitySpineImporter/Scripts/Editor/SpineImporterWizard.cs +++ b/Assets/UnitySpineImporter/Scripts/Editor/SpineImporterWizard.cs @@ -6,15 +6,11 @@ namespace UnitySpineImporter{ - public enum AnimationImportType{ - MECANIM, - LEGACY - } public class SpineImporterWizard :ScriptableWizard { public int pixelsPerUnit = 100; public bool buildAvatarMask = true; - public AnimationImportType animationImportType = AnimationImportType.MECANIM; + public bool useLegacyAnimation = false; //false - means mecanim public bool updateResources = true; public float zStep = 0.01f; [HideInInspector] @@ -42,7 +38,7 @@ void OnWizardUpdate() { else errorString =""; isValid = errorString.Equals(""); - if (animationImportType == AnimationImportType.LEGACY && buildAvatarMask) + if (useLegacyAnimation && buildAvatarMask) helpString += "\n buildAvatarMask will be ignored"; } @@ -67,16 +63,15 @@ void OnWizardCreate(){ rootGO.name = name; SpineUtil.addAllAttahcmentsSlots(spineData, spriteByName, slotByName, pixelsPerUnit, out skins, out attachmentGOByNameBySlot); SkinController sk = SpineUtil.addSkinController(rootGO, spineData, skins, slotByName); - if (animationImportType == AnimationImportType.MECANIM){ + if (!useLegacyAnimation){ Animator animator = SpineUtil.addAnimator(rootGO); if (buildAvatarMask) SpineUtil.builAvatarMask(rootGO,spineData, animator, directory, name); } - ModelImporterAnimationType modelImporterAnimationType = getModelImporterAnimationType(); if (spineData.animations !=null && spineData.animations.Count > 0) SpineUtil.addAnimation(rootGO, directory, spineData, boneGOByName, slotByName, attachmentGOByNameBySlot, skins, - pixelsPerUnit, zStep, modelImporterAnimationType, updateResources ); + pixelsPerUnit, zStep, useLegacyAnimation, updateResources ); sk.showDefaulSlots(); SpineUtil.buildPrefab(rootGO, directory, name); GameObject.DestroyImmediate(rootGO); @@ -90,19 +85,6 @@ void OnWizardCreate(){ } } } - - ModelImporterAnimationType getModelImporterAnimationType(){ - ModelImporterAnimationType result = ModelImporterAnimationType.Generic; - switch(animationImportType){ - case AnimationImportType.LEGACY: - result = ModelImporterAnimationType.Legacy; - break; - case AnimationImportType.MECANIM: - result = ModelImporterAnimationType.Generic; - break; - } - return result; - } static string getAtlasFilePath(string path){ string dir = Path.GetDirectoryName(path); diff --git a/Assets/UnitySpineImporter/Scripts/Editor/UnityInternalMethods.cs b/Assets/UnitySpineImporter/Scripts/Editor/UnityInternalMethods.cs new file mode 100644 index 0000000..196e150 --- /dev/null +++ b/Assets/UnitySpineImporter/Scripts/Editor/UnityInternalMethods.cs @@ -0,0 +1,20 @@ + +using UnityEditor.Animations; +using UnityEngine; +using System.Reflection; +using UnityEditor; + +public class UnityInternalMethods { + public static AnimatorController GetEffectiveAnimatorController(Animator animator){ + return (AnimatorController) (typeof(AnimatorController).GetMethod("GetEffectiveAnimatorController" + , BindingFlags.Static | BindingFlags.NonPublic).Invoke(null, new object[]{ animator})); + } + + public static void GetTextureSize(TextureImporter textureImporter, out int width, out int height){ + object[] args = new object[2] { 0, 0 }; + MethodInfo mi = typeof(TextureImporter).GetMethod("GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Instance); + mi.Invoke(textureImporter, args); + width = (int)args[0]; + height = (int)args[1]; + } +} diff --git a/Assets/UnitySpineImporter/Scripts/Editor/UnityInternalMethods.cs.meta b/Assets/UnitySpineImporter/Scripts/Editor/UnityInternalMethods.cs.meta new file mode 100644 index 0000000..d23c196 --- /dev/null +++ b/Assets/UnitySpineImporter/Scripts/Editor/UnityInternalMethods.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: 0431ec8deb4b24d35b064852bd344afc +timeCreated: 1436945266 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs b/Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs index 2d7a5f3..a6dde86 100644 --- a/Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs +++ b/Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs @@ -7,7 +7,7 @@ using UnityEditorInternal; using CurveExtended; using LitJson; -using System.Reflection; +using UnityEditor.Animations; namespace UnitySpineImporter{ public class AtlasImageNotFoundException: System.Exception{ @@ -85,12 +85,8 @@ public static string[] getTransformPaths(GameObject go, SpineData spineData){ static void fixTextureSize(string imagePath){ TextureImporter importer = TextureImporter.GetAtPath(imagePath) as TextureImporter; if (importer != null) { - object[] args = new object[2] { 0, 0 }; - MethodInfo mi = typeof(TextureImporter).GetMethod("GetWidthAndHeight", BindingFlags.NonPublic | BindingFlags.Instance); - mi.Invoke(importer, args); - - int width = (int)args[0]; - int height = (int)args[1]; + int width, height; + UnityInternalMethods.GetTextureSize(importer, out width, out height); int max = Mathf.Max(width,height); if (max > 4096){ @@ -393,7 +389,7 @@ public static void addAnimation(GameObject rootGO, List skinList, int pixelsPerUnit, float zStep, - ModelImporterAnimationType modelImporterAnimationType, + bool useLegacyAnimation, bool updateResources) { float ratio = 1.0f / (float)pixelsPerUnit; @@ -413,8 +409,7 @@ public static void addAnimation(GameObject rootGO, updateCurve = true; } } - - AnimationUtility.SetAnimationType(animationClip, modelImporterAnimationType); + animationClip.legacy = useLegacyAnimation; if (spineAnimation.bones!=null) addBoneAnimationToClip(animationClip,spineAnimation.bones, spineData, boneGOByName, ratio); if (spineAnimation.slots!=null) @@ -434,10 +429,11 @@ public static void addAnimation(GameObject rootGO, AssetDatabase.CreateAsset(animationClip, assetPath); AssetDatabase.SaveAssets(); - if (modelImporterAnimationType == ModelImporterAnimationType.Generic) - AddClipToAnimatorComponent(rootGO,animationClip); - else + if (useLegacyAnimation){ AddClipToLegacyAnimationComponent(rootGO, animationClip); + } else { + AddClipToAnimatorComponent(rootGO,animationClip); + } } } @@ -1076,13 +1072,14 @@ public static AnimationClip AddClipToAnimatorComponent(GameObject animatedObject Animator animator = animatedObject.GetComponent(); if ( animator == null) animator = animatedObject.AddComponent(); - AnimatorController animatorController = AnimatorController.GetEffectiveAnimatorController(animator); + + UnityEditor.Animations.AnimatorController animatorController = UnityInternalMethods.GetEffectiveAnimatorController(animator); if (animatorController == null) { string path = Path.GetDirectoryName( AssetDatabase.GetAssetPath(newClip)) +"/"+animatedObject.name+".controller"; - AnimatorController controllerForClip = AnimatorController.CreateAnimatorControllerAtPathWithClip(path, newClip); - AnimatorController.SetAnimatorController(animator, controllerForClip); + UnityEditor.Animations.AnimatorController controllerForClip = UnityEditor.Animations.AnimatorController.CreateAnimatorControllerAtPathWithClip(path, newClip); + UnityEditor.Animations.AnimatorController.SetAnimatorController(animator, controllerForClip); if (controllerForClip != null) return newClip; else @@ -1090,7 +1087,7 @@ public static AnimationClip AddClipToAnimatorComponent(GameObject animatedObject } else { - AnimatorController.AddAnimationClipToController(animatorController, newClip); + animatorController.AddMotion((Motion)newClip); return newClip; } } diff --git a/ProjectSettings/GraphicsSettings.asset b/ProjectSettings/GraphicsSettings.asset index 4a440d2..4744c5a 100644 Binary files a/ProjectSettings/GraphicsSettings.asset and b/ProjectSettings/GraphicsSettings.asset differ diff --git a/ProjectSettings/NavMeshAreas.asset b/ProjectSettings/NavMeshAreas.asset new file mode 100644 index 0000000..2f17c97 Binary files /dev/null and b/ProjectSettings/NavMeshAreas.asset differ diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 815ecb3..916f659 100644 Binary files a/ProjectSettings/ProjectSettings.asset and b/ProjectSettings/ProjectSettings.asset differ diff --git a/ProjectSettings/ProjectVersion.txt b/ProjectSettings/ProjectVersion.txt new file mode 100644 index 0000000..b150ff3 --- /dev/null +++ b/ProjectSettings/ProjectVersion.txt @@ -0,0 +1,2 @@ +m_EditorVersion: 5.1.1p3 +m_StandardAssetsVersion: 0