private static void DrawKeyWordFun(ref DrawPropertyContext context) { bool isEnable = context.material.IsKeywordEnabled(context.spi.shaderFeature.propertyName); if (context.spi.shaderFeature.readOnly) { EditorGUILayout.Toggle(context.spi.shaderFeature.name, isEnable); } else { EditorGUI.BeginChangeCheck(); bool enable = EditorGUILayout.Toggle(context.spi.shaderFeature.name, isEnable); if (EditorGUI.EndChangeCheck()) { if (isEnable != enable) { SetKeyword(context.material, context.spi.shaderFeature.propertyName, enable); } if (enable && !context.hasDepency.Contains(context.spi.shaderFeature.name)) { context.hasDepency.Add(context.spi.shaderFeature.name); } else if (!enable && context.hasDepency.Contains(context.spi.shaderFeature.name)) { context.hasDepency.Remove(context.spi.shaderFeature.name); } context.materialEditor.RegisterPropertyChangeUndo(context.spi.shaderFeature.name); } } }
protected void BlendModePopup(ref DrawPropertyContext context) { BlendMode blendMode = ShaderAssets.GetBlendMode(m_Material); EditorGUI.BeginChangeCheck(); var mode = (BlendMode)EditorGUILayout.Popup(Styles.renderingMode, (int)blendMode, Styles.blendNames); if (EditorGUI.EndChangeCheck()) { if (mode != blendMode) { ShaderAssets.SetupMaterialWithBlendMode(m_Material, mode); } } }
private static void DrawCustomFun(ref DrawPropertyContext context) { if (context.spi.property != null) { if (context.spi.shaderFeature.readOnly) { EditorGUILayout.Vector4Field(context.spi.property.displayName, context.spi.property.vectorValue); } else { EditorGUI.BeginChangeCheck(); PropertyDrawer.OnGUI(context.spi.property, context.materialEditor, context.spi.shaderFeature); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(context.materialEditor.target, context.spi.property.displayName); } } } }
private static void DrawCustomGroupFun(ref DrawPropertyContext context) { if (context.spi.property != null && context.spi.scp != null) { var scp = context.spi.scp; if (context.spi.shaderFeature.readOnly) { EditorGUILayout.FloatField(scp.desc, context.spi.property.vectorValue[context.spi.customIndex]); } else { EditorGUI.BeginChangeCheck(); PropertyDrawer.OnGUI(context.spi.property, context.materialEditor, scp, context.spi.customIndex); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(context.materialEditor.target, context.spi.property.displayName); } } } }
private static void DrawRenderQueueFun(ref DrawPropertyContext context) { if (context.spi.shaderFeature != null) { if (context.spi.shaderFeature.readOnly) { EditorGUILayout.IntField(context.spi.shaderFeature.name, context.material.renderQueue); } else { EditorGUI.BeginChangeCheck(); int renderQueue = EditorGUILayout.IntField(context.spi.shaderFeature.name, context.material.renderQueue); if (EditorGUI.EndChangeCheck()) { renderQueue = Mathf.Clamp(renderQueue, -1, 5000); context.material.renderQueue = renderQueue; Undo.RecordObject(context.materialEditor.target, context.spi.shaderFeature.name); } } } }
protected void DoDebugArea(ref DrawPropertyContext context) { if (context.spi.property != null) { if (AssetsConfig.shaderDebugNames != null) { GUILayout.Label(Styles.debugText, EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); var mode = context.spi.property.floatValue; mode = EditorGUILayout.Popup(Styles.debugMode, (int)mode, AssetsConfig.shaderDebugNames); if (EditorGUI.EndChangeCheck()) { m_MaterialEditor.RegisterPropertyChangeUndo("Debug Mode"); context.spi.property.floatValue = mode; } string debugName = AssetsConfig.shaderDebugNames[(int)mode]; if (debugName == "CubeMipmap") { GUILayout.BeginHorizontal(); int swatchSize = 22; int viewWidth = (int)EditorGUIUtility.currentViewWidth - 12; int swatchesPerRow = viewWidth / (swatchSize + 4); swatchSize += (viewWidth % (swatchSize + 4)) / swatchesPerRow; for (int i = 0; i < mipMapColors.Length; ++i) { GUI.backgroundColor = mipMapColors[i].linear; GUILayout.Button(i.ToString(), GUILayout.MinWidth(swatchSize), GUILayout.MaxWidth(swatchSize), GUILayout.MinHeight(swatchSize), GUILayout.MaxHeight(swatchSize)); } GUI.backgroundColor = Color.white; GUILayout.EndHorizontal(); } } } }
private static void DrawColorFun(ref DrawPropertyContext context) { if (context.spi.property != null) { if (context.spi.shaderFeature.readOnly) { EditorGUILayout.ColorField(context.spi.property.displayName, context.spi.property.colorValue); } else { EditorGUI.BeginChangeCheck(); context.materialEditor.ColorProperty(context.spi.property, context.spi.property.displayName); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(context.materialEditor.target, context.spi.property.displayName); if (context.dd != null) { context.dd.SetColor(context.spi.property.name, context.spi.property.colorValue); } } } } }
private static void DrawTexFun(ref DrawPropertyContext context) { if (context.spi.property != null) { if (context.spi.shaderFeature.readOnly) { EditorGUILayout.ObjectField(context.spi.property.displayName, context.spi.property.textureValue, typeof(Texture), false); } else { EditorGUI.BeginChangeCheck(); context.materialEditor.TextureProperty(context.spi.property, context.spi.property.displayName, false); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(context.materialEditor.target, context.spi.property.displayName); if (context.dd != null) { context.dd.SetTexture(context.spi.property.name, context.spi.property.textureValue); } } } } }
private static void DrawGroupEnd(ref DrawPropertyContext context) { EditorGUI.indentLevel--; }
private static void DrawGroupBegin(ref DrawPropertyContext context) { EditorGUILayout.LabelField(context.sgi.name, EditorStyles.boldLabel); EditorGUI.indentLevel++; }
private void Update() { if (shaderPropertyGroups != null) { drawList.Clear(); for (int i = 0; i < shaderPropertyGroups.Count; ++i) { ShaderGroupInstance sgi = shaderPropertyGroups[i]; if (sgi.hasCustomGroup) { sgi.spiList.Sort((x, y) => { int idx = x.scp != null ? x.scp.indexInGroup : 0; int idy = y.scp != null ? y.scp.indexInGroup : 0; return(idx - idy); }); } bool hasBeginFun = false; for (int j = 0; j < sgi.spiList.Count; ++j) { ShaderPropertyInstance spi = sgi.spiList[j]; var sf = spi.shaderFeature; if (j == 0 && (sf.indexInGroup >= 0 || sf.type == AssetsConfig.ShaderPropertyType.CustomGroup)) { DrawPropertyContext context = new DrawPropertyContext(); context.fun = drawGroupBegin; context.sgi = sgi; drawList.Add(context); hasBeginFun = true; } if (sf.type == AssetsConfig.ShaderPropertyType.CustomFun) { DrawFun fun = null; if (customFunc.TryGetValue(sf.name, out fun)) { DrawPropertyContext context = new DrawPropertyContext(); context.fun = fun; context.material = m_Material; context.materialEditor = m_MaterialEditor; context.hasDepency = hasDepency; context.spi = spi; context.dd = dd; drawList.Add(context); } } else { bool show = true; if (sf.dependencyPropertys != null && sf.dependencyPropertys.dependencyShaderProperty.Count > 0) { bool hasFeature = false; for (int k = 0; k < sf.dependencyPropertys.dependencyShaderProperty.Count; ++k) { string featureName = sf.dependencyPropertys.dependencyShaderProperty[k]; if (sf.dependencyPropertys.dependencyType == AssetsConfig.DependencyType.Or) { hasFeature |= hasDepency.Contains(featureName); if (hasFeature) { break; } } else if (sf.dependencyPropertys.dependencyType == AssetsConfig.DependencyType.And) { hasFeature &= hasDepency.Contains(featureName); if (!hasFeature) { break; } } } if (sf.dependencyPropertys.isNor) { hasFeature = !hasFeature; } show = hasFeature; } if (show && !sf.hide) { var drawFun = drawPropertyFun[(int)sf.type]; if (drawFun != null) { DrawPropertyContext context = new DrawPropertyContext(); context.fun = drawFun; context.material = m_Material; context.materialEditor = m_MaterialEditor; context.hasDepency = hasDepency; context.spi = spi; context.dd = dd; context.sgi = sgi; drawList.Add(context); } } if (j == sgi.spiList.Count - 1 && hasBeginFun) { DrawPropertyContext context = new DrawPropertyContext(); context.fun = drawGroupEnd; context.sgi = sgi; drawList.Add(context); } } } } } }