Exemple #1
0
        private void GetDefaultBrush()
        {
            if (!PaintingEnabled)
            {
                return;
            }

            if (_brushCache == null)
            {
                _brushCache = new Dictionary <Type, IBrush>();
                Type[] types = new Type[]
                {
                    typeof(DefaultBrush),
                    typeof(BlurBrush),
                    typeof(ClusterBrush),
                    typeof(FillBrush),
                };
                foreach (var type in types)
                {
                    var key = "Painter_Brush_" + type.AssemblyQualifiedName;
                    if (EditorPrefs.HasKey(key))
                    {
                        var json  = EditorPrefs.GetString(key);
                        var brush = JsonUtility.FromJson(json, type) as MadMaps.Common.Painter.IBrush;
                        _brushCache.Add(type, brush);
                    }
                    else
                    {
                        _brushCache.Add(type, Activator.CreateInstance(type) as MadMaps.Common.Painter.IBrush);
                    }
                }
            }

            if (CurrentBrush == null)
            {
                CurrentBrush = _brushCache[typeof(DefaultBrush)];
            }
        }
Exemple #2
0
        private void DrawSceneControls()
        {
            if (Event.current.type == EventType.MouseMove)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                UIBlockers.Clear();
            }
            Handles.BeginGUI();
            GUILayout.BeginArea(new Rect(0, 0, 240, Screen.height));

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            EditorGUILayout.LabelField(EditorCellHelper.UseCPU() ? "Using CPU Painting" : "Using GPU Painting");
            EditorGUILayout.LabelField(string.Format("Grid Size: {0}", GridManager.GetGridSize().ToString("n2")));

            var offset = EditorPrefs.GetFloat("Painter_PlaneOffset", 0);

            offset = EditorGUILayout.FloatField("Plane Offset", offset);
            if (!Mathf.Approximately(PlaneOffset, offset))
            {
                PlaneOffset = offset;
                EditorPrefs.SetFloat("Painter_PlaneOffset", offset);
                _repaint = true;
            }

            MinValue = EditorGUILayout.FloatField("Min", MinValue);
            MaxValue = EditorGUILayout.FloatField("Max", MaxValue);
            Ramp     = GUIGradientField.GradientField("Ramp", Ramp);

            var opacity = EditorPrefs.GetFloat("Painter_Opacity", 0.5f);

            opacity = Mathf.Clamp01(EditorGUILayout.FloatField("Opacity", opacity));
            if (!Mathf.Approximately(Opacity, opacity))
            {
                Opacity = opacity;
                EditorPrefs.SetFloat("Painter_Opacity", opacity);
                _repaint = true;
            }

            EditorGUILayout.EndVertical();
            if (Event.current.type == EventType.Repaint)
            {
                // Update blocking rect
                var guiRect = GUILayoutUtility.GetLastRect();
                UIBlockers.Add(guiRect);
            }

            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            EditorGUILayout.BeginHorizontal();

            if (!PaintingEnabled)
            {
                EditorGUILayout.LabelField("Painting is Disabled");
            }

            GUI.enabled = PaintingEnabled;
            EditorGUILayout.LabelField(CurrentBrush != null ? CurrentBrush.GetType().Name : "Null");
            if (GUILayout.Button("...", EditorStyles.toolbarButton, GUILayout.Width(32)))
            {
                var menu = new GenericMenu();
                menu.AddItem(new GUIContent("Paint Brush"), true, () => CurrentBrush   = new DefaultBrush());
                menu.AddItem(new GUIContent("Blur Brush"), true, () => CurrentBrush    = new BlurBrush());
                menu.AddItem(new GUIContent("Cluster Brush"), true, () => CurrentBrush = new ClusterBrush());
                menu.AddItem(new GUIContent("Fill Brush"), true, () => CurrentBrush    = new FillBrush());
                menu.ShowAsContext();
            }

            EditorGUILayout.EndHorizontal();
            if (CurrentBrush != null)
            {
                CurrentBrush.DrawGUI();
            }
            EditorGUILayout.EndVertical();
            if (Event.current.type == EventType.Repaint)
            {
                // Update blocking rect
                var guiRect = GUILayoutUtility.GetLastRect();
                UIBlockers.Add(guiRect);
            }
            GUI.enabled = true;
            GUILayout.EndArea();

            Handles.EndGUI();

            // Save brush
            if (CurrentBrush != null)
            {
                EditorPrefs.SetString("Painter_LastBrushType", CurrentBrush.GetType().AssemblyQualifiedName);
                EditorPrefs.SetString("Painter_Brush_" + CurrentBrush.GetType().AssemblyQualifiedName, JsonUtility.ToJson(CurrentBrush));
            }
        }