Skip to content

Commit

Permalink
made some fields and methods extendable, added property to set world …
Browse files Browse the repository at this point in the history
…plane.
  • Loading branch information
TomSimons committed Apr 16, 2024
1 parent 0ae6a6f commit 6b6c81b
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions Runtime/Scripts/SelectionTools/PolygonInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public enum DrawMode
[SerializeField] private DrawMode mode = DrawMode.CreateAndEdit;
public DrawMode Mode => mode;

private InputAction pointerAction;
private InputAction tapAction;
private InputAction escapeAction;
private InputAction finishAction;
private InputAction tapSecondaryAction;
private InputAction clickAction;
private InputAction modifierAction;
protected InputAction pointerAction;
protected InputAction tapAction;
protected InputAction escapeAction;
protected InputAction finishAction;
protected InputAction tapSecondaryAction;
protected InputAction clickAction;
protected InputAction modifierAction;

[SerializeField] private LineRenderer polygonLineRenderer;
[SerializeField] private LineRenderer previewLineRenderer;
Expand All @@ -91,6 +91,12 @@ public enum DrawMode
protected Vector3 lastNormal = Vector3.zero;
protected Plane worldPlane;

public Plane WorldPlane
{
get => worldPlane;
set => worldPlane = value;
}

private bool closedLoop = false;
private bool snappingToStartPoint = false;
private bool polygonFinished = false;
Expand All @@ -111,12 +117,14 @@ public enum DrawMode
[Header("Invoke")]
public UnityEvent<bool> blockCameraDrag;
public UnityEvent<List<Vector3>> createdNewPolygonArea;

[Header("Optional Invoke")]
public UnityEvent<List<Vector3>> editedPolygonArea;

[Tooltip("Contains the list of points the line is made of")] public UnityEvent<List<Vector3>> previewLineHasChanged;
[Tooltip("Contains the list of points the line is made of")]
public UnityEvent<List<Vector3>> previewLineHasChanged;

void Awake()
protected virtual void Awake()
{
mainCamera = Camera.main;
polygonLineRenderer.startColor = polygonLineRenderer.endColor = lineColor;
Expand Down Expand Up @@ -274,7 +282,7 @@ private void DetermineIfShouldAutoDraw()

return;
}

//if mode is not edit mode, we check if we are not auto drawing, but we are clicking and the auto draw modifier is pressed
if (!autoDrawPolygon && clickAction.IsPressed() && modifierAction.IsPressed())
{
Expand Down Expand Up @@ -379,8 +387,8 @@ private void CloseLoop(bool isNewPolygon, bool checkPreviewLine = true)
{
if (closedLoop)
return;
if (positions.Count == minPointsToCloseLoop -1) // add an extra point at the current mouse position to attempt to create a valid shape

if (positions.Count == minPointsToCloseLoop - 1) // add an extra point at the current mouse position to attempt to create a valid shape
{
Tap();
}
Expand Down Expand Up @@ -421,7 +429,7 @@ private void CloseLoop(bool isNewPolygon, bool checkPreviewLine = true)
positions.Add(closingLineEnd);
}
}

closedLoop = true;
}

Expand Down

0 comments on commit 6b6c81b

Please sign in to comment.