Created
August 15, 2019 10:02
-
-
Save nicloay/28e861cf3b3d88f283df7c5ac7f0c1c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace PaintCraft.Controllers{ | |
[RequireComponent(typeof(Camera))] | |
public class ScreenCameraController : InputController, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler { | |
... | |
void Update() | |
{ | |
UpdateDragIfNeeded(); | |
... | |
} | |
... | |
HashSet<PointerEventData> _activeDragIds = new HashSet<PointerEventData>(); | |
public void OnPointerDown(PointerEventData eventData) | |
{ | |
var worldPosition = eventData.pointerCurrentRaycast.worldPosition; | |
if (!Canvas.IsWithinInputRect(worldPosition)) | |
{ | |
return; | |
} | |
_activeDragIds.Add(eventData); | |
BeginLine(LineConfig, eventData.pointerId, worldPosition, true); | |
eventData.selectedObject = gameObject; | |
eventData.Use(); | |
_deactivateRaycasterOnDrawing.ForEach(raycaster => raycaster.enabled = false); | |
Debug.Log("FrameNumber[down] = "+Time.frameCount); | |
} | |
public void OnPointerUp(PointerEventData eventData) | |
{ | |
EndLine(eventData.pointerId, eventData.pointerCurrentRaycast.worldPosition); | |
eventData.selectedObject = null; | |
eventData.Use(); | |
_deactivateRaycasterOnDrawing.ForEach(raycaster => raycaster.enabled = true); | |
_activeDragIds.Remove(eventData); | |
Debug.Log("FrameNumber[up] = "+Time.frameCount); | |
} | |
private void UpdateDragIfNeeded() | |
{ | |
foreach (var eventData in _activeDragIds) | |
{ | |
if (!eventData.used) | |
{ | |
Debug.Log("FrameNumber[update] = "+Time.frameCount); | |
ContinueLine(eventData.pointerId, eventData.pointerCurrentRaycast.worldPosition); | |
} | |
} | |
} | |
public void OnPointerClick(PointerEventData eventData) | |
{ | |
if (eventData.used || eventData.selectedObject != null) | |
{ | |
return; | |
} | |
var worldPosition = eventData.pointerCurrentRaycast.worldPosition; | |
if (!Canvas.IsWithinInputRect(worldPosition)) | |
{ | |
return; | |
} | |
MakeSingleDot(LineConfig, eventData.pointerId, worldPosition, true); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment