[unity] Adapted skeleton baking window to Unity 2018.3 prefab API and added it to context menu again. Closes #1471.

This commit is contained in:
Harald Csaszar 2019-09-27 17:22:19 +02:00
parent 19bbd5519f
commit 9c11431988
2 changed files with 15 additions and 11 deletions

View File

@ -184,9 +184,7 @@ namespace Spine.Unity.Editor {
Debug.LogError("Could not export Spine Skeleton because SkeletonDataAsset is null or invalid!");
return;
}
#if !NEW_PREFAB_SYSTEM
if (outputPath == "") {
outputPath = System.IO.Path.GetDirectoryName(AssetDatabase.GetAssetPath(skeletonDataAsset)) + "/Baked";
System.IO.Directory.CreateDirectory(outputPath);
@ -281,7 +279,13 @@ namespace Spine.Unity.Editor {
Object prefab = AssetDatabase.LoadAssetAtPath(prefabPath, typeof(GameObject));
if (prefab == null) {
#if NEW_PREFAB_SYSTEM
GameObject emptyGameObject = new GameObject();
prefab = PrefabUtility.SaveAsPrefabAssetAndConnect(emptyGameObject, prefabPath, InteractionMode.AutomatedAction);
GameObject.DestroyImmediate(emptyGameObject);
#else
prefab = PrefabUtility.CreateEmptyPrefab(prefabPath);
#endif
newPrefab = true;
}
@ -428,14 +432,22 @@ namespace Spine.Unity.Editor {
}
if (newPrefab) {
#if NEW_PREFAB_SYSTEM
PrefabUtility.SaveAsPrefabAssetAndConnect(prefabRoot, prefabPath, InteractionMode.AutomatedAction);
#else
PrefabUtility.ReplacePrefab(prefabRoot, prefab, ReplacePrefabOptions.ConnectToPrefab);
#endif
} else {
foreach (string str in unusedMeshNames) {
Mesh.DestroyImmediate(meshTable[str], true);
}
#if NEW_PREFAB_SYSTEM
PrefabUtility.SaveAsPrefabAssetAndConnect(prefabRoot, prefabPath, InteractionMode.AutomatedAction);
#else
PrefabUtility.ReplacePrefab(prefabRoot, prefab, ReplacePrefabOptions.ReplaceNameBased);
#endif
}
@ -447,8 +459,6 @@ namespace Spine.Unity.Editor {
GameObject.DestroyImmediate(prefabRoot);
}
#endif
}
#region Attachment Baking

View File

@ -27,10 +27,6 @@
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#if UNITY_2018_3 || UNITY_2019 || UNITY_2018_3_OR_NEWER
#define NEW_PREFAB_SYSTEM
#endif
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
@ -44,7 +40,6 @@ namespace Spine.Unity.Editor {
public class SkeletonBakingWindow : EditorWindow {
const bool IsUtilityWindow = true;
#if !NEW_PREFAB_SYSTEM
[MenuItem("CONTEXT/SkeletonDataAsset/Skeleton Baking", false, 5000)]
public static void Init (MenuCommand command) {
var window = EditorWindow.GetWindow<SkeletonBakingWindow>(IsUtilityWindow);
@ -54,7 +49,6 @@ namespace Spine.Unity.Editor {
window.skeletonDataAsset = command.context as SkeletonDataAsset;
window.Show();
}
#endif
public SkeletonDataAsset skeletonDataAsset;
[SpineSkin(dataField:"skeletonDataAsset")]