mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-23 02:06:46 +08:00
[unity] SetDefaultTextureSettings was not called properly on import. Now fixed with working proper meta-file based solution. Closes #1514.
This commit is contained in:
parent
f595659423
commit
ae2d40fd84
@ -659,7 +659,7 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DoReimport () {
|
void DoReimport () {
|
||||||
AssetUtility.ImportSpineContent(new [] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, true);
|
AssetUtility.ImportSpineContent(new [] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, null, true);
|
||||||
preview.Clear();
|
preview.Clear();
|
||||||
InitializeEditor();
|
InitializeEditor();
|
||||||
EditorUtility.SetDirty(targetSkeletonDataAsset);
|
EditorUtility.SetDirty(targetSkeletonDataAsset);
|
||||||
|
|||||||
@ -65,7 +65,7 @@ namespace Spine.Unity.Editor {
|
|||||||
public static readonly List<ScriptableObject> protectFromStackGarbageCollection = new List<ScriptableObject>();
|
public static readonly List<ScriptableObject> protectFromStackGarbageCollection = new List<ScriptableObject>();
|
||||||
public static HashSet<string> assetsImportedInWrongState = new HashSet<string>();
|
public static HashSet<string> assetsImportedInWrongState = new HashSet<string>();
|
||||||
|
|
||||||
public static void HandleOnPostprocessAllAssets (string[] imported) {
|
public static void HandleOnPostprocessAllAssets (string[] imported, List<string> texturesWithoutMetaFile) {
|
||||||
// In case user used "Assets -> Reimport All", during the import process,
|
// In case user used "Assets -> Reimport All", during the import process,
|
||||||
// asset database is not initialized until some point. During that period,
|
// asset database is not initialized until some point. During that period,
|
||||||
// all attempts to load any assets using API (i.e. AssetDatabase.LoadAssetAtPath)
|
// all attempts to load any assets using API (i.e. AssetDatabase.LoadAssetAtPath)
|
||||||
@ -87,7 +87,7 @@ namespace Spine.Unity.Editor {
|
|||||||
if (AssetDatabaseAvailabilityDetector.IsAssetDatabaseAvailable()) {
|
if (AssetDatabaseAvailabilityDetector.IsAssetDatabaseAvailable()) {
|
||||||
string[] combinedAssets = AssetUtility.assetsImportedInWrongState.ToArray();
|
string[] combinedAssets = AssetUtility.assetsImportedInWrongState.ToArray();
|
||||||
AssetUtility.assetsImportedInWrongState.Clear();
|
AssetUtility.assetsImportedInWrongState.Clear();
|
||||||
AssetUtility.ImportSpineContent(combinedAssets);
|
AssetUtility.ImportSpineContent(combinedAssets, texturesWithoutMetaFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,7 +243,9 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public static void ImportSpineContent (string[] imported, bool reimport = false) {
|
public static void ImportSpineContent (string[] imported, List<string> texturesWithoutMetaFile,
|
||||||
|
bool reimport = false) {
|
||||||
|
|
||||||
var atlasPaths = new List<string>();
|
var atlasPaths = new List<string>();
|
||||||
var imagePaths = new List<string>();
|
var imagePaths = new List<string>();
|
||||||
var skeletonPaths = new List<PathAndProblemInfo>();
|
var skeletonPaths = new List<PathAndProblemInfo>();
|
||||||
@ -285,7 +287,7 @@ namespace Spine.Unity.Editor {
|
|||||||
if (ap.StartsWith("Packages"))
|
if (ap.StartsWith("Packages"))
|
||||||
continue;
|
continue;
|
||||||
TextAsset atlasText = AssetDatabase.LoadAssetAtPath<TextAsset>(ap);
|
TextAsset atlasText = AssetDatabase.LoadAssetAtPath<TextAsset>(ap);
|
||||||
AtlasAssetBase atlas = IngestSpineAtlas(atlasText);
|
AtlasAssetBase atlas = IngestSpineAtlas(atlasText, texturesWithoutMetaFile);
|
||||||
atlases.Add(atlas);
|
atlases.Add(atlas);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,7 +430,7 @@ namespace Spine.Unity.Editor {
|
|||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static AtlasAssetBase IngestSpineAtlas (TextAsset atlasText) {
|
static AtlasAssetBase IngestSpineAtlas (TextAsset atlasText, List<string> texturesWithoutMetaFile) {
|
||||||
if (atlasText == null) {
|
if (atlasText == null) {
|
||||||
Debug.LogWarning("Atlas source cannot be null!");
|
Debug.LogWarning("Atlas source cannot be null!");
|
||||||
return null;
|
return null;
|
||||||
@ -469,8 +471,9 @@ namespace Spine.Unity.Editor {
|
|||||||
for (int i = 0; i < pageFiles.Count; i++) {
|
for (int i = 0; i < pageFiles.Count; i++) {
|
||||||
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 (SpineEditorUtilities.Preferences.setTextureImporterSettings) {
|
bool textureIsUninitialized = texturesWithoutMetaFile != null && texturesWithoutMetaFile.Contains(texturePath);
|
||||||
SetDefaultTextureSettingsIfNew(texturePath, atlasAsset);
|
if (SpineEditorUtilities.Preferences.setTextureImporterSettings && textureIsUninitialized) {
|
||||||
|
SetDefaultTextureSettings(texturePath, atlasAsset);
|
||||||
}
|
}
|
||||||
|
|
||||||
string pageName = Path.GetFileNameWithoutExtension(pageFiles[i]);
|
string pageName = Path.GetFileNameWithoutExtension(pageFiles[i]);
|
||||||
@ -546,27 +549,13 @@ namespace Spine.Unity.Editor {
|
|||||||
return (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAssetBase));
|
return (AtlasAssetBase)AssetDatabase.LoadAssetAtPath(atlasPath, typeof(AtlasAssetBase));
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool SetDefaultTextureSettingsIfNew (string texturePath, SpineAtlasAsset atlasAsset) {
|
static bool SetDefaultTextureSettings (string texturePath, SpineAtlasAsset atlasAsset) {
|
||||||
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));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if UNITY_2018_1_OR_NEWER
|
|
||||||
bool customTextureSettingsExist = !texImporter.importSettingsMissing;
|
|
||||||
#else
|
|
||||||
// unfortunately, importSettingsMissing is not available in Unity 2017,
|
|
||||||
// so we check if any settings deviate from Unity's default texture settings.
|
|
||||||
bool customTextureSettingsExist = texImporter.mipmapEnabled != true ||
|
|
||||||
texImporter.maxTextureSize != 2048 ||
|
|
||||||
texImporter.alphaIsTransparency != true ||
|
|
||||||
texImporter.wrapMode != TextureWrapMode.Repeat ||
|
|
||||||
texImporter.filterMode != FilterMode.Bilinear;
|
|
||||||
#endif
|
|
||||||
if (customTextureSettingsExist)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
texImporter.textureCompression = TextureImporterCompression.Uncompressed;
|
texImporter.textureCompression = TextureImporterCompression.Uncompressed;
|
||||||
texImporter.alphaSource = TextureImporterAlphaSource.FromInput;
|
texImporter.alphaSource = TextureImporterAlphaSource.FromInput;
|
||||||
texImporter.mipmapEnabled = false;
|
texImporter.mipmapEnabled = false;
|
||||||
|
|||||||
@ -65,13 +65,27 @@ namespace Spine.Unity.Editor {
|
|||||||
public static string editorPath = "";
|
public static string editorPath = "";
|
||||||
public static string editorGUIPath = "";
|
public static string editorGUIPath = "";
|
||||||
public static bool initialized;
|
public static bool initialized;
|
||||||
|
private static List<string> texturesWithoutMetaFile = new List<string>();
|
||||||
|
|
||||||
// Auto-import entry point
|
// Auto-import entry point for textures
|
||||||
|
void OnPreprocessTexture () {
|
||||||
|
#if UNITY_2018_1_OR_NEWER
|
||||||
|
bool customTextureSettingsExist = !assetImporter.importSettingsMissing;
|
||||||
|
#else
|
||||||
|
bool customTextureSettingsExist = System.IO.File.Exists(assetImporter.assetPath + ".meta");
|
||||||
|
#endif
|
||||||
|
if (!customTextureSettingsExist) {
|
||||||
|
texturesWithoutMetaFile.Add(assetImporter.assetPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Auto-import post process entry point for all assets
|
||||||
static void OnPostprocessAllAssets (string[] imported, string[] deleted, string[] moved, string[] movedFromAssetPaths) {
|
static void OnPostprocessAllAssets (string[] imported, string[] deleted, string[] moved, string[] movedFromAssetPaths) {
|
||||||
if (imported.Length == 0)
|
if (imported.Length == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
AssetUtility.HandleOnPostprocessAllAssets(imported);
|
AssetUtility.HandleOnPostprocessAllAssets(imported, texturesWithoutMetaFile);
|
||||||
|
texturesWithoutMetaFile.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Initialization
|
#region Initialization
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user