public Material RecreateShaderAndCreateMaterial(Shader patternShader) { #if UNITY_EDITOR var oldShaderPath = ShaderCustomizationUtils.RetriveShaderPath(patternShader); var text = System.IO.File.ReadAllText(oldShaderPath); text = ModifyShaderText(text); var newFileSuffix = GetInstanceID().ToString(); var newShaderPath = ShaderCustomizationUtils.CreateImitationShaderPath(oldShaderPath, newFileSuffix, _imitationsDirectoryName); File.WriteAllText(newShaderPath, text); AssetDatabase.Refresh(); var newShader = ShaderCustomizationUtils.LoadAssetAtPath(newShaderPath); var newMaterial = new Material(newShader); return(newMaterial); #else Preconditions.Fail("RecreateShaderAndCreateMaterial is not supported in build "); return(null); #endif }
public void RecreateShader() { #if UNITY_EDITOR var oldShaderPath = ShaderCustomizationUtils.RetriveShaderPath(PatternShader); var text = System.IO.File.ReadAllText(oldShaderPath); var newFileSuffix = GetInstanceID().ToString(); text = ModifyShaderText(text, newFileSuffix); var newShaderPath = ShaderCustomizationUtils.CreateImitationShaderPath(oldShaderPath, newFileSuffix, _imitationsDirectoryName); File.WriteAllText(newShaderPath, text); AssetDatabase.Refresh(); var newShader = ShaderCustomizationUtils.LoadAssetAtPath(newShaderPath); var newMaterial = new Material(newShader); var renderer = GetComponent <Renderer>(); ShaderCustomizationUtils.TransferProperties(renderer.sharedMaterial, newMaterial); SetMaterialAndUpdateBuffers(renderer, newMaterial); #else Preconditions.Fail("RecteateShader is not supported in build "); #endif }