Hi, I tried your APK but still not working with my device (SS Galaxy S8) . I have no idea why. I can just zoom in/out and tilt. No long press event shown up.
Anyway,
I tried to dbug and added many comments into codes and suddenly found another weired unity's behaviour. I added debug messages along OnMapBasePress() also in WaitLongPress() coroutine. I found the coroutine just stuck at before the line
yield return watiforsecond (longpressDelay); No thing printed after that line.
Then, I tried to fix without any clues, so I went to OnMapBaseRelease() and just add two debug messages. Then I have no idea why it work now.
Please trust me about what I said. I have stucked at this issue for 3 days before it gets fixed with big doubt.
protected virtual void OnMapBasePress()
{
isMapPress = false;
Debug.Log("ismapPress=false"); //--------------------> added here
if (waitZeroTouches)
{
if (GetTouchCount() <= 1) waitZeroTouches = false;
else return;
}
Debug.Log("Waitzerotouches"); //--------------------> added here
dragMarker = null;
Vector2 inputPosition = GetInputPosition();
Debug.Log("get position"); //--------------------> added here
if (!HitTest(inputPosition)) return;
Debug.Log("hit test!!!"); //--------------------> added here
if (IsCursorOnUIElement(inputPosition)) return;
Debug.Log("cursor on UI Element");
if (OnMapPress != null) OnMapPress();
Debug.Log("Map pressed"); //--------------------> added here
lastClickTimes[0] = lastClickTimes[1];
lastClickTimes[1] = Time.realtimeSinceStartup;
double tx, ty;
lastInputPosition = pressPoint = inputPosition;
if (!GetTile(inputPosition, out tx, out ty)) return;
Debug.Log("can't get tile"); //--------------------> added here
isMapPress = true;
OnlineMapsMarkerBase marker = null;
OnlineMapsDrawingElement drawingElement = null;
IOnlineMapsInteractiveElement interactiveElement = GetInteractiveElement(inputPosition);
if (interactiveElement != null)
{
if (interactiveElement is OnlineMapsMarkerBase) marker = interactiveElement as OnlineMapsMarkerBase;
else if (interactiveElement is OnlineMapsDrawingElement) drawingElement = interactiveElement as OnlineMapsDrawingElement;
}
if (marker != null)
{
if (marker.OnPress != null) marker.OnPress(marker);
if (map.showMarkerTooltip == OnlineMapsShowMarkerTooltip.onPress)
{
OnlineMapsTooltipDrawerBase.tooltipMarker = marker;
OnlineMapsTooltipDrawerBase.tooltip = marker.label;
}
if (Input.GetKey(KeyCode.LeftControl)) dragMarker = marker;
}
else if (drawingElement != null)
{
if (drawingElement.OnPress != null) drawingElement.OnPress(drawingElement);
if (map.showMarkerTooltip == OnlineMapsShowMarkerTooltip.onPress)
{
OnlineMapsTooltipDrawerBase.tooltipDrawingElement = drawingElement;
OnlineMapsTooltipDrawerBase.tooltip = drawingElement.tooltip;
}
}
if (dragMarker == null) isMapDrag = true;
activeElement = interactiveElement;
Debug.Log("wait long pressed"); //--------------------> added here
if (longPressEnumerator == null)
{
longPressEnumerator = WaitLongPress();
StartCoroutine(longPressEnumerator);
}
if (allowUserControl) OnlineMaps.isUserControl = true;
}
===================================================
private IEnumerator WaitLongPress()
{
Debug.Log("wait long pressed..."+longPressDelay); //--------------------> added here
//yield return new WaitForSeconds(longPressDelay);
float t = 0;
while (t < longPressDelay)
{
yield return null;
t += Time.deltaTime;
}
OnlineMapsMarkerBase marker = null;
OnlineMapsDrawingElement drawingElement = null;
Vector2 inputPosition = GetInputPosition();
Debug.Log("inputPosition" ); //--------------------> added here
IOnlineMapsInteractiveElement interactiveElement = GetInteractiveElement(inputPosition);
Debug.Log("interactiveElement");
if (interactiveElement != null)
{
if (interactiveElement is OnlineMapsMarkerBase) marker = interactiveElement as OnlineMapsMarkerBase;
else if (interactiveElement is OnlineMapsDrawingElement) drawingElement = interactiveElement as OnlineMapsDrawingElement;
}
Debug.Log("marker");
if (marker != null && marker.OnLongPress != null) { marker.OnLongPress(marker); Debug.Log("marker longpress"); }
else if (drawingElement != null && drawingElement.OnLongPress != null) { drawingElement.OnLongPress(drawingElement); Debug.Log("drawing element"); }
else if (OnMapLongPress != null)
{
Debug.Log("finally long pressed");//--------------------> added here
OnMapLongPress();
isMapDrag = false;
}
Debug.Log("wait long pressed end");//--------------------> added here
longPressEnumerator = null;
}
===================================================
protected virtual void OnMapBaseRelease()
{
Debug.Log("Release"); //=> I added here then the problem solved........???!!!!!******
if (waitZeroTouches && GetTouchCount() == 0) waitZeroTouches = false;
if (GUIUtility.hotControl != 0) return;
Vector2 inputPosition = GetInputPosition();
bool isClick = (pressPoint - inputPosition).sqrMagnitude < 400 && !lockClick;
lockClick = false;
isMapDrag = false;
mapDragStarted = false;
dragMarker = null;
if (longPressEnumerator != null)
{
StopCoroutine(longPressEnumerator);
longPressEnumerator = null;
Debug.Log("stop coroutine"); //=> I added here then the problem solved........???!!!!!******
}
lastInputPosition = Vector2.zero;
OnlineMaps.isUserControl = false;
if (!isMapPress) return;
isMapPress = false;
if (OnMapRelease != null) OnMapRelease();
OnlineMapsMarkerBase marker = null;
OnlineMapsDrawingElement drawingElement = null;
IOnlineMapsInteractiveElement interactiveElement = GetInteractiveElement(inputPosition);
if (interactiveElement != null)
{
if (interactiveElement is OnlineMapsMarkerBase) marker = interactiveElement as OnlineMapsMarkerBase;
else if (interactiveElement is OnlineMapsDrawingElement) drawingElement = interactiveElement as OnlineMapsDrawingElement;
}
if (map.showMarkerTooltip == OnlineMapsShowMarkerTooltip.onPress && (OnlineMapsTooltipDrawerBase.tooltipMarker != null || OnlineMapsTooltipDrawerBase.tooltipDrawingElement != null))
{
OnlineMapsTooltipDrawerBase.tooltipMarker = null;
OnlineMapsTooltipDrawerBase.tooltipDrawingElement = null;
OnlineMapsTooltipDrawerBase.tooltip = null;
}
bool isClicked = false;
if (marker != null)
{
if (marker.OnRelease != null) marker.OnRelease(marker);
if (isClick && marker.OnClick != null)
{
marker.OnClick(marker);
isClicked = true;
}
}
else if (drawingElement != null)
{
if (drawingElement.OnRelease != null) drawingElement.OnRelease(drawingElement);
}
if (activeElement != null && activeElement != interactiveElement)
{
if (activeElement is OnlineMapsMarkerBase)
{
OnlineMapsMarkerBase m = activeElement as OnlineMapsMarkerBase;
if (m.OnRelease != null) m.OnRelease(m);
}
else if (activeElement is OnlineMapsDrawingElement)
{
OnlineMapsDrawingElement d = activeElement as OnlineMapsDrawingElement;
if (d.OnRelease != null) d.OnRelease(d);
}
activeElement = null;
}
if (isClick && Time.realtimeSinceStartup - lastClickTimes[0] < 0.5f)
{
if (marker != null && marker.OnDoubleClick != null) marker.OnDoubleClick(marker);
else if (drawingElement != null && drawingElement.OnDoubleClick != null) drawingElement.OnDoubleClick(drawingElement);
else
{
if (OnMapDoubleClick != null) OnMapDoubleClick();
if (allowZoom && zoomInOnDoubleClick)
{
if (!((marker != null && marker.OnClick != null) || (drawingElement != null && drawingElement.OnClick != null)))
{
if (OnValidateZoom == null || OnValidateZoom(OnlineMapsZoomEvent.doubleClick, map.floatZoom + 1))
{
if (zoomMode == OnlineMapsZoomMode.target) ZoomOnPoint(1, inputPosition);
else map.floatZoom += 1;
}
}
}
}
lastClickTimes[0] = 0;
lastClickTimes[1] = 0;
}
else if (isClick && !isClicked)
{
if (drawingElement != null && drawingElement.OnClick != null) drawingElement.OnClick(drawingElement);
else if (OnMapClick != null) OnMapClick();
}
if (map.bufferStatus == OnlineMapsBufferStatus.wait) map.needRedraw = true;
}