Commit 2fa117114e77a36e2be59b157f58b6844baf96fb

Authored by Mateus Lustosa
1 parent 51953e0e

Mensagem de loading responsivo; Legenda responsiva.

Assets/Scripts/UIManager.cs
... ... @@ -3,29 +3,48 @@ using UnityEngine.UI;
3 3  
4 4 public abstract class UIManager : MonoBehaviour {
5 5  
6   - public virtual void Start ()
7   - {
8   - float scale;
  6 + protected const int LDPI = 0;
  7 + protected const int MDPI = 1;
  8 + protected const int HDPI = 2;
  9 + protected const int XHDPI = 3;
  10 + protected const int XXHDPI = 4;
  11 +
  12 + protected int resolution;
9 13  
  14 + protected virtual void Start ()
  15 + {
10 16 if (Screen.dpi < 140)
11   - scale = 0.22F;
  17 + resolution = LDPI;
12 18  
13 19 // 240
14 20 else if (Screen.dpi < 280)
15   - scale = 0.35F;
  21 + resolution = MDPI;
16 22  
17 23 // 320
18 24 else if (Screen.dpi < 400)
19   - scale = 0.5F;
  25 + resolution = HDPI;
20 26  
21 27 // 480
22 28 else if (Screen.dpi < 500)
23   - scale = 0.7F;
  29 + resolution = XHDPI;
24 30  
25 31 else
26   - scale = 1F;
  32 + resolution = XXHDPI;
27 33  
28   - rebuild(scale);
  34 + rebuild(getScale());
  35 + }
  36 +
  37 + private float getScale()
  38 + {
  39 + switch (this.resolution)
  40 + {
  41 + case LDPI: return 0.22F;
  42 + case MDPI: return 0.35F;
  43 + case HDPI: return 0.5F;
  44 + case XHDPI: return 0.7F;
  45 + case XXHDPI: return 1F;
  46 + default: return 1F;
  47 + }
29 48 }
30 49  
31 50 protected abstract void rebuild(float scale);
... ...
Assets/Scripts/UIManagers/UIManagerInfo.cs
... ... @@ -47,7 +47,6 @@ public class UIManagerInfo : UIManager {
47 47 // info
48 48 {
49 49 info.transform.localScale = new Vector3(scale, scale, 1);
50   - //info.transform.position -= new Vector3(0, 540 * (1F - scale), 0);
51 50 }
52 51 }
53 52  
... ...
Assets/Scripts/UIManagers/UIManagerLoading.cs
... ... @@ -12,7 +12,19 @@ public class UIManagerLoading : UIManager {
12 12  
13 13 // text
14 14 {
15   - text.fontSize = (int)( text.fontSize * scale );
  15 + float fontScale;
  16 +
  17 + switch (base.resolution)
  18 + {
  19 + case LDPI: fontScale = 0.30F; break;
  20 + case MDPI: fontScale = 0.45F; break;
  21 + case HDPI: fontScale = 0.65F; break;
  22 + case XHDPI: fontScale = 0.8F; break;
  23 + case XXHDPI: fontScale = 1F; break;
  24 + default: fontScale = 1F; break;
  25 + }
  26 +
  27 + text.fontSize = (int)( text.fontSize * fontScale );
16 28  
17 29 Vector2 textSize = text.GetComponent<RectTransform>().sizeDelta;
18 30 textSize.y = textHeight;
... ... @@ -26,7 +38,7 @@ public class UIManagerLoading : UIManager {
26 38 // image
27 39 {
28 40 image.transform.localScale = new Vector3(scale, scale, 1);
29   -
  41 +
30 42 Vector3 imagePosition = image.transform.position;
31 43 imagePosition.y = textHeight - (90 * scale);
32 44 image.transform.position = imagePosition;
... ...
Assets/Scripts/UIManagers/UIManagerSubtitles.cs
... ... @@ -8,21 +8,17 @@ public class UIManagerSubtitles : UIManager {
8 8  
9 9 protected override void rebuild(float scale)
10 10 {
11   -// container.transform.localScale = new Vector3(scale, 1, 1);
12   -// bar.transform.localScale = new Vector3(1, scale, 1);
13   -// bar.transform.position -= new Vector3(0, 165 * (1F - scale), 0);
  11 + Vector3 barSize = bar.GetComponent<RectTransform>().sizeDelta;
  12 + barSize *= scale;
14 13  
  14 + Vector3 textSize = text.GetComponent<RectTransform>().sizeDelta;
  15 + textSize.y *= scale;
  16 + text.GetComponent<RectTransform>().sizeDelta = textSize;
15 17  
  18 + Vector3 textPosition = text.transform.position;
  19 + textPosition.y = barSize.y + (textSize.y * 0.75F);
  20 + text.transform.position = textPosition;
16 21  
17   -
18   - //text.transform.localScale = new Vector3(scale*2, 2, 2);
19   -
20   - //text.GetComponent<RectTransform>().position = new Vector3((1F - scale), 165 * (1F - scale), 0);
21   - //text.GetComponent<RectTransform>().localScale = new Vector3(1, 1, 1);
22   -
23   - //text.transform.position = new Vector3(2, 1, 1);
24   -
25   - text.transform.position = new Vector3(Screen.width/2, Screen.height/5.5f, 0);
26   -
  22 + text.fontSize = (int)( text.fontSize * scale );
27 23 }
28 24 }
... ...