private void UpdateFeaturesFromShader() { if (targetMaterial != null && targetMaterial.shader != null) { string name = targetMaterial.shader.name; if (name.Contains("Mobile")) { isMobileShader = true; } else { isMobileShader = false; } List <string> nameFeatures = new List <string>(name.Split(' ')); for (int i = 0; i < ShaderVariants.Count; i++) { ShaderVariantsEnabled[i] = nameFeatures.Contains(ShaderVariants[i]); } //Get flags for compiled shader to hide certain parts of the UI ShaderImporter shaderImporter = ShaderImporter.GetAtPath(AssetDatabase.GetAssetPath(targetMaterial.shader)) as ShaderImporter; if (shaderImporter != null) { // mShaderFeatures = new List<string>(shaderImporter.userData.Split(new string[]{","}, System.StringSplitOptions.RemoveEmptyEntries)); TCP2_ShaderGeneratorUtils.ParseUserData(shaderImporter, out mShaderFeatures); if (mShaderFeatures.Count > 0 && mShaderFeatures[0] == "USER") { isGeneratedShader = true; } } } }
private void LoadCurrentConfigFromShader(Shader shader) { ShaderImporter shaderImporter = ShaderImporter.GetAtPath(AssetDatabase.GetAssetPath(shader)) as ShaderImporter; string[] features; string[] flags; string[] customData; Dictionary <string, string> keywords; TCP2_ShaderGeneratorUtils.ParseUserData(shaderImporter, out features, out flags, out keywords, out customData); if (features != null && features.Length > 0 && features[0] == "USER") { mCurrentConfig = new TCP2_Config(); mCurrentConfig.ShaderName = shader.name; mCurrentConfig.Filename = System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(shader)); mCurrentConfig.Features = new List <string>(features); mCurrentConfig.Flags = (flags != null) ? new List <string>(flags) : new List <string>(); mCurrentConfig.Keywords = (keywords != null) ? new Dictionary <string, string>(keywords) : new Dictionary <string, string>(); mCurrentShader = shader; mConfigChoice = mUserShadersLabels.IndexOf(shader.name); mDirtyConfig = false; AutoNames(); mCurrentHash = mCurrentConfig.ToHash(); mIsModified = false; if (customData != null && customData.Length > 0) { ulong timestamp; if (ulong.TryParse(customData[0], out timestamp)) { if (shaderImporter.assetTimeStamp != timestamp) { mIsModified = true; } } } } else { EditorApplication.Beep(); this.ShowNotification(new GUIContent("Invalid shader loaded: it doesn't seem to have been generated by the TCP2 Shader Generator!")); mCurrentShader = null; NewShader(); } }
//-------------------------------------------------------------------------------------------------- public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader) { base.AssignNewShaderToMaterial(material, oldShader, newShader); //Detect if User Shader (from Shader Generator) isGeneratedShader = false; mShaderFeatures = null; ShaderImporter shaderImporter = ShaderImporter.GetAtPath(AssetDatabase.GetAssetPath(newShader)) as ShaderImporter; if (shaderImporter != null) { TCP2_ShaderGeneratorUtils.ParseUserData(shaderImporter, out mShaderFeatures); if (mShaderFeatures.Count > 0 && mShaderFeatures[0] == "USER") { isGeneratedShader = true; } } }
static public TCP2_Config CreateFromShader(Shader shader) { ShaderImporter shaderImporter = ShaderImporter.GetAtPath(AssetDatabase.GetAssetPath(shader)) as ShaderImporter; string[] features; string[] flags; string[] customData; Dictionary <string, string> keywords; TCP2_ShaderGeneratorUtils.ParseUserData(shaderImporter, out features, out flags, out keywords, out customData); if (features != null && features.Length > 0 && features[0] == "USER") { var config = new TCP2_Config(); config.ShaderName = shader.name; config.Filename = System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(shader)); config.Features = new List <string>(features); config.Flags = (flags != null) ? new List <string>(flags) : new List <string>(); config.Keywords = (keywords != null) ? new Dictionary <string, string>(keywords) : new Dictionary <string, string>(); config.AutoNames(); //mCurrentShader = shader; //mConfigChoice = mUserShadersLabels.IndexOf(shader.name); //mDirtyConfig = false; //AutoNames(); //mCurrentHash = mCurrentConfig.ToHash(); config.isModifiedExternally = false; if (customData != null && customData.Length > 0) { foreach (string data in customData) { //Hash if (data.Length > 0 && data[0] == 'h') { string dataHash = data; string fileHash = TCP2_ShaderGeneratorUtils.GetShaderContentHash(shaderImporter); if (!string.IsNullOrEmpty(fileHash) && dataHash != fileHash) { config.isModifiedExternally = true; } } //Timestamp else { ulong timestamp; if (ulong.TryParse(data, out timestamp)) { if (shaderImporter.assetTimeStamp != timestamp) { config.isModifiedExternally = true; } } } //Shader Model target if (data.StartsWith("SM:")) { config.shaderTarget = int.Parse(data.Substring(3)); } //Configuration Type if (data.StartsWith("CT:")) { config.configType = data.Substring(3); } //Configuration File if (data.StartsWith("CF:")) { config.templateFile = data.Substring(3); } } } return(config); } else { return(null); } }