using UnityEngine;
using System.Collections;
using System.Collections.Generic;
/// <summary>
/// Atlas changer dependant on the device's resolution.
/// </summary>
/// <description>
/// This is a script that changes the reference atlas in the UI to any of the
/// other atlasses based on the device's resolution, so that the pixel
/// perfectness is not lost.
/// </description>
/// <remarks>
/// This script is meant to be attached to the UIRoot object.
/// </remarks>
public class ResolutionSetup : MonoBehaviour
{
private UIRoot uiRoot;
public UIAtlas[] usedAtlasses;
public UIAtlas[] lowResAtlasses;
public UIAtlas[] highResAtlasses;
/// <summary>
/// Awake this instance.
/// </summary>
private void Awake()
{
uiRoot = this.GetComponent<UIRoot>();
if (lowResAtlasses.Length != highResAtlasses.Length)
{
Debug.LogWarning("Low and high res atlasses do not fit");
return;
}
if (DeviceHelper.IsHighRes())
{
// Handle high res atlas
for (int i = 0; i < usedAtlasses.Length; i++)
{
usedAtlasses[i].replacement = highResAtlasses[i];
}
}
else
{
// Handle low res atlas
for (int i = 0; i < usedAtlasses.Length; i++)
{
usedAtlasses[i].replacement = lowResAtlasses[i];
}
}
}
/// <summary>
/// Raises the disable event.
/// </summary>
private void OnDisable()
{
if (DeviceHelper.IsHighRes())
{
// Prevent replacement from sticking.
// In low res, there is no atlas change.
for (int i = 0; i < highResAtlasses.Length; i++)
{
usedAtlasses[i].replacement = lowResAtlasses[i];
}
}
}
/// <summary>
/// Start this instance.
/// </summary>
private void Start()
{
uiRoot.manualHeight = uiRoot.minimumHeight = uiRoot.maximumHeight = DeviceHelper.Height();
}
}