Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canvas Rescaler #1781

Merged
merged 14 commits into from
Mar 23, 2017
39 changes: 39 additions & 0 deletions Assets/UIRescaler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#region License
// ====================================================
// Project Porcupine Copyright(C) 2016 Team Porcupine
// This program comes with ABSOLUTELY NO WARRANTY; This is free software,
// and you are welcome to redistribute it under certain conditions; See
// file LICENSE, which is part of this source code package, for details.
// ====================================================
#endregion

using System.Collections;
using UnityEngine;
using UnityEngine.UI;

public class UIRescaler : MonoBehaviour
{
public int lastScreenWidth = 0;

public void Start()
{
lastScreenWidth = Screen.width;
StartCoroutine("AdjustScale");
Debug.LogWarning(lastScreenWidth);
}

public void Update()
{
if (lastScreenWidth != Screen.width)
{
lastScreenWidth = Screen.width;
StartCoroutine("AdjustScale");
}
}

private IEnumerator AdjustScale()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a coroutine? This will behave just like a function the way you have implemented it, since nothing happens after or while it yields.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No reason, other than leftovers... it used to do something, but I was tweaking all sorts of things trying to get things to behave how I wanted, and I forgot to uncoroutine it.

{
this.GetComponent<CanvasScaler>().scaleFactor = Screen.width / 1920f;
yield return null;
}
}
12 changes: 12 additions & 0 deletions Assets/UIRescaler.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions Assets/_Scenes_/_World.unity
Original file line number Diff line number Diff line change
Expand Up @@ -1664,6 +1664,7 @@ GameObject:
- 223: {fileID: 2038247392}
- 114: {fileID: 2038247391}
- 114: {fileID: 2038247390}
- 114: {fileID: 2038247393}
m_Layer: 5
m_Name: Canvas
m_TagString: Untagged
Expand Down Expand Up @@ -1749,6 +1750,18 @@ Canvas:
m_SortingLayerID: 0
m_SortingOrder: 0
m_TargetDisplay: 0
--- !u!114 &2038247393
MonoBehaviour:
m_ObjectHideFlags: 0
m_PrefabParentObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 2038247388}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 2125ec9446c957546833e5124271beda, type: 3}
m_Name:
m_EditorClassIdentifier:
lastScreenWidth: 0
--- !u!1 &2048170185
GameObject:
m_ObjectHideFlags: 0
Expand Down