mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-05 23:05:01 +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
24d4185016
commit
732595eb01
@ -659,7 +659,7 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
|
||||
void DoReimport () {
|
||||
AssetUtility.ImportSpineContent(new [] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, true);
|
||||
AssetUtility.ImportSpineContent(new [] { AssetDatabase.GetAssetPath(skeletonJSON.objectReferenceValue) }, null, true);
|
||||
preview.Clear();
|
||||
InitializeEditor();
|
||||
EditorUtility.SetDirty(targetSkeletonDataAsset);
|
||||
|
||||
@ -65,7 +65,7 @@ namespace Spine.Unity.Editor {
|
||||
public static readonly List<ScriptableObject> protectFromStackGarbageCollection = new List<ScriptableObject>();
|
||||
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,
|
||||
// asset database is not initialized until some point. During that period,
|
||||
// all attempts to load any assets using API (i.e. AssetDatabase.LoadAssetAtPath)
|
||||
@ -87,7 +87,7 @@ namespace Spine.Unity.Editor {
|
||||
if (AssetDatabaseAvailabilityDetector.IsAssetDatabaseAvailable()) {
|
||||
string[] combinedAssets = AssetUtility.assetsImportedInWrongState.ToArray();
|
||||
AssetUtility.assetsImportedInWrongState.Clear();
|
||||
AssetUtility.ImportSpineContent(combinedAssets);
|
||||
AssetUtility.ImportSpineContent(combinedAssets, texturesWithoutMetaFile);
|
||||
}
|
||||
}
|
||||
|
||||
@ -243,7 +243,9 @@ namespace Spine.Unity.Editor {
|
||||
}
|
||||
#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 imagePaths = new List<string>();
|
||||
var skeletonPaths = new List<PathAndProblemInfo>();
|
||||
@ -285,7 +287,7 @@ namespace Spine.Unity.Editor {
|
||||
if (ap.StartsWith("Packages"))
|
||||
continue;
|
||||
TextAsset atlasText = AssetDatabase.LoadAssetAtPath<TextAsset>(ap);
|
||||
AtlasAssetBase atlas = IngestSpineAtlas(atlasText);
|
||||
AtlasAssetBase atlas = IngestSpineAtlas(atlasText, texturesWithoutMetaFile);
|
||||
atlases.Add(atlas);
|
||||
}
|
||||
|
||||
@ -428,7 +430,7 @@ namespace Spine.Unity.Editor {
|
||||
return arr;
|
||||
}
|
||||
|
||||
static AtlasAssetBase IngestSpineAtlas (TextAsset atlasText) {
|
||||
static AtlasAssetBase IngestSpineAtlas (TextAsset atlasText, List<string> texturesWithoutMetaFile) {
|
||||
if (atlasText == null) {
|
||||
Debug.LogWarning("Atlas source cannot be null!");
|
||||
return null;
|
||||
@ -469,8 +471,9 @@ namespace Spine.Unity.Editor {
|
||||
for (int i = 0; i < pageFiles.Count; i++) {
|
||||
string texturePath = assetPath + "/" + pageFiles[i];
|
||||
Texture2D texture = (Texture2D)AssetDatabase.LoadAssetAtPath(texturePath, typeof(Texture2D));
|
||||
if (SpineEditorUtilities.Preferences.setTextureImporterSettings) {
|
||||
SetDefaultTextureSettingsIfNew(texturePath, atlasAsset);
|
||||
bool textureIsUninitialized = texturesWithoutMetaFile != null && texturesWithoutMetaFile.Contains(texturePath);
|
||||
if (SpineEditorUtilities.Preferences.setTextureImporterSettings && textureIsUninitialized) {
|
||||
SetDefaultTextureSettings(texturePath, atlasAsset);
|
||||
}
|
||||
|
||||
string pageName = Path.GetFileNameWithoutExtension(pageFiles[i]);
|
||||
@ -546,27 +549,13 @@ namespace Spine.Unity.Editor {
|
||||
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);
|
||||
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));
|
||||
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.alphaSource = TextureImporterAlphaSource.FromInput;
|
||||
texImporter.mipmapEnabled = false;
|
||||
|
||||
@ -65,13 +65,27 @@ namespace Spine.Unity.Editor {
|
||||
public static string editorPath = "";
|
||||
public static string editorGUIPath = "";
|
||||
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) {
|
||||
if (imported.Length == 0)
|
||||
return;
|
||||
|
||||
AssetUtility.HandleOnPostprocessAllAssets(imported);
|
||||
AssetUtility.HandleOnPostprocessAllAssets(imported, texturesWithoutMetaFile);
|
||||
texturesWithoutMetaFile.Clear();
|
||||
}
|
||||
|
||||
#region Initialization
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user