mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[unity] More class segregation for SpineEditorUtilities.
This commit is contained in:
parent
2a792c0247
commit
a04242cacf
@ -81,9 +81,7 @@ namespace Spine.Unity.Editor {
|
|||||||
public static Texture2D hingeChain;
|
public static Texture2D hingeChain;
|
||||||
public static Texture2D subMeshRenderer;
|
public static Texture2D subMeshRenderer;
|
||||||
public static Texture2D skeletonDataAssetIcon;
|
public static Texture2D skeletonDataAssetIcon;
|
||||||
|
|
||||||
public static Texture2D info;
|
public static Texture2D info;
|
||||||
|
|
||||||
public static Texture2D unity;
|
public static Texture2D unity;
|
||||||
// public static Texture2D controllerIcon;
|
// public static Texture2D controllerIcon;
|
||||||
|
|
||||||
@ -163,8 +161,6 @@ namespace Spine.Unity.Editor {
|
|||||||
static readonly List<ScriptableObject> protectFromStackGarbageCollection = new List<ScriptableObject>();
|
static readonly List<ScriptableObject> protectFromStackGarbageCollection = new List<ScriptableObject>();
|
||||||
static HashSet<string> assetsImportedInWrongState = new HashSet<string>();
|
static HashSet<string> assetsImportedInWrongState = new HashSet<string>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if SPINE_TK2D
|
#if SPINE_TK2D
|
||||||
const float DEFAULT_DEFAULT_SCALE = 1f;
|
const float DEFAULT_DEFAULT_SCALE = 1f;
|
||||||
#else
|
#else
|
||||||
@ -189,6 +185,10 @@ namespace Spine.Unity.Editor {
|
|||||||
const string SHOW_HIERARCHY_ICONS_KEY = "SPINE_SHOW_HIERARCHY_ICONS";
|
const string SHOW_HIERARCHY_ICONS_KEY = "SPINE_SHOW_HIERARCHY_ICONS";
|
||||||
public static bool showHierarchyIcons = DEFAULT_SHOW_HIERARCHY_ICONS;
|
public static bool showHierarchyIcons = DEFAULT_SHOW_HIERARCHY_ICONS;
|
||||||
|
|
||||||
|
const bool DEFAULT_SET_TEXTUREIMPORTER_SETTINGS = true;
|
||||||
|
const string SET_TEXTUREIMPORTER_SETTINGS_KEY = "SPINE_SET_TEXTUREIMPORTER_SETTINGS";
|
||||||
|
public static bool setTextureImporterSettings = DEFAULT_SET_TEXTUREIMPORTER_SETTINGS;
|
||||||
|
|
||||||
internal const float DEFAULT_MIPMAPBIAS = -0.5f;
|
internal const float DEFAULT_MIPMAPBIAS = -0.5f;
|
||||||
|
|
||||||
public const float DEFAULT_SCENE_ICONS_SCALE = 1f;
|
public const float DEFAULT_SCENE_ICONS_SCALE = 1f;
|
||||||
@ -205,6 +205,7 @@ namespace Spine.Unity.Editor {
|
|||||||
defaultZSpacing = EditorPrefs.GetFloat(DEFAULT_ZSPACING_KEY, DEFAULT_DEFAULT_ZSPACING);
|
defaultZSpacing = EditorPrefs.GetFloat(DEFAULT_ZSPACING_KEY, DEFAULT_DEFAULT_ZSPACING);
|
||||||
defaultShader = EditorPrefs.GetString(DEFAULT_SHADER_KEY, DEFAULT_DEFAULT_SHADER);
|
defaultShader = EditorPrefs.GetString(DEFAULT_SHADER_KEY, DEFAULT_DEFAULT_SHADER);
|
||||||
showHierarchyIcons = EditorPrefs.GetBool(SHOW_HIERARCHY_ICONS_KEY, DEFAULT_SHOW_HIERARCHY_ICONS);
|
showHierarchyIcons = EditorPrefs.GetBool(SHOW_HIERARCHY_ICONS_KEY, DEFAULT_SHOW_HIERARCHY_ICONS);
|
||||||
|
setTextureImporterSettings = EditorPrefs.GetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, DEFAULT_SET_TEXTUREIMPORTER_SETTINGS);
|
||||||
SpineHandles.handleScale = EditorPrefs.GetFloat(SCENE_ICONS_SCALE_KEY, DEFAULT_SCENE_ICONS_SCALE);
|
SpineHandles.handleScale = EditorPrefs.GetFloat(SCENE_ICONS_SCALE_KEY, DEFAULT_SCENE_ICONS_SCALE);
|
||||||
preferencesLoaded = true;
|
preferencesLoaded = true;
|
||||||
}
|
}
|
||||||
@ -285,6 +286,13 @@ namespace Spine.Unity.Editor {
|
|||||||
EditorPrefs.SetString(DEFAULT_SHADER_KEY, defaultShader);
|
EditorPrefs.SetString(DEFAULT_SHADER_KEY, defaultShader);
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
|
|
||||||
|
EditorGUI.BeginChangeCheck();
|
||||||
|
setTextureImporterSettings = EditorGUILayout.Toggle(new GUIContent("Apply Atlas Texture Settings", "Apply the recommended settings for Texture Importers."), showHierarchyIcons);
|
||||||
|
if (EditorGUI.EndChangeCheck()) {
|
||||||
|
EditorPrefs.SetBool(SET_TEXTUREIMPORTER_SETTINGS_KEY, showHierarchyIcons);
|
||||||
|
SpineEditorHierarchyHandler.HierarchyIconsOnPlaymodeStateChanged();
|
||||||
|
}
|
||||||
|
|
||||||
EditorGUILayout.LabelField("Editor Instantiation", EditorStyles.boldLabel);
|
EditorGUILayout.LabelField("Editor Instantiation", EditorStyles.boldLabel);
|
||||||
EditorGUI.BeginChangeCheck();
|
EditorGUI.BeginChangeCheck();
|
||||||
defaultZSpacing = EditorGUILayout.Slider("Default Slot Z-Spacing", defaultZSpacing, -0.1f, 0f);
|
defaultZSpacing = EditorGUILayout.Slider("Default Slot Z-Spacing", defaultZSpacing, -0.1f, 0f);
|
||||||
@ -308,9 +316,9 @@ namespace Spine.Unity.Editor {
|
|||||||
using (new GUILayout.HorizontalScope()) {
|
using (new GUILayout.HorizontalScope()) {
|
||||||
EditorGUILayout.PrefixLabel("Define TK2D");
|
EditorGUILayout.PrefixLabel("Define TK2D");
|
||||||
if (GUILayout.Button("Enable", GUILayout.Width(64)))
|
if (GUILayout.Button("Enable", GUILayout.Width(64)))
|
||||||
EnableTK2D();
|
SpineTK2DEditorUtility.EnableTK2D();
|
||||||
if (GUILayout.Button("Disable", GUILayout.Width(64)))
|
if (GUILayout.Button("Disable", GUILayout.Width(64)))
|
||||||
DisableTK2D();
|
SpineTK2DEditorUtility.DisableTK2D();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
@ -624,12 +632,12 @@ namespace Spine.Unity.Editor {
|
|||||||
break;
|
break;
|
||||||
case ".json":
|
case ".json":
|
||||||
var jsonAsset = (TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset));
|
var jsonAsset = (TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset));
|
||||||
if (jsonAsset != null && IsSpineData(jsonAsset))
|
if (jsonAsset != null && SkeletonDataFileValidator.IsSpineData(jsonAsset))
|
||||||
skeletonPaths.Add(str);
|
skeletonPaths.Add(str);
|
||||||
break;
|
break;
|
||||||
case ".bytes":
|
case ".bytes":
|
||||||
if (str.ToLower().EndsWith(".skel.bytes", System.StringComparison.Ordinal)) {
|
if (str.ToLower().EndsWith(".skel.bytes", System.StringComparison.Ordinal)) {
|
||||||
if (IsSpineData((TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset))))
|
if (SkeletonDataFileValidator.IsSpineData((TextAsset)AssetDatabase.LoadAssetAtPath(str, typeof(TextAsset))))
|
||||||
skeletonPaths.Add(str);
|
skeletonPaths.Add(str);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -647,7 +655,7 @@ namespace Spine.Unity.Editor {
|
|||||||
// Import skeletons and match them with atlases.
|
// Import skeletons and match them with atlases.
|
||||||
bool abortSkeletonImport = false;
|
bool abortSkeletonImport = false;
|
||||||
foreach (string sp in skeletonPaths) {
|
foreach (string sp in skeletonPaths) {
|
||||||
if (!reimport && CheckForValidSkeletonData(sp)) {
|
if (!reimport && SkeletonDataFileValidator.CheckForValidSkeletonData(sp)) {
|
||||||
ReloadSkeletonData(sp);
|
ReloadSkeletonData(sp);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -770,7 +778,6 @@ namespace Spine.Unity.Editor {
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Match SkeletonData with Atlases
|
#region Match SkeletonData with Atlases
|
||||||
//static readonly AttachmentType[] NonAtlasTypes = { AttachmentType.Boundingbox, AttachmentType.Path };
|
|
||||||
static readonly AttachmentType[] AtlasTypes = { AttachmentType.Region, AttachmentType.Linkedmesh, AttachmentType.Mesh };
|
static readonly AttachmentType[] AtlasTypes = { AttachmentType.Region, AttachmentType.Linkedmesh, AttachmentType.Mesh };
|
||||||
|
|
||||||
static List<AtlasAsset> MultiAtlasDialog (List<string> requiredPaths, string initialDirectory, string filename = "") {
|
static List<AtlasAsset> MultiAtlasDialog (List<string> requiredPaths, string initialDirectory, string filename = "") {
|
||||||
@ -1042,27 +1049,24 @@ namespace Spine.Unity.Editor {
|
|||||||
string texturePath = assetPath + "/" + pageFiles[i];
|
string texturePath = assetPath + "/" + pageFiles[i];
|
||||||
Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D));
|
Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D));
|
||||||
|
|
||||||
|
if (setTextureImporterSettings) {
|
||||||
TextureImporter texImporter = (TextureImporter)TextureImporter.GetAtPath(texturePath);
|
TextureImporter texImporter = (TextureImporter)TextureImporter.GetAtPath(texturePath);
|
||||||
if (texImporter == null) {
|
if (texImporter == null) {
|
||||||
Debug.LogWarning(string.Format("{0} ::: Texture asset \"{1}\" not found. Skipping. Please check your atlas file for renamed files.", atlasAsset.name, texturePath));
|
Debug.LogWarning(string.Format("{0} ::: Texture asset \"{1}\" not found. Skipping. Please check your atlas file for renamed files.", atlasAsset.name, texturePath));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_5_5_OR_NEWER
|
|
||||||
texImporter.textureCompression = TextureImporterCompression.Uncompressed;
|
texImporter.textureCompression = TextureImporterCompression.Uncompressed;
|
||||||
texImporter.alphaSource = TextureImporterAlphaSource.FromInput;
|
texImporter.alphaSource = TextureImporterAlphaSource.FromInput;
|
||||||
#else
|
|
||||||
texImporter.textureType = TextureImporterType.Advanced;
|
|
||||||
texImporter.textureFormat = TextureImporterFormat.AutomaticTruecolor;
|
|
||||||
#endif
|
|
||||||
texImporter.mipmapEnabled = false;
|
texImporter.mipmapEnabled = false;
|
||||||
texImporter.alphaIsTransparency = false; // Prevent the texture importer from applying bleed to the transparent parts.
|
texImporter.alphaIsTransparency = false; // Prevent the texture importer from applying bleed to the transparent parts for PMA.
|
||||||
texImporter.spriteImportMode = SpriteImportMode.None;
|
texImporter.spriteImportMode = SpriteImportMode.None;
|
||||||
texImporter.maxTextureSize = 2048;
|
texImporter.maxTextureSize = 2048;
|
||||||
|
|
||||||
EditorUtility.SetDirty(texImporter);
|
EditorUtility.SetDirty(texImporter);
|
||||||
AssetDatabase.ImportAsset(texturePath);
|
AssetDatabase.ImportAsset(texturePath);
|
||||||
AssetDatabase.SaveAssets();
|
AssetDatabase.SaveAssets();
|
||||||
|
}
|
||||||
|
|
||||||
string pageName = Path.GetFileNameWithoutExtension(pageFiles[i]);
|
string pageName = Path.GetFileNameWithoutExtension(pageFiles[i]);
|
||||||
|
|
||||||
@ -1116,7 +1120,7 @@ namespace Spine.Unity.Editor {
|
|||||||
bool hasBakedRegions = false;
|
bool hasBakedRegions = false;
|
||||||
for (int i = 0; i < regions.Count; i++) {
|
for (int i = 0; i < regions.Count; i++) {
|
||||||
AtlasRegion region = regions[i];
|
AtlasRegion region = regions[i];
|
||||||
string bakedPrefabPath = Path.Combine(bakedDirPath, SpineEditorUtilities.GetPathSafeRegionName(region) + ".prefab").Replace("\\", "/");
|
string bakedPrefabPath = Path.Combine(bakedDirPath, SpineEditorUtilities.GetPathSafeName(region.name) + ".prefab").Replace("\\", "/");
|
||||||
GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(GameObject));
|
GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(GameObject));
|
||||||
if (prefab != null) {
|
if (prefab != null) {
|
||||||
BakeRegion(atlasAsset, region, false);
|
BakeRegion(atlasAsset, region, false);
|
||||||
@ -1140,7 +1144,7 @@ namespace Spine.Unity.Editor {
|
|||||||
string atlasAssetPath = AssetDatabase.GetAssetPath(atlasAsset);
|
string atlasAssetPath = AssetDatabase.GetAssetPath(atlasAsset);
|
||||||
string atlasAssetDirPath = Path.GetDirectoryName(atlasAssetPath);
|
string atlasAssetDirPath = Path.GetDirectoryName(atlasAssetPath);
|
||||||
string bakedDirPath = Path.Combine(atlasAssetDirPath, atlasAsset.name);
|
string bakedDirPath = Path.Combine(atlasAssetDirPath, atlasAsset.name);
|
||||||
string bakedPrefabPath = Path.Combine(bakedDirPath, GetPathSafeRegionName(region) + ".prefab").Replace("\\", "/");
|
string bakedPrefabPath = Path.Combine(bakedDirPath, GetPathSafeName(region.name) + ".prefab").Replace("\\", "/");
|
||||||
|
|
||||||
GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(GameObject));
|
GameObject prefab = (GameObject)AssetDatabase.LoadAssetAtPath(bakedPrefabPath, typeof(GameObject));
|
||||||
GameObject root;
|
GameObject root;
|
||||||
@ -1239,12 +1243,13 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Checking Methods
|
#region SkeletonDataFileValidator
|
||||||
|
internal static class SkeletonDataFileValidator {
|
||||||
static int[][] compatibleBinaryVersions = { new[] { 3, 6, 0 }, new[] { 3, 5, 0 } };
|
static int[][] compatibleBinaryVersions = { new[] { 3, 6, 0 }, new[] { 3, 5, 0 } };
|
||||||
static int[][] compatibleJsonVersions = { new[] { 3, 6, 0 }, new[] { 3, 7, 0 }, new[] { 3, 5, 0 } };
|
static int[][] compatibleJsonVersions = { new[] { 3, 6, 0 }, new[] { 3, 7, 0 }, new[] { 3, 5, 0 } };
|
||||||
//static bool isFixVersionRequired = false;
|
//static bool isFixVersionRequired = false;
|
||||||
|
|
||||||
static bool CheckForValidSkeletonData (string skeletonJSONPath) {
|
public static bool CheckForValidSkeletonData (string skeletonJSONPath) {
|
||||||
string dir = Path.GetDirectoryName(skeletonJSONPath);
|
string dir = Path.GetDirectoryName(skeletonJSONPath);
|
||||||
TextAsset textAsset = (TextAsset)AssetDatabase.LoadAssetAtPath(skeletonJSONPath, typeof(TextAsset));
|
TextAsset textAsset = (TextAsset)AssetDatabase.LoadAssetAtPath(skeletonJSONPath, typeof(TextAsset));
|
||||||
DirectoryInfo dirInfo = new DirectoryInfo(dir);
|
DirectoryInfo dirInfo = new DirectoryInfo(dir);
|
||||||
@ -1262,7 +1267,8 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static bool IsSpineData (TextAsset asset) {
|
public static bool IsSpineData (TextAsset asset) {
|
||||||
if (asset == null) return false;
|
if (asset == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
bool isSpineData = false;
|
bool isSpineData = false;
|
||||||
string rawVersion = null;
|
string rawVersion = null;
|
||||||
@ -1329,36 +1335,11 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
return isSpineData;
|
return isSpineData;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region SkeletonAnimation Menu
|
#region SkeletonAnimation Menu
|
||||||
// [MenuItem("Assets/Spine/Instantiate (SkeletonAnimation)", false, 10)]
|
|
||||||
// static void InstantiateSkeletonAnimation () {
|
|
||||||
// Object[] arr = Selection.objects;
|
|
||||||
// foreach (Object o in arr) {
|
|
||||||
// string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(o));
|
|
||||||
// string skinName = EditorPrefs.GetString(guid + "_lastSkin", "");
|
|
||||||
//
|
|
||||||
// InstantiateSkeletonAnimation((SkeletonDataAsset)o, skinName, false);
|
|
||||||
// SceneView.RepaintAll();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// [MenuItem("Assets/Spine/Instantiate (SkeletonAnimation)", true, 10)]
|
|
||||||
// static bool ValidateInstantiateSkeletonAnimation () {
|
|
||||||
// Object[] arr = Selection.objects;
|
|
||||||
//
|
|
||||||
// if (arr.Length == 0)
|
|
||||||
// return false;
|
|
||||||
//
|
|
||||||
// foreach (Object o in arr) {
|
|
||||||
// if (o.GetType() != typeof(SkeletonDataAsset))
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static void IngestAdvancedRenderSettings (SkeletonRenderer skeletonRenderer) {
|
public static void IngestAdvancedRenderSettings (SkeletonRenderer skeletonRenderer) {
|
||||||
const string PMAShaderQuery = "Spine/Skeleton";
|
const string PMAShaderQuery = "Spine/Skeleton";
|
||||||
const string TintBlackShaderQuery = "Tint Black";
|
const string TintBlackShaderQuery = "Tint Black";
|
||||||
@ -1504,7 +1485,8 @@ namespace Spine.Unity.Editor {
|
|||||||
#endif
|
#endif
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region TK2D Support
|
#region SpineTK2DEditorUtility
|
||||||
|
internal static class SpineTK2DEditorUtility {
|
||||||
const string SPINE_TK2D_DEFINE = "SPINE_TK2D";
|
const string SPINE_TK2D_DEFINE = "SPINE_TK2D";
|
||||||
|
|
||||||
static bool IsInvalidGroup (BuildTargetGroup group) {
|
static bool IsInvalidGroup (BuildTargetGroup group) {
|
||||||
@ -1515,7 +1497,7 @@ namespace Spine.Unity.Editor {
|
|||||||
group == BuildTargetGroup.Unknown;
|
group == BuildTargetGroup.Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void EnableTK2D () {
|
internal static void EnableTK2D () {
|
||||||
bool added = false;
|
bool added = false;
|
||||||
foreach (BuildTargetGroup group in System.Enum.GetValues(typeof(BuildTargetGroup))) {
|
foreach (BuildTargetGroup group in System.Enum.GetValues(typeof(BuildTargetGroup))) {
|
||||||
if (IsInvalidGroup(group))
|
if (IsInvalidGroup(group))
|
||||||
@ -1541,7 +1523,7 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void DisableTK2D () {
|
internal static void DisableTK2D () {
|
||||||
bool removed = false;
|
bool removed = false;
|
||||||
foreach (BuildTargetGroup group in System.Enum.GetValues(typeof(BuildTargetGroup))) {
|
foreach (BuildTargetGroup group in System.Enum.GetValues(typeof(BuildTargetGroup))) {
|
||||||
if (IsInvalidGroup(group))
|
if (IsInvalidGroup(group))
|
||||||
@ -1565,10 +1547,15 @@ namespace Spine.Unity.Editor {
|
|||||||
Debug.LogWarning("Already Removed Scripting Define Symbol " + SPINE_TK2D_DEFINE);
|
Debug.LogWarning("Already Removed Scripting Define Symbol " + SPINE_TK2D_DEFINE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public static string GetPathSafeRegionName (AtlasRegion region) {
|
//public static string GetPathSafeRegionName (AtlasRegion region) {
|
||||||
return region.name.Replace("/", "_");
|
// return region.name.Replace("/", "_");
|
||||||
|
//}
|
||||||
|
|
||||||
|
public static string GetPathSafeName (string name) {
|
||||||
|
return name.Replace("/", "_");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user