[unity] Fixed null reference exception upon import when default shader is used but preferences has default shader set to a non-existing/null shader path.

This commit is contained in:
Harald Csaszar 2022-05-05 17:34:21 +02:00
parent e6688e2514
commit d00be040e2
2 changed files with 14 additions and 9 deletions

View File

@ -575,22 +575,23 @@ namespace Spine.Unity.Editor {
pageName = "Material";
string materialPath = assetPath + "/" + primaryName + "_" + pageName + ".mat";
Material mat = (Material)AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material));
Material material = (Material)AssetDatabase.LoadAssetAtPath(materialPath, typeof(Material));
if (mat == null) {
mat = new Material(Shader.Find(SpineEditorUtilities.Preferences.defaultShader));
ApplyPMAOrStraightAlphaSettings(mat, SpineEditorUtilities.Preferences.textureSettingsReference);
AssetDatabase.CreateAsset(mat, materialPath);
if (material == null) {
Shader defaultShader = Shader.Find(SpineEditorUtilities.Preferences.DefaultShader);
material = defaultShader != null ? new Material(defaultShader) : null;
ApplyPMAOrStraightAlphaSettings(material, SpineEditorUtilities.Preferences.textureSettingsReference);
AssetDatabase.CreateAsset(material, materialPath);
} else {
vestigialMaterials.Remove(mat);
vestigialMaterials.Remove(material);
}
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.
populatingMaterials.Add(mat); //atlasAsset.materials[i] = mat;
populatingMaterials.Add(material); //atlasAsset.materials[i] = mat;
}
atlasAsset.materials = populatingMaterials.ToArray();

View File

@ -66,6 +66,10 @@ namespace Spine.Unity.Editor {
internal const string DEFAULT_DEFAULT_SHADER = "Spine/Skeleton";
public string defaultShader = DEFAULT_DEFAULT_SHADER;
public string DefaultShader {
get { return !string.IsNullOrEmpty(defaultShader) ? defaultShader : DEFAULT_DEFAULT_SHADER; }
set { defaultShader = value; }
}
internal const float DEFAULT_DEFAULT_ZSPACING = 0f;
public float defaultZSpacing = DEFAULT_DEFAULT_ZSPACING;