Skip to content

Commit c22f854

Browse files
committed
Implemented portrait mode
1 parent e1a244a commit c22f854

21 files changed

Lines changed: 222 additions & 96 deletions
Binary file not shown.

Assets/AddressableAssetsData/link.xml

Lines changed: 0 additions & 25 deletions
This file was deleted.

Assets/AddressableAssetsData/link.xml.meta

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
using DaggerfallWorkshop;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using UnityEngine;
5+
6+
namespace DaggerfallWorkshop.Game
7+
{
8+
9+
/// <summary>
10+
/// Handles Android's Screen stuff like resolution setting and orientation
11+
/// </summary>
12+
public class AndroidScreenManager : MonoBehaviour
13+
{
14+
public static event System.Action<Resolution> ScreenResolutionChanged;
15+
private Resolution lastResolution;
16+
17+
private void Awake()
18+
{
19+
// Set resolution to the current resolution, just so that it's not using a stale setting from when
20+
// another Simulator was being used.
21+
if (AndroidUtils.IsRunningInSimulator)
22+
{
23+
DaggerfallUnity.Settings.ResolutionWidth = Screen.currentResolution.width;
24+
DaggerfallUnity.Settings.ResolutionHeight = Screen.currentResolution.height;
25+
lastResolution = Screen.currentResolution;
26+
}
27+
else
28+
{
29+
DaggerfallUnity.Settings.ResolutionWidth = Screen.width;
30+
DaggerfallUnity.Settings.ResolutionHeight = Screen.height;
31+
lastResolution = new Resolution() { width = Screen.width, height = Screen.height };
32+
}
33+
}
34+
// private void OnGUI()
35+
// {
36+
// if (GUI.Button(new Rect(10, 70, 50, 30), "Any"))
37+
// SetOrientationToAny();
38+
// if (GUI.Button(new Rect(10, 170, 50, 30), "Landscape"))
39+
// SetOrientationToLandscape();
40+
// if (GUI.Button(new Rect(10, 270, 50, 30), "Portrait"))
41+
// SetOrientationToPortrait();
42+
// }
43+
private void Update()
44+
{
45+
int x = Screen.width;
46+
int y = Screen.height;
47+
if (x != lastResolution.width || y != lastResolution.height){
48+
// looks like the resolution changed. Let's update the daggerfall unity resolution
49+
SetResolution(x, y);
50+
lastResolution = new Resolution() { width = x, height = y };
51+
}
52+
}
53+
public static void SetResolution(int x, int y)
54+
{
55+
Debug.Log("AndroidSimulationManager: Current screen updated to new resolution");
56+
DaggerfallUnity.Settings.ResolutionWidth = x;
57+
DaggerfallUnity.Settings.ResolutionHeight = y;
58+
59+
SettingsManager.SetScreenResolution(x, y, true);
60+
var allCams = FindObjectsOfType<Camera>();
61+
foreach (var cam in allCams)
62+
cam.ResetAspect();
63+
if(TouchscreenInputManager.Instance)
64+
TouchscreenInputManager.Instance.SetupUIRenderTexture();
65+
66+
ScreenResolutionChanged?.Invoke(new Resolution(){width=x, height=y});
67+
}
68+
public static void SetOrientationToAny()
69+
{
70+
Debug.Log("AndroidScreenManager: Setting oritentation to Any");
71+
Screen.autorotateToLandscapeLeft = true;
72+
Screen.autorotateToLandscapeRight = true;
73+
Screen.autorotateToPortrait = true;
74+
Screen.autorotateToPortraitUpsideDown = true;
75+
Screen.orientation = ScreenOrientation.AutoRotation;
76+
}
77+
public static void SetOrientationToPortrait()
78+
{
79+
Debug.Log("AndroidScreenManager: Setting oritentation to Portrait");
80+
Screen.autorotateToLandscapeLeft = false;
81+
Screen.autorotateToLandscapeRight = false;
82+
Screen.autorotateToPortrait = true;
83+
Screen.autorotateToPortraitUpsideDown = true;
84+
Screen.orientation = ScreenOrientation.AutoRotation;
85+
}
86+
public static void SetOrientationToLandscape()
87+
{
88+
Debug.Log("AndroidScreenManager: Setting oritentation to Landscape");
89+
Screen.autorotateToLandscapeLeft = true;
90+
Screen.autorotateToLandscapeRight = true;
91+
Screen.autorotateToPortrait = false;
92+
Screen.autorotateToPortraitUpsideDown = false;
93+
Screen.orientation = ScreenOrientation.AutoRotation;
94+
// DeviceOrientationManager.ForceOrientation(ScreenOrientation.AutoRotation);
95+
}
96+
}
97+
}
File renamed without changes.

Assets/Android/Scripts/AndroidSimulationManager.cs

Lines changed: 0 additions & 55 deletions
This file was deleted.

Assets/Android/Scripts/VirtualJoystick.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void Start()
5656
rootRectTF = rootRectTF.parent as RectTransform;
5757

5858
// set size to half of the screen area
59-
(transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rootRectTF.rect.width / 2f);
59+
UpdateSizeOfRectTF(rootRectTF.rect.width);
6060

6161
// set vars
6262
Rect joystickRect = UnityUIUtils.GetScreenspaceRect(background, myCam);
@@ -65,6 +65,18 @@ void Start()
6565

6666
// Initially invisible
6767
SetJoystickVisibility(false);
68+
69+
AndroidScreenManager.ScreenResolutionChanged += AndroidScreenManager_ScreenResolutionChanged;
70+
}
71+
void OnDestroy()
72+
{
73+
AndroidScreenManager.ScreenResolutionChanged -= AndroidScreenManager_ScreenResolutionChanged;
74+
}
75+
// set size to half of the screen area
76+
private void UpdateSizeOfRectTF(float screenWidth)
77+
{
78+
Debug.Log("VirtualJoystick: Updating size of rect tf");
79+
(transform as RectTransform).SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, screenWidth / 2f);
6880
}
6981
private void LateUpdate()
7082
{
@@ -158,5 +170,9 @@ public void OnPointerClick(PointerEventData eventData)
158170
if (JoystickTapsShouldActivateCenterObject && isWithinDeadzone && Time.time-TouchStartTime < .5f)
159171
TouchscreenInputManager.TriggerAction(InputManager.Actions.ActivateCenterObject);
160172
}
173+
void AndroidScreenManager_ScreenResolutionChanged(Resolution newResolution)
174+
{
175+
UpdateSizeOfRectTF(newResolution.width);
176+
}
161177
}
162178
}

Assets/Localization/StringTables/Internal_Settings Shared Data.asset

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ MonoBehaviour:
151151
m_Key: framerate
152152
m_Metadata:
153153
m_Items: []
154+
- m_Id: 170425305900507136
155+
m_Key: screenOrientationModes
156+
m_Metadata:
157+
m_Items: []
154158
m_Metadata:
155159
m_Items: []
156160
m_KeyGenerator:

Assets/Localization/StringTables/Internal_Settings_en.asset

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ MonoBehaviour:
254254
120'
255255
m_Metadata:
256256
m_Items: []
257+
- m_Id: 170425305900507136
258+
m_Localized: 'Any
259+
260+
Landscape
261+
262+
Portrait'
263+
m_Metadata:
264+
m_Items: []
257265
references:
258266
version: 2
259267
RefIds: []

Assets/Resources/defaults.ini.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ FieldOfView=65
2020
MainFilterMode=0
2121
QualityLevel=5
2222
ShadowResolutionMode=0
23+
ScreenOrientationMode=1
2324
DungeonLightShadows=False
2425
InteriorLightShadows=True
2526
ExteriorLightShadows=True

0 commit comments

Comments
 (0)