//property.Expanded = EditorGUILayout.Foldout( property.Expanded, property.GetPropertyType().PropertyTypeString() ); public void Draw() { var shaderNameContent = new GUIContent( "Shader Name", "Name for shader. Includes the hierarchy listing, that is, MyShaders/Shader will be in a folder called \"MyShaders\" in the shader selection dropdown. Also used when referring to fallback shaders."); var oldColor = GUI.color; if (string.IsNullOrEmpty(_shaderName)) { GUI.color = Color.red; } _shaderName.Value = EditorGUILayout.TextField(shaderNameContent, _shaderName.Value); GUI.color = oldColor; var shaderFallbackContent = new GUIContent( "Shader Fallback", "Fallback shader to use in case this shader can not be used."); _shaderFallback.Value = EditorGUILayout.TextField(shaderFallbackContent, _shaderFallback.Value); var targetContent = new GUIContent("Shader Model", "Requires more recent hardware to use the shader, but allows for more instructions, texture reads, and more input information."); _shaderTarget = (ShaderTarget)EditorGUILayout.EnumPopup(targetContent, _shaderTarget); var excludePathContent = new GUIContent("Exclude Path", "Exclude a renderpath from shader generation"); _excludePath = (ExcludePath)EditorGUILayout.EnumPopup(excludePathContent, _excludePath); #if UNITY_5_3_OR_NEWER var shaderTypeContent = new GUIContent("Shader Type", "You can select Physically Based Rendering after Unity 5.3"); var currentshaderType = _shaderType; _shaderType = (ShaderType)EditorGUILayout.EnumPopup(shaderTypeContent, currentshaderType); if ((currentshaderType != _shaderType) && (OnChangeShaderType != null)) { OnChangeShaderType(); } #endif GUILayout.Space(8); _showQueueSettings = EditorGUILayout.Foldout(_showQueueSettings, "Queue Settings"); if (_showQueueSettings) { var renderTypeContent = new GUIContent("Render Type", "This is the rendertype tag inserted into the shader. Can be used for shader replace"); _renderType = (RenderType)EditorGUILayout.EnumPopup(renderTypeContent, _renderType); if (_renderType == RenderType.Custom) { _renderTypeCustom.Value = EditorGUILayout.TextField("Custom Type", _renderTypeCustom.Value); } var queueContent = new GUIContent("Render Queue", "The render queue that this material will be put in"); _queue = (Queue)EditorGUILayout.EnumPopup(queueContent, _queue); var offContent = new GUIContent( "Queue Offset", "Offset for drawing. Used to ensure some things draw before or after others, it specifically is an offset from the given queue- That is to say, you won't have a transparent object draw before an opaque object (or similar) due to this offset."); _queueAdjust = EditorGUILayout.IntSlider(offContent, _queueAdjust.Value, -100, 100); } GUILayout.Space(8); _showCullingAndDepthSettings = EditorGUILayout.Foldout(_showCullingAndDepthSettings, "Culling and Depth Settings"); if (_showCullingAndDepthSettings) { var zWriteContent = new GUIContent("Write Depth", "Depth is considered when testing other objects. Disable for certain effects, like letting other things draw over yourself, or for speed on most overlays."); _zWrite = (ZWrite)EditorGUILayout.EnumPopup(zWriteContent, _zWrite); var cullModeContent = new GUIContent("CullMode", "Select back / forward to clip backwards facing polygons"); _cullMode = (CullMode)EditorGUILayout.EnumPopup(cullModeContent, _cullMode); var zTestContent = new GUIContent("ZTest", "Select Z-Test Value"); _zTest = (ZTest)EditorGUILayout.EnumPopup(zTestContent, _zTest); var enableLODContent = new GUIContent("Enable LOD", "Enable Shader LOD scaling"); _enableLOD = EditorGUILayout.BeginToggleGroup(enableLODContent, _enableLOD); _lod = EditorGUILayout.IntSlider("LOD", _lod, 0, 1000); EditorGUILayout.EndToggleGroup(); } GUILayout.Space(8); _showBlending = EditorGUILayout.Foldout(_showBlending, "Blending Settings"); if (_showBlending) { var blendingTypeContent = new GUIContent("Blend Type", "Use a build in blend mode or a custom blend mode"); _blending = (BlendingType)EditorGUILayout.EnumPopup(blendingTypeContent, _blending); if (CustomBlendingEnabled()) { var srcBlendContent = new GUIContent("Src Blend Mode", "How the source channel of blending is used"); _srcBlend = (BlendingMode)EditorGUILayout.EnumPopup(srcBlendContent, _srcBlend); var dstBlendContent = new GUIContent("Dst Blend Mode", "How the destination channel of blending is used"); _dstBlend = (BlendingMode)EditorGUILayout.EnumPopup(dstBlendContent, _dstBlend); } } GUILayout.Space(8); _showColorAndLighting = EditorGUILayout.Foldout(_showColorAndLighting, "Color And Lighting Settings"); if (_showColorAndLighting) { GUILayout.BeginHorizontal(); GUILayout.Label("Color Mask:", GUILayout.ExpandWidth(false)); _colorMaskR.Value = EditorExtensions.ToggleButton(_colorMaskR.Value, "R", "Mask R Channel"); _colorMaskG.Value = EditorExtensions.ToggleButton(_colorMaskG.Value, "G", "Mask G Channel"); _colorMaskB.Value = EditorExtensions.ToggleButton(_colorMaskB.Value, "B", "Mask B Channel"); _colorMaskA.Value = EditorExtensions.ToggleButton(_colorMaskA.Value, "A", "Mask A Channel"); GUILayout.EndHorizontal(); _dualForward = GUILayout.Toggle(_dualForward, new GUIContent("Forward Dual Lightmaps", "Use dual lightmaps in the forward rendering path")); _fullForwardShadows = GUILayout.Toggle(_fullForwardShadows, new GUIContent("Forward Full Shadows", "Support all shadow types in Forward rendering path.")); _softVegetation = GUILayout.Toggle(_softVegetation, new GUIContent("Soft Vegetation", "Makes the surface shader only be rendered when Soft Vegetation is on.")); _noAmbient = GUILayout.Toggle(_noAmbient, new GUIContent("No Ambient", "Do not apply any ambient lighting or spherical harmonics lights.")); _noLightmap = GUILayout.Toggle(_noLightmap, new GUIContent("No Lightmaps", "Disables lightmap support in this shader (makes a shader smaller).")); _addShadow = GUILayout.Toggle(_addShadow, new GUIContent("Advanced Shadow Pass", "Performs vertex transformations and clipping for the shadow pass, you need to use this if shadows do not display properly.")); _ignoreProjectors = GUILayout.Toggle(_ignoreProjectors, new GUIContent("Ignore Projectors", "Ignores projector components, should be used if your doing custom vertex transformations or most transparency")); _approxview = GUILayout.Toggle(_approxview, new GUIContent("Approximate View", "Computes normalized view direction per-vertex instead of per-pixel, for shaders that need it. This is faster, but view direction is not entirely correct when camera gets close to surface.")); _halfasview = GUILayout.Toggle(_halfasview, new GUIContent("Half As View", "Pass half-direction vector into the lighting function instead of view-direction. Half-direction will be computed and normalized per vertex. This is faster, but not entirely correct.")); _noForwardAdd = GUILayout.Toggle(_noForwardAdd, new GUIContent("Disable Forward Add", "Disables Forward rendering additive pass. This makes the shader support one full directional light, with all other lights computed per-vertex/SH. Makes shaders smaller as well.")); } GUILayout.Space(8); _showFogSettings = EditorGUILayout.Foldout(_showFogSettings, "Fog Settings"); if (_showFogSettings) { _fogModeOverride = EditorGUILayout.BeginToggleGroup("Fog Mode Override", _fogModeOverride); var fogModeContent = new GUIContent("Fog Mode", "The type of fog to use"); _fogMode = (FogMode)EditorGUILayout.EnumPopup(fogModeContent, _fogMode); if (_fogMode == FogMode.Linear) { _fogNearLinear.Value = EditorGUILayout.FloatField("Near Linear Range:", _fogNearLinear); _fogFarLinear.Value = EditorGUILayout.FloatField("Far Linear Range:", _fogFarLinear); } EditorGUILayout.EndToggleGroup(); _fogColorOverride = EditorGUILayout.BeginToggleGroup("Fog Color Override", _fogColorOverride); _fogColor.Value = EditorGUILayout.ColorField("Fog Color:", _fogColor); EditorGUILayout.EndToggleGroup(); _fogDensityOverride = EditorGUILayout.BeginToggleGroup("Fog Density Override", _fogDensityOverride); _fogDensity.Value = EditorGUILayout.FloatField("Fog Density:", _fogDensity); EditorGUILayout.EndToggleGroup(); } }
void OnGUI() { var drawPos = new Rect(0, 0, (int)position.width, (int)position.height - 40); lock ( _previewTexture ) { GUI.Box(drawPos, _previewTextureContent); } if (_parent.ShaderNeedsUpdate()) { GUILayout.BeginArea(new Rect(0, 0, (int)position.width, (int)position.height - 40)); GUILayout.BeginHorizontal(); var oColor = GUI.color; // Cache old content color GUI.color = Color.red; // Make the warning red var oldFontSize = GUI.skin.label.fontSize; GUI.skin.label.fontSize = 20; GUILayout.FlexibleSpace(); // Flexible space (ensures buttohns don't move) GUILayout.Label("Shader Needs Updating"); // Draw the warning GUILayout.FlexibleSpace(); GUI.skin.label.fontSize = oldFontSize; GUILayout.EndHorizontal(); GUILayout.EndArea(); GUI.color = oColor; // Revert the color } int dragControl = GUIUtility.GetControlID(_hotControlHash, FocusType.Passive); switch (Event.current.type) { case EventType.MouseDown: if (drawPos.Contains(Event.current.mousePosition)) { GUIUtility.hotControl = dragControl; } break; case EventType.MouseDrag: if (GUIUtility.hotControl == dragControl) { _cameraRotation -= Event.current.delta; } break; case EventType.MouseUp: if (GUIUtility.hotControl == dragControl) { GUIUtility.hotControl = 0; } break; } GUILayout.FlexibleSpace(); _previewMesh = (Mesh)EditorGUILayout.ObjectField("Mesh:", _previewMesh, typeof(Mesh)); GUILayout.BeginHorizontal( ); _drawBackground = EditorExtensions.ToggleButton(_drawBackground, "Draw Background"); if (GUILayout.Button("Update Preview")) { _parent.UpdateShader(); } GUILayout.EndHorizontal(); }
void OnGUI() { var drawPos = new Rect(0, 0, (int)position.width, (int)position.height - 40); if (_previewTexture != null) { lock (_previewTexture) { GUI.Box(drawPos, _previewTextureContent); } } if (_parent.ShaderNeedsUpdate() && _autoUpdate && !_parent.isShaderBroken) { _parent.UpdateShader(); GUILayout.BeginArea(new Rect(0, 0, (int)position.width, (int)position.height - 40)); GUILayout.BeginHorizontal(); GUI.Box(new Rect(0, 0, position.width, 30), "", GUI.skin.box); var oColor = GUI.color; // Cache old content color GUI.color = Color.white; var oldFontSize = GUI.skin.label.fontSize; GUI.skin.label.fontSize = 20; GUILayout.FlexibleSpace(); // Flexible space (ensures buttons don't move) GUILayout.Label("Shader Updating"); // Draw the warning GUILayout.FlexibleSpace(); GUI.skin.label.fontSize = oldFontSize; GUILayout.EndHorizontal(); GUILayout.EndArea(); GUI.color = oColor; // Revert the color } if (_parent.isShaderBroken) { _parent.UpdateShader(); } int dragControl = GUIUtility.GetControlID(_hotControlHash, FocusType.Passive); switch (Event.current.type) { case EventType.MouseDown: if (drawPos.Contains(Event.current.mousePosition)) { GUIUtility.hotControl = dragControl; if (_rotate) { _tempStopRot = true; float oldRotationVal; oldRotationVal = _cameraRotation.x; _cameraRotation.x = oldRotationVal; _cameraRotation.y = 0; } } break; case EventType.MouseDrag: if (GUIUtility.hotControl == dragControl) { _cameraRotation -= Event.current.delta; } break; case EventType.MouseUp: if (GUIUtility.hotControl == dragControl) { GUIUtility.hotControl = 0; if (_tempStopRot == true) { _tempStopRot = false; _rotate = true; } } break; } GUILayout.FlexibleSpace(); _previewMesh = (Mesh)EditorGUILayout.ObjectField("Mesh:", _previewMesh, typeof(Mesh), true); GUILayout.BeginHorizontal(); _drawBackground = EditorExtensions.ToggleButton(_drawBackground, "Background"); if (GUILayout.Button("Update")) { _parent.UpdateShader(); } _autoUpdate = EditorExtensions.ToggleButton(_autoUpdate, "Auto"); _rotate = EditorExtensions.ToggleButton(_rotate, "Rotate"); GUILayout.EndHorizontal(); }