12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// 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
- /// </summary>
- 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<UISprite>(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;
- }
- }
- }
- }
|