Esempio n. 1
0
        public static void ApplyColliderInfoToTile(Tile tile, ColliderInfo colliderInfo)
        {
            if (tile == null || colliderInfo == null)
            {
                return;
            }

            CollisionType collisionType = colliderInfo.CollisionType;

            switch (collisionType)
            {
            case CollisionType.Box: {
                BoxCollider2DInfo info     = colliderInfo as BoxCollider2DInfo;
                BoxCollider2D     collider = tile.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
                if (info != null && collider != null)
                {
                    collider.size = info.Size;

#if UNITY_5_0
                    collider.offset = info.Center;
#else
                    collider.offset = info.Center;
#endif
                }
                break;
            }

            case CollisionType.Circle: {
                CircleCollider2DInfo info     = colliderInfo as CircleCollider2DInfo;
                CircleCollider2D     collider = tile.GetComponent(typeof(CircleCollider2D)) as CircleCollider2D;
                if (info != null && collider != null)
                {
#if UNITY_5_0
                    collider.offset = info.Center;
#else
                    collider.offset = info.Center;
#endif

                    collider.radius = info.Radius;
                }
                break;
            }

            case CollisionType.Polygon: {
                PolygonCollider2DInfo info     = colliderInfo as PolygonCollider2DInfo;
                PolygonCollider2D     collider = tile.GetComponent(typeof(PolygonCollider2D)) as PolygonCollider2D;
                if (info != null && collider != null)
                {
                    collider.pathCount = info.PathCount;
                    collider.points    = info.Points;
                }
                break;
            }

            default:
                break;
            }
        }
Esempio n. 2
0
        public static ColliderInfo GetColliderInfoFromTile(Tile tile)
        {
            if (tile == null)
            {
                return(null);
            }

            ColliderInfo  info          = null;
            CollisionType collisionType = tile.Collision;

            switch (collisionType)
            {
            case CollisionType.Box:
            {
                BoxCollider2D collider = tile.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
                if (collider)
                {
#if UNITY_5_0
                    info = new BoxCollider2DInfo(collider.offset, collider.size);
#else
                    info = new BoxCollider2DInfo(collider.center, collider.size);
#endif
                }
                break;
            }

            case CollisionType.Circle:
            {
                CircleCollider2D collider = tile.GetComponent(typeof(CircleCollider2D)) as CircleCollider2D;
                if (collider)
                {
#if UNITY_5_0
                    info = new CircleCollider2DInfo(collider.offset, collider.radius);
#else
                    info = new CircleCollider2DInfo(collider.center, collider.radius);
#endif
                }
                break;
            }

            case CollisionType.Polygon:
            {
                PolygonCollider2D collider = tile.GetComponent(typeof(PolygonCollider2D)) as PolygonCollider2D;
                if (collider)
                {
                    info = new PolygonCollider2DInfo(collider.pathCount, collider.points);
                }
                break;
            }

            default:
                break;
            }

            return(info);
        }
Esempio n. 3
0
        public static ColliderInfo GetColliderInfoFromTile(Tile tile)
        {
            if (tile == null)
            {
                return null;
            }

            ColliderInfo info = null;
            CollisionType collisionType = tile.Collision;

            switch (collisionType)
            {
                case CollisionType.Box:
                    {
                        BoxCollider2D collider = tile.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
                        if (collider)
                        {
#if UNITY_5_0
                            info = new BoxCollider2DInfo(collider.offset, collider.size);
#else
                              info = new BoxCollider2DInfo(collider.offset, collider.size);
#endif

                        }
                        break;
                    }
                case CollisionType.Circle:
                    {
                        CircleCollider2D collider = tile.GetComponent(typeof(CircleCollider2D)) as CircleCollider2D;
                        if (collider)
                        {
#if UNITY_5_0
                            info = new CircleCollider2DInfo(collider.offset, collider.radius);
#else
                              info = new CircleCollider2DInfo(collider.offset, collider.radius);
#endif

                        }
                        break;
                    }
                case CollisionType.Polygon:
                    {
                        PolygonCollider2D collider = tile.GetComponent(typeof(PolygonCollider2D)) as PolygonCollider2D;
                        if (collider)
                        {
                            info = new PolygonCollider2DInfo(collider.pathCount, collider.points);
                        }
                        break;
                    }
                default:
                    break;
            }

            return info;
        }
Esempio n. 4
0
        public static bool IsTileColliderEqualsToColliderInfo(Tile tile, ColliderInfo colliderInfo)
        {
            if (tile == null || colliderInfo == null)
            {
                return(false);
            }
            switch (colliderInfo.CollisionType)
            {
            case CollisionType.Box: {
                BoxCollider2D     collider = tile.GetComponent(typeof(BoxCollider2D)) as BoxCollider2D;
                BoxCollider2DInfo info     = colliderInfo as BoxCollider2DInfo;
                if (collider == null || info == null)
                {
                    return(false);
                }
#if UNITY_5_0
                if (info.Center == collider.offset && info.Size == collider.size)
#else
                if (info.Center == collider.offset && info.Size == collider.size)
#endif
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            case CollisionType.Circle: {
                CircleCollider2D     collider = tile.GetComponent(typeof(CircleCollider2D)) as CircleCollider2D;
                CircleCollider2DInfo info     = colliderInfo as CircleCollider2DInfo;
                if (collider == null || info == null)
                {
                    return(false);
                }
#if UNITY_5_0
                if (collider.offset == info.Center && collider.radius == info.Radius)
#else
                if (collider.offset == info.Center && collider.radius == info.Radius)
#endif
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            case CollisionType.Polygon: {
                PolygonCollider2D     collider = tile.GetComponent(typeof(PolygonCollider2D)) as PolygonCollider2D;
                PolygonCollider2DInfo info     = colliderInfo as PolygonCollider2DInfo;
                if (collider == null || info == null)
                {
                    return(false);
                }

                if (collider.pathCount == info.PathCount)
                {
                    for (int i = 0; i < collider.pathCount; ++i)
                    {
                        if (collider.points[i] != info.Points[i])
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            default:
                return(true);
            }
        }