public static OrientedBox GetNonMeshWorldOrientedBox(this GameObject gameObject) { SpriteRenderer spriteRenderer = gameObject.GetComponent <SpriteRenderer>(); if (spriteRenderer != null) { return(new OrientedBox(Box.FromBounds(spriteRenderer.GetModelSpaceBounds()), gameObject.transform)); } else { OrientedBox modelSpaceOrientedBox = gameObject.GetNonMeshModelSpaceOrientedBox(); if (!modelSpaceOrientedBox.IsValid()) { return(modelSpaceOrientedBox); } OrientedBox worldOrientedBox = new OrientedBox(modelSpaceOrientedBox); Transform objectTransform = gameObject.transform; worldOrientedBox.Center = objectTransform.position; worldOrientedBox.Rotation = objectTransform.rotation; worldOrientedBox.Scale = objectTransform.lossyScale; return(worldOrientedBox); } }
public static OrientedBox GetModelSpaceOrientedBox(this GameObject gameObject) { OrientedBox modelSpaceOrientedBox = gameObject.GetMeshModelSpaceOrientedBox(); if (modelSpaceOrientedBox.IsValid()) { return(modelSpaceOrientedBox); } return(gameObject.GetNonMeshModelSpaceOrientedBox()); }
public static OrientedBox GetWorldOrientedBox(this GameObject gameObject) { OrientedBox worldOrientedBox = gameObject.GetMeshWorldOrientedBox(); if (worldOrientedBox.IsValid()) { return(worldOrientedBox); } return(gameObject.GetNonMeshWorldOrientedBox()); }