mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-06 10:46:53 +08:00
[unity] Fixed import infinite loop when Spine Preferences Default Shader does not exist. Closes #2310.
This commit is contained in:
parent
d75f2d1568
commit
3d2b6e50f3
@ -664,7 +664,7 @@ namespace Spine.Unity.Editor {
|
|||||||
Material material = (Material)AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material));
|
Material material = (Material)AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material));
|
||||||
|
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
Shader defaultShader = Shader.Find(SpineEditorUtilities.Preferences.DefaultShader);
|
Shader defaultShader = GetDefaultShader();
|
||||||
material = defaultShader != null ? new Material(defaultShader) : null;
|
material = defaultShader != null ? new Material(defaultShader) : null;
|
||||||
if (material) {
|
if (material) {
|
||||||
ApplyPMAOrStraightAlphaSettings(material, SpineEditorUtilities.Preferences.textureSettingsReference);
|
ApplyPMAOrStraightAlphaSettings(material, SpineEditorUtilities.Preferences.textureSettingsReference);
|
||||||
@ -737,6 +737,13 @@ namespace Spine.Unity.Editor {
|
|||||||
return loadedAtlas != null ? loadedAtlas : atlasAsset;
|
return loadedAtlas != null ? loadedAtlas : atlasAsset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Shader GetDefaultShader () {
|
||||||
|
Shader shader = Shader.Find(SpineEditorUtilities.Preferences.DefaultShader);
|
||||||
|
if (shader == null) shader = Shader.Find("Spine/Skeleton");
|
||||||
|
if (shader == null) shader = Shader.Find("Standard");
|
||||||
|
return shader;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool SpriteAtlasSettingsNeedAdjustment (UnityEngine.U2D.SpriteAtlas spriteAtlas) {
|
public static bool SpriteAtlasSettingsNeedAdjustment (UnityEngine.U2D.SpriteAtlas spriteAtlas) {
|
||||||
#if EXPOSES_SPRITE_ATLAS_UTILITIES
|
#if EXPOSES_SPRITE_ATLAS_UTILITIES
|
||||||
UnityEditor.U2D.SpriteAtlasPackingSettings packingSettings = UnityEditor.U2D.SpriteAtlasExtensions.GetPackingSettings(spriteAtlas);
|
UnityEditor.U2D.SpriteAtlasPackingSettings packingSettings = UnityEditor.U2D.SpriteAtlasExtensions.GetPackingSettings(spriteAtlas);
|
||||||
@ -851,24 +858,24 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
{
|
{
|
||||||
string pageName = "SpriteAtlas";
|
string pageName = "SpriteAtlas";
|
||||||
|
|
||||||
string materialPath = assetPath + "/" + primaryName + "_" + pageName + ".mat";
|
string materialPath = assetPath + "/" + primaryName + "_" + pageName + ".mat";
|
||||||
Material mat = AssetDatabase.LoadAssetAtPath<Material>(materialPath);
|
Material material = AssetDatabase.LoadAssetAtPath<Material>(materialPath);
|
||||||
|
|
||||||
if (mat == null) {
|
if (material == null) {
|
||||||
mat = new Material(Shader.Find(SpineEditorUtilities.Preferences.defaultShader));
|
Shader defaultShader = GetDefaultShader();
|
||||||
ApplyPMAOrStraightAlphaSettings(mat, SpineEditorUtilities.Preferences.textureSettingsReference);
|
material = defaultShader != null ? new Material(defaultShader) : null;
|
||||||
AssetDatabase.CreateAsset(mat, materialPath);
|
ApplyPMAOrStraightAlphaSettings(material, SpineEditorUtilities.Preferences.textureSettingsReference);
|
||||||
|
AssetDatabase.CreateAsset(material, materialPath);
|
||||||
} else {
|
} else {
|
||||||
vestigialMaterials.Remove(mat);
|
vestigialMaterials.Remove(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (texture != null)
|
if (texture != null)
|
||||||
mat.mainTexture = texture;
|
material.mainTexture = texture;
|
||||||
|
|
||||||
EditorUtility.SetDirty(mat);
|
EditorUtility.SetDirty(material);
|
||||||
// note: don't call AssetDatabase.SaveAssets() since this would trigger OnPostprocessAllAssets() every time unnecessarily.
|
// note: don't call AssetDatabase.SaveAssets() since this would trigger OnPostprocessAllAssets() every time unnecessarily.
|
||||||
populatingMaterials.Add(mat); //atlasAsset.materials[i] = mat;
|
populatingMaterials.Add(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
atlasAsset.materials = populatingMaterials.ToArray();
|
atlasAsset.materials = populatingMaterials.ToArray();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user