private static Material CreateStep_Material(Shader shader) { string path = ""; if (edit.newCopy || string.IsNullOrEmpty(edit.data.materialGUID) || string.IsNullOrEmpty(AssetDatabase.GUIDToAssetPath(edit.data.materialGUID))) { path = string.Format("{0}{1}.mat", edit.folderPath, edit.data.title); } else { path = SWCommon.AssetDBPath2Path(AssetDatabase.GUIDToAssetPath(edit.data.materialGUID)); } Material m = AssetDatabase.LoadAssetAtPath <Material> (SWCommon.Path2AssetDBPath(path)); if (m == null) { m = new Material(shader); SetMaterialProp(m, edit); m = SWCommon.SaveReload <Material> (m, path); } else { m.shader = shader; SetMaterialProp(m, edit); } edit.data.materialGUID = SWEditorTools.ObjectToGUID(m); return(m); }
public static Material CreateMaterial(SWWindowMain edit) { foreach (var item in edit.NodeAll()) { item.Value.shaderOutput = null; } SWShaderCreaterBase sc = null; if (edit.data.shaderType == SWShaderType.normal) { sc = new SWShaderCreaterBase (edit); } if (edit.data.shaderType == SWShaderType.ui) { sc = new SWShaderCreaterUI (edit); } if (edit.data.shaderType == SWShaderType.uiFont) { sc = new SWShaderCreaterUIFont (edit); } if (edit.data.shaderType == SWShaderType.sprite) { if(edit.data.spriteLightType == SWSpriteLightType.no) sc = new SWShaderCreaterSprite (edit); else if(edit.data.spriteLightType == SWSpriteLightType.diffuse) sc = new SWShaderCreaterSpriteLight (edit); } float f = Time.realtimeSinceStartup; string txt = sc.CreateShaderText(); var shader = CreateShader (edit,txt); string path = ""; if (edit.newCopy || string.IsNullOrEmpty (edit.data.materialGUID)) path = string.Format ("{0}{1}.mat", edit.folderPath, edit.data.title); else path = SWCommon.AssetDBPath2Path(AssetDatabase.GUIDToAssetPath (edit.data.materialGUID)); Material m = AssetDatabase.LoadAssetAtPath<Material> (SWCommon.Path2AssetDBPath(path)); if (m == null) { m = new Material (shader); SetMaterialProp (m, edit); m = SWCommon.SaveReload<Material> (m, path); } else { m.shader = shader; SetMaterialProp (m, edit); } edit.data.materialGUID = SWEditorTools.ObjectToGUID (m); return m; }