using System.Collections.Generic; using System.Runtime.CompilerServices; using UnityEngine; // Shapes © Freya Holmér - https://twitter.com/FreyaHolmer/ // Website & Documentation - https://acegikmo.com/shapes/ namespace Shapes { public class PointPath : DisposableMesh { protected List path = new List(); public int Count => path.Count; public T LastPoint => path[path.Count - 1]; protected void OnSetFirstDataPoint() { hasData = true; meshDirty = true; } public void ClearAllPoints() { path.Clear(); hasData = false; } public T this[ int i ] { get => path[i]; set { path[i] = value; meshDirty = true; } } public void SetPoint( int index, T point ) { path[index] = point; meshDirty = true; } public void AddPoint( T p ) { if( hasData == false ) OnSetFirstDataPoint(); path.Add( p ); hasData = true; meshDirty = true; } public void AddPoints( params T[] pts ) => AddPoints( (IEnumerable)pts ); public void AddPoints( IEnumerable ptsToAdd ) { int prevCount = path.Count; path.AddRange( ptsToAdd ); int pathCount = path.Count; int addedPtCount = pathCount - prevCount; if( addedPtCount > 0 ) { if( hasData == false ) OnSetFirstDataPoint(); hasData = true; meshDirty = true; } } protected bool CheckCanAddContinuePoint( [CallerMemberName] string callerName = null ) { if( hasData == false ) { Debug.LogWarning( $"{callerName} requires adding a point before calling it, to determine starting point" ); return true; } return false; } } }