private void HandlePortalDefinition() { if (!_inPortalMode) { return; } var p = this.target as GridPortalComponent; int id = GUIUtility.GetControlID(_idHash, FocusType.Passive); var groundRect = new Plane(Vector3.up, new Vector3(0f, 0f, 0f)); var evt = Event.current; if (evt.type == EventType.MouseDown && evt.button == 0) { GUIUtility.hotControl = id; evt.Use(); if (!EditorUtilities.MouseToWorldPoint(groundRect, out _portalRectStart)) { GUIUtility.hotControl = 0; } _shiftDown = (evt.modifiers & EventModifiers.Shift) > 0; _gridConnectMode = (evt.modifiers & EventModifiers.Control) > 0 || (evt.modifiers & EventModifiers.Command) > 0; _portalRectEnd = _portalRectStart; return; } else if (evt.type == EventType.KeyDown && evt.keyCode == KeyCode.Escape) { GUIUtility.hotControl = id; evt.Use(); return; } else if (evt.type == EventType.KeyUp && evt.keyCode == KeyCode.Escape) { GUIUtility.hotControl = 0; evt.Use(); ToggleEditMode(false); this.Repaint(); return; } else if (GUIUtility.hotControl != id) { if (evt.type == EventType.Repaint) { DrawActiveIndication(p); } return; } if (evt.type == EventType.MouseDrag) { evt.Use(); if (!EditorUtilities.MouseToWorldPoint(groundRect, out _portalRectEnd)) { _portalRectEnd = _portalRectStart; } } else if (evt.type == EventType.MouseUp) { GUIUtility.hotControl = 0; evt.Use(); var startToEnd = (_portalRectEnd - _portalRectStart); var portalBounds = new Bounds( _portalRectStart + (startToEnd * 0.5f), new Vector3(Mathf.Abs(startToEnd.x), Mathf.Max(Mathf.Abs(startToEnd.y), 0.1f), Mathf.Abs(startToEnd.z))); _gridConnectMode = _gridConnectMode || (evt.modifiers & EventModifiers.Control) > 0 || (evt.modifiers & EventModifiers.Command) > 0; _shiftDown = _shiftDown || (evt.modifiers & EventModifiers.Shift) > 0; if (p.type == PortalType.Connector) { HandleConnector(portalBounds, p); } else { HandleNormal(portalBounds, p); } EditorUtility.SetDirty(p); } else if (evt.type == EventType.Repaint) { Handles.color = _shiftDown ? p.portalTwoColor : p.portalOneColor; var y = Mathf.Max(_portalRectStart.y, _portalRectEnd.y); var c1 = new Vector3(_portalRectStart.x, y, _portalRectEnd.z); var c2 = new Vector3(_portalRectEnd.x, y, _portalRectStart.z); Handles.DrawDottedLine(_portalRectStart, c1, 10f); Handles.DrawDottedLine(c1, _portalRectEnd, 10f); Handles.DrawDottedLine(_portalRectEnd, c2, 10f); Handles.DrawDottedLine(c2, _portalRectStart, 10f); } }
private void OnSceneGUI() { var evt = Event.current; var p = this.target as PatrolPointsComponent; if (evt.type == EventType.Repaint) { if (_emphasize && GUIUtility.hotControl != _id) { DrawActiveIndication(p); } DrawNumberLabels(p); return; } if (!_inPlacementMode) { return; } var groundRect = new Plane(Vector3.up, new Vector3(0f, 0f, 0f)); if (evt.type == EventType.KeyDown && evt.keyCode >= KeyCode.Alpha0 && evt.keyCode <= KeyCode.Alpha9) { GUIUtility.hotControl = _id; evt.Use(); } else if (evt.type == EventType.KeyUp && evt.keyCode >= KeyCode.Alpha0 && evt.keyCode <= KeyCode.Alpha9) { evt.Use(); Vector3 point; if (!EditorUtilities.MouseToWorldPoint(groundRect, out point)) { GUIUtility.hotControl = 0; return; } if (p.relativeToTransform) { point = p.transform.InverseTransformPoint(point); } int idx = ((int)evt.keyCode) - 48; var points = p.points; if (points.Length < idx + 1) { var tmp = new Vector3[idx + 1]; Array.Copy(points, tmp, points.Length); points = tmp; p.points = tmp; } points[idx] = point; EditorUtility.SetDirty(p); GUIUtility.hotControl = 0; } else if (evt.type == EventType.KeyDown && evt.keyCode == KeyCode.Escape) { GUIUtility.hotControl = _id; evt.Use(); } else if (evt.type == EventType.KeyUp && evt.keyCode == KeyCode.Escape) { GUIUtility.hotControl = 0; evt.Use(); _inPlacementMode = false; this.Repaint(); } }
private void HandlePortalDefinition() { if (!_inPortalMode) { return; } var p = this.target as GridPortalComponent; int id = GUIUtility.GetControlID(_idHash, FocusType.Passive); var groundRect = new Plane(Vector3.up, new Vector3(0f, 0f, 0f)); var evt = Event.current; if (evt.type == EventType.MouseDown && evt.button == 0) { GUIUtility.hotControl = id; evt.Use(); if (!EditorUtilities.MouseToWorldPoint(groundRect, out _portalRectStart)) { GUIUtility.hotControl = 0; } _shiftDown = (evt.modifiers & EventModifiers.Shift) > 0; _gridConnectMode = (evt.modifiers & EventModifiers.Control) > 0 || (evt.modifiers & EventModifiers.Command) > 0; _portalRectEnd = _portalRectStart; return; } else if (evt.type == EventType.KeyDown && evt.keyCode == KeyCode.Escape) { GUIUtility.hotControl = id; evt.Use(); return; } else if (evt.type == EventType.KeyUp && evt.keyCode == KeyCode.Escape) { GUIUtility.hotControl = 0; evt.Use(); _inPortalMode = false; this.Repaint(); return; } else if (GUIUtility.hotControl != id) { return; } if (evt.type == EventType.MouseDrag) { evt.Use(); if (!EditorUtilities.MouseToWorldPoint(groundRect, out _portalRectEnd)) { _portalRectEnd = _portalRectStart; } } else if (evt.type == EventType.MouseUp) { GUIUtility.hotControl = 0; evt.Use(); _portalRectStart.y = _portalRectEnd.y = Mathf.Max(_portalRectStart.y, _portalRectEnd.y); var grid = GridManager.instance.GetGridComponent(_portalRectStart); if (grid == null) { grid = GridManager.instance.GetGridComponent(_portalRectEnd); if (grid == null) { return; } } var startToEnd = (_portalRectEnd - _portalRectStart); var portalBounds = new Bounds( _portalRectStart + (startToEnd * 0.5f), new Vector3(Mathf.Abs(startToEnd.x), Mathf.Abs(startToEnd.y) + 0.1f, Mathf.Abs(startToEnd.z))); _gridConnectMode = _gridConnectMode || (evt.modifiers & EventModifiers.Control) > 0 || (evt.modifiers & EventModifiers.Command) > 0; portalBounds = EditorUtilities.SnapToGrid(grid, portalBounds, _gridConnectMode); if (p.relativeToTransform) { portalBounds.center = p.transform.InverseTransformPoint(portalBounds.center); } _shiftDown = _shiftDown || (evt.modifiers & EventModifiers.Shift) > 0; if (_shiftDown) { p.portalTwo = portalBounds; } else { p.portalOne = portalBounds; } EditorUtility.SetDirty(p); } else if (evt.type == EventType.Repaint) { Handles.color = _shiftDown ? p.portalTwoColor : p.portalOneColor; var c1 = new Vector3(_portalRectStart.x, _portalRectStart.y, _portalRectEnd.z); var c2 = new Vector3(_portalRectEnd.x, _portalRectEnd.y, _portalRectStart.z); Handles.DrawDottedLine(_portalRectStart, c1, 10f); Handles.DrawDottedLine(c1, _portalRectEnd, 10f); Handles.DrawDottedLine(_portalRectEnd, c2, 10f); Handles.DrawDottedLine(c2, _portalRectStart, 10f); } }