-
-
Notifications
You must be signed in to change notification settings - Fork 96
Open
Description
SafePadding
renders incorrect padding on non-mobile platforms in 2019.3 and Device Simulator 2.+
As a workaround, I use the following scripts:
/// <summary>
/// Provides a replacement for <see cref="Application"/> that better reports the platform currently being used.
/// </summary>
public static class EditorCompatibleApplication
{
public static RuntimePlatform platform
{
get
{
#if UNITY_ANDROID
return RuntimePlatform.Android;
#elif UNITY_IOS
return RuntimePlatform.IPhonePlayer;
#elif UNITY_STANDALONE_OSX
return RuntimePlatform.OSXPlayer;
#elif UNITY_STANDALONE_WIN
return RuntimePlatform.WindowsPlayer;
#elif UNITY_WEBGL
return RuntimePlatform.WebGLPlayer;
#endif
}
}
public static bool isLandscape => Camera.main.aspect > 1f;
public static bool isMobilePlatform
{
get
{
#if UNITY_EDITOR
// Game is being played in the editor and the selected BuildTarget is either Android or iOS
if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android ||
EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS)
{
return true;
}
#endif
// Game is being played on an Android or iOS device
if (platform == RuntimePlatform.Android ||
platform == RuntimePlatform.IPhonePlayer)
{
return true;
}
// Game is being played on something other then an Android or iOS device
else
{
return Application.isMobilePlatform;
}
}
}
}
/// <summary>
/// Disables the safe area when in WebGL, since it appears to misread the device stats in 2019.3.
/// </summary>
public sealed class SafeAreaInfluenceFix : UIBehaviour
{
[SerializeField] private SafePadding m_Target;
private void Start()
{
if (!EditorCompatibleApplication.isMobilePlatform)
{
StartCoroutine(SetInfluence(0f));
}
else
{
StartCoroutine(SetInfluence(1f));
}
}
private IEnumerator SetInfluence(float value)
{
m_Target.influence = value;
yield return new WaitForEndOfFrame();
m_Target.enabled = false;
yield return new WaitForEndOfFrame();
m_Target.enabled = true;
}
}
Metadata
Metadata
Assignees
Labels
No labels