/// <summary> /// For when the undo/redo actions happen, this updates settings. /// </summary> void ApplyChanges() { DFA.PixelNostalgia pixelNostalgia = (target as DFA.PixelNostalgia); settings.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties(); pixelNostalgia.UpdateEffectSettings(); }
/// <summary> /// Draw the custom inspector GUI. /// </summary> public override void OnInspectorGUI() { settings.Update(); serializedObject.Update(); EditorGUI.BeginChangeCheck(); var originalColor = GUI.backgroundColor; foldoutA = EditorGUILayout.Foldout(foldoutA, "Resolution Settings"); if (foldoutA) { EditorGUI.indentLevel++; GUI.backgroundColor = new Color32(249, 255, 214, 255); EditorGUILayout.PropertyField(customWindowSize, new GUIContent() { text = "New Resolution" }); EditorGUI.indentLevel--; if (GUILayout.Button("Apply")) { if (customWindowSize.vector2Value.x >= 1 && customWindowSize.vector2Value.y >= 1 && customWindowSize.vector2Value.x < 8192 && customWindowSize.vector2Value.y < 8192) { // Can increase this if you need a larger texture matchCameraSize.boolValue = false; windowSize.vector2Value = customWindowSize.vector2Value; } } GUI.backgroundColor = new Color32(214, 255, 224, 255); if (GUILayout.Button("Match Camera")) { matchCameraSize.boolValue = true; scalarSize.floatValue = 1.0f; } EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("1/8 Cam")) { matchCameraSize.boolValue = true; scalarSize.floatValue = 0.125f; } if (GUILayout.Button("1/4 Cam")) { matchCameraSize.boolValue = true; scalarSize.floatValue = 0.25f; } if (GUILayout.Button("1/2 Cam")) { matchCameraSize.boolValue = true; scalarSize.floatValue = 0.5f; } } EditorGUILayout.EndHorizontal(); GUI.backgroundColor = new Color32(220, 214, 255, 255); selectedSizeOption.intValue = EditorGUILayout.Popup(selectedSizeOption.intValue, resolutionStrings); if (GUILayout.Button("Apply " + resolutionStrings[selectedSizeOption.intValue])) { matchCameraSize.boolValue = false; windowSize.vector2Value = resolutionValues[selectedSizeOption.intValue]; } string label = string.Format("Resolution: {0} Camera", scalarSize.floatValue == 1.0f ? "Matching" : scalarSize.floatValue == 0.5f ? "1/2" : scalarSize.floatValue == 0.25f ? "1/4" : "1/8" ); if (!matchCameraSize.boolValue) { var style = EditorStyles.wordWrappedLabel; style.richText = true; label = string.Format("Resolution: {0}x{1}", windowSize.vector2Value.x, windowSize.vector2Value.y); EditorGUILayout.LabelField(label, EditorStyles.boldLabel); EditorGUILayout.LabelField("<b>Camera aspect ratio may not match texture aspect ratio</b>", style); } else { EditorGUILayout.LabelField(label, EditorStyles.boldLabel); } EditorGUILayout.Space(); GUI.backgroundColor = originalColor; } foldoutB = EditorGUILayout.Foldout(foldoutB, "Color Depth Settings"); if (foldoutB) { EditorGUI.indentLevel++; grayscale.boolValue = selectedBitDepthOption.intValue == bitDepthStrings.Length - 2; EditorGUI.BeginDisabledGroup(!grayscale.boolValue); { GUI.backgroundColor = Color.white; grayscaleDepth.intValue = EditorGUILayout.IntSlider("B&W", grayscaleDepth.intValue, 1, 8); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(selectedBitDepthOption.intValue != bitDepthStrings.Length - 1 || grayscale.boolValue); { GUI.backgroundColor = new Color32(255, 153, 153, 255); rBitDepth.intValue = EditorGUILayout.IntSlider("Red", rBitDepth.intValue, 1, 8); GUI.backgroundColor = new Color32(153, 255, 153, 255); gBitDepth.intValue = EditorGUILayout.IntSlider("Green", gBitDepth.intValue, 1, 8); GUI.backgroundColor = new Color32(153, 153, 255, 255); bBitDepth.intValue = EditorGUILayout.IntSlider("Blue", bBitDepth.intValue, 1, 8); } GUI.backgroundColor = originalColor; EditorGUI.EndDisabledGroup(); if (selectedBitDepthOption.intValue < bitDepthStrings.Length - 2) { rBitDepth.intValue = (int)bitDepthValues[selectedBitDepthOption.intValue].x; gBitDepth.intValue = (int)bitDepthValues[selectedBitDepthOption.intValue].y; bBitDepth.intValue = (int)bitDepthValues[selectedBitDepthOption.intValue].z; } if (!grayscale.boolValue) { string maxColors = ( Mathf.Pow(2, rBitDepth.intValue) * Mathf.Pow(2, gBitDepth.intValue) * Mathf.Pow(2, bBitDepth.intValue)).ToString("N0"); EditorGUILayout.LabelField(maxColors + " possible colors", EditorStyles.boldLabel); } else { string maxColors = ( Mathf.Pow(2, grayscaleDepth.intValue)).ToString("N0"); EditorGUILayout.LabelField(maxColors + " possible shades", EditorStyles.boldLabel); } selectedBitDepthOption.intValue = EditorGUILayout.Popup(selectedBitDepthOption.intValue, bitDepthStrings); if (selectedBitDepthOption.intValue < bitDepthStrings.Length - 2) { rBitDepth.intValue = (int)bitDepthValues[selectedBitDepthOption.intValue].x; gBitDepth.intValue = (int)bitDepthValues[selectedBitDepthOption.intValue].y; bBitDepth.intValue = (int)bitDepthValues[selectedBitDepthOption.intValue].z; } grayscale.boolValue = selectedBitDepthOption.intValue == bitDepthStrings.Length - 2; EditorGUI.indentLevel--; } foldoutC = EditorGUILayout.Foldout(foldoutC, "Dithering Settings"); if (foldoutC) { EditorGUILayout.PropertyField(doDithering, new GUIContent() { text = "Dithering Enabled" }); EditorGUI.BeginDisabledGroup(!doDithering.boolValue); { EditorGUI.indentLevel++; bayerIndex.intValue = EditorGUILayout.Popup(bayerIndex.intValue, ditherStrings); EditorGUI.BeginDisabledGroup(autoSelectSeparation.intValue == 0); { EditorGUILayout.PropertyField(ditherSeparation, new GUIContent() { text = "Separation" }); } EditorGUI.EndDisabledGroup(); autoSelectSeparation.intValue = EditorGUILayout.Popup(autoSelectSeparation.intValue, selectStrings); if (autoSelectSeparation.intValue == 0) { switch (bayerIndex.intValue) { case 0: // 2x2 ditherSeparation.intValue = 422; break; case 1: // 3x3 ditherSeparation.intValue = 323; break; case 2: // 4x4 ditherSeparation.intValue = 285; break; case 3: // 8x8 ditherSeparation.intValue = 256; break; } } EditorGUI.indentLevel--; } EditorGUI.EndDisabledGroup(); } foldoutD = EditorGUILayout.Foldout(foldoutD, "Extra Effects"); if (foldoutD) { EditorGUI.indentLevel++; // Simple radio toggle asc = EditorGUILayout.Toggle("ASCII Effect", doAscii.boolValue); if (asc != doAscii.boolValue) { if (asc) { doCRT.boolValue = false; } doAscii.boolValue = asc; } crt = EditorGUILayout.Toggle("CRT Effect", doCRT.boolValue); if (crt != doCRT.boolValue) { if (crt) { doAscii.boolValue = false; } doCRT.boolValue = crt; } EditorGUI.indentLevel--; } EditorGUILayout.Space(); DFA.PixelNostalgia pixelNostalgia = (target as DFA.PixelNostalgia); if (EditorGUI.EndChangeCheck()) { settings.ApplyModifiedProperties(); serializedObject.ApplyModifiedProperties(); pixelNostalgia.UpdateEffectSettings(); } }