com.unity.uiextensions/Runtime/Scripts/Utilities/PPIViewer.cs

40 lines
1.0 KiB
C#
Raw Normal View History

/// Credit FireOApache
/// sourced from: http://answers.unity3d.com/questions/1149417/ui-button-onclick-sensitivity-for-high-dpi-devices.html#answer-1197307
/*USAGE:
2020-07-09 03:38:28 +08:00
Simply place the script on A Text control in the scene to display the current PPI / DPI of the screen*/
namespace UnityEngine.UI.Extensions
{
2023-02-04 19:22:31 +08:00
#if UNITY_2022_1_OR_NEWER
[RequireComponent(typeof(TMPro.TMP_Text))]
#else
[RequireComponent(typeof(Text))]
2023-02-04 19:22:31 +08:00
#endif
[AddComponentMenu("UI/Extensions/PPIViewer")]
public class PPIViewer : MonoBehaviour
{
2023-02-04 19:22:31 +08:00
#if UNITY_2022_1_OR_NEWER
private TMPro.TMP_Text label;
#else
private Text label;
2023-02-04 19:22:31 +08:00
#endif
void Awake()
{
2023-02-04 19:22:31 +08:00
#if UNITY_2022_1_OR_NEWER
label = GetComponentInChildren<TMPro.TMP_Text>();
#else
label = GetComponentInChildren<Text>();
#endif
}
void Start()
{
if (label != null)
{
label.text = "PPI: " + Screen.dpi.ToString();
}
}
}
}