Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,109 changes: 889 additions & 220 deletions Assets/DragonBone/Editor/AnimFile.cs

Large diffs are not rendered by default.

86 changes: 79 additions & 7 deletions Assets/DragonBone/Editor/ArmatureEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public Atlas GetAtlasByTextureName(string textureName){
public Dictionary<string,Sprite> spriteKV = new Dictionary<string, Sprite>();//single sprite

public Dictionary<string , Atlas> atlasKV = new Dictionary<string, Atlas>();
public Dictionary<string,Matrix2D> bonePoseKV = new Dictionary<string, Matrix2D>() ; //bonePose , key is bone name
public Dictionary<string,Matrix2D> bonePoseKV = new Dictionary<string, Matrix2D>() ; //bonePose , key is textureName + bone name
public Dictionary<string,bool> ffdKV = new Dictionary<string, bool>();//skinnedMesh animation or ffd animation, key is skin name/texture name

public Dictionary<Material,bool> spriteMeshUsedMatKV = new Dictionary<Material, bool>();
Expand All @@ -76,9 +76,12 @@ static void CreateWizard () {
ArmatureEditor editor = ScriptableWizard.DisplayWizard<ArmatureEditor>("Create DragonBone", "Create");
editor.minSize = new Vector2(200f,400f);

if(Selection.activeObject is DefaultAsset)
if(Selection.activeObject != null)
{
string dirPath = AssetDatabase.GetAssetOrScenePath(Selection.activeObject);
if(File.Exists(dirPath)){
dirPath = dirPath.Substring(0,dirPath.LastIndexOf("/"));
}
if(Directory.Exists(dirPath)){
string animJsonPath=null;
Dictionary<string,string> texturePathKV = new Dictionary<string, string>();
Expand Down Expand Up @@ -160,9 +163,12 @@ static void CreateDragbonBoneByDir_UnitySprite()
}

static void CreateDragonBoneByDir(bool useUnitySprite){
if(Selection.activeObject is DefaultAsset)
if(Selection.activeObject != null)
{
string dirPath = AssetDatabase.GetAssetOrScenePath(Selection.activeObject);
if(File.Exists(dirPath)){
dirPath = dirPath.Substring(0,dirPath.LastIndexOf("/"));
}
if(Directory.Exists(dirPath)){
string animJsonPath=null;
Dictionary<string,string> texturePathKV = new Dictionary<string, string>();
Expand Down Expand Up @@ -254,6 +260,7 @@ public void SetAtlasTextureImporter(string atlasPath){


public void OnWizardCreate(){
Debug.ClearDeveloperConsole();
if(isSingleSprite){
useUnitySprite = true;
}
Expand Down Expand Up @@ -316,7 +323,7 @@ public void InitShow(){
slots[s].displayIndex = slots[s].displayIndex;
}

Renderer[] renders = _armature.GetComponentsInChildren<Renderer>();
Renderer[] renders = _armature.GetComponentsInChildren<Renderer>(true);
foreach(Renderer r in renders){
if(r.GetComponent<SpriteFrame>()){
//optimize memory
Expand All @@ -327,17 +334,82 @@ public void InitShow(){
}
dba.attachments = renders;
dba.slots = slots.ToArray();
dba.bones = bones.ToArray();
dba.zSpace = zoffset;
dba.ResetSlotZOrder();

string path = AssetDatabase.GetAssetPath(animTextAsset);
path = path.Substring(0,path.LastIndexOf('/'))+"/"+_armature.name+".prefab";
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(path);
path = path.Substring(0,path.LastIndexOf('/'))+"/"+_armature.name;


//create pose data
PoseData poseData = ScriptableObject.CreateInstance<PoseData>();
poseData.slotDatas = new PoseData.SlotData[slots.Count];
for(int i=0;i<slots.Count;++i){
poseData.slotDatas[i] = new PoseData.SlotData();
poseData.slotDatas[i].color = slots[i].color;
poseData.slotDatas[i].displayIndex = slots[i].displayIndex;
poseData.slotDatas[i].zorder = slots[i].z;
}
poseData.boneDatas = new PoseData.TransformData[bones.Count];
for(int i=0;i<bones.Count;++i){
poseData.boneDatas[i] = new PoseData.TransformData();
poseData.boneDatas[i].x = bones[i].localPosition.x;
poseData.boneDatas[i].y = bones[i].localPosition.y;
poseData.boneDatas[i].sx = bones[i].localScale.x;
poseData.boneDatas[i].sy = bones[i].localScale.y;
poseData.boneDatas[i].rotation = bones[i].localEulerAngles.z;
}
poseData.displayDatas = new PoseData.DisplayData[dba.attachments.Length];
for(int i=0;i<dba.attachments.Length;++i){
poseData.displayDatas[i] = new PoseData.DisplayData();
Renderer render = dba.attachments[i];

SpriteFrame sf = render.GetComponent<SpriteFrame>();
if(sf){
poseData.displayDatas[i].type= PoseData.AttachmentType.IMG;
poseData.displayDatas[i].color = sf.color;
}
else
{
SpriteMesh sm = render.GetComponent<SpriteMesh>();
if(sm){
poseData.displayDatas[i].type= PoseData.AttachmentType.MESH;
poseData.displayDatas[i].color = sm.color;
poseData.displayDatas[i].vertex = sm.vertices;
}
else
{
SpriteRenderer sr = render.GetComponent<SpriteRenderer>();
if(sr){
poseData.displayDatas[i].type= PoseData.AttachmentType.IMG;
poseData.displayDatas[i].color = sr.color;
}
else
{
poseData.displayDatas[i].type= PoseData.AttachmentType.BOX;
}
}
}
poseData.displayDatas[i].transform = new PoseData.TransformData();
poseData.displayDatas[i].transform.x = render.transform.localPosition.x;
poseData.displayDatas[i].transform.y = render.transform.localPosition.y;
poseData.displayDatas[i].transform.sx = render.transform.localScale.x;
poseData.displayDatas[i].transform.sy = render.transform.localScale.y;
poseData.displayDatas[i].transform.rotation = render.transform.localEulerAngles.z;
}
AssetDatabase.CreateAsset(poseData,path+"_Pose.asset");
dba.poseData = poseData;


string prefabPath = path+".prefab";
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>(prefabPath);
if(!prefab){
PrefabUtility.CreatePrefab(path,_armature.gameObject,ReplacePrefabOptions.ConnectToPrefab);
PrefabUtility.CreatePrefab(prefabPath,_armature.gameObject,ReplacePrefabOptions.ConnectToPrefab);
}else{
PrefabUtility.ReplacePrefab( _armature.gameObject,prefab,ReplacePrefabOptions.ConnectToPrefab);
}

}
}
}
26 changes: 17 additions & 9 deletions Assets/DragonBone/Editor/CurveExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public static float CalculateLinearTangent(AnimationCurve curve, int index, int







#region custom curve

public static void OptimizesCurve( AnimationCurve curve){
Expand All @@ -58,33 +62,37 @@ public static void OptimizesCurve( AnimationCurve curve){
}
}

public static void ClampCurveRotate360(AnimationCurve rotatecurve){
public static void ClampCurveRotate360(AnimationCurve rotatecurve,bool rotateCircle = true){
if(rotatecurve.length>1){
for(int f=1;f<rotatecurve.length;++f){
ClampCurveRotate360(rotatecurve,f);
ClampCurveRotate360(rotatecurve,f,rotateCircle);
}
}
}
public static void ClampCurveRotate360(AnimationCurve rotatecurve,int f){
public static void ClampCurveRotate360(AnimationCurve rotatecurve,int f,bool rotateCircle){
float prev = rotatecurve.keys[f-1].value;
float curr = rotatecurve.keys[f].value;
if(curr<-180f || curr>180f) return;
if(prev<-180f||prev>180f){
if(f>1) prev = rotatecurve.keys[f-2].value;
if(rotateCircle){
//rotate beyond 1 circle
if(curr<-180f || curr>180f) return;
if(prev<-180f||prev>180f){
if(f>1) prev = rotatecurve.keys[f-2].value;
}
}

while ((curr - prev) > 180 ){
curr -= 360;
}
while ((curr - prev) < -180){
curr += 360;
}
if (rotatecurve.keys[f].value != curr){
rotatecurve.MoveKey(f, new Keyframe(rotatecurve.keys[f].time , curr));
TangentMode modeIn = KeyframeUtil.GetKeyTangentMode(rotatecurve.keys[f].tangentMode,(int)rotatecurve.keys[f].inTangent);
TangentMode modeOut = KeyframeUtil.GetKeyTangentMode(rotatecurve.keys[f].tangentMode,(int)rotatecurve.keys[f].outTangent);
if(f==rotatecurve.length-1) modeIn = TangentMode.Linear;
rotatecurve.MoveKey(f, KeyframeUtil.GetNew(rotatecurve.keys[f].time , curr,modeIn,modeOut ));
}
}


// p0, p3 - start, end points
// p1, p2 - conrol points
// t - value on x [0,1]
Expand Down
45 changes: 26 additions & 19 deletions Assets/DragonBone/Editor/DragonBoneArmatureEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override void OnInspectorGUI(){
EditorUtility.SetDirty(armature);
}
if(GUILayout.Button("Update All Sorting Order",GUILayout.Height(20))){
foreach(Renderer render in armature.GetComponentsInChildren<Renderer>()){
foreach(Renderer render in armature.GetComponentsInChildren<Renderer>(true)){
render.sortingLayerName = armature.sortingLayerName;
render.sortingOrder = armature.sortingOrder;
EditorUtility.SetDirty(render);
Expand All @@ -60,6 +60,7 @@ public override void OnInspectorGUI(){
}
}
}
EditorUtility.SetDirty(armature);
if (!string.IsNullOrEmpty(armature.gameObject.scene.name)){
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
}
Expand All @@ -68,32 +69,38 @@ public override void OnInspectorGUI(){
serializedObject.Update();
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_FlipX"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("m_FlipY"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("zSpace"), true);
if(!Application.isPlaying){
EditorGUILayout.PropertyField(serializedObject.FindProperty("zSpace"), true);
}
EditorGUILayout.PropertyField(serializedObject.FindProperty("poseData"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("slots"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("bones"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("attachments"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("materials"), true);
EditorGUILayout.PropertyField(serializedObject.FindProperty("textureFrames"), true);
serializedObject.ApplyModifiedProperties();

if(armature.flipX!=flipX){
armature.flipX = armature.flipX;
flipX = armature.flipX;
if (!string.IsNullOrEmpty(armature.gameObject.scene.name)){
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
if(!Application.isPlaying){
if(armature.flipX!=flipX){
armature.flipX = armature.flipX;
flipX = armature.flipX;
if (!string.IsNullOrEmpty(armature.gameObject.scene.name)){
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
}
}
}
if(armature.flipY!=flipY){
armature.flipY = armature.flipY;
flipY = armature.flipY;
if (!string.IsNullOrEmpty(armature.gameObject.scene.name)){
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
if(armature.flipY!=flipY){
armature.flipY = armature.flipY;
flipY = armature.flipY;
if (!string.IsNullOrEmpty(armature.gameObject.scene.name)){
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
}
}
}
if(armature.zSpace!=zspace){
zspace = armature.zSpace;
armature.ResetSlotZOrder();
if (!string.IsNullOrEmpty(armature.gameObject.scene.name)){
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
if(armature.zSpace!=zspace){
zspace = armature.zSpace;
armature.ResetSlotZOrder();
if (!string.IsNullOrEmpty(armature.gameObject.scene.name)){
UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
}
}
}
}
Expand Down
21 changes: 20 additions & 1 deletion Assets/DragonBone/Editor/DragonBoneData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,25 @@ public class AnimSubData{
public string slot;//如果有slot,就用slot
public float scale=1f;
public float offset=0f;
public AnimFrameData[] frameDatas;
public AnimFrameData[] frameDatas;//for 5.3

//for 5.5
public AnimFrameData[] translateFrameDatas;
public AnimFrameData[] rotateFrameDatas;
public AnimFrameData[] scaleFrameDatas;
public AnimFrameData[] colorFrameDatas;
public AnimFrameData[] displayFrameDatas;
}

public enum FrameType{
Frame,
TranslateFrame,
RotateFrame,
ScaleFrame,
ColorFrame,
DisplayFrame
}

public class AnimFrameData { //此动画包含的关键帧列表
public int duration = 1;
public float[] curve;
Expand All @@ -100,6 +117,7 @@ public class AnimFrameData { //此动画包含的关键帧列表
public float z;
public TransformData transformData ;
public ColorData color;
public FrameType frameType = FrameType.Frame;

//网格动画
public int offset=0;//顶点坐标索引偏移
Expand All @@ -117,6 +135,7 @@ public class SkinSlotData{
}
public class SkinSlotDisplayData{
public string textureName;
public string texturePath;
public string type = "image";//armature,mesh,boundingBox
public string subType="polygon";
public Vector2 pivot = new Vector2(0.5f,0.5f);
Expand Down
Loading