using UnityEngine;
using System.Collections;
///
/// This component is responsible for fixing the slicing according to what atlas resolution is being used.
/// This is an annoyance that NGUI doesn't take into consideration and so we have to fix it on Start
///
public class FixSlicingOnDifferentResolutions : MonoBehaviour
{
void Start()
{
if (ResolutionSwitchController.IsSD)
{
ScaleSpritesBy(0.5f);
} else
if (ResolutionSwitchController.IsSHD)
{
ScaleSpritesBy(2);
}
Destroy(this);
}
void ScaleSpritesBy(float scaleFactor)
{
Vector3 scale = transform.localScale;
scale.x /= scaleFactor;
scale.y /= scaleFactor;
transform.localScale = scale;
UISprite[] sprites = GetComponentsInChildren(true);
foreach (UISprite sprite in sprites)
{
if (sprite.type == UISprite.Type.Sliced)
{
scale = sprite.cachedTransform.localScale;
scale.x *= scaleFactor;
scale.y *= scaleFactor;
sprite.cachedTransform.localScale = scale;
}
}
}
}