Skip to content

Commit

Permalink
Merge branch 'release/v0.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
nicloay committed Feb 8, 2014
2 parents 9133da5 + d6e175e commit 7ff1e1c
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class SpineData{
public string defaultSkinName;
public string[] skinNames;
public string[] defaultPoseSlots;
public Dictionary<string,string> slotDefaultAttachments;



Expand Down Expand Up @@ -95,13 +96,16 @@ static void setCachedData (SpineData data)
data.slotOrder = new Dictionary<string, int>();

data.slotPathByName = new Dictionary<string, string>();
data.slotDefaultAttachments = new Dictionary<string, string>();
for (int i = 0; i < data.slots.Count; i++) {
string slotName = data.slots[i].name;
string defaultAttachment = data.slots[i].attachment;
data.slotOrder.Add(slotName, i);
string boneName = data.slots[i].bone;
string bonePath = data.bonePathByName[boneName];
string slotPath = bonePath+"/" + SpineUtil.getSlotGOName(slotName);
data.slotPathByName.Add(slotName, slotPath);
data.slotDefaultAttachments.Add(slotName, defaultAttachment);
}
}

Expand Down
38 changes: 28 additions & 10 deletions Assets/UnitySpineImporter/Scripts/Editor/Util/SpineUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ public AtlasImageDuplicateSpriteName(string message):base(message){
}

public class SpineUtil {
public static string SLOT_PREFIX="slot";
public static string SKIN_PREFIX="skin";
public static string ANIMATION_FOLDER="animation";
public static string SLOT_PREFIX = "slot";
public static string SKIN_PREFIX = "skin";
public static string ANIMATION_FOLDER = "animation";
public static string SLASH_REPLACEMENT = "|";

public static Vector2 lineToVector2(string line){
string[] xy = null;
Expand Down Expand Up @@ -297,17 +298,18 @@ public static void addAllAttahcmentsSlots(SpineData spineData, SpritesByName spr

GameObject parentGO;
GameObject spriteGO;
string fixedName = attachmenName.Replace("/",SLASH_REPLACEMENT);
if (isDefault){
parentGO = slotGO;
spriteGO = new GameObject(attachmenName);
spriteGO = new GameObject(fixedName);
Attachment a = new Attachment(attachmenName, AttachmentType.SINGLE_SPRITE, spriteGO);
slot.addAttachment(a);
} else {
spriteGO = new GameObject(skinName);
Attachment a;
slot.attachmentByName.TryGetValue(attachmenName, out a);
if (a == null){
GameObject attachmentGO = new GameObject(attachmenName);
GameObject attachmentGO = new GameObject(fixedName);
attachmentGO.transform.parent = slotGO.transform;
resetLocalTRS(attachmentGO);
a = new Attachment(attachmenName, AttachmentType.SKINED_SPRITE, attachmentGO);
Expand Down Expand Up @@ -433,6 +435,7 @@ public static void addSlotAnimationToClip(AnimationClip
{
foreach(KeyValuePair<string, SpineSlotAnimation> kvp in slotsAnimation){
string slotName = kvp.Key;
string defaultAttachment = spineData.slotDefaultAttachments[slotName];
SpineSlotAnimation slotAnimation = kvp.Value;
if (slotAnimation.attachment != null && slotAnimation.attachment.Count > 0){
Dictionary<string, AnimationCurve> curveByName = new Dictionary<string, AnimationCurve>();
Expand All @@ -446,22 +449,37 @@ public static void addSlotAnimationToClip(AnimationClip
enableCurve = curveByName[anim.name];
} else {
enableCurve = new AnimationCurve();
if ((i==0 && anim.time != 0) || i > 0){
enableCurve.AddKey(KeyframeUtil.GetNew(0, 0, TangentMode.Stepped));
}
if (anim.time > 0.0f)
enableCurve.AddKey(KeyframeUtil.GetNew(0, 0.0f, TangentMode.Stepped));

curveByName.Add(anim.name, enableCurve);

if (i==0 && !anim.name.Equals(defaultAttachment)){
AnimationCurve defSlotCurve = new AnimationCurve();
curveByName.Add(defaultAttachment, defSlotCurve);

if (anim.time !=0.0f){
defSlotCurve.AddKey(KeyframeUtil.GetNew(0, 1, TangentMode.Stepped));
defSlotCurve.AddKey(KeyframeUtil.GetNew((float)anim.time, 0, TangentMode.Stepped));
} else {
defSlotCurve.AddKey(KeyframeUtil.GetNew(0, 0, TangentMode.Stepped));
}

}
}

enableCurve.AddKey(KeyframeUtil.GetNew((float)anim.time, 1, TangentMode.Stepped));
if (i< (slotAnimation.attachment.Count - 1)){
SpineSlotAttachmentAnimation nextAnim = slotAnimation.attachment[i+1];
enableCurve.AddKey(KeyframeUtil.GetNew((float)nextAnim.time, 0, TangentMode.Stepped));
if (!nextAnim.name.Equals(anim.name))
enableCurve.AddKey(KeyframeUtil.GetNew((float)nextAnim.time, 0, TangentMode.Stepped));
}
}
foreach(KeyValuePair<string, AnimationCurve> kvp2 in curveByName){
string attachmentName = kvp2.Key;
AnimationCurve animationCurve = kvp2.Value;
string attachmentPath = spineData.slotPathByName[slotName] + "/" + attachmentName;
string attachmentPath = spineData.slotPathByName[slotName] + "/" + attachmentName.Replace("/",SLASH_REPLACEMENT);
Debug.Log(attachmentPath);
clip.SetCurve(attachmentPath, typeof(GameObject),"m_IsActive", animationCurve);
}

Expand Down

0 comments on commit 7ff1e1c

Please sign in to comment.