using System; using System.Collections; using System.Collections.Generic; using UnityEngine; [Serializable] public class ToolEraser { [HideInInspector] public Vector3 cursorPos; [HideInInspector] public List selected = new List(); public void Reset() { // for resetting the tool (when swapping around, initializing, etc) selected.Clear(); } public void Frame(Input input, Pixelgon pixelgon) { Vector3 rawCursorPos = cursorPos = input.dragCursor; if (input.mainCon.trigger.held) { selected.Clear(); int length = 0; for (int i = 0; i < pixelgon.vectors.Count; i++) { if (pixelgon.vectors[i] == Vector3.zero) { length = 0; } else { if (length > 0) { Vector3 edgeSnapPos = StaticMethods.EdgeSnap(pixelgon.vectors[i - 1], pixelgon.vectors[i], rawCursorPos); if (Vector3.Distance(rawCursorPos, edgeSnapPos) < 0.015f) { cursorPos = edgeSnapPos; if (cursorPos == pixelgon.vectors[i - 1]) { selected.Add(i - 1); break; } if (cursorPos == pixelgon.vectors[i]) { selected.Add(i); break; } selected.Add(i - 1); selected.Add(i); break; } } length++; } } } if (selected.Count > 0 && input.mainCon.one.down) { if (selected.Count == 1) { pixelgon.vectors.RemoveAt(selected[0]); } else { pixelgon.vectors.Insert(selected[1], Vector3.zero); } pixelgon.vectors = StaticMethods.DeleteLoose(pixelgon.vectors); Reset(); } } }