Exemplo n.º 1
0
 // Apply preset settings
 public void ApplyPreset(HighlightingPreset preset)
 {
     downsampleFactor = preset.downsampleFactor;
     iterations       = preset.iterations;
     blurMinSpread    = preset.blurMinSpread;
     blurSpread       = preset.blurSpread;
     blurIntensity    = preset.blurIntensity;
     blurDirections   = preset.blurDirections;
 }
Exemplo n.º 2
0
 // Find stored preset by name and remove it
 public bool RemovePreset(string name)
 {
     for (int i = 0; i < _presets.Count; i++)
     {
         HighlightingPreset p = _presets[i];
         if (p.name == name)
         {
             _presets.RemoveAt(i);
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 3
0
 // Get stored preset by name
 public bool GetPreset(string name, out HighlightingPreset preset)
 {
     for (int i = 0; i < _presets.Count; i++)
     {
         HighlightingPreset p = _presets[i];
         if (p.name == name)
         {
             preset = p;
             return(true);
         }
     }
     preset = new HighlightingPreset();
     return(false);
 }
Exemplo n.º 4
0
        // Returns current preset index
        protected virtual int IdentifyCurrentPreset()
        {
            ReadOnlyCollection <HighlightingPreset> presets = hr.presets;

            for (int i = presets.Count - 1; i >= 0; i--)
            {
                HighlightingPreset p = presets[i];
                if (hr.downsampleFactor == p.downsampleFactor &&
                    hr.iterations == p.iterations &&
                    hr.blurMinSpread == p.blurMinSpread &&
                    hr.blurSpread == p.blurSpread &&
                    hr.blurIntensity == p.blurIntensity &&
                    hr.blurDirections == p.blurDirections)
                {
                    return(i);
                }
            }
            return(-1);
        }
Exemplo n.º 5
0
 // Add (store) preset
 public bool AddPreset(HighlightingPreset preset, bool overwrite)
 {
     for (int i = 0; i < _presets.Count; i++)
     {
         HighlightingPreset p = _presets[i];
         if (p.name == preset.name)
         {
             if (overwrite)
             {
                 _presets[i] = preset;
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     _presets.Add(preset);
     return(true);
 }
Exemplo n.º 6
0
        //
        protected virtual void InitializePresetNames()
        {
            ReadOnlyCollection <HighlightingPreset> presets = hr.presets;
            int presetCount = presets.Count;

            if (presetNames == null || presetNames.Length != presetCount)
            {
                presetNames = new GUIContent[presetCount];
            }

            for (int i = 0; i < presetCount; i++)
            {
                HighlightingPreset preset     = presets[i];
                GUIContent         presetName = presetNames[i];
                if (presetName == null)
                {
                    presetName     = new GUIContent();
                    presetNames[i] = presetName;
                }
                presetName.text = preset.name;
            }
        }
Exemplo n.º 7
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();
        }