mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-26 22:49:01 +08:00
Added SkeletonBaker system
This commit is contained in:
parent
c5273fc6d7
commit
ca97abb2a1
1350
spine-unity/Assets/spine-unity/Editor/SkeletonBaker.cs
Normal file
1350
spine-unity/Assets/spine-unity/Editor/SkeletonBaker.cs
Normal file
File diff suppressed because it is too large
Load Diff
@ -48,6 +48,10 @@ public class SkeletonDataAssetInspector : Editor {
|
||||
static bool showAnimationList = true;
|
||||
static bool showSlotList = false;
|
||||
static bool showAttachments = false;
|
||||
static bool showBaking = true;
|
||||
static bool bakeAnimations = true;
|
||||
static bool bakeIK = true;
|
||||
static SendMessageOptions bakeEventOptions = SendMessageOptions.DontRequireReceiver;
|
||||
|
||||
private SerializedProperty atlasAssets, skeletonJSON, scale, fromAnimation, toAnimation, duration, defaultMix;
|
||||
|
||||
@ -82,6 +86,8 @@ public class SkeletonDataAssetInspector : Editor {
|
||||
|
||||
m_skeletonData = m_skeletonDataAsset.GetSkeletonData(true);
|
||||
|
||||
showBaking = EditorPrefs.GetBool("SkeletonDataAssetInspector_showBaking", true);
|
||||
|
||||
RepopulateWarnings();
|
||||
}
|
||||
|
||||
@ -120,11 +126,10 @@ public class SkeletonDataAssetInspector : Editor {
|
||||
|
||||
|
||||
if (m_skeletonData != null) {
|
||||
|
||||
DrawAnimationStateInfo();
|
||||
DrawAnimationList();
|
||||
DrawSlotList();
|
||||
|
||||
DrawBaking();
|
||||
} else {
|
||||
|
||||
DrawReimportButton();
|
||||
@ -142,9 +147,91 @@ public class SkeletonDataAssetInspector : Editor {
|
||||
}
|
||||
}
|
||||
|
||||
void DrawBaking () {
|
||||
|
||||
bool pre = showBaking;
|
||||
showBaking = EditorGUILayout.Foldout(showBaking, new GUIContent("Baking", SpineEditorUtilities.Icons.unityIcon));
|
||||
if (pre != showBaking)
|
||||
EditorPrefs.SetBool("SkeletonDataAssetInspector_showBaking", showBaking);
|
||||
|
||||
if (showBaking) {
|
||||
EditorGUI.indentLevel++;
|
||||
bakeAnimations = EditorGUILayout.Toggle("Bake Animations", bakeAnimations);
|
||||
EditorGUI.BeginDisabledGroup(bakeAnimations == false);
|
||||
{
|
||||
EditorGUI.indentLevel++;
|
||||
bakeIK = EditorGUILayout.Toggle("Bake IK", bakeIK);
|
||||
bakeEventOptions = (SendMessageOptions)EditorGUILayout.EnumPopup("Event Options", bakeEventOptions);
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
|
||||
EditorGUI.indentLevel++;
|
||||
GUILayout.BeginHorizontal();
|
||||
{
|
||||
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Bake All Skins", SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(150)))
|
||||
SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, m_skeletonData.Skins, "", bakeAnimations, bakeIK, bakeEventOptions);
|
||||
|
||||
string skinName = "<No Skin>";
|
||||
|
||||
if (m_skeletonAnimation != null && m_skeletonAnimation.skeleton != null) {
|
||||
|
||||
Skin bakeSkin = m_skeletonAnimation.skeleton.Skin;
|
||||
if (bakeSkin == null){
|
||||
skinName = "Default";
|
||||
bakeSkin = m_skeletonData.Skins[0];
|
||||
}
|
||||
else
|
||||
skinName = m_skeletonAnimation.skeleton.Skin.Name;
|
||||
|
||||
bool oops = false;
|
||||
|
||||
try {
|
||||
GUILayout.BeginVertical();
|
||||
if (GUILayout.Button(new GUIContent("Bake " + skinName, SpineEditorUtilities.Icons.unityIcon), GUILayout.Height(32), GUILayout.Width(250)))
|
||||
SkeletonBaker.BakeToPrefab(m_skeletonDataAsset, new List<Skin>(new Skin[] { bakeSkin }), "", bakeAnimations, bakeIK, bakeEventOptions);
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Label(new GUIContent("Skins", SpineEditorUtilities.Icons.skinsRoot), GUILayout.Width(50));
|
||||
if (GUILayout.Button(skinName, EditorStyles.popup, GUILayout.Width(196))) {
|
||||
SelectSkinContext();
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
|
||||
|
||||
} catch {
|
||||
oops = true;
|
||||
//GUILayout.BeginVertical();
|
||||
}
|
||||
|
||||
|
||||
|
||||
if(!oops)
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
}
|
||||
GUILayout.EndHorizontal();
|
||||
EditorGUI.indentLevel--;
|
||||
|
||||
EditorGUI.indentLevel--;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
void DrawReimportButton () {
|
||||
EditorGUI.BeginDisabledGroup(skeletonJSON.objectReferenceValue == null);
|
||||
if (GUILayout.Button(new GUIContent("Attempt Reimport", SpineEditorUtilities.Icons.warning))) {
|
||||
DoReimport();
|
||||
return;
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
}
|
||||
|
||||
void DoReimport () {
|
||||
SpineEditorUtilities.ImportSpineContent(new string[] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, true);
|
||||
|
||||
if (m_previewUtility != null) {
|
||||
@ -154,10 +241,8 @@ public class SkeletonDataAssetInspector : Editor {
|
||||
|
||||
RepopulateWarnings();
|
||||
OnEnable();
|
||||
return;
|
||||
|
||||
}
|
||||
EditorGUI.EndDisabledGroup();
|
||||
EditorUtility.SetDirty(m_skeletonDataAsset);
|
||||
}
|
||||
|
||||
void DrawAnimationStateInfo () {
|
||||
@ -435,6 +520,8 @@ public class SkeletonDataAssetInspector : Editor {
|
||||
this.m_previewUtility.m_Camera.isOrthoGraphic = true;
|
||||
this.m_previewUtility.m_Camera.orthographicSize = 1;
|
||||
this.m_previewUtility.m_Camera.cullingMask = -2147483648;
|
||||
this.m_previewUtility.m_Camera.nearClipPlane = 0.01f;
|
||||
this.m_previewUtility.m_Camera.farClipPlane = 1000f;
|
||||
this.CreatePreviewInstances();
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,6 +43,8 @@ using System.Linq;
|
||||
using System.Reflection;
|
||||
using Spine;
|
||||
|
||||
using System.Security.Cryptography;
|
||||
|
||||
[InitializeOnLoad]
|
||||
public class SpineEditorUtilities : AssetPostprocessor {
|
||||
|
||||
@ -70,6 +72,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
||||
public static Texture2D skeletonUtility;
|
||||
public static Texture2D hingeChain;
|
||||
public static Texture2D subMeshRenderer;
|
||||
public static Texture2D unityIcon;
|
||||
|
||||
public static Mesh boneMesh {
|
||||
get {
|
||||
@ -136,6 +139,8 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
||||
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");
|
||||
|
||||
unityIcon = EditorGUIUtility.FindTexture("SceneAsset Icon");
|
||||
}
|
||||
}
|
||||
|
||||
@ -225,6 +230,8 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
||||
}
|
||||
public static void ImportSpineContent(string[] imported, bool reimport = false) {
|
||||
|
||||
MD5 md5 = MD5.Create();
|
||||
|
||||
List<string> atlasPaths = new List<string>();
|
||||
List<string> imagePaths = new List<string>();
|
||||
List<string> skeletonPaths = new List<string>();
|
||||
@ -267,7 +274,7 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
||||
bool abortSkeletonImport = false;
|
||||
foreach (string sp in skeletonPaths) {
|
||||
if (!reimport && CheckForValidSkeletonData(sp)) {
|
||||
Debug.Log("Automatically skipping: " + sp);
|
||||
ResetExistingSkeletonData(sp);
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -351,6 +358,32 @@ public class SpineEditorUtilities : AssetPostprocessor {
|
||||
return false;
|
||||
}
|
||||
|
||||
static void ResetExistingSkeletonData (string skeletonJSONPath) {
|
||||
|
||||
string dir = Path.GetDirectoryName(skeletonJSONPath);
|
||||
TextAsset textAsset = (TextAsset)AssetDatabase.LoadAssetAtPath(skeletonJSONPath, typeof(TextAsset));
|
||||
DirectoryInfo dirInfo = new DirectoryInfo(dir);
|
||||
|
||||
FileInfo[] files = dirInfo.GetFiles("*.asset");
|
||||
|
||||
foreach (var f in files) {
|
||||
string localPath = dir + "/" + f.Name;
|
||||
var obj = AssetDatabase.LoadAssetAtPath(localPath, typeof(Object));
|
||||
if (obj is SkeletonDataAsset) {
|
||||
var skeletonDataAsset = (SkeletonDataAsset)obj;
|
||||
|
||||
if (skeletonDataAsset.skeletonJSON == textAsset) {
|
||||
if (Selection.activeObject == skeletonDataAsset)
|
||||
Selection.activeObject = null;
|
||||
|
||||
skeletonDataAsset.Reset();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static bool CheckForValidAtlas(string atlasPath) {
|
||||
|
||||
string dir = Path.GetDirectoryName(atlasPath);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user