Ejemplo n.º 1
0
    void OnDrawGizmos()//Selected()
    {
        IntegerRect bounds = this.Bounds;

        Gizmos.color = Color.red;
        Gizmos.DrawWireSphere(new Vector3(bounds.Center.X, bounds.Center.Y), this.Radius);
    }
Ejemplo n.º 2
0
    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;
    }
Ejemplo n.º 4
0
    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));
    }
Ejemplo n.º 5
0
    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);
    }
Ejemplo n.º 6
0
    public static IntegerRect CreateFromMinMax(IntegerVector min, IntegerVector max)
    {
        IntegerRect rect = new IntegerRect();

        rect.Center = (min + max) / 2;
        rect.Size   = max - min;
        return(rect);
    }
Ejemplo n.º 7
0
    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));
    }
Ejemplo n.º 8
0
    //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);
     }
 }
Ejemplo n.º 10
0
 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);
     }
 }
Ejemplo n.º 11
0
 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));
     }
 }
Ejemplo n.º 12
0
    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);
    }
Ejemplo n.º 13
0
    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)));
    }
Ejemplo n.º 14
0
    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));
    }
Ejemplo n.º 15
0
    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);
    }
Ejemplo n.º 17
0
 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);
 }