private static float GetInspectorRotationValue(EditorRotationUnit unit, float rawValue) { switch (unit) { case EditorRotationUnit.Rounds: return(rawValue); case EditorRotationUnit.Degrees: return(rawValue * RoundsToDegree); case EditorRotationUnit.Radians: return(rawValue * RoundsToRadian); default: throw new ArgumentOutOfRangeException(); } }
private void Draw(MaterialEditor materialEditor, Material[] materials) { EditorGUI.BeginChangeCheck(); { _version.floatValue = Utils.VersionNumber; EditorGUILayout.LabelField("Rendering", EditorStyles.boldLabel); EditorGUILayout.BeginVertical(GUI.skin.box); { EditorGUILayout.LabelField("Mode", EditorStyles.boldLabel); if (PopupEnum <RenderMode>("Rendering Type", _blendMode, materialEditor)) { ModeChanged(materials, isBlendModeChangedByUser: true); } if ((RenderMode)_blendMode.floatValue == RenderMode.TransparentWithZWrite) { EditorGUILayout.HelpBox("TransparentWithZWrite mode can cause problems with rendering.", MessageType.Warning); } if (PopupEnum <CullMode>("Cull Mode", _cullMode, materialEditor)) { ModeChanged(materials); } } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Color", EditorStyles.boldLabel); EditorGUILayout.BeginVertical(GUI.skin.box); { EditorGUILayout.LabelField("Texture", EditorStyles.boldLabel); { materialEditor.TexturePropertySingleLine(new GUIContent("Lit Color, Alpha", "Lit (RGB), Alpha (A)"), _mainTex, _color); materialEditor.TexturePropertySingleLine(new GUIContent("Shade Color", "Shade (RGB)"), _shadeTexture, _shadeColor); } var bm = (RenderMode)_blendMode.floatValue; if (bm == RenderMode.Cutout) { EditorGUILayout.Space(); EditorGUILayout.LabelField("Alpha", EditorStyles.boldLabel); { materialEditor.ShaderProperty(_cutoff, "Cutoff"); } } } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Lighting", EditorStyles.boldLabel); EditorGUILayout.BeginVertical(GUI.skin.box); { { materialEditor.ShaderProperty(_shadeToony, new GUIContent("Shading Toony", "0.0 is Lambert. Higher value get toony shading.")); // Normal EditorGUI.BeginChangeCheck(); materialEditor.TexturePropertySingleLine(new GUIContent("Normal Map [Normal]", "Normal Map (RGB)"), _bumpMap, _bumpScale); if (EditorGUI.EndChangeCheck()) { materialEditor.RegisterPropertyChangeUndo("BumpEnabledDisabled"); ModeChanged(materials); } } EditorGUILayout.Space(); EditorGUI.indentLevel++; { isAdvancedLightingPanelFoldout = EditorGUILayout.Foldout(isAdvancedLightingPanelFoldout, "Advanced Settings", EditorStyles.boldFont); if (isAdvancedLightingPanelFoldout) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.HelpBox( "The default settings are suitable for Advanced Settings if you want to toony result.", MessageType.Info); if (GUILayout.Button("Use Default")) { _shadeShift.floatValue = 0; _receiveShadowTexture.textureValue = null; _receiveShadowRate.floatValue = 1; _shadingGradeTexture.textureValue = null; _shadingGradeRate.floatValue = 1; _lightColorAttenuation.floatValue = 0; _indirectLightIntensity.floatValue = 0.1f; } EditorGUILayout.EndHorizontal(); materialEditor.ShaderProperty(_shadeShift, new GUIContent("Shading Shift", "Zero is Default. Negative value increase lit area. Positive value increase shade area.")); materialEditor.TexturePropertySingleLine( new GUIContent("Shadow Receive Multiplier", "Texture (R) * Rate. White is Default. Black attenuates shadows."), _receiveShadowTexture, _receiveShadowRate); materialEditor.TexturePropertySingleLine( new GUIContent("Lit & Shade Mixing Multiplier", "Texture (R) * Rate. Compatible with UTS2 ShadingGradeMap. White is Default. Black amplifies shade."), _shadingGradeTexture, _shadingGradeRate); materialEditor.ShaderProperty(_lightColorAttenuation, "LightColor Attenuation"); materialEditor.ShaderProperty(_indirectLightIntensity, "GI Intensity"); } } EditorGUI.indentLevel--; } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Emission", EditorStyles.boldLabel); EditorGUILayout.BeginVertical(GUI.skin.box); { TextureWithHdrColor(materialEditor, "Emission", "Emission (RGB)", _emissionMap, _emissionColor); materialEditor.TexturePropertySingleLine(new GUIContent("MatCap", "MatCap Texture (RGB)"), _sphereAdd); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Rim", EditorStyles.boldLabel); EditorGUILayout.BeginVertical(GUI.skin.box); { TextureWithHdrColor(materialEditor, "Color", "Rim Color (RGB)", _rimTexture, _rimColor); materialEditor.DefaultShaderProperty(_rimLightingMix, "Lighting Mix"); materialEditor.ShaderProperty(_rimFresnelPower, new GUIContent("Fresnel Power", "If you increase this value, you get sharpness rim light.")); materialEditor.ShaderProperty(_rimLift, new GUIContent("Lift", "If you increase this value, you can lift rim light.")); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Outline", EditorStyles.boldLabel); EditorGUILayout.BeginVertical(GUI.skin.box); { // Outline EditorGUILayout.LabelField("Width", EditorStyles.boldLabel); { if (PopupEnum <OutlineWidthMode>("Mode", _outlineWidthMode, materialEditor)) { ModeChanged(materials); } if ((RenderMode)_blendMode.floatValue == RenderMode.Transparent && (OutlineWidthMode)_outlineWidthMode.floatValue != OutlineWidthMode.None) { EditorGUILayout.HelpBox("Outline with Transparent material cause problem with rendering.", MessageType.Warning); } var widthMode = (OutlineWidthMode)_outlineWidthMode.floatValue; if (widthMode != OutlineWidthMode.None) { materialEditor.TexturePropertySingleLine( new GUIContent("Width", "Outline Width Texture (RGB)"), _outlineWidthTexture, _outlineWidth); } if (widthMode == OutlineWidthMode.ScreenCoordinates) { materialEditor.ShaderProperty(_outlineScaledMaxDistance, "Width Scaled Max Distance"); } } EditorGUILayout.Space(); EditorGUILayout.LabelField("Color", EditorStyles.boldLabel); { var widthMode = (OutlineWidthMode)_outlineWidthMode.floatValue; if (widthMode != OutlineWidthMode.None) { EditorGUI.BeginChangeCheck(); if (PopupEnum <OutlineColorMode>("Mode", _outlineColorMode, materialEditor)) { ModeChanged(materials); } var colorMode = (OutlineColorMode)_outlineColorMode.floatValue; materialEditor.ShaderProperty(_outlineColor, "Color"); if (colorMode == OutlineColorMode.MixedLighting) { materialEditor.DefaultShaderProperty(_outlineLightingMix, "Lighting Mix"); } } } } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.LabelField("UV Coordinates", EditorStyles.boldLabel); EditorGUILayout.BeginVertical(GUI.skin.box); { // UV EditorGUILayout.LabelField("Scale & Offset", EditorStyles.boldLabel); { materialEditor.TextureScaleOffsetProperty(_mainTex); } EditorGUILayout.Space(); EditorGUILayout.LabelField("Auto Animation", EditorStyles.boldLabel); { materialEditor.TexturePropertySingleLine(new GUIContent("Mask", "Auto Animation Mask Texture (R)"), _uvAnimMaskTexture); materialEditor.ShaderProperty(_uvAnimScrollX, "Scroll X (per second)"); materialEditor.ShaderProperty(_uvAnimScrollY, "Scroll Y (per second)"); { var control = EditorGUILayout.GetControlRect(hasLabel: true); const int popupMargin = 5; const int popupWidth = 80; var floatControl = new Rect(control); floatControl.width -= popupMargin + popupWidth; var popupControl = new Rect(control); popupControl.x = floatControl.x + floatControl.width + popupMargin; popupControl.width = popupWidth; EditorGUI.BeginChangeCheck(); var inspectorRotationValue = GetInspectorRotationValue(editorRotationUnit, _uvAnimRotation.floatValue); inspectorRotationValue = EditorGUI.FloatField(floatControl, "Rotation value (per second)", inspectorRotationValue); if (EditorGUI.EndChangeCheck()) { materialEditor.RegisterPropertyChangeUndo("UvAnimRotationValueChanged"); _uvAnimRotation.floatValue = GetRawRotationValue(editorRotationUnit, inspectorRotationValue); } editorRotationUnit = (EditorRotationUnit)EditorGUI.EnumPopup(popupControl, editorRotationUnit); } } } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Options", EditorStyles.boldLabel); EditorGUILayout.BeginVertical(GUI.skin.box); { EditorGUILayout.LabelField("Debugging Options", EditorStyles.boldLabel); { if (PopupEnum <DebugMode>("Visualize", _debugMode, materialEditor)) { ModeChanged(materials); } } EditorGUILayout.Space(); EditorGUILayout.LabelField("Advanced Options", EditorStyles.boldLabel); { #if UNITY_5_6_OR_NEWER // materialEditor.EnableInstancingField(); materialEditor.DoubleSidedGIField(); #endif EditorGUI.BeginChangeCheck(); materialEditor.RenderQueueField(); if (EditorGUI.EndChangeCheck()) { ModeChanged(materials); } } } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } EditorGUI.EndChangeCheck(); }