Identifies a specific variant of a shader.
static void CollectShaderVariants() { var collection = new ShaderVariantCollection(); var folders = new string[]{"Assets/Shaders"}; var shaders = AssetDatabase.FindAssets("t:Shader", folders); foreach (var guid in shaders) { var path = AssetDatabase.GUIDToAssetPath(guid); var shader = AssetDatabase.LoadAssetAtPath<Shader>(path); var variant = new ShaderVariantCollection.ShaderVariant(shader, PassType.ForwardAdd, "DIRECTIONAL", "SHADOWS_OFF"); collection.Add(variant); } AssetDatabase.CreateAsset(collection, "Assets/AutoGenerated.shadervariants"); }
private void AddVariantMenuSelected(object userData, string[] options, int selected) { AddVariantMenuData data = (AddVariantMenuData) userData; char[] separator = new char[] { ' ' }; string[] keywords = data.keywords[selected].Split(separator); ShaderVariantCollection.ShaderVariant variant = new ShaderVariantCollection.ShaderVariant(data.shader, (PassType) data.types[selected], keywords); Undo.RecordObject(data.collection, "Add variant"); data.collection.Add(variant); }
private void AddVariantMenuSelected(object userData, string[] options, int selected) { ShaderVariantCollectionInspector.AddVariantMenuData addVariantMenuData = (ShaderVariantCollectionInspector.AddVariantMenuData)userData; string[] keywords = addVariantMenuData.keywords[selected].Split(new char[] { ' ' }); ShaderVariantCollection.ShaderVariant variant = new ShaderVariantCollection.ShaderVariant(addVariantMenuData.shader, (PassType)addVariantMenuData.types[selected], keywords); Undo.RecordObject(addVariantMenuData.collection, "Add variant"); addVariantMenuData.collection.Add(variant); }
static int _CreateShaderVariantCollection_ShaderVariant(IntPtr L) { int count = LuaDLL.lua_gettop(L); if (LuaScriptMgr.CheckTypes(L, 1, typeof(Shader), typeof(UnityEngine.Rendering.PassType)) && LuaScriptMgr.CheckParamsType(L, typeof(string), 3, count - 2)) { Shader arg0 = (Shader)LuaScriptMgr.GetUnityObject(L, 1, typeof(Shader)); UnityEngine.Rendering.PassType arg1 = (UnityEngine.Rendering.PassType)LuaScriptMgr.GetNetObject(L, 2, typeof(UnityEngine.Rendering.PassType)); string[] objs2 = LuaScriptMgr.GetParamsString(L, 3, count - 2); ShaderVariantCollection.ShaderVariant obj = new ShaderVariantCollection.ShaderVariant(arg0,arg1,objs2); LuaScriptMgr.PushValue(L, obj); return 1; } else if (count == 0) { ShaderVariantCollection.ShaderVariant obj = new ShaderVariantCollection.ShaderVariant(); LuaScriptMgr.PushValue(L, obj); return 1; } else { LuaDLL.luaL_error(L, "invalid arguments to method: ShaderVariantCollection.ShaderVariant.New"); } return 0; }
public bool Contains(ShaderVariantCollection.ShaderVariant variant) { return(this.ContainsInternal(variant.shader, variant.passType, variant.keywords)); }
public bool Remove(ShaderVariantCollection.ShaderVariant variant) { return(this.RemoveInternal(variant.shader, variant.passType, variant.keywords)); }
public bool Add(ShaderVariantCollection.ShaderVariant variant) { return(this.AddVariant(variant.shader, variant.passType, variant.keywords)); }
private void Draw(Rect windowRect) { Rect rect = new Rect(2f, 2f, windowRect.width - 4f, 16f); this.DrawSectionHeader(ref rect, "Pick shader keywords to narrow down variant list:", false); this.DrawKeywordsList(ref rect, this.m_AvailableKeywords, true); this.DrawSectionHeader(ref rect, "Selected keywords:", true); this.DrawKeywordsList(ref rect, this.m_SelectedKeywords, false); this.DrawSectionHeader(ref rect, "Shader variants with these keywords (click to select):", true); if (this.m_FilteredVariants.Count > 0) { int b = (int) (this.CalcVerticalSpaceForVariants() / 16f); for (int i = 0; i < Mathf.Min(this.m_FilteredVariants.Count, b); i++) { int index = this.m_FilteredVariants[i]; PassType type = (PassType) this.m_Data.types[index]; bool flag = this.m_SelectedVariants.Contains(index); string text = type.ToString() + " " + string.Join(" ", this.m_Data.keywords[index]).ToLowerInvariant(); bool flag2 = GUI.Toggle(rect, flag, text, Styles.sMenuItem); rect.y += rect.height; if (flag2 && !flag) { this.m_SelectedVariants.Add(index); } else if (!flag2 && flag) { this.m_SelectedVariants.Remove(index); } } if (this.m_FilteredVariants.Count > b) { GUI.Label(rect, string.Format("[{0} more variants skipped]", this.m_FilteredVariants.Count - b), EditorStyles.miniLabel); rect.y += rect.height; } } else { GUI.Label(rect, "No variants with these keywords"); rect.y += rect.height; } rect.y = ((windowRect.height - 2f) - 6f) - 16f; rect.height = 16f; using (new EditorGUI.DisabledScope(this.m_SelectedVariants.Count == 0)) { if (GUI.Button(rect, string.Format("Add {0} selected variants", this.m_SelectedVariants.Count))) { Undo.RecordObject(this.m_Data.collection, "Add variant"); for (int j = 0; j < this.m_SelectedVariants.Count; j++) { int num5 = this.m_SelectedVariants[j]; ShaderVariantCollection.ShaderVariant variant = new ShaderVariantCollection.ShaderVariant(this.m_Data.shader, (PassType) this.m_Data.types[num5], this.m_Data.keywords[num5]); this.m_Data.collection.Add(variant); } base.Close(); GUIUtility.ExitGUI(); } } }