예제 #1
0
        /// <summary>
        /// Get all raycast hits.
        /// </summary>
        override public RaycastHit2D[] GetRaycastHits()
        {
            if (Disabled)
            {
                for (int j = 0; j < hits.Length; j++)
                {
                    hits[j] = new RaycastHit2D();
                }
                return(hits);
            }
            int     pos           = 0;
            Vector3 worldPosition = WorldPosition;
            Vector3 direction     = Transform.rotation * GetDirection();
            float   length        = Length + LookAhead;

            for (int i = 0; i < MAX_LAYER; i++)
            {
                // Skip the built-in layers except default and water
                if (i == 0 || i == 4 || i > 7)
                {
                    if (pos >= hits.Length)
                    {
                        break;
                    }
                    if ((LayerMask & (1 << i)) == 1 << i)
                    {
                        hits[pos] = Physics2D.Raycast(worldPosition, direction, length, 1 << i);
                        if (hits[pos].collider != null && !character.IsColliderIgnored(hits[pos].collider))
                        {
                            pos++;
                        }
                    }
                }
            }
            for (int j = pos; j < hits.Length; j++)
            {
                hits[j] = EmptyRaycastHit;
            }
            return(hits);
        }