Example #1
0
 public void QueueCell(EditorCellHelper.Cell cell)
 {
     if (EditorCellHelper.UseCPU())
     {
         var cellSize = EditorCellHelper.CellSize;
         int index    = _verts.Count;
         _verts.Add(cell.Center + new Vector3(cellSize / 2, 0, cellSize / 2));
         _verts.Add(cell.Center + new Vector3(-cellSize / 2, 0, cellSize / 2));
         _verts.Add(cell.Center + new Vector3(cellSize / 2, 0, -cellSize / 2));
         _verts.Add(cell.Center + new Vector3(-cellSize / 2, 0, -cellSize / 2));
         _uvs.Add(new Vector2(1, 1));
         _uvs.Add(new Vector2(0, 1));
         _uvs.Add(new Vector2(1, 0));
         _uvs.Add(new Vector2(0, 0));
         _colors.Add(cell.Color);
         _colors.Add(cell.Color);
         _colors.Add(cell.Color);
         _colors.Add(cell.Color);
         _tris.Add(index + 0);
         _tris.Add(index + 1);
         _tris.Add(index + 2);
         _tris.Add(index + 1);
         _tris.Add(index + 2);
         _tris.Add(index + 3);
     }
     else
     {
         _verts.Add(cell.Center);
         _tris.Add(_verts.Count - 1);
         _tris.Add(_verts.Count - 1);
         _tris.Add(_verts.Count - 1);
         _colors.Add(cell.Color);
     }
 }
Example #2
0
        public void Destroy()
        {
            EditorCellHelper.Clear(true);
            EditorApplication.update -= Update;

            //Debug.Log("Destroyed painter");
        }
Example #3
0
 private void Update()
 {
     if (Canvas == null)
     {
         return;
     }
     EditorCellHelper.SetAlive();
 }
Example #4
0
 public void Finalise()
 {
     Initialise();
     Mesh.Clear();
     Mesh.SetVertices(_verts);
     Mesh.SetTriangles(_tris, 0);
     Mesh.SetColors(_colors);
     if (EditorCellHelper.UseCPU())
     {
         Mesh.SetUVs(0, _uvs);
     }
 }
Example #5
0
 public void Initialise()
 {
     if (Mesh == null)
     {
         Mesh           = new Mesh();
         Mesh.hideFlags = HideFlags.DontSave;
         Mesh.MarkDynamic();
     }
     if (MeshFilter == null)
     {
         MeshFilter            = gameObject.AddComponent <MeshFilter>();
         MeshFilter.sharedMesh = Mesh;
     }
     if (Renderer == null)
     {
         Renderer = gameObject.AddComponent <MeshRenderer>();
     }
     EditorCellHelper.Register(this);
     gameObject.hideFlags = HideFlags.HideAndDontSave;
 }
Example #6
0
 public void Update()
 {
     EditorCellHelper.Register(this);
 #if UNITY_EDITOR
     var t = UnityEditor.EditorApplication.timeSinceStartup;
 #else
     var t = (double)Time.time;
 #endif
     if (_lastAliveTime + EditorCellHelper.AutoClearTime < t)
     {
         if (Application.isPlaying)
         {
             Destroy(gameObject);
         }
         else
         {
             DestroyImmediate(gameObject);
         }
     }
 }
Example #7
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));
            }
        }
Example #8
0
        private void UpdateVisualisation()
        {
            if (Canvas == null)
            {
                Debug.LogWarning("Trying to draw Painter with null Canvas?");
                return;
            }

            DrawSceneControls();
            for (var i = 0; i < 5; ++i)
            {
                var scale = TRS.GetScale();
                scale = new Vector3(scale.x * Rect.size.x, 0, scale.z * Rect.size.y);
                var rectPos = TRS.MultiplyPoint(Rect.min.x0z(PlaneOffset) + Vector3.up * i + Rect.size.x0z() / 2);
                HandleExtensions.DrawWireCube(rectPos, scale / 2, TRS.GetRotation(), Color.cyan.WithAlpha(1 - i / 5f));
            }
            Handles.color = Color.white;

            if (CurrentBrush != null)
            {
                CurrentBrush.DrawGizmos(GridManager, _currentInputState, Rect, TRS);
            }

            var cellColor = Color.white;

            if (!_currentInputState.MouseBlocked && DoSceneGUIForHoverCell != null)
            {
                DoSceneGUIForHoverCell(GridManager.GetCell(_currentInputState.GridPosition));
            }

            Handles.color = Color.magenta.WithAlpha(.2f);
            Handles.DrawDottedLine(_currentInputState.PlanePosition, _currentInputState.GridPosition, 1);

            _repaint |= Canvas.Dirty;

            EditorCellHelper.SetAlive(); // Tell the cell renderer that it should keep rendering
            EditorCellHelper.CellSize = GridManager.GetGridSize();
            EditorCellHelper.TRS      = TRS;
            if (_repaint)
            {
                EditorCellHelper.Clear(false);
                lock (Canvas)
                {
                    Canvas.Dirty = false;
                    var enumerator = Canvas.AllValues();
                    while (enumerator.MoveNext())
                    {
                        cellColor = Ramp.Evaluate((enumerator.Current.Value - MinValue) / MaxValue);
                        cellColor = cellColor.WithAlpha(cellColor.a * Opacity);
                        if (TransmuteCellColor != null)
                        {
                            cellColor = TransmuteCellColor(enumerator.Current.Key, cellColor);
                        }
                        var cellPos = GridManager.GetCellCenter(enumerator.Current.Key).x0z(PlaneOffset);
                        EditorCellHelper.AddCell(cellPos, cellColor);
                    }
                }
                EditorCellHelper.Invalidate();
                _repaint = false;
            }
        }