mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 22:34:53 +08:00
[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:
parent
e6688e2514
commit
d00be040e2
@ -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();
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user