public Vector2 GetCornerPosition(BoxCorner corner) { Vector2 pos = Vector2.zero; switch (corner) { case BoxCorner.UpperLeft: pos = bound.center + Vector3.Scale(bound.extents, new Vector3(-1, 1, 0)); break; case BoxCorner.UpperRight: pos = bound.center + Vector3.Scale(bound.extents, new Vector3(1, 1, 0)); break; case BoxCorner.LowerLeft: pos = bound.center + Vector3.Scale(bound.extents, new Vector3(-1, -1, 0)); break; case BoxCorner.LowerRight: pos = bound.center + Vector3.Scale(bound.extents, new Vector3(1, -1, 0)); break; } return(pos); }
private void ShowPoint(BoxCorner corner) { Vector3 point = area.GetCornerPosition(corner); EditorGUI.BeginChangeCheck(); point = Handles.FreeMoveHandle(point, Quaternion.identity, 0.1f, Vector3.one, Handles.DotHandleCap); if (EditorGUI.EndChangeCheck()) { area.SetCornerPosition(corner, point); changing = true; } else if (changing) { Undo.RecordObject(area, "Change area"); EditorUtility.SetDirty(area); area.SetCornerPosition(corner, point); changing = false; } }
public void SetCornerPosition(BoxCorner corner, Vector2 newPosition) { Vector3 LowerLeft = GetCornerPosition(BoxCorner.UpperLeft); Vector3 UpperRight = GetCornerPosition(BoxCorner.LowerRight); Vector3 UnchangedPoint = Vector3.zero; switch (corner) { case BoxCorner.UpperLeft: UnchangedPoint = GetCornerPosition(BoxCorner.LowerRight); LowerLeft = new Vector2(newPosition.x, UnchangedPoint.y); UpperRight = new Vector2(UnchangedPoint.x, newPosition.y); break; case BoxCorner.UpperRight: UnchangedPoint = GetCornerPosition(BoxCorner.LowerLeft); LowerLeft = UnchangedPoint; UpperRight = newPosition; break; case BoxCorner.LowerLeft: UnchangedPoint = GetCornerPosition(BoxCorner.UpperRight); LowerLeft = newPosition; UpperRight = UnchangedPoint; break; case BoxCorner.LowerRight: UnchangedPoint = GetCornerPosition(BoxCorner.UpperLeft); LowerLeft = new Vector2(UnchangedPoint.x, newPosition.y); UpperRight = new Vector2(newPosition.x, UnchangedPoint.y); break; } UpperRight.z = transform.position.z; LowerLeft.z = transform.position.z; bound.SetMinMax(UpperRight, LowerLeft); }