示例#1
0
        //
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            // Draw label
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            int indent = EditorGUI.indentLevel;

            EditorGUI.indentLevel = 0;

            // Calculate rects
            HighlightingRendererEditor.GetRowRects(position, rowSpace, rects);

            // Find properties
            SerializedProperty propertyName             = property.FindPropertyRelative("_name");
            SerializedProperty propertyFillAlpha        = property.FindPropertyRelative("_fillAlpha");
            SerializedProperty propertyDownsampleFactor = property.FindPropertyRelative("_downsampleFactor");
            SerializedProperty propertyIterations       = property.FindPropertyRelative("_iterations");
            SerializedProperty propertyBlurMinSpread    = property.FindPropertyRelative("_blurMinSpread");
            SerializedProperty propertyBlurSpread       = property.FindPropertyRelative("_blurSpread");
            SerializedProperty propertyBlurIntensty     = property.FindPropertyRelative("_blurIntensity");
            SerializedProperty propertyBlurDirections   = property.FindPropertyRelative("_blurDirections");

            // Draw properties
            int index = 0;

            propertyName.stringValue              = EditorGUI.TextField(rects[index], propertyName.stringValue); index++;
            propertyFillAlpha.floatValue          = EditorGUI.Slider(rects[index], labelFillAlpha, propertyFillAlpha.floatValue, 0f, 1f); index++;
            propertyDownsampleFactor.intValue     = downsampleSet[EditorGUI.Popup(rects[index], labelDownsampling, downsampleGet[propertyDownsampleFactor.intValue], downsampleOptions)]; index++;
            propertyIterations.intValue           = Mathf.Clamp(EditorGUI.IntField(rects[index], labelIterations, propertyIterations.intValue), 0, 50); index++;
            propertyBlurMinSpread.floatValue      = EditorGUI.Slider(rects[index], labelBlurMinSpread, propertyBlurMinSpread.floatValue, 0f, 3f); index++;
            propertyBlurSpread.floatValue         = EditorGUI.Slider(rects[index], labelBlurSpread, propertyBlurSpread.floatValue, 0f, 3f); index++;
            propertyBlurIntensty.floatValue       = EditorGUI.Slider(rects[index], labelBlurIntensity, propertyBlurIntensty.floatValue, 0f, 1f); index++;
            propertyBlurDirections.enumValueIndex = (int)EditorGUI.Popup(rects[index], labelBlurDirections, propertyBlurDirections.enumValueIndex, blurDirections); index++;

            EditorGUI.indentLevel = indent;

            EditorGUI.EndProperty();
        }
示例#2
0
        //
        public override void OnInspectorGUI()
        {
                        #if UNITY_IPHONE || UNITY_ANDROID || UNITY_WP8 || UNITY_BLACKBERRY
            if (!PlayerSettings.use32BitDisplayBuffer)
            {
                EditorGUILayout.HelpBox("Highlighting System requires 32-bit display buffer. Set the 'Use 32-bit Display Buffer' checkbox under the 'Resolution and Presentation' section of Player Settings.", MessageType.Error);
            }
                        #endif

            EditorGUILayout.Space();

            // HighlightingBlitter field
            if (hr.blitter == null)
            {
                EditorGUILayout.HelpBox("Use order of this component (relatively to other Image Effects on this camera) to control the point at which highlighting will be applied to the framebuffer (click on a little gear icon to the right and choose Move Up / Move Down) or assign HighlightingBlitter component from another camera.", MessageType.Info);
            }
            else if (hr.GetComponent <Camera>() == hr.blitter.GetComponent <Camera>())
            {
                EditorGUILayout.HelpBox("Assigned HighlightingBlitter component exists on the same camera. This is not really necessary in most situations and affects rendering performance! Please make sure this is intended.", MessageType.Warning);
            }
            hr.blitter = EditorGUILayout.ObjectField("Blitter (Optional)", hr.blitter, typeof(HighlightingBlitter), true) as HighlightingBlitter;

            hr.antiAliasing = (AntiAliasing)EditorGUILayout.Popup(labelAntiAliasing, (int)hr.antiAliasing, antiAliasingOptions);

            InitializePresetNames();
            int presetIndex = IdentifyCurrentPreset();

            // Preset fields start
            EditorGUILayout.LabelField("Preset:");

            // Preset selection popup
            int oldIndex = presetIndex;
            int newIndex = EditorGUILayout.Popup(oldIndex, presetNames);
            if (oldIndex != newIndex)
            {
                hr.LoadPreset(presetNames[newIndex].text);
                presetIndex = newIndex;
            }

            HighlightingPreset currentPreset = new HighlightingPreset();
            if (presetIndex >= 0)
            {
                hr.GetPreset(presetNames[presetIndex].text, out currentPreset);
            }

            EditorGUI.BeginChangeCheck();

            // Downsample factor
            SetBoldDefaultFont(presetIndex < 0 || hr.downsampleFactor != currentPreset.downsampleFactor);
            hr.downsampleFactor = HighlightingPresetEditor.downsampleSet[EditorGUILayout.Popup(HighlightingPresetEditor.labelDownsampling, HighlightingPresetEditor.downsampleGet[hr.downsampleFactor], HighlightingPresetEditor.downsampleOptions)];

            // Iterations
            SetBoldDefaultFont(presetIndex < 0 || hr.iterations != currentPreset.iterations);
            hr.iterations = Mathf.Clamp(EditorGUILayout.IntField(HighlightingPresetEditor.labelIterations, hr.iterations), 0, 50);

            // Blur min spread
            SetBoldDefaultFont(presetIndex < 0 || hr.blurMinSpread != currentPreset.blurMinSpread);
            hr.blurMinSpread = EditorGUILayout.Slider(HighlightingPresetEditor.labelBlurMinSpread, hr.blurMinSpread, 0f, 3f);

            // Blur spread
            SetBoldDefaultFont(presetIndex < 0 || hr.blurSpread != currentPreset.blurSpread);
            hr.blurSpread = EditorGUILayout.Slider(HighlightingPresetEditor.labelBlurSpread, hr.blurSpread, 0f, 3f);

            // Blur intensity
            SetBoldDefaultFont(presetIndex < 0 || hr.blurIntensity != currentPreset.blurIntensity);
            hr.blurIntensity = EditorGUILayout.Slider(HighlightingPresetEditor.labelBlurIntensity, hr.blurIntensity, 0f, 1f);

            // Blur straight directions
            SetBoldDefaultFont(presetIndex < 0 || hr.blurDirections != currentPreset.blurDirections);
            hr.blurDirections = (BlurDirections)EditorGUILayout.Popup(HighlightingPresetEditor.labelBlurDirections, (int)hr.blurDirections, HighlightingPresetEditor.blurDirections);

            SetBoldDefaultFont(false);

            if (EditorGUI.EndChangeCheck())
            {
                EditorUtility.SetDirty(hr);
            }

            // Define button rects
            Rect position = GUILayoutUtility.GetRect(0f, 16f, GUILayout.ExpandWidth(true));
            HighlightingRendererEditor.GetColumnRects(position, 2f, buttonRects);

            bool cachedEnabled;

            // Save preset button
            cachedEnabled = GUI.enabled;
            GUI.enabled   =
                !Application.isPlaying ||
                hr.downsampleFactor != currentPreset.downsampleFactor ||
                hr.iterations != currentPreset.iterations ||
                hr.blurMinSpread != currentPreset.blurMinSpread ||
                hr.blurSpread != currentPreset.blurSpread ||
                hr.blurIntensity != currentPreset.blurIntensity ||
                hr.blurDirections != currentPreset.blurDirections;
            if (GUI.Button(buttonRects[0], "Save Preset"))
            {
                window = SavePresetWindow.Init(presetIndex < 0 ? "My Preset" : presetNames[presetIndex].text, SavePresetAs);
            }
            GUI.enabled = cachedEnabled;

            // Remove preset button
            cachedEnabled = GUI.enabled;
            GUI.enabled   = !Application.isPlaying || presetIndex < 0;
            if (GUI.Button(buttonRects[1], labelButtonRemove) && presetIndex >= 0)
            {
                string presetName = presetNames[presetIndex].text;
                if (EditorUtility.DisplayDialog("Removing Preset", "Are you sure you want to remove Preset '" + presetName + "'?", "Yes", "No"))
                {
                    hr.RemovePreset(presetName);
                    EditorUtility.SetDirty(hr);
                    ReadOnlyCollection <HighlightingPreset> presets = hr.presets;
                    if (presets.Count > 0)
                    {
                        presetIndex = 0;
                        hr.ApplyPreset(presets[presetIndex]);
                    }
                    InitializePresetNames();
                }
            }
            GUI.enabled = cachedEnabled;

            EditorGUILayout.Space();
        }