1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using UnityEngine;
- using System.Collections;
- /// <summary>
- /// This component is responsible for detecting which definition of atlases and textures to use
- /// It is partly an NGUI Atlas Resolution switch controller adapted from http://www.tasharen.com/forum/index.php?topic=832.0
- /// and also a Unity quality setter (http://answers.unity3d.com/questions/28515/dynamically-choosing-a-high-resolution-texture-at.html)
- /// Note that atlas textures need to be set as "GUI" as Texture Type. Otherwise the quality settings would scale them down.
- /// </summary>
- public class ResolutionSwitchController : MonoBehaviour
- {
- public UIAtlas[] referenceAtlases;
- public UIFont[] referenceFonts;
- public bool disableInEditor = true;
- public int HDResolutionCutOff = 800;
- public int SHDResolutionCutOff = 1500;
- private static bool _isHD = false;
- private static bool _isSD = false;
- private static bool _isSHD = false;
- public static bool IsHD { get { return _isHD; } }
- public static bool IsSD { get { return _isSD; } }
- public static bool IsSHD { get { return _isSHD; } }
- void Awake()
- {
- NotificationCenter.AddListener(OnApplyAtlasBundle, NotificationType.ApplyAtlasBundle);
- #if UNITY_WEBPLAYER
- _isHD = true;
- #else
- if (disableInEditor && Application.isEditor)
- {
- return;
- }
- int screenWidth = Screen.width;
- AVDebug.Log("Screen resolution is "+Screen.width+"x"+Screen.height);
- //Debug.LogError("Screen resolution is " + Screen.width + "x" + Screen.height);
- //Set Quality Settings
- if (screenWidth >= SHDResolutionCutOff)
- {
- #if UNITY_ANDROID
- QualitySettings.SetQualityLevel(1);
- AVDebug.Log("Setting texture to SHD");
- _isSHD = true;
- #else
- QualitySettings.SetQualityLevel(2);
- AVDebug.Log("Setting texture to SHD");
- _isSHD = true;
- #endif
- }
- else
- if (screenWidth >= HDResolutionCutOff)
- {
- QualitySettings.SetQualityLevel(1);
- AVDebug.Log("Setting texture to HD");
- _isHD = true;
- }
- else
- {
- QualitySettings.SetQualityLevel(0);
- AVDebug.Log("Setting texture to SD");
- _isSD = true;
- }
- #endif
- }
- void OnDestroy()
- {
- NotificationCenter.RemoveListener(OnApplyAtlasBundle, NotificationType.ApplyAtlasBundle);
- }
- void OnApplyAtlasBundle(Notification note)
- {
- AtlasBundle atlasBundle = (AtlasBundle)note.data;
- referenceAtlases[0].replacement = atlasBundle.atlasPrefab;
- //Note: the following order is extremely important. It is dependent on how they are dragged in the component in Unity Editor in referenceFonts variable
- referenceFonts[0].replacement = atlasBundle.buttonFontPrefab;
- referenceFonts[1].replacement = atlasBundle.textFontPrefab;
- referenceFonts[2].replacement = atlasBundle.scoreFontPrefab;
- }
- }
|