// private static string[] syncChannelOptions = new string[]{ "None", "Splat", "Node Targets", "Node Children" }; public void OnEnable() { painter = (NodePainter)target; if (painter.painter == null) { throw new Exception("Painter not initialized!"); } editor = new PaintingEditor(painter.painter); editor.MultiChannelSyncGUI = DrawMultiChannelSyncGUI; //GetPreviewTextures (); painter.UpdateTerrains(); GlobalPainting.UpdateTerrainBrush(); GlobalPainting.HideCanvasProjection(); if (!System.IO.Directory.Exists(Settings.paintingResourcesFolder)) { Debug.LogWarning("Resource folder does not exist! Please select a valid path in the settings!"); return; } }
public void OnSceneGUI() { if (!painter.painter.hasCanvas) { return; } if (!editor.isMouseInWindow || Event.current.modifiers == EventModifiers.Alt) { GlobalPainting.UpdateTerrainBrush(); return; } if (vizCanvasOnTerrain) { GlobalPainting.ShowCanvasProjection(painter.transform.position + Vector3.up * painter.canvasSize.y, painter.transform.rotation, new Vector2(painter.transform.lossyScale.x * painter.canvasSize.x, painter.transform.lossyScale.z * painter.canvasSize.z), painter.painter.vizCanvas, painter.painter.canvasFormat == Painting.Format.Value); } if (debugGenerateRect) { Vector2 totalAreaSize = new Vector2(painter.areaSize.x * painter.areaTiles.x, painter.areaSize.z * painter.areaTiles.y); Rect rect = new Rect(Vector2.Scale(painter.generateRect.position, totalAreaSize) - totalAreaSize / 2, Vector2.Scale(painter.generateRect.size, totalAreaSize)); rect.position += new Vector2(painter.areaPos.x, painter.areaPos.z); Handles.DrawSolidRectangleWithOutline(new Vector3[] { new Vector3(rect.xMin, 0, rect.yMin), new Vector3(rect.xMax, 0, rect.yMin), new Vector3(rect.xMax, 0, rect.yMax), new Vector3(rect.xMin, 0, rect.yMax) }, new Color(1, 1, 1, 0), Color.green); } if (debugNodeRect) { Rect rect = painter.nodeRect; Handles.DrawSolidRectangleWithOutline(new Vector3[] { new Vector3(rect.xMin, 0, rect.yMin), new Vector3(rect.xMax, 0, rect.yMin), new Vector3(rect.xMax, 0, rect.yMax), new Vector3(rect.xMin, 0, rect.yMax) }, new Color(1, 1, 1, 0), Color.red); } painter.painter.blockPainting = Tools.current != Tool.None; if ((Event.current.type == EventType.MouseUp && Event.current.button == 0) || Event.current.button != 0) { painter.painter.StopPainting(SceneViewID); } editor.controlID = GUIUtility.GetControlID(FocusType.Passive); HandleUtility.AddDefaultControl(editor.controlID); if (Event.current.GetTypeForControl(editor.controlID) == EventType.MouseDown) { // Block left-click in scene view GUIUtility.hotControl = editor.controlID; // Event.current.Use (); } Vector2 brushPos; Vector3 worldPos; if (painter.CalcBrushWorldPos(out brushPos, out worldPos)) { if (Event.current.type != EventType.Repaint && Event.current.type != EventType.Layout) { Undo.RecordObject(painter, "Node Painter Shortcut"); } string undoRecord; bool blockPainting = editor.HandleShortcuts(out undoRecord) || painter.painter.blockPainting; if (!string.IsNullOrEmpty(undoRecord)) { Undo.FlushUndoRecordObjects(); } if (Event.current.type == EventType.Layout) { if (blockPainting) { GlobalPainting.UpdateTerrainBrush(); } else if (painter.TCNodeTarget != null) { GlobalPainting.ShowTerrainBrush(painter.painter, worldPos, painter.painter.curBrush.size * painter.TCNodeTarget.size.x * painter.transform.lossyScale.x); } else { GlobalPainting.ShowTerrainBrush(painter.painter, worldPos, painter.painter.curBrush.size * TC_Area2D.current.bounds.size.x * painter.transform.lossyScale.x); } } float expand = painter.painter.curBrush.size; bool isInCanvas = (brushPos.x >= -expand && brushPos.x <= 1 + expand) && (brushPos.y >= -expand && brushPos.y <= 1 + expand); if (painter.painter.PaintUpdate(SceneViewID, editor.controlID, isInCanvas, blockPainting, brushPos)) { Repaint(); } } else { if (GUIUtility.hotControl == editor.controlID) { GUIUtility.hotControl = 0; } GlobalPainting.UpdateTerrainBrush(); } if (editor.isMouseInWindow) { HandleUtility.Repaint(); } }
public void OnDisable() { editor.Close(); GlobalPainting.UpdateTerrainBrush(); GlobalPainting.HideCanvasProjection(); }