Skip to content

Commit

Permalink
#2 import settings to switch between mecanim and legacy animation fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
nicloay committed Jan 30, 2014
1 parent fa77212 commit b0c30a1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
33 changes: 29 additions & 4 deletions Assets/UnitySpineImporter/Scripts/Editor/SpineImporterWizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@


namespace UnitySpineImporter{
public enum AnimationImportType{
MECANIM,
LEGACY
}

public class SpineImporterWizard :ScriptableWizard {
public int pixelsPerUnit = 100;
public bool buildAvatarMask = true;
public AnimationImportType animationImportType = AnimationImportType.MECANIM;
[HideInInspector]
public string path;

Expand All @@ -33,6 +39,8 @@ void OnWizardUpdate() {
else
errorString ="";
isValid = errorString.Equals("");
if (animationImportType == AnimationImportType.LEGACY && buildAvatarMask)
helpString += "\n buildAvatarMask will be ignored";
}


Expand All @@ -55,10 +63,14 @@ void OnWizardCreate(){
rootGO.name = name;
SpineUtil.addAllAttahcmentsSlots(spineData, spriteByName, slotByName, pixelsPerUnit, out skins, out attachmentGOByNameBySlot);
SkinController sk = SpineUtil.addSkinController(rootGO, spineData, skins, slotByName);
Animator animator = SpineUtil.addAnimator(rootGO);
if (buildAvatarMask)
SpineUtil.builAvatarMask(rootGO,spineData, animator, directory, name);
SpineUtil.addAnimation(rootGO, directory, spineData, boneGOByName, attachmentGOByNameBySlot, pixelsPerUnit);
if (animationImportType == AnimationImportType.MECANIM){
Animator animator = SpineUtil.addAnimator(rootGO);
if (buildAvatarMask)
SpineUtil.builAvatarMask(rootGO,spineData, animator, directory, name);
}

ModelImporterAnimationType modelImporterAnimationType = getModelImporterAnimationType();
SpineUtil.addAnimation(rootGO, directory, spineData, boneGOByName, attachmentGOByNameBySlot, pixelsPerUnit, modelImporterAnimationType);
sk.showDefaulSlots();

SpineUtil.buildPrefab(rootGO, directory, name);
Expand All @@ -75,6 +87,19 @@ 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);
string fileName = Path.GetFileNameWithoutExtension(path+"ffff");
Expand Down
17 changes: 14 additions & 3 deletions Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,14 +383,15 @@ public static void addAnimation(GameObject rootGO,
SpineData spineData,
Dictionary<string, GameObject> boneGOByName,
AttachmentGOByNameBySlot attachmentGOByNameBySlot,
int pixelsPerUnit)
int pixelsPerUnit,
ModelImporterAnimationType modelImporterAnimationType)
{
float ratio = 1.0f / (float)pixelsPerUnit;
foreach(KeyValuePair<string,SpineAnimation> kvp in spineData.animations){
string animationName = kvp.Key;
SpineAnimation spineAnimation = kvp.Value;
AnimationClip animationClip = new AnimationClip();
AnimationUtility.SetAnimationType(animationClip, ModelImporterAnimationType.Generic);
AnimationUtility.SetAnimationType(animationClip, modelImporterAnimationType);
if (spineAnimation.bones!=null)
addBoneAnimationToClip(animationClip,spineAnimation.bones, spineData, boneGOByName, ratio);
if (spineAnimation.slots!=null)
Expand All @@ -404,10 +405,20 @@ public static void addAnimation(GameObject rootGO,

AssetDatabase.CreateAsset(animationClip, animationFolder + "/" + animationName+".anim");
AssetDatabase.SaveAssets();
AddClipToAnimatorComponent(rootGO,animationClip);
if (modelImporterAnimationType == ModelImporterAnimationType.Generic)
AddClipToAnimatorComponent(rootGO,animationClip);
else
AddClipToLegacyAnimationComponent(rootGO, animationClip);
}
}

static void AddClipToLegacyAnimationComponent(GameObject rootGO, AnimationClip animationClip){
Animation animation = rootGO.GetComponent<Animation>();
if (animation == null)
animation = rootGO.AddComponent<Animation>();
animation.AddClip(animationClip, animationClip.name);
}

static void createFolderIfNoExists(string root, string folderName){
string path = root+"/"+folderName;
if (!Directory.Exists(path))
Expand Down

0 comments on commit b0c30a1

Please sign in to comment.