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); } }
public void Finalise() { Initialise(); Mesh.Clear(); Mesh.SetVertices(_verts); Mesh.SetTriangles(_tris, 0); Mesh.SetColors(_colors); if (EditorCellHelper.UseCPU()) { Mesh.SetUVs(0, _uvs); } }
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)); } }