[unity] Rearrange SpineEditorUtilities classes.

This commit is contained in:
pharan 2018-07-12 18:08:05 +08:00
parent d336712ccc
commit 6187e2b89e
3 changed files with 609 additions and 598 deletions

View File

@ -80,7 +80,7 @@ namespace Spine.Unity.Editor {
}
string dataPath = AssetDatabase.GetAssetPath(skeletonDataAsset);
string controllerPath = dataPath.Replace(SpineEditorUtilities.SkeletonDataSuffix, "_Controller").Replace(".asset", ".controller");
string controllerPath = dataPath.Replace(SpineEditorUtilities.AssetUtility.SkeletonDataSuffix, "_Controller").Replace(".asset", ".controller");
UnityEditor.Animations.AnimatorController controller;
if (skeletonDataAsset.controller != null) {
controller = (UnityEditor.Animations.AnimatorController)skeletonDataAsset.controller;
@ -1406,6 +1406,53 @@ namespace Spine.Unity.Editor {
#endregion
#endregion
#region Region Baking
public static GameObject BakeRegion (SpineAtlasAsset atlasAsset, AtlasRegion region, bool autoSave = true) {
atlasAsset.GetAtlas(); // Initializes atlasAsset.
string atlasAssetPath = AssetDatabase.GetAssetPath(atlasAsset);
string atlasAssetDirPath = Path.GetDirectoryName(atlasAssetPath);
string bakedDirPath = Path.Combine(atlasAssetDirPath, atlasAsset.name);
string bakedPrefabPath = Path.Combine(bakedDirPath, SpineEditorUtilities.GetPathSafeName(region.name) + ".prefab").Replace("\\", "/");
GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(GameObject));
GameObject root;
Mesh mesh;
bool isNewPrefab = false;
if (!Directory.Exists(bakedDirPath))
Directory.CreateDirectory(bakedDirPath);
if (prefab == null) {
root = new GameObject("temp", typeof(MeshFilter), typeof(MeshRenderer));
prefab = PrefabUtility.CreatePrefab(bakedPrefabPath, root);
isNewPrefab = true;
Object.DestroyImmediate(root);
}
mesh = (Mesh)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(Mesh));
Material mat = null;
mesh = atlasAsset.GenerateMesh(region.name, mesh, out mat);
if (isNewPrefab) {
AssetDatabase.AddObjectToAsset(mesh, prefab);
prefab.GetComponent<MeshFilter>().sharedMesh = mesh;
}
EditorUtility.SetDirty(mesh);
EditorUtility.SetDirty(prefab);
if (autoSave) {
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
}
prefab.GetComponent<MeshRenderer>().sharedMaterial = mat;
return prefab;
}
#endregion
static string GetPath (BoneData b) {
return GetPathRecurse(b).Substring(1);
}

View File

@ -28,7 +28,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#define SPINE_SKELETON_ANIMATOR
#define SPINE_SKELETON_MECANIM
using System;
using System.Reflection;
@ -55,7 +55,7 @@ namespace Spine.Unity.Editor {
SerializedProperty spriteCollection;
#endif
#if SPINE_SKELETON_ANIMATOR
#if SPINE_SKELETON_MECANIM
static bool isMecanimExpanded = false;
SerializedProperty controller;
#endif
@ -100,7 +100,7 @@ namespace Spine.Unity.Editor {
duration = serializedObject.FindProperty("duration");
defaultMix = serializedObject.FindProperty("defaultMix");
#if SPINE_SKELETON_ANIMATOR
#if SPINE_SKELETON_MECANIM
controller = serializedObject.FindProperty("controller");
#endif
@ -494,7 +494,7 @@ namespace Spine.Unity.Editor {
}
void DrawUnityTools () {
#if SPINE_SKELETON_ANIMATOR
#if SPINE_SKELETON_MECANIM
using (new SpineInspectorUtility.BoxScope()) {
isMecanimExpanded = EditorGUILayout.Foldout(isMecanimExpanded, SpineInspectorUtility.TempContent("SkeletonAnimator", SpineInspectorUtility.UnityIcon<SceneAsset>()));
if (isMecanimExpanded) {
@ -569,7 +569,7 @@ namespace Spine.Unity.Editor {
} else {
List<string> missingPaths = null;
if (atlasAssets.arraySize > 0) {
missingPaths = SpineEditorUtilities.GetRequiredAtlasRegions(AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue));
missingPaths = SpineEditorUtilities.AssetUtility.GetRequiredAtlasRegions(AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue));
foreach (var atlas in atlasList) {
for (int i = 0; i < missingPaths.Count; i++) {
@ -587,8 +587,8 @@ namespace Spine.Unity.Editor {
}
if (missingPaths != null) {
foreach (string str in missingPaths)
warnings.Add("Missing Region: '" + str + "'");
foreach (string missingRegion in missingPaths)
warnings.Add(string.Format("Missing Region: '{0}'", missingRegion));
}
}
@ -599,7 +599,7 @@ namespace Spine.Unity.Editor {
}
void DoReimport () {
SpineEditorUtilities.ImportSpineContent(new [] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, true);
SpineEditorUtilities.AssetUtility.ImportSpineContent(new [] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, true);
preview.Clear();
InitializeEditor();
EditorUtility.SetDirty(targetSkeletonDataAsset);