void OnDrawGizmos()//Selected() { IntegerRect bounds = this.Bounds; Gizmos.color = Color.red; Gizmos.DrawWireSphere(new Vector3(bounds.Center.X, bounds.Center.Y), this.Radius); }
public List <IntegerCollider> GetPotentialCollisions(float vx, float vy, int offsetX = 0, int offsetY = 0, int mask = Physics2D.DefaultRaycastLayers) { IntegerRect bounds = this.Bounds; IntegerRect range = new IntegerRect(bounds.Center.X + offsetX, bounds.Center.Y + offsetY, this.Bounds.Size.X + Mathf.RoundToInt(Mathf.Abs(vx * 2) + 1.55f), this.Bounds.Size.Y + (Mathf.RoundToInt(Mathf.Abs(vy * 2) + 1.55f))); return(this.CollisionManager.GetCollidersInRange(range, mask)); }
public List<IntegerCollider> GetCollidersInRange(IntegerRect range, int mask = Physics2D.DefaultRaycastLayers, string objectTag = null) { List<IntegerCollider> colliders = new List<IntegerCollider>(); foreach (LayerMask key in _collidersByLayer.Keys) { if ((key & mask) != 0) { foreach (IntegerCollider collider in _collidersByLayer[key]) { if ((objectTag == null || collider.tag == objectTag) && collider.enabled && collider.Bounds.Overlaps(range)) colliders.Add(collider); } } } if ((mask & this.SolidsLayerMask) != 0) { for (int x = xPositionToSolidsIndex(range.Min.X - this.MaxSolidSize); x <= xPositionToSolidsIndex(range.Max.X + this.MaxSolidSize); ++x) { for (int y = yPositionToSolidsIndex(range.Min.Y - this.MaxSolidSize); y <= yPositionToSolidsIndex(range.Max.Y + this.MaxSolidSize); ++y) { if (_solids[x, y] != null) colliders.AddRange(_solids[x, y]); } } } return colliders; }
void OnDrawGizmosSelected() { IntegerRect bounds = this.Bounds; Gizmos.color = Color.red; Gizmos.DrawWireCube(new Vector3(bounds.Center.X, bounds.Center.Y), new Vector3(this.Size.X, this.Size.Y)); }
public List <IntegerCollider> GetCollidersInRange(IntegerRect range, int mask = Physics2D.DefaultRaycastLayers, string objectTag = null) { List <IntegerCollider> colliders = new List <IntegerCollider>(); foreach (LayerMask key in _collidersByLayer.Keys) { if ((key & mask) != 0) { foreach (IntegerCollider collider in _collidersByLayer[key]) { if ((objectTag == null || collider.tag == objectTag) && collider.Bounds.Overlaps(range)) { colliders.Add(collider); } } } } if ((mask & this.SolidsLayerMask) != 0) { for (int x = xPositionToSolidsIndex(range.Min.X - this.MaxColliderSize); x <= xPositionToSolidsIndex(range.Max.X + this.MaxColliderSize); ++x) { for (int y = yPositionToSolidsIndex(range.Min.Y - this.MaxColliderSize); y <= yPositionToSolidsIndex(range.Max.Y + this.MaxColliderSize); ++y) { if (_solids[x, y] != null) { colliders.AddRange(_solids[x, y]); } } } } return(colliders); }
public static IntegerRect CreateFromMinMax(IntegerVector min, IntegerVector max) { IntegerRect rect = new IntegerRect(); rect.Center = (min + max) / 2; rect.Size = max - min; return(rect); }
public virtual bool Contains(IntegerVector point, int offsetX = 0, int offsetY = 0) { IntegerRect bounds = this.Bounds; bounds.Center.X += offsetX; bounds.Center.Y += offsetY; return(bounds.Contains(point)); }
//TODO - use dynamic keyword to make use of run-time overloading? and have an extensions method place for inter-collider type collisions? //http://stackoverflow.com/questions/13095544/overloaded-method-why-is-base-class-given-precedence#comment25529590_13096565 public virtual bool Overlaps(IntegerCollider other, int offsetX = 0, int offsetY = 0) { IntegerRect bounds = this.Bounds; bounds.Center.X += offsetX; bounds.Center.Y += offsetY; return(bounds.Overlaps(other.Bounds)); }
void OnDrawGizmosSelected() { if (this.enabled) { IntegerRect bounds = this.Bounds; Gizmos.color = this.DebugColor; Gizmos.DrawLine((Vector2)bounds.Min, (Vector2)bounds.Max); } }
void OnDrawGizmos()//Selected() { if (this.enabled) { IntegerRect bounds = this.Bounds; Gizmos.color = this.DebugColor; Gizmos.DrawWireSphere(new Vector3(bounds.Center.X, bounds.Center.Y), this.Radius); } }
void OnDrawGizmosSelected() { if (this.enabled) { IntegerRect bounds = this.Bounds; Gizmos.color = this.DebugColor; Gizmos.DrawWireCube(new Vector3(bounds.Center.X, bounds.Center.Y), new Vector3(this.Size.X, this.Size.Y)); } }
public List <IntegerCollider> GetCollidersInRange(IntegerRect range, int mask = Physics2D.DefaultRaycastLayers, string objectTag = null, List <IntegerCollider> _listRef = null) { List <IntegerCollider> colliders; if (_listRef != null) { _listRef.Clear(); colliders = _listRef; } else { colliders = new List <IntegerCollider>(); } foreach (LayerMask key in _collidersByLayer.Keys) { if ((key & mask) != 0) { List <IntegerCollider> collidersInLayer = _collidersByLayer[key]; for (int i = 0; i < collidersInLayer.Count; ++i) { IntegerCollider collider = collidersInLayer[i]; if (collider == null) { Debug.LogWarning("Null collider!! key = " + LayerMask.LayerToName(Mathf.RoundToInt(Mathf.Sqrt(key)))); } else { if ((objectTag == null || collider.tag == objectTag) && collider.enabled && collider.Bounds.Overlaps(range)) { colliders.Add(collider); } } } } } if ((mask & this.SolidsLayerMask) != 0) { for (int x = xPositionToSolidsIndex(range.Min.X - this.MaxSolidSize); x <= xPositionToSolidsIndex(range.Max.X + this.MaxSolidSize); ++x) { for (int y = yPositionToSolidsIndex(range.Min.Y - this.MaxSolidSize); y <= yPositionToSolidsIndex(range.Max.Y + this.MaxSolidSize); ++y) { if (_solids[x, y] != null) { colliders.AddRange(_solids[x, y]); } } } } return(colliders); }
public bool Overlaps(IntegerRect other) { IntegerVector selfMin = this.Min; IntegerVector selfMax = this.Max; IntegerVector otherMin = other.Min; IntegerVector otherMax = other.Max; return(((otherMin.X >= selfMin.X && otherMin.X < selfMax.X) || (otherMax.X > selfMin.X && otherMax.X <= selfMax.X) || (selfMin.X >= otherMin.X && selfMin.X < otherMax.X) || (selfMax.X > otherMin.X && selfMax.X <= otherMax.X)) && ((otherMin.Y >= selfMin.Y && otherMin.Y < selfMax.Y) || (otherMax.Y > selfMin.Y && otherMax.Y <= selfMax.Y) || (selfMin.Y >= otherMin.Y && selfMin.Y < otherMax.Y) || (selfMax.Y > otherMin.Y && selfMax.Y <= otherMax.Y))); }
public bool Overlaps(IntegerRect other) { IntegerVector selfMin = this.Min; IntegerVector selfMax = this.Max; IntegerVector otherMin = other.Min; IntegerVector otherMax = other.Max; return ((otherMin.X >= selfMin.X && otherMin.X < selfMax.X) || (otherMax.X > selfMin.X && otherMax.X <= selfMax.X) || (selfMin.X >= otherMin.X && selfMin.X < otherMax.X) || (selfMax.X > otherMin.X && selfMax.X <= otherMax.X)) && ((otherMin.Y >= selfMin.Y && otherMin.Y < selfMax.Y) || (otherMax.Y > selfMin.Y && otherMax.Y <= selfMax.Y) || (selfMin.Y >= otherMin.Y && selfMin.Y < otherMax.Y) || (selfMax.Y > otherMin.Y && selfMax.Y <= otherMax.Y)); }
public List <IntegerCollider> GetPotentialCollisions(float vx, float vy, int offsetX = 0, int offsetY = 0, int mask = Physics2D.DefaultRaycastLayers, List <IntegerCollider> _listRef = null, int enlargeX = 0, int enlargeY = 0) { if (this.CollisionManager == null) { return(new List <IntegerCollider>()); } IntegerRect bounds = this.Bounds; IntegerRect range = new IntegerRect(bounds.Center.X + offsetX, bounds.Center.Y + offsetY, this.Bounds.Size.X + Mathf.RoundToInt(Mathf.Abs(vx * 2) + 1.55f) + enlargeX, this.Bounds.Size.Y + (Mathf.RoundToInt(Mathf.Abs(vy * 2) + 1.55f)) + enlargeY); return(this.CollisionManager.GetCollidersInRange(range, mask, null, _listRef)); }
//NOTE: Only partial support of circle colliders here public override bool Overlaps(IntegerCollider other, int offsetX = 0, int offsetY = 0) { IntegerRect otherBounds = other.Bounds; int otherY = other.Bounds.Min.Y; IntegerVector ourPos = this.integerPosition + this.Offset; // Check if the colliders current position is above us, and their new (offset) position is on or below us if (otherY > ourPos.Y && otherY - offsetY <= ourPos.Y) { IntegerRect ourBounds = this.Bounds; // Make sure they're within our width return(otherBounds.Min.X - offsetX <= ourBounds.Max.X && otherBounds.Max.X - offsetX >= ourBounds.Min.X); } return(false); }
public List<IntegerCollider> GetPotentialCollisions(float vx, float vy, int offsetX = 0, int offsetY = 0, int mask = Physics2D.DefaultRaycastLayers) { IntegerRect bounds = this.Bounds; IntegerRect range = new IntegerRect(bounds.Center.X + offsetX, bounds.Center.Y + offsetY, this.Bounds.Size.X + Mathf.RoundToInt(Mathf.Abs(vx * 2) + 1.55f), this.Bounds.Size.Y + (Mathf.RoundToInt(Mathf.Abs(vy * 2) + 1.55f))); return this.CollisionManager.GetCollidersInRange(range, mask); }