2016-06-04 00:36:55 +08:00
|
|
|
|
/// 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*/
|
2016-06-04 00:36:55 +08:00
|
|
|
|
|
|
|
|
|
namespace UnityEngine.UI.Extensions
|
|
|
|
|
{
|
2023-02-04 19:22:31 +08:00
|
|
|
|
#if UNITY_2022_1_OR_NEWER
|
|
|
|
|
[RequireComponent(typeof(TMPro.TMP_Text))]
|
|
|
|
|
#else
|
2016-06-04 00:36:55 +08:00
|
|
|
|
[RequireComponent(typeof(Text))]
|
2023-02-04 19:22:31 +08:00
|
|
|
|
#endif
|
2016-06-04 00:36:55 +08:00
|
|
|
|
[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
|
2016-06-04 00:36:55 +08:00
|
|
|
|
private Text label;
|
2023-02-04 19:22:31 +08:00
|
|
|
|
#endif
|
2016-06-04 00:36:55 +08:00
|
|
|
|
|
|
|
|
|
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
|
2016-06-04 00:36:55 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
if (label != null)
|
|
|
|
|
{
|
|
|
|
|
label.text = "PPI: " + Screen.dpi.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|