using UnityEngine;
using System.Collections;
[RequireComponent
(typeof(UITexture
))] public class NGUITextureSwitcher : MonoBehaviour
{
public UITextureSet[] atlasSets;
private UITexture m_texture;
private void Awake()
{
this.m_texture = GetComponent<UITexture>();
}
private void Start()
{
if (atlasSets.Length == 0) return;
UITextureSet set = atlasSets[0];
for (int i = 0; i < atlasSets.Length; i++)
{
Debug.Log (Screen.height);
if (Screen.height >= atlasSets[i].triggerHeight)
set = atlasSets[i];
}
if (set != null)
{
if (m_texture.name != set.textureName)
{
if (m_texture.mainTexture != null)
{
Resources.UnloadAsset(m_texture.mainTexture);
}
m_texture.mainTexture = Resources.Load("Backgrounds/" + set.textureName) as Texture2D;
}
}
}
}
[System.Serializable]
public class UITextureSet
{
public string name;
public int triggerHeight;
public Vector2 spriteRes;
public Vector2 textureRes;
public string textureName;
}