internal override void ResetValues() { base.ResetValues(); this.propertyNames = new List <string>(); this.displayNames = new List <string>(); this.textures = new List <Texture>(); this.dimensions = new List <ShaderUtil.ShaderPropertyTexDim>(); ShaderImporter target = this.target as ShaderImporter; if ((UnityEngine.Object)target == (UnityEngine.Object)null) { return; } Shader shader = target.GetShader(); if ((UnityEngine.Object)shader == (UnityEngine.Object)null) { return; } int propertyCount = ShaderUtil.GetPropertyCount(shader); for (int propertyIdx = 0; propertyIdx < propertyCount; ++propertyIdx) { if (ShaderUtil.GetPropertyType(shader, propertyIdx) == ShaderUtil.ShaderPropertyType.TexEnv) { string propertyName = ShaderUtil.GetPropertyName(shader, propertyIdx); string propertyDescription = ShaderUtil.GetPropertyDescription(shader, propertyIdx); Texture defaultTexture = target.GetDefaultTexture(propertyName); this.propertyNames.Add(propertyName); this.displayNames.Add(propertyDescription); this.textures.Add(defaultTexture); this.dimensions.Add(ShaderUtil.GetTexDim(shader, propertyIdx)); } } }
internal override bool HasModified() { if (base.HasModified()) { return(true); } ShaderImporter target = this.target as ShaderImporter; if ((UnityEngine.Object)target == (UnityEngine.Object)null) { return(false); } Shader shader = target.GetShader(); if ((UnityEngine.Object)shader == (UnityEngine.Object)null) { return(false); } int propertyCount = ShaderUtil.GetPropertyCount(shader); for (int propertyIdx = 0; propertyIdx < propertyCount; ++propertyIdx) { string propertyName = ShaderUtil.GetPropertyName(shader, propertyIdx); for (int index = 0; index < this.propertyNames.Count; ++index) { if (this.propertyNames[index] == propertyName && (UnityEngine.Object) this.textures[index] != (UnityEngine.Object)target.GetDefaultTexture(propertyName)) { return(true); } } } return(false); }
internal override bool HasModified() { if (base.HasModified()) { return(true); } ShaderImporter shaderImporter = this.target as ShaderImporter; if (shaderImporter == null) { return(false); } Shader shader = shaderImporter.GetShader(); if (shader == null) { return(false); } int propertyCount = ShaderUtil.GetPropertyCount(shader); for (int i = 0; i < propertyCount; i++) { string propertyName = ShaderUtil.GetPropertyName(shader, i); for (int j = 0; j < this.propertyNames.Count; j++) { if (this.propertyNames[j] == propertyName && this.textures[j] != shaderImporter.GetDefaultTexture(propertyName)) { return(true); } } } return(false); }
internal override void ResetValues() { base.ResetValues(); this.propertyNames = new List <string>(); this.displayNames = new List <string>(); this.textures = new List <Texture>(); this.dimensions = new List <TextureDimension>(); ShaderImporter shaderImporter = this.target as ShaderImporter; if (shaderImporter == null) { return; } Shader shader = shaderImporter.GetShader(); if (shader == null) { return; } int propertyCount = ShaderUtil.GetPropertyCount(shader); for (int i = 0; i < propertyCount; i++) { if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv) { string propertyName = ShaderUtil.GetPropertyName(shader, i); string propertyDescription = ShaderUtil.GetPropertyDescription(shader, i); Texture defaultTexture = shaderImporter.GetDefaultTexture(propertyName); this.propertyNames.Add(propertyName); this.displayNames.Add(propertyDescription); this.textures.Add(defaultTexture); this.dimensions.Add(ShaderUtil.GetTexDim(shader, i)); } } }
protected override void Apply() { base.Apply(); ShaderImporter shaderImporter = base.target as ShaderImporter; if (!(shaderImporter == null)) { shaderImporter.SetDefaultTextures(this.propertyNames.ToArray(), this.textures.ToArray()); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(shaderImporter)); } }
internal override void Apply() { base.Apply(); ShaderImporter target = base.target as ShaderImporter; if (target != null) { target.SetDefaultTextures(this.propertyNames.ToArray(), this.textures.ToArray()); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(target)); } }
internal override void Apply() { base.Apply(); ShaderImporter target = this.target as ShaderImporter; if ((UnityEngine.Object)target == (UnityEngine.Object)null) { return; } target.SetDefaultTextures(this.propertyNames.ToArray(), this.textures.ToArray()); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath((UnityEngine.Object)target)); }
internal override void Apply() { base.Apply(); ShaderImporter shaderImporter = this.target as ShaderImporter; if (shaderImporter == null) { return; } shaderImporter.SetDefaultTextures(this.propertyNames.ToArray(), this.textures.ToArray()); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(shaderImporter)); }
//Returns hash of file content to check for manual modifications (with 'h' prefix) public static string GetShaderContentHash(ShaderImporter importer) { string shaderHash = null; string shaderFilePath = Application.dataPath.Replace("Assets", "") + importer.assetPath; if(System.IO.File.Exists( shaderFilePath )) { string shaderContent = System.IO.File.ReadAllText( shaderFilePath ); shaderHash = (shaderContent != null) ? string.Format("h{0}", shaderContent.GetHashCode().ToString("X")) : ""; } return shaderHash; }
public override bool HasModified() { bool result; if (base.HasModified()) { result = true; } else { ShaderImporter shaderImporter = base.target as ShaderImporter; if (shaderImporter == null) { result = false; } else { Shader shader = shaderImporter.GetShader(); if (shader == null) { result = false; } else { int propertyCount = ShaderUtil.GetPropertyCount(shader); for (int i = 0; i < propertyCount; i++) { string propertyName = ShaderUtil.GetPropertyName(shader, i); for (int j = 0; j < this.m_Properties.Count; j++) { if (this.m_Properties[j].propertyName == propertyName) { Texture y = (!this.m_Properties[j].modifiable) ? shaderImporter.GetNonModifiableTexture(propertyName) : shaderImporter.GetDefaultTexture(propertyName); if (this.m_Properties[j].texture != y) { result = true; return(result); } } } } result = false; } } } return(result); }
// Compiled shader code button+dropdown private void ShowCompiledCodeButton(Shader s) { EditorGUILayout.BeginVertical(); ShaderImporter importer = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(s.GetInstanceID())) as ShaderImporter; bool enablePreprocessOnly = EditorSettings.cachingShaderPreprocessor; if (importer && importer.preprocessorOverride == PreprocessorOverride.ForceCachingPreprocessor) { enablePreprocessOnly = true; } using (new EditorGUI.DisabledScope(!enablePreprocessOnly)) s_PreprocessOnly = EditorGUILayout.Toggle(Styles.togglePreprocess, s_PreprocessOnly); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Compiled code", EditorStyles.miniButton); var hasCode = ShaderUtil.HasShaderSnippets(s) || ShaderUtil.HasSurfaceShaders(s) || ShaderUtil.HasFixedFunctionShaders(s); if (hasCode) { // button with a drop-down part on the right var modeContent = Styles.showCurrent; var modeRect = GUILayoutUtility.GetRect(modeContent, EditorStyles.miniButton, GUILayout.ExpandWidth(false)); var modeDropRect = new Rect(modeRect.xMax - 16, modeRect.y, 16, modeRect.height); if (EditorGUI.DropdownButton(modeDropRect, GUIContent.none, FocusType.Passive, GUIStyle.none)) { Rect rect = GUILayoutUtility.topLevel.GetLast(); PopupWindow.Show(rect, new ShaderInspectorPlatformsPopup(s)); GUIUtility.ExitGUI(); } if (GUI.Button(modeRect, modeContent, EditorStyles.miniButton)) { ShaderUtil.OpenCompiledShader(s, ShaderInspectorPlatformsPopup.currentMode, ShaderInspectorPlatformsPopup.currentPlatformMask, ShaderInspectorPlatformsPopup.currentVariantStripping == 0, enablePreprocessOnly && s_PreprocessOnly); GUIUtility.ExitGUI(); } } else { // Note: PrefixLabel is sometimes buggy if followed by a non-control (like Label). // We just want to show a label here, but have to pretend it's a button so it is treated like // a control. GUILayout.Button("none (precompiled shader)", GUI.skin.label); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); }
public override void OnInspectorGUI() { ShaderImporter target = base.target as ShaderImporter; if (target != null) { Shader shader = target.GetShader(); if (shader != null) { if (GetNumberOfTextures(shader) != this.propertyNames.Count) { this.ResetValues(); } this.ShowDefaultTextures(); base.ApplyRevertGUI(); } } }
public override void OnInspectorGUI() { ShaderImporter shaderImporter = base.target as ShaderImporter; if (!(shaderImporter == null)) { Shader shader = shaderImporter.GetShader(); if (!(shader == null)) { if (ShaderImporterInspector.GetNumberOfTextures(shader) != this.m_Properties.Count) { this.ResetValues(); } this.ShowTextures(); base.ApplyRevertGUI(); } } }
protected override void ResetValues() { base.ResetValues(); this.m_Properties.Clear(); ShaderImporter shaderImporter = base.target as ShaderImporter; if (!(shaderImporter == null)) { Shader shader = shaderImporter.GetShader(); if (!(shader == null)) { int propertyCount = ShaderUtil.GetPropertyCount(shader); for (int i = 0; i < propertyCount; i++) { if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv) { string propertyName = ShaderUtil.GetPropertyName(shader, i); string propertyDescription = ShaderUtil.GetPropertyDescription(shader, i); bool flag = !ShaderUtil.IsShaderPropertyNonModifiableTexureProperty(shader, i); Texture texture; if (!flag) { texture = shaderImporter.GetNonModifiableTexture(propertyName); } else { texture = shaderImporter.GetDefaultTexture(propertyName); } ShaderImporterInspector.TextureProp item = new ShaderImporterInspector.TextureProp { propertyName = propertyName, texture = texture, dimension = ShaderUtil.GetTexDim(shader, i), displayName = propertyDescription, modifiable = flag }; this.m_Properties.Add(item); } } } } }
public override void OnInspectorGUI() { ShaderImporter target = this.target as ShaderImporter; if ((UnityEngine.Object)target == (UnityEngine.Object)null) { return; } Shader shader = target.GetShader(); if ((UnityEngine.Object)shader == (UnityEngine.Object)null) { return; } if (ShaderImporterInspector.GetNumberOfTextures(shader) != this.propertyNames.Count) { this.ResetValues(); } this.ShowDefaultTextures(); this.ApplyRevertGUI(); }
protected override void Apply() { base.Apply(); ShaderImporter shaderImporter = base.target as ShaderImporter; if (!(shaderImporter == null)) { string[] name = (from x in this.m_Properties where x.modifiable select x.propertyName).ToArray <string>(); Texture[] textures = (from x in this.m_Properties where x.modifiable select x.texture).ToArray <Texture>(); shaderImporter.SetDefaultTextures(name, textures); string[] name2 = (from x in this.m_Properties where !x.modifiable select x.propertyName).ToArray <string>(); Texture[] textures2 = (from x in this.m_Properties where !x.modifiable select x.texture).ToArray <Texture>(); shaderImporter.SetNonModifiableTextures(name2, textures2); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(shaderImporter)); } }
public static string[] GetUserDataFeatures(ShaderImporter importer) { //Contains Features & Flags if(importer.userData.Contains("|")) { string[] data = importer.userData.Split('|'); if(data.Length < 2) { Debug.LogError("[TCP2 Shader Generator] Invalid userData in ShaderImporter.\n" + importer.userData); return null; } else { string[] features = data[0].Split(new string[]{","}, System.StringSplitOptions.RemoveEmptyEntries); return features; } } //No Flags data else { return importer.userData.Split(','); } }
public static void ParseUserData(ShaderImporter importer, out string[] Features, out string[] Flags, out Dictionary<string,string> Keywords, out string[] CustomData) { List<string> featuresList = new List<string>(); List<string> flagsList = new List<string>(); List<string> customDataList = new List<string>(); Dictionary<string,string> keywordsDict = new Dictionary<string,string>(); string[] data = importer.userData.Split(new string[]{","}, System.StringSplitOptions.RemoveEmptyEntries); foreach(string d in data) { if(string.IsNullOrEmpty(d)) continue; switch(d[0]) { //Features case 'F': featuresList.Add(d.Substring(1)); break; //Flags case 'f': flagsList.Add(d.Substring(1)); break; //Keywords case 'K': string[] kw = d.Substring(1).Split(':'); if(kw.Length != 2) { Debug.LogError("[TCP2 Shader Generator] Error while parsing userData: invalid Keywords format."); Features = null; Flags = null; Keywords = null; CustomData = null; return; } else { keywordsDict.Add(kw[0], kw[1]); } break; //Custom Data case 'c': customDataList.Add(d.Substring(1)); break; //old format default: featuresList.Add(d); break; } } Features = featuresList.ToArray(); Flags = flagsList.ToArray(); Keywords = keywordsDict; CustomData = customDataList.ToArray(); }
//Get Features array from ShaderImporter public static void ParseUserData(ShaderImporter importer, out List<string> Features) { string[] array; string[] dummy; Dictionary<string,string> dummyDict; ParseUserData(importer, out array, out dummy, out dummyDict, out dummy); Features = new List<string>(array); }