Fix MapInteractionHandler script. Explicitly unregister and deregister InputSystem handlers.
This commit is contained in:
Родитель
eee9ea67c4
Коммит
e374f60123
|
@ -41,52 +41,16 @@ public class MapInteractionHandler : MonoBehaviour, IMixedRealityPointerHandler,
|
|||
_mapRenderer = GetComponent<MapRenderer>();
|
||||
}
|
||||
|
||||
public void OnPointerClicked(MixedRealityPointerEventData eventData)
|
||||
private void OnEnable()
|
||||
{
|
||||
}
|
||||
|
||||
public void OnPointerDown(MixedRealityPointerEventData eventData)
|
||||
{
|
||||
if (CoreServices.InputSystem.FocusProvider.TryGetFocusDetails(eventData.Pointer, out FocusDetails focusDetails) &&
|
||||
focusDetails.Object == gameObject)
|
||||
if (CoreServices.InputSystem != null)
|
||||
{
|
||||
_panningPointer = eventData.Pointer;
|
||||
_startingPointInLocalSpace = focusDetails.PointLocalSpace;
|
||||
_startingPointInMercatorSpace =
|
||||
_mapRenderer.TransformLocalPointToMercatorWithAltitude(
|
||||
_startingPointInLocalSpace,
|
||||
out _startingAltitudeInMeters,
|
||||
out _startingMercatorScale);
|
||||
_currentPointInLocalSpace = _startingPointInLocalSpace;
|
||||
_startingMapCenterInMercator = _mapRenderer.Center.ToMercatorPosition();
|
||||
|
||||
eventData.Use();
|
||||
CoreServices.InputSystem.RegisterHandler<IMixedRealityInputHandler<Vector2>>(this);
|
||||
CoreServices.InputSystem.RegisterHandler<IMixedRealityPointerHandler>(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerDragged(MixedRealityPointerEventData eventData)
|
||||
{
|
||||
if (_panningPointer == eventData.Pointer)
|
||||
{
|
||||
eventData.Use();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerUp(MixedRealityPointerEventData eventData)
|
||||
{
|
||||
_panningPointer = null;
|
||||
}
|
||||
|
||||
public void OnInputChanged(InputEventData<Vector2> eventData)
|
||||
{
|
||||
if (eventData.MixedRealityInputAction.Description == "Zoom Map")
|
||||
{
|
||||
_currentZoomValue = eventData.InputData;
|
||||
eventData.Use();
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
var isInteractingWithMap = _panningPointer != null;
|
||||
if (isInteractingWithMap &&
|
||||
|
@ -170,6 +134,60 @@ public class MapInteractionHandler : MonoBehaviour, IMixedRealityPointerHandler,
|
|||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (CoreServices.InputSystem != null)
|
||||
{
|
||||
CoreServices.InputSystem.UnregisterHandler<IMixedRealityInputHandler<Vector2>>(this);
|
||||
CoreServices.InputSystem.UnregisterHandler<IMixedRealityPointerHandler>(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClicked(MixedRealityPointerEventData eventData)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnPointerDown(MixedRealityPointerEventData eventData)
|
||||
{
|
||||
if (CoreServices.InputSystem.FocusProvider.TryGetFocusDetails(eventData.Pointer, out FocusDetails focusDetails) &&
|
||||
focusDetails.Object == gameObject)
|
||||
{
|
||||
_panningPointer = eventData.Pointer;
|
||||
_startingPointInLocalSpace = focusDetails.PointLocalSpace;
|
||||
_startingPointInMercatorSpace =
|
||||
_mapRenderer.TransformLocalPointToMercatorWithAltitude(
|
||||
_startingPointInLocalSpace,
|
||||
out _startingAltitudeInMeters,
|
||||
out _startingMercatorScale);
|
||||
_currentPointInLocalSpace = _startingPointInLocalSpace;
|
||||
_startingMapCenterInMercator = _mapRenderer.Center.ToMercatorPosition();
|
||||
|
||||
eventData.Use();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerDragged(MixedRealityPointerEventData eventData)
|
||||
{
|
||||
if (_panningPointer == eventData.Pointer)
|
||||
{
|
||||
eventData.Use();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerUp(MixedRealityPointerEventData eventData)
|
||||
{
|
||||
_panningPointer = null;
|
||||
}
|
||||
|
||||
public void OnInputChanged(InputEventData<Vector2> eventData)
|
||||
{
|
||||
if (eventData.MixedRealityInputAction.Description == "Zoom Map")
|
||||
{
|
||||
_currentZoomValue = eventData.InputData;
|
||||
eventData.Use();
|
||||
}
|
||||
}
|
||||
|
||||
private static Vector3 DynamicExpDecay(Vector3 from, Vector3 to, float halfLife)
|
||||
{
|
||||
return Vector3.Lerp(from, to, DynamicExpCoefficient(halfLife, Vector3.Distance(to, from)));
|
||||
|
|
Загрузка…
Ссылка в новой задаче