├── LICENSE
├── LICENSE.meta
├── README.md
├── README.md.meta
├── Scripts.meta
├── Scripts
├── FreeCam.cs
├── FreeCam.cs.meta
├── InputHandlers.meta
└── InputHandlers
│ ├── FreeCamDisabledInput.cs
│ ├── FreeCamDisabledInput.cs.meta
│ ├── FreeCamInput.cs
│ ├── FreeCamInput.cs.meta
│ ├── FreeCamMouseInput.cs
│ ├── FreeCamMouseInput.cs.meta
│ ├── FreeCamTouchInput.cs
│ └── FreeCamTouchInput.cs.meta
├── _Extra.meta
└── _Extra
├── ExampleScene.meta
├── ExampleScene
├── Scene.unity
└── Scene.unity.meta
├── Prefabs.meta
├── Prefabs
├── FreeCamDefault.prefab
└── FreeCamDefault.prefab.meta
├── Scripts.meta
└── Scripts
├── FreeCamInitPosRotZoom.cs
└── FreeCamInitPosRotZoom.cs.meta
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/LICENSE.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 986c2959ed5ef40459ac3f6a0e8b4b8a
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UnityFreeCam
2 | A free moving camera system for Unity. Smoooooth camera movements!
3 |
4 | Simply drop in the prefab in the "Extras" folder and hit play. Or check out the example scene! The inspector for the FreeCam script contains tooltips, so you can read those to figure out how to configure the camera, though the default configuration should suit most projects.
5 |
6 | [Visit the 'Releases' page](https://github.com/prodigga/UnityFreeCam/releases) to download the latest FreeCam UnityPackage! If you'd like to try it out, just dump it into your project and check out the example scene. Everything is contained in its of folder.
7 |
8 | [Web Player here](https://dl.dropboxusercontent.com/u/21307579/FreeCam/WebBuild.html)
--------------------------------------------------------------------------------
/README.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d52268590136432488f4bb75f7a9e375
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Scripts.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 7867a0763a330dd4eb9ad72d38558ce4
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/Scripts/FreeCam.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | public class FreeCam : MonoBehaviour
4 | {
5 | [Header("Position")]
6 | [Tooltip("How quickly the camera will move left and right (X) and up and down (Y)")]
7 | public Vector2 PositionalSensitivity;
8 | [Tooltip("How quickly the camera will actually move towards the new position")]
9 | public float PositionalFollowSpeed;
10 | [Tooltip("How many units away from the target position must we be before we start scaling the follow speed by the curve")]
11 | public float PositionalFollowCurveStart;
12 | [Tooltip("Scale the follow speed by this curve once we are PositionalFollowCurveStart units away from the target position")]
13 | public AnimationCurve PositionalFollowCurve;
14 | [Tooltip("Scale the above values uniformally once the zoom level is passed this point (ie, a value of 5 will mean when we are at zoom value 10, all the values above will be multipled by 2)")]
15 | public float PositionalZoomScale;
16 |
17 | [Header("Rotation")]
18 | [Tooltip("How quickly the camera will rotate left and right (X) and up and down (Y)")]
19 | public Vector2 RotationSensitivity;
20 | [Tooltip("How quickly the camera will actually rotate towards the new rotation")]
21 | public float RotationalFollowSpeed;
22 | [Tooltip("How many degrees away from the target rotation must we be before we start scaling the follow speed by the curve")]
23 | public float RotationalFollowCurveStart;
24 | [Tooltip("Scale the follow speed by this curve once we are RotationalFollowCurveStart degrees away from the target rotation")]
25 | public AnimationCurve RotationalFollowCurve;
26 |
27 | [Header("Zoom")]
28 | [Tooltip("Scrollwheel delta * this value")]
29 | public float ZoomSensitivity;
30 | [Tooltip("How quickly the camera will actually match its zoom value with the target zoom")]
31 | public float ZoomFollowSpeed;
32 | [Tooltip("(Target zoom / this value) will be used to sample the curve bellow and the result will be used to scale ZoomFollowSpeed")]
33 | public float ZoomFollowCurveStart;
34 | [Tooltip("See ZoomFollowCurveStart")]
35 | public AnimationCurve ZoomFollowCurve;
36 |
37 | [Space(10)]
38 | public float MinZoom;
39 | public float MaxZoom;
40 |
41 | [Header("Misc")]
42 | [Tooltip("A GameObject with a camera attached should be childed to GameObject that this script is attached to.")]
43 | public Camera ChildCamera;
44 | [Tooltip("When the use middle mouse clicks on an object in the game, we will only center on it if it is on this layer.")]
45 | public LayerMask CenterClickMask;
46 | [Tooltip("Use mouse or touch screen. Automatic will pick the appropriate one by itself (Recommended)")]
47 | public InputMode Mode;
48 |
49 | public enum InputMode
50 | {
51 | Automatic,
52 | Mouse,
53 | Touch,
54 | }
55 |
56 | private Vector3 _targetMovePosition;
57 | private Vector3 _actualMovePosition;
58 |
59 | private Vector2 _targetLookEuler;
60 | private Vector2 _actualLookEuler;
61 |
62 | private float _targetZoom;
63 | private float _actualZoom;
64 |
65 | private FreeCamInput _input;
66 | private InputMode _currentMode;
67 |
68 | private float _sensitivity = 1;
69 |
70 | void Awake()
71 | {
72 | InitializeFreeCamInput();
73 | }
74 |
75 | void InitializeFreeCamInput()
76 | {
77 | _currentMode = Mode;
78 | InputMode modeToTest = _currentMode;
79 |
80 | if (_currentMode == InputMode.Automatic)
81 | modeToTest = ResolveAutomaticInputMode();
82 |
83 | switch (modeToTest)
84 | {
85 | case InputMode.Mouse:
86 | _input = new FreeCamMouseInput();
87 | break;
88 | case InputMode.Touch:
89 | _input = new FreeCamTouchInput();
90 | break;
91 | }
92 | }
93 |
94 | void Update()
95 | {
96 | if (Input.GetKeyDown(KeyCode.P))
97 | {
98 | if(IsInputEnabled())
99 | DisableInput();
100 | else
101 | EnableInput();
102 | }
103 |
104 | if (_currentMode != Mode || _input == null)
105 | InitializeFreeCamInput();
106 |
107 | _input.Update();
108 |
109 | //Update the target rotation
110 | if (_input.ShouldRotate())
111 | {
112 | _targetLookEuler.y -= _input.GetPrimaryDelta().x * Time.deltaTime * RotationSensitivity.x * _sensitivity;
113 | _targetLookEuler.x += _input.GetPrimaryDelta().y * Time.deltaTime * RotationSensitivity.y * _sensitivity;
114 | }
115 | if (_targetLookEuler.x > 90) _targetLookEuler.x = 90;
116 | if (_targetLookEuler.x < -90) _targetLookEuler.x = -90;
117 |
118 | //Update the target position
119 | if (_input.ShouldDrag())
120 | {
121 | float scaleFactor = Mathf.Clamp(Mathf.Abs(_actualZoom)/PositionalZoomScale, 1, float.MaxValue);
122 | _targetMovePosition += transform.up * _input.GetPrimaryDelta().y * Time.deltaTime * PositionalSensitivity.y * scaleFactor * _sensitivity;
123 | _targetMovePosition += transform.right * _input.GetPrimaryDelta().x * Time.deltaTime * PositionalSensitivity.x * scaleFactor * _sensitivity;
124 | }
125 |
126 | //Update the target zoom
127 | _targetZoom -= _input.GetZoomDelta() * Time.deltaTime * ZoomSensitivity * ZoomFollowCurve.Evaluate((Mathf.Abs(_targetZoom) / ZoomFollowCurveStart));
128 | _targetZoom = Mathf.Clamp(_targetZoom, MinZoom, MaxZoom);
129 |
130 | //When mid mouse is released and if it was released within the 'click' threshold,
131 | //raycast from the currnet mouse position to try and find an object to center on
132 | if (_input.ShouldCenterOnTarget())
133 | {
134 | var ray = ChildCamera.ScreenPointToRay(Input.mousePosition);
135 | var hit = new RaycastHit();
136 | if (Physics.Raycast(ray, out hit, 1000, CenterClickMask))
137 | {
138 | _targetMovePosition = hit.collider.transform.position;
139 | }
140 | }
141 | }
142 |
143 | void LateUpdate()
144 | {
145 | //Tween rotation
146 | _actualLookEuler = Vector3.MoveTowards(_actualLookEuler, _targetLookEuler,
147 | RotationalFollowSpeed *
148 | RotationalFollowCurve.Evaluate((Vector3.Distance(_actualLookEuler, _targetLookEuler) / RotationalFollowCurveStart)) *
149 | Time.deltaTime);
150 |
151 | transform.rotation = Quaternion.Euler(_actualLookEuler);
152 |
153 | //Tween position
154 | float scaleFactor = Mathf.Clamp(Mathf.Abs(_actualZoom)/PositionalZoomScale, 1, float.MaxValue);
155 | _actualMovePosition = Vector3.MoveTowards(_actualMovePosition, _targetMovePosition,
156 | PositionalFollowSpeed *
157 | PositionalFollowCurve.Evaluate((Vector3.Distance(_actualMovePosition, _targetMovePosition) / PositionalFollowCurveStart)) *
158 | Time.deltaTime * scaleFactor);
159 |
160 | transform.position = _actualMovePosition;
161 |
162 | //Tween zoom
163 | _actualZoom = Mathf.MoveTowards(_actualZoom, _targetZoom,
164 | ZoomFollowSpeed * ZoomFollowCurve.Evaluate((Mathf.Abs(_targetZoom) / ZoomFollowCurveStart)) *
165 | Time.deltaTime);
166 |
167 | ChildCamera.transform.localPosition = new Vector3(0, 0, -_actualZoom);
168 |
169 | }
170 |
171 | ///
172 | /// Disabled input handling. Does not disable smoothing/etc, so the other functions will
173 | /// still work and the camera will even come to a smooth stop if you call this method while
174 | /// the user is dragging the camera
175 | ///
176 | public void DisableInput()
177 | {
178 | if (!(_input is FreeCamDisabledInput))
179 | _input = new FreeCamDisabledInput();
180 | }
181 |
182 | ///
183 | /// Enables input handling.
184 | ///
185 | public void EnableInput()
186 | {
187 | if (_input is FreeCamDisabledInput)
188 | InitializeFreeCamInput();
189 | }
190 |
191 | public bool IsInputEnabled()
192 | {
193 | return !(_input is FreeCamDisabledInput);
194 | }
195 |
196 | ///
197 | /// Snaps to position
198 | ///
199 | public void SetPosition(Vector3 pos)
200 | {
201 | _targetMovePosition = _actualMovePosition = pos;
202 | }
203 |
204 | ///
205 | /// Snaps to rotation
206 | ///
207 | public void SetRotation(Quaternion rot)
208 | {
209 | _targetLookEuler = _actualLookEuler = rot.eulerAngles;
210 | }
211 |
212 | ///
213 | /// Snaps to zoom
214 | ///
215 | public void SetZoom(float zoom)
216 | {
217 | _targetZoom = _actualZoom = zoom;
218 | }
219 |
220 | ///
221 | /// Smoothly moves to position
222 | ///
223 | public void SetSmoothPosition(Vector3 pos)
224 | {
225 | _targetMovePosition = pos;
226 | }
227 |
228 | ///
229 | /// Smoothly rotates to rotation
230 | ///
231 | public void SetSmoothRotation(Quaternion rot)
232 | {
233 | _targetLookEuler = rot.eulerAngles;
234 | }
235 |
236 | ///
237 | /// Smoothly zooms to zoom
238 | ///
239 | public void SetSmoothZoom(float zoom)
240 | {
241 | _targetZoom = zoom;
242 | }
243 |
244 | ///
245 | /// Conveniance method, see the other
246 | /// SetFocusToArea method. Uses bounds center
247 | /// as point and bounds extends magnitude as areaSize
248 | ///
249 | public void SetFocusToArea(Bounds b)
250 | {
251 | SetFocusToArea(b.center, b.extents.magnitude);
252 | }
253 |
254 | ///
255 | /// Centers the camera on 'point' and attempts to fit into view
256 | /// an area that is 'areaSize' units away from that point by zooming
257 | /// in or out as neccesary. The zoom is capped at MinZoom and MaxZoom
258 | /// so the area you specify is not garunteed to fall entirely within
259 | /// the cameras view.
260 | ///
261 | public void SetFocusToArea(Vector3 point, float areaSize)
262 | {
263 | _targetMovePosition = point;
264 |
265 | float requiredZoomOffset = 0;
266 | if (!ChildCamera.isOrthoGraphic)
267 | {
268 | Plane leftFrustumPlane = GeometryUtility.CalculateFrustumPlanes(ChildCamera)[0];
269 | Ray r = new Ray(transform.position + ChildCamera.transform.right * -(areaSize / 2f), ChildCamera.transform.forward);
270 |
271 | leftFrustumPlane.Raycast(r, out requiredZoomOffset);
272 | }
273 |
274 | _targetZoom = Mathf.Clamp(_targetZoom + requiredZoomOffset, MinZoom, MaxZoom);
275 | }
276 |
277 | public void SetSensitivity(float Sensitivity)
278 | {
279 | if (_currentMode != Mode || _input == null)
280 | InitializeFreeCamInput();
281 | _sensitivity = _input.Sensitivity = Sensitivity;
282 | }
283 |
284 | public static InputMode ResolveAutomaticInputMode()
285 | {
286 | if (Application.isEditor)
287 | {
288 | return InputMode.Mouse;
289 | }
290 | else
291 | {
292 | #if UNITY_ANDROID || UNITY_IPHONE
293 | return InputMode.Touch;
294 | #else
295 | return InputMode.Mouse;
296 | #endif
297 | }
298 | }
299 | }
--------------------------------------------------------------------------------
/Scripts/FreeCam.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e3426ddc38a0c15429eb6c6bb1670cf0
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Scripts/InputHandlers.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f7cf92228a5752b48b066099c0d93b70
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/Scripts/InputHandlers/FreeCamDisabledInput.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | public class FreeCamDisabledInput : FreeCamInput
4 | {
5 | public override Vector2 GetPrimaryDelta() { return Vector2.zero; }
6 |
7 | public override float GetZoomDelta() { return 0; }
8 |
9 | public override bool ShouldRotate() { return false; }
10 |
11 | public override bool ShouldDrag() { return false; }
12 |
13 | public override bool ShouldCenterOnTarget() { return false; }
14 |
15 | public override void Update() { }
16 | }
17 |
--------------------------------------------------------------------------------
/Scripts/InputHandlers/FreeCamDisabledInput.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 20e7a5975f95743449ce714991073e5d
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Scripts/InputHandlers/FreeCamInput.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | public abstract class FreeCamInput
4 | {
5 | public float Sensitivity = 1;
6 |
7 | public abstract Vector2 GetPrimaryDelta();
8 | public abstract float GetZoomDelta();
9 | public abstract bool ShouldRotate();
10 | public abstract bool ShouldDrag();
11 | public abstract bool ShouldCenterOnTarget();
12 |
13 | public abstract void Update();
14 | }
15 |
--------------------------------------------------------------------------------
/Scripts/InputHandlers/FreeCamInput.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 5a0cbbf90809d09438b0b83df3875fb2
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Scripts/InputHandlers/FreeCamMouseInput.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | public class FreeCamMouseInput : FreeCamInput
4 | {
5 | private Vector3 _mouseDelta;
6 | private Vector3 _lastMousePosition;
7 | private float _middleDownTime;
8 |
9 | private bool _caughtMouseButton1, _caughtMouseButton2;
10 |
11 |
12 | public override Vector2 GetPrimaryDelta()
13 | {
14 | return _mouseDelta * Sensitivity;
15 | }
16 |
17 | public override float GetZoomDelta()
18 | {
19 | return Input.mouseScrollDelta.y * Sensitivity;
20 | }
21 |
22 | public override bool ShouldRotate()
23 | {
24 | return _caughtMouseButton1 && !Input.GetMouseButtonDown(1) && Input.GetMouseButton(1);
25 | }
26 |
27 | public override bool ShouldDrag()
28 | {
29 | return _caughtMouseButton2 && !Input.GetMouseButtonDown(2) && Input.GetMouseButton(2);
30 | }
31 |
32 | public override bool ShouldCenterOnTarget()
33 | {
34 | return _caughtMouseButton2 && Input.GetMouseButtonUp(2) && (_middleDownTime < 0.125f);
35 | }
36 |
37 | public override void Update()
38 | {
39 | //If input becomes enabled while the user is dragging the mouse across the screen with MB1 clicked,
40 | //the camera would start rotating all of a sudden (since MB1 = true). The user should have to release the mouse and re-click
41 | //to start interacting with the camera. Thats where this bool comes in to play
42 | if (Input.GetMouseButtonDown(1))
43 | _caughtMouseButton1 = true;
44 | else if (!Input.GetMouseButton(1) && !Input.GetMouseButtonUp(1))
45 | _caughtMouseButton1 = false;
46 |
47 | if (Input.GetMouseButtonDown(2))
48 | _caughtMouseButton2 = true;
49 | else if (!Input.GetMouseButton(2) && !Input.GetMouseButtonUp(2))
50 | _caughtMouseButton2 = false;
51 |
52 | //Update mouse info
53 | _mouseDelta = _lastMousePosition - Input.mousePosition;
54 | _lastMousePosition = Input.mousePosition;
55 |
56 | if (Input.GetMouseButton(2))
57 | _middleDownTime += Time.deltaTime;
58 | if (Input.GetMouseButtonDown(2))
59 | _middleDownTime = 0;
60 |
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/Scripts/InputHandlers/FreeCamMouseInput.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e0a3c89e1daec804895da1e21bc8d66d
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Scripts/InputHandlers/FreeCamTouchInput.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | public class FreeCamTouchInput : FreeCamInput
4 | {
5 | private class TouchDetails
6 | {
7 | public bool HasValidTouch
8 | {
9 | get { return TouchID != -1; }
10 | }
11 |
12 | public int TouchID = -1;
13 | public Vector2 StartPosition;
14 | public Vector2 CurrentPosition;
15 | public Vector2 PrevPosition;
16 | public Vector2 Delta;
17 | public float DownTime;
18 | public bool WasDown, WasUp;
19 |
20 | public void SetTouch(Touch t)
21 | {
22 | TouchID = t.fingerId;
23 | StartPosition = CurrentPosition = PrevPosition = t.position;
24 | Delta = Vector3.zero;
25 | DownTime = 0;
26 | WasDown = true;
27 | }
28 |
29 | public void UpdateTouch(Touch t)
30 | {
31 | PrevPosition = CurrentPosition;
32 | CurrentPosition = t.position;
33 | Delta = t.deltaPosition;
34 | DownTime += Time.deltaTime;
35 | }
36 |
37 | public void RemoveTouch(Touch t)
38 | {
39 | TouchID = -1;
40 | WasUp = true;
41 | }
42 |
43 | public void ResetUpDown()
44 | {
45 | WasUp = WasDown = false;
46 | }
47 | }
48 |
49 | private TouchDetails
50 | _activeFinger = new TouchDetails(),
51 | _activeSecondFinger = new TouchDetails();
52 |
53 | private Vector3 _mouseDelta;
54 | private Vector3 _lastMousePosition;
55 | private float _timeSinceLastTouch;
56 |
57 | public override Vector2 GetPrimaryDelta()
58 | {
59 | //invert the delta, coz thats how mobile do
60 | return _activeFinger.HasValidTouch ? -_activeFinger.Delta * Sensitivity : Vector2.zero;
61 | }
62 |
63 | public override float GetZoomDelta()
64 | {
65 | //no zoom :(
66 | return 0 * Sensitivity;
67 | }
68 |
69 | public override bool ShouldRotate()
70 | {
71 | return _activeFinger.HasValidTouch && !_activeSecondFinger.HasValidTouch;
72 | }
73 |
74 | public override bool ShouldDrag()
75 | {
76 | return _activeFinger.HasValidTouch && _activeSecondFinger.HasValidTouch;
77 | }
78 |
79 | public override bool ShouldCenterOnTarget()
80 | {
81 | return (_timeSinceLastTouch < 0.25f) && (_activeFinger.DownTime < 0.125f) && _activeFinger.WasUp;
82 | }
83 |
84 | public override void Update()
85 | {
86 | //we reset the _timeSinceLastTouch here instead of bellow when the
87 | //finger actually gets released because it would be reseting too early at that point
88 | //we need to perform a whole update loop where _timeSinceLastTouch is still valid from the previous touch
89 | //and _activeFinger is still in 'WasUp' (released) mode. This is all so ShouldCenterOnTarget can work properly
90 | if (_activeFinger.WasUp)
91 | _timeSinceLastTouch = 0;
92 |
93 | _activeFinger.ResetUpDown();
94 | _activeSecondFinger.ResetUpDown();
95 | _timeSinceLastTouch += Time.deltaTime;
96 |
97 | foreach (var touch in Input.touches)
98 | {
99 | if (_activeFinger.TouchID == touch.fingerId)
100 | {
101 | _activeFinger.UpdateTouch(touch);
102 | }
103 | else if (_activeSecondFinger.TouchID == touch.fingerId)
104 | {
105 | _activeSecondFinger.UpdateTouch(touch);
106 | }
107 |
108 | if (_activeFinger.TouchID == touch.fingerId && touch.phase == TouchPhase.Ended)
109 | {
110 | _activeFinger.RemoveTouch(touch);
111 | }
112 | else if (_activeSecondFinger.TouchID == touch.fingerId && touch.phase == TouchPhase.Ended)
113 | {
114 | _activeSecondFinger.RemoveTouch(touch);
115 | }
116 |
117 | if (!_activeFinger.HasValidTouch && touch.phase == TouchPhase.Began)
118 | {
119 | _activeFinger.SetTouch(touch);
120 | }
121 | else if (!_activeSecondFinger.HasValidTouch && touch.phase == TouchPhase.Began)
122 | {
123 | _activeSecondFinger.SetTouch(touch);
124 | }
125 | }
126 | }
127 | }
--------------------------------------------------------------------------------
/Scripts/InputHandlers/FreeCamTouchInput.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: de065971c399f3041b24106c6e4d95ec
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/_Extra.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d69532178d12237449dee9e17382c539
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/_Extra/ExampleScene.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ec8b3f01cc77a24439a31064412b23b2
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/_Extra/ExampleScene/Scene.unity:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prodigga/UnityFreeCam/b3ca13042e0ab6cfb73ae0a8b9e12c2f32323597/_Extra/ExampleScene/Scene.unity
--------------------------------------------------------------------------------
/_Extra/ExampleScene/Scene.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 91cadce5c7cf25e40824568558b6b0b7
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/_Extra/Prefabs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: bcaf43cd588b2a3479d7f2f416124671
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/_Extra/Prefabs/FreeCamDefault.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/prodigga/UnityFreeCam/b3ca13042e0ab6cfb73ae0a8b9e12c2f32323597/_Extra/Prefabs/FreeCamDefault.prefab
--------------------------------------------------------------------------------
/_Extra/Prefabs/FreeCamDefault.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 99b4f5becf9b83e47be063933d8b3fc1
3 | NativeFormatImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/_Extra/Scripts.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: c29ecec7452d6954ab244fd8e88d2fa0
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/_Extra/Scripts/FreeCamInitPosRotZoom.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using System.Collections;
3 |
4 | [RequireComponent(typeof(FreeCam))]
5 | public class FreeCamInitPosRotZoom : MonoBehaviour
6 | {
7 | [Header("Initial Values")]
8 | public Vector3 Position;
9 | public Vector3 RotationEuler;
10 | public float Zoom;
11 | public float SensitivityMouse = 1;
12 | public float SensitivityTouch = 3;
13 |
14 | void Awake()
15 | {
16 | FreeCam fc = GetComponent();
17 | fc.SetPosition(Position);
18 | fc.SetRotation(Quaternion.Euler(RotationEuler));
19 | fc.SetZoom(Zoom);
20 |
21 | FreeCam.InputMode IM = fc.Mode;
22 | if(fc.Mode == FreeCam.InputMode.Automatic)
23 | IM = FreeCam.ResolveAutomaticInputMode();
24 |
25 | fc.SetSensitivity(IM == FreeCam.InputMode.Mouse ? SensitivityMouse : SensitivityTouch);
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/_Extra/Scripts/FreeCamInitPosRotZoom.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: d23c29a3b83847e49bbf0cffa5e41a2e
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------