void OnSceneGUI() { Event e = Event.current; if (e.type == EventType.KeyDown) { if (e.keyCode == KeyCode.G) { editing = true; Tools.current = Tool.None; } } if (Tools.current != Tool.None) { editing = false; } if (editing == false) { return; } HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); switch (e.type) { // case EventType. case EventType.MouseDrag: if (e.button == 0) { targetTile = (Tile)target; VectorT newPos = VectorT.WorldToGrid(SceneViewToWorld(e.mousePosition)); newPos.z = targetTile.gPosition.z; targetTile.SetPosition(newPos); } break; } }
public void OnSceneGUI(SceneView sceneView) { if (Tools.current != Tool.None && addTiles == true) { addTiles = false; SceneView.onSceneGUIDelegate -= OnSceneGUI; } HandleUtility.AddDefaultControl(GUIUtility.GetControlID(FocusType.Passive)); Event e = Event.current; switch (e.type) { case EventType.MouseDown: if (e.button != 0) { break; } selectionStart = VectorT.WorldToGrid(SceneViewToWorld(e.mousePosition)); selectionSet = true; selectionEnd = selectionStart; break; case EventType.MouseDrag: if (e.button != 0) { break; } selectionEnd = VectorT.WorldToGrid(SceneViewToWorld(e.mousePosition)); break; case EventType.MouseUp: if (e.button != 0) { break; } if (selectionSet == true) { selectionEnd = VectorT.WorldToGrid(SceneViewToWorld(e.mousePosition)); AddTiles(); selectionSet = false; } break; } if (selectionSet == false) { return; } Vector3[] verts = new Vector3[4]; verts[0] = selectionStart.ToWorld(); verts[1] = new VectorT(selectionStart.x, selectionEnd.y).ToWorld(); verts[2] = selectionEnd.ToWorld(); verts[3] = new VectorT(selectionEnd.x, selectionStart.y).ToWorld(); Handles.DrawSolidRectangleWithOutline(verts, new Color(0, 0.25f, 1, 0.25f), new Color(0, 0, 0.25f, 0.5f)); HandleUtility.Repaint(); }