public void SetHorizontalPivot(AnchorModes newAnchoring) { anchorHorizontal = newAnchoring; if (menuController != null) { menuController.rightAlingment(newAnchoring == AnchorModes.min); } }
private void OnEnable() { creator = (HandleTest)target; if (Path[0] == null) { creator.CreatePath(); } handleMode = AnchorModes.POSITION; Tools.hidden = true; SceneView.onSceneGUIDelegate += CustomOnSceneGUI; }
void Input() { if (guiEvent.type == EventType.MouseDown && guiEvent.isMouse) { if (guiEvent.button == 0 && guiEvent.shift && !guiEvent.control) { //DONT DO ANYTHING IF NOT CURRENT HOVERED PATH if (selectedSegmentIndex != -1) { if (hoveredPathIndex != currentPathIndex) { } else { Undo.RecordObject(creator, "Split segment"); Vector3[] points = Path[currentPathIndex].GetPointsInSegment(selectedSegmentIndex); Vector3 nearestPointToCurve = ApproximateNearestPointBezierMousePos(points[0], points[3], points[1], points[2]); Path[currentPathIndex].SplitSegment(nearestPointToCurve, selectedSegmentIndex); creator.SetVertPath(Path[currentPathIndex].CalculateEvenlySpacedPointsAndNormals(VertOptions.VertSpacing, VertOptions.Resolution), currentPathIndex); } } else if (!Path[currentPathIndex].IsClosed) { Undo.RecordObject(creator, "Add segment"); Ray mouseRay = Camera.current.ScreenPointToRay(screenSpaceMousePos); RaycastHit hit; Vector3 segmentPos = mouseRay.origin + mouseRay.direction * 5f; if (Physics.Raycast(mouseRay.origin, mouseRay.direction, out hit, 30f)) { segmentPos = hit.point; } Path[currentPathIndex].AddSegment(segmentPos); creator.SetVertPath(Path[currentPathIndex].CalculateEvenlySpacedPointsAndNormals(VertOptions.VertSpacing, VertOptions.Resolution), currentPathIndex); //Path.CalculateEvenlySpacedPoints(creator.VertSpacing); } } else if (guiEvent.button == 0 && guiEvent.control && guiEvent.shift) { if (hoveredPathIndex != currentPathIndex) { } else if (selectedSegmentIndex != -1) { Undo.RecordObject(creator, "Add New PathSplit On Currently Selected"); Vector3[] points = Path[currentPathIndex].GetPointsInSegment(selectedSegmentIndex); Vector3 nearestPointToCurve = ApproximateNearestPointBezierMousePos(points[0], points[3], points[1], points[2]); creator.AddNewPathSplit(currentPathIndex, nearestPointToCurve); currentPathIndex = Path.Count - 1; creator.SetVertPath(Path[currentPathIndex].CalculateEvenlySpacedPointsAndNormals(VertOptions.VertSpacing, VertOptions.Resolution), currentPathIndex); } } else if (guiEvent.button == 0) { Undo.RecordObject(creator, "Select Path"); currentPathIndex = (hoveredPathIndex == -1) ? currentPathIndex : hoveredPathIndex; } } else if (guiEvent.isKey && guiEvent.type == EventType.KeyDown) { if (guiEvent.character == 'p' || guiEvent.character == 'P') { handleMode = AnchorModes.POSITION; } if (guiEvent.character == 'r' || guiEvent.character == 'R') { handleMode = AnchorModes.ROTATION; } } else if (guiEvent.type == EventType.MouseMove) { float minDstToSegment = segmentSelectDistanceThreshold; int newSelectedSegmentIndex = -1; int newHoveredPathIndex = -1; for (int i = 0; i < Path.Count; i++) { for (int j = 0; j < Path[i].NumSegments; j++) { Vector3[] points = Path[i].GetPointsInSegment(j); Vector2[] screenSpacePoints = new Vector2[points.Length]; float minX = 0, maxX = 0, minY = 0, maxY = 0; for (int k = 0; k < points.Length; k++) { screenSpacePoints[k] = Camera.current.WorldToScreenPoint(points[k]); if (k == 0) { minX = screenSpacePoints[k].x; maxX = screenSpacePoints[k].x; minY = screenSpacePoints[k].y; maxY = screenSpacePoints[k].y; } else { if (screenSpacePoints[k].x < minX) { minX = screenSpacePoints[k].x; } else if (screenSpacePoints[k].x > maxX) { maxX = screenSpacePoints[k].x; } if (screenSpacePoints[k].y < minY) { minY = screenSpacePoints[k].y; } else if (screenSpacePoints[k].y > maxY) { maxY = screenSpacePoints[k].y; } } } if (screenSpaceMousePos.x > minX && screenSpaceMousePos.x < maxX && screenSpaceMousePos.y > minY && screenSpaceMousePos.y < maxY) { Vector3 nearestPointToCurve = ApproximateNearestPointBezierMousePos(points[0], points[3], points[1], points[2]); float dst = HandleUtility.DistancePointBezier(nearestPointToCurve, points[0], points[3], points[1], points[2]); if (dst < minDstToSegment) { minDstToSegment = dst; newSelectedSegmentIndex = j; newHoveredPathIndex = i; } } } } if (newSelectedSegmentIndex != selectedSegmentIndex) { selectedSegmentIndex = newSelectedSegmentIndex; hoveredPathIndex = newHoveredPathIndex; HandleUtility.Repaint(); } } }
public void SetVerticalPivot(AnchorModes newAnchoring) { anchorVertical = newAnchoring; SetAnchorAndPivotBasedOnAnchoring(); }