-
Notifications
You must be signed in to change notification settings - Fork 225
Updated manual synchornization example scene #636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
ffecaf8
d7bfb5b
62542da
e0d5008
4abc9e9
c9fa5a2
46708ca
c268409
bcf09d4
c1afe31
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| namespace Mapbox.Examples | ||
| { | ||
| // Just add this script to your camera. It doesn't need any configuration. | ||
|
|
||
| using UnityEngine; | ||
| using Mapbox.Unity.Location; | ||
|
|
||
| public class ManualTouchCamera : MonoBehaviour | ||
| { | ||
| [SerializeField] | ||
| Camera _camera; | ||
|
|
||
| [SerializeField] | ||
| Transform _mapRoot; | ||
|
|
||
| [SerializeField] | ||
| Transform _mapHolder; | ||
|
|
||
| float speed = 1f; | ||
|
|
||
| Vector2?[] _oldTouchPositions = { null, null }; | ||
|
|
||
| Vector2 _oldTouchVector; | ||
| Vector3 _delta; | ||
| float _oldTouchDistance; | ||
| Vector3 _origin; | ||
|
|
||
| bool _wasTouching; | ||
|
|
||
| bool _shouldDrag; | ||
|
|
||
| void Update() | ||
| { | ||
|
|
||
| if (Input.touchCount == 0) | ||
| { | ||
| _oldTouchPositions[0] = null; | ||
| _oldTouchPositions[1] = null; | ||
| _shouldDrag = false; | ||
|
|
||
| } | ||
| else if (Input.touchCount == 1) | ||
| { | ||
| if (_oldTouchPositions[0] == null || _oldTouchPositions[1] != null) | ||
| { | ||
| _oldTouchPositions[0] = Input.GetTouch(0).position; | ||
| _oldTouchPositions[1] = null; | ||
| } | ||
|
|
||
| if (Input.GetTouch(0).phase == TouchPhase.Began) | ||
| { | ||
| _origin = Input.GetTouch(0).position; | ||
| } | ||
|
|
||
| if (Input.GetTouch(0).phase == TouchPhase.Moved) | ||
| { | ||
| var touchDelta = Input.GetTouch(0).deltaPosition; | ||
| var offset = new Vector3(touchDelta.x, 0f, touchDelta.y); | ||
| offset = _camera.transform.rotation * offset; | ||
| var newPos = new Vector3(offset.x, 0, offset.y); | ||
| _mapRoot.position = newPos + _mapRoot.position; | ||
| } | ||
| } | ||
| else | ||
| { | ||
| if (_oldTouchPositions[1] == null) | ||
| { | ||
| _oldTouchPositions[0] = Input.GetTouch(0).position; | ||
| _oldTouchPositions[1] = Input.GetTouch(1).position; | ||
| _oldTouchVector = (Vector2)(_oldTouchPositions[0] - _oldTouchPositions[1]); | ||
| _oldTouchDistance = _oldTouchVector.magnitude; | ||
| } | ||
| else | ||
| { | ||
| //Vector2 screen = new Vector2(_camera.pixelWidth, _camera.pixelHeight); | ||
| Vector2[] newTouchPositions = { Input.GetTouch(0).position, Input.GetTouch(1).position }; | ||
| Vector2 newTouchVector = newTouchPositions[0] - newTouchPositions[1]; | ||
| float newTouchDistance = newTouchVector.magnitude; | ||
| _mapHolder.rotation *= Quaternion.Euler(new Vector3(0, Mathf.Asin(Mathf.Clamp((_oldTouchVector.y * newTouchVector.x - _oldTouchVector.x * newTouchVector.y) / _oldTouchDistance / newTouchDistance, -1f, 1f)) / 0.0174532924f, 0)); | ||
| _oldTouchPositions[0] = newTouchPositions[0]; | ||
| _oldTouchPositions[1] = newTouchPositions[1]; | ||
| _oldTouchVector = newTouchVector; | ||
| _oldTouchDistance = newTouchDistance; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| public class FollowTargetTransform : MonoBehaviour | ||
| { | ||
| [SerializeField] | ||
| Transform _targetTransform; | ||
|
|
||
| void Update() | ||
| { | ||
| transform.position = new Vector3(_targetTransform.position.x, transform.position.y, _targetTransform.position.z); | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| using System.Collections; | ||
|
||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| using Mapbox.Unity.Location; | ||
| using Mapbox.Unity.Map; | ||
| using UnityEngine.UI; | ||
|
|
||
| public class RelocateMapByGPS : MonoBehaviour | ||
| { | ||
|
|
||
| [SerializeField] | ||
| AbstractMap _map; | ||
|
|
||
| [SerializeField] | ||
| Button _button; | ||
|
|
||
| private void Start() | ||
| { | ||
| _button.onClick.AddListener(UpdateMapLocation); | ||
| } | ||
|
|
||
| public void UpdateMapLocation() | ||
| { | ||
| var location = LocationProviderFactory.Instance.DefaultLocationProvider.CurrentLocation; | ||
| _map.SetCenterLatitudeLongitude(location.LatitudeLongitude); | ||
| _map.GetComponent<Transform>().position = Camera.main.transform.position; | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| using System.Collections; | ||
|
||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
|
|
||
| public class RotateOnYTargetTransform : MonoBehaviour | ||
| { | ||
| [SerializeField] | ||
| Transform _targetTransform; | ||
|
|
||
| void Update() | ||
| { | ||
| transform.eulerAngles = new Vector3(transform.eulerAngles.x, _targetTransform.eulerAngles.y, transform.eulerAngles.z); | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| using System.Collections; | ||
|
||
| using System.Collections.Generic; | ||
| using UnityEngine; | ||
| using UnityARInterface; | ||
|
|
||
| public class UpdateMapPosByARPlaneY : MonoBehaviour | ||
| { | ||
| [SerializeField] | ||
| Transform _mapRoot; | ||
|
|
||
|
|
||
| void Start() | ||
| { | ||
| ARInterface.planeAdded += UpdateMapPosOnY; | ||
| ARInterface.planeUpdated += UpdateMapPosOnY; | ||
| } | ||
|
|
||
| void UpdateMapPosOnY(BoundedPlane plane) | ||
| { | ||
| var pos = _mapRoot.position; | ||
| _mapRoot.position = new Vector3(pos.x, plane.center.y, pos.z); | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ PlayerSettings: | |
| useOnDemandResources: 0 | ||
| accelerometerFrequency: 60 | ||
| companyName: Mapbox | ||
| productName: MBX SDK | ||
| productName: manual | ||
| defaultCursor: {fileID: 0} | ||
| cursorHotspot: {x: 0, y: 0} | ||
| m_SplashScreenBackgroundColor: {r: 0.13725491, g: 0.12156863, b: 0.1254902, a: 1} | ||
|
|
@@ -161,7 +161,7 @@ PlayerSettings: | |
| Android: com.mapbox.unitysdk | ||
| Standalone: unity.Mapbox.MBX SDK | ||
| Tizen: com.mapbox.unitysdk | ||
| iOS: com.mapbox.MBX-SDK | ||
| iOS: com.mapbox.manual | ||
|
||
| tvOS: com.mapbox.unitysdk | ||
| buildNumber: | ||
| iOS: 1 | ||
|
|
@@ -210,7 +210,6 @@ PlayerSettings: | |
| tvOSSmallIconLayers: [] | ||
| tvOSSmallIconLayers2x: [] | ||
| tvOSLargeIconLayers: [] | ||
| tvOSLargeIconLayers2x: [] | ||
| tvOSTopShelfImageLayers: [] | ||
| tvOSTopShelfImageLayers2x: [] | ||
| tvOSTopShelfImageWideLayers: [] | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add namespace