mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-08 03:36:52 +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";
|
pageName = "Material";
|
||||||
|
|
||||||
string materialPath = assetPath + "/" + primaryName + "_" + pageName + ".mat";
|
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) {
|
if (material == null) {
|
||||||
mat = new Material(Shader.Find(SpineEditorUtilities.Preferences.defaultShader));
|
Shader defaultShader = Shader.Find(SpineEditorUtilities.Preferences.DefaultShader);
|
||||||
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[i] = mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
atlasAsset.materials = populatingMaterials.ToArray();
|
atlasAsset.materials = populatingMaterials.ToArray();
|
||||||
|
|||||||
@ -66,6 +66,10 @@ namespace Spine.Unity.Editor {
|
|||||||
|
|
||||||
internal const string DEFAULT_DEFAULT_SHADER = "Spine/Skeleton";
|
internal const string DEFAULT_DEFAULT_SHADER = "Spine/Skeleton";
|
||||||
public string defaultShader = DEFAULT_DEFAULT_SHADER;
|
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;
|
internal const float DEFAULT_DEFAULT_ZSPACING = 0f;
|
||||||
public float defaultZSpacing = DEFAULT_DEFAULT_ZSPACING;
|
public float defaultZSpacing = DEFAULT_DEFAULT_ZSPACING;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user