Fixed screen rotation issue with DetailsPanel

This commit is contained in:
2018-11-16 16:55:32 +01:00
parent f084413f90
commit dc5fe321c7
4 changed files with 22 additions and 45 deletions

View File

@@ -48,7 +48,12 @@ namespace RothenburgAR.UI
? transform.offsetMax.y ? transform.offsetMax.y
: initialHeight; : initialHeight;
if (Screen.orientation == ScreenOrientation.Portrait) Debug.Log(String.Format("Recalculating DetailsPanel position. Orientation: [{1}x{2}]{0}\n",
Screen.orientation.ToString(),
Screen.currentResolution.width,
Screen.currentResolution.height));
if (DisplayManager.Instance.ScreenOrientation == ScreenOrientation.Portrait)
{ {
// stretch horizontally // stretch horizontally
transform.anchorMax = new Vector2(1, 0); transform.anchorMax = new Vector2(1, 0);

View File

@@ -16,10 +16,10 @@ namespace RothenburgAR.UI
} }
} }
public readonly UnityEvent OnResolutionChange = new UnityEvent();
public readonly UnityEvent OnOrientationChange = new UnityEvent(); public readonly UnityEvent OnOrientationChange = new UnityEvent();
Vector2 resolution; // Current Resolution public ScreenOrientation ScreenOrientation;
ScreenOrientation orientation; // Current Screen Orientation private Vector2 resolution; // Current Resolution
private ScreenOrientation orientation; // Current Screen Orientation
static void Init() static void Init()
{ {
@@ -37,6 +37,10 @@ namespace RothenburgAR.UI
instance.resolution = new Vector2(Screen.width, Screen.height); instance.resolution = new Vector2(Screen.width, Screen.height);
instance.orientation = Screen.orientation; instance.orientation = Screen.orientation;
instance.ScreenOrientation = instance.resolution.x < instance.resolution.y
? ScreenOrientation.Portrait
: ScreenOrientation.Landscape;
} }
private void Start() private void Start()
@@ -49,49 +53,16 @@ namespace RothenburgAR.UI
private void OnRectTransformDimensionsChange() private void OnRectTransformDimensionsChange()
{ {
// Check for an orientation change. if (orientation != Screen.orientation || !(resolution.x == Screen.width && resolution.y == Screen.height))
ScreenOrientation curOri = Screen.orientation;
switch (curOri)
{
case ScreenOrientation.Unknown: // Ignore
{
break;
}
default:
{
if (orientation != curOri)
{
orientation = curOri;
OnOrientationChange.Invoke();
}
break;
}
}
// Check for a resolution change.
if ((resolution.x != Screen.width && resolution.x != Screen.height) || (resolution.y != Screen.height && resolution.y != Screen.width))
{ {
orientation = Screen.orientation;
resolution = new Vector2(Screen.width, Screen.height); resolution = new Vector2(Screen.width, Screen.height);
OnResolutionChange.Invoke(); ScreenOrientation = resolution.x < resolution.y
} ? ScreenOrientation.Portrait
: ScreenOrientation.Landscape;
#if UNITY_EDITOR
else
{
// PC doesn't have device orientation, so do this for testing purposes
OnOrientationChange.Invoke(); OnOrientationChange.Invoke();
} }
#endif
}
public void AddResolutionChangeListener(UnityAction callback)
{
OnResolutionChange.AddListener(callback);
}
public void RemoveResolutionChangeListener(UnityAction callback)
{
OnResolutionChange.RemoveListener(callback);
} }
public void AddOrientationChangeListener(UnityAction callback) public void AddOrientationChangeListener(UnityAction callback)
@@ -109,7 +80,6 @@ namespace RothenburgAR.UI
if (instance == this) if (instance == this)
{ {
// Clean up memory. // Clean up memory.
OnResolutionChange.RemoveAllListeners();
OnOrientationChange.RemoveAllListeners(); OnOrientationChange.RemoveAllListeners();
instance = null; instance = null;
} }

View File

@@ -39,8 +39,7 @@ namespace RothenburgAR.UI
if (previousStatus == TrackableBehaviour.Status.TRACKED && newStatus == TrackableBehaviour.Status.NOT_FOUND) if (previousStatus == TrackableBehaviour.Status.TRACKED && newStatus == TrackableBehaviour.Status.NOT_FOUND)
{ {
var poi = UIManager.Instance.ARViewBehaviour.ProjectionEffect.SelectedPOI; var poi = UIManager.Instance.ARViewBehaviour.ProjectionEffect.SelectedPOI;
if ( if (UIManager.Instance.ARViewBehaviour.DetailsPanel.gameObject.activeInHierarchy && poi != null)
UIManager.Instance.ARViewBehaviour.DetailsPanel.gameObject.activeInHierarchy && poi != null)
{ {
if (poi.GetComponent<PoiBehaviour>().Exhibit == Exhibit) if (poi.GetComponent<PoiBehaviour>().Exhibit == Exhibit)
{ {

View File

@@ -160,6 +160,7 @@ PlayerSettings:
applicationIdentifier: applicationIdentifier:
Android: de.fhws.rothenburgar Android: de.fhws.rothenburgar
Standalone: de.fhws.rothenburgar Standalone: de.fhws.rothenburgar
iOS: de.fhws.rothenburgar
buildNumber: {} buildNumber: {}
AndroidBundleVersionCode: 1 AndroidBundleVersionCode: 1
AndroidMinSdkVersion: 16 AndroidMinSdkVersion: 16
@@ -276,6 +277,8 @@ PlayerSettings:
m_Enabled: 1 m_Enabled: 1
- m_BuildTarget: Standalone - m_BuildTarget: Standalone
m_Enabled: 1 m_Enabled: 1
- m_BuildTarget: iOS
m_Enabled: 1
openGLRequireES31: 0 openGLRequireES31: 0
openGLRequireES31AEP: 0 openGLRequireES31AEP: 0
m_TemplateCustomTags: {} m_TemplateCustomTags: {}