Skip to content

Commit

Permalink
Move camera to zoomed location
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter226 committed Nov 27, 2023
1 parent 69258b7 commit 5bf2cb0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
13 changes: 10 additions & 3 deletions Assets/Scripts/GameOfLifeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ void Start()
void Update()
{
//zoom the camera, and restrict it's zoom level within reasonable numbers
Vector3 lastWorldScrollPosition = _camera.ScreenToWorldPoint(Input.mousePosition); ;

_camera.orthographicSize *= -Input.mouseScrollDelta.y * 0.1f + 1;
_camera.orthographicSize = Mathf.Clamp(_camera.orthographicSize,0.0001f,1.0f);

Vector3 nowWorldScrollPosition = _camera.ScreenToWorldPoint(Input.mousePosition);
transform.position += lastWorldScrollPosition - nowWorldScrollPosition;

if (Input.GetMouseButtonDown(2))
{
previousMousePosition = Input.mousePosition;
Expand All @@ -32,11 +38,12 @@ void Update()
Vector3 delta = lastWorld - nowWorld;
transform.position += new Vector3(delta.x, delta.y);
previousMousePosition = Input.mousePosition;
//restrict camera position
Vector3 camPos = _camera.transform.position;
_camera.transform.position = new Vector3(Mathf.Clamp(camPos.x,-0.5f, 0.5f),Mathf.Clamp(camPos.y,-0.5f, 0.5f),camPos.z);
}

//restrict camera position
Vector3 camPos = transform.position;
transform.position = new Vector3(Mathf.Clamp(camPos.x, -0.5f, 0.5f), Mathf.Clamp(camPos.y, -0.5f, 0.5f), camPos.z);

}
}

20 changes: 10 additions & 10 deletions UserSettings/Layouts/CurrentMaximizeLayout.dwlt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ MonoBehaviour:
m_MinSize: {x: 300, y: 200}
m_MaxSize: {x: 24288, y: 16192}
vertical: 0
controlID: 71
controlID: 212
--- !u!114 &2
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -141,7 +141,7 @@ MonoBehaviour:
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 16192, y: 16192}
vertical: 1
controlID: 72
controlID: 213
--- !u!114 &4
MonoBehaviour:
m_ObjectHideFlags: 52
Expand All @@ -166,7 +166,7 @@ MonoBehaviour:
m_MinSize: {x: 200, y: 100}
m_MaxSize: {x: 16192, y: 8096}
vertical: 0
controlID: 47
controlID: 214
--- !u!114 &5
MonoBehaviour:
m_ObjectHideFlags: 52
Expand Down Expand Up @@ -269,8 +269,8 @@ MonoBehaviour:
y: 0
width: 760.8
height: 560
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_MinSize: {x: 202, y: 221}
m_MaxSize: {x: 4002, y: 4021}
m_ActualView: {fileID: 2}
m_Panes:
- {fileID: 8}
Expand Down Expand Up @@ -601,8 +601,8 @@ MonoBehaviour:
y: 560
width: 1097.6
height: 170.79999
m_MinSize: {x: 100, y: 100}
m_MaxSize: {x: 4000, y: 4000}
m_MinSize: {x: 101, y: 121}
m_MaxSize: {x: 4001, y: 4021}
m_ActualView: {fileID: 11}
m_Panes:
- {fileID: 10}
Expand Down Expand Up @@ -796,8 +796,8 @@ MonoBehaviour:
y: 0
width: 438.40002
height: 730.8
m_MinSize: {x: 275, y: 50}
m_MaxSize: {x: 4000, y: 4000}
m_MinSize: {x: 276, y: 71}
m_MaxSize: {x: 4001, y: 4021}
m_ActualView: {fileID: 13}
m_Panes:
- {fileID: 13}
Expand Down Expand Up @@ -837,7 +837,7 @@ MonoBehaviour:
m_CachedPref: 160
m_ControlHash: -371814159
m_PrefName: Preview_InspectorPreview
m_LastInspectedObjectInstanceID: -1
m_LastInspectedObjectInstanceID: 23382
m_LastVerticalScrollValue: 0
m_GlobalObjectId:
m_InspectorMode: 0
Expand Down

0 comments on commit 5bf2cb0

Please sign in to comment.