From 94ae4bb5bce4bfacec245ef158d289e6340aa4bd Mon Sep 17 00:00:00 2001 From: Xevion Date: Thu, 21 May 2020 01:53:56 -0500 Subject: [PATCH] added resolution scaling for title/about screen buttons, ready for settings/play screens --- Boids/Assets/Scenes/Project.unity | 322 +++++++++++++++++++++++++-- Boids/Assets/Scripts/UIController.cs | 88 ++++---- Boids/Assets/Scripts/Util.cs | 19 +- 3 files changed, 360 insertions(+), 69 deletions(-) diff --git a/Boids/Assets/Scenes/Project.unity b/Boids/Assets/Scenes/Project.unity index b6fe8bb..aa6c33d 100644 --- a/Boids/Assets/Scenes/Project.unity +++ b/Boids/Assets/Scenes/Project.unity @@ -185,6 +185,127 @@ Transform: m_Father: {fileID: 0} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1 &357551011 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 357551012} + - component: {fileID: 357551015} + - component: {fileID: 357551014} + - component: {fileID: 357551013} + m_Layer: 5 + m_Name: AboutCloseButton + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &357551012 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 357551011} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: + - {fileID: 1241320721} + m_Father: {fileID: 882182194} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 313.4, y: 214.6} + m_SizeDelta: {x: 25, y: 25} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &357551013 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 357551011} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 1392445389, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Navigation: + m_Mode: 3 + m_SelectOnUp: {fileID: 0} + m_SelectOnDown: {fileID: 0} + m_SelectOnLeft: {fileID: 0} + m_SelectOnRight: {fileID: 0} + m_Transition: 1 + m_Colors: + m_NormalColor: {r: 1, g: 1, b: 1, a: 1} + m_HighlightedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_PressedColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 1} + m_SelectedColor: {r: 0.9607843, g: 0.9607843, b: 0.9607843, a: 1} + m_DisabledColor: {r: 0.78431374, g: 0.78431374, b: 0.78431374, a: 0.5019608} + m_ColorMultiplier: 1 + m_FadeDuration: 0.1 + m_SpriteState: + m_HighlightedSprite: {fileID: 0} + m_PressedSprite: {fileID: 0} + m_SelectedSprite: {fileID: 0} + m_DisabledSprite: {fileID: 0} + m_AnimationTriggers: + m_NormalTrigger: Normal + m_HighlightedTrigger: Highlighted + m_PressedTrigger: Pressed + m_SelectedTrigger: Selected + m_DisabledTrigger: Disabled + m_Interactable: 1 + m_TargetGraphic: {fileID: 357551014} + m_OnClick: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.Button+ButtonClickedEvent, UnityEngine.UI, Version=1.0.0.0, + Culture=neutral, PublicKeyToken=null +--- !u!114 &357551014 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 357551011} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: -765806418, guid: f70555f144d8491a825f0804e09c671c, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 0, g: 0, b: 0, a: 0} + m_RaycastTarget: 0 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_Sprite: {fileID: 10905, guid: 0000000000000000f000000000000000, type: 0} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 +--- !u!222 &357551015 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 357551011} + m_CullTransparentMesh: 0 --- !u!1 &410394593 GameObject: m_ObjectHideFlags: 0 @@ -692,8 +813,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: 608, y: 5} - m_SizeDelta: {x: -852.6, y: 0} + m_AnchoredPosition: {x: 624.755, y: 5} + m_SizeDelta: {x: -886.11, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &789036918 MonoBehaviour: @@ -763,13 +884,14 @@ RectTransform: m_Children: - {fileID: 2098048398} - {fileID: 1872191079} + - {fileID: 357551012} m_Father: {fileID: 1384661769} m_RootOrder: 5 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: -3.380005, y: 37.69} - m_SizeDelta: {x: -390.7, y: -132.1} + m_AnchoredPosition: {x: 0.000022888, y: -0.0000019073} + m_SizeDelta: {x: -400, y: -130} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &882182195 MonoBehaviour: @@ -784,7 +906,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 0.2830189, g: 0.2830189, b: 0.2830189, a: 0.9372549} + m_Color: {r: 0.2830189, g: 0.2830189, b: 0.2830189, a: 0.9098039} m_RaycastTarget: 1 m_OnCullStateChanged: m_PersistentCalls: @@ -842,7 +964,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 181.8, y: -55.5} + m_AnchoredPosition: {x: 190.47, y: -55.5} m_SizeDelta: {x: 40, y: 35} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1009112610 @@ -922,6 +1044,8 @@ MonoBehaviour: settingsButton: {fileID: 2044694039} aboutButton: {fileID: 783353683} titleText: {fileID: 1363541045} + aboutPanel: {fileID: 882182194} + aboutCloseButton: {fileID: 357551013} --- !u!4 &1165952972 Transform: m_ObjectHideFlags: 0 @@ -1015,6 +1139,164 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1222535311} m_CullTransparentMesh: 0 +--- !u!1 &1241320720 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1241320721} + - component: {fileID: 1241320723} + - component: {fileID: 1241320722} + m_Layer: 5 + m_Name: Text (TMP) + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &1241320721 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1241320720} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_Children: [] + m_Father: {fileID: 357551012} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 0, y: 0} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &1241320722 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1241320720} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Material: {fileID: 0} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_RaycastTarget: 1 + m_OnCullStateChanged: + m_PersistentCalls: + m_Calls: [] + m_TypeName: UnityEngine.UI.MaskableGraphic+CullStateChangedEvent, UnityEngine.UI, + Version=1.0.0.0, Culture=neutral, PublicKeyToken=null + m_text: X + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: d6ea291f4e788d84dbca1ad85398677b, type: 2} + m_sharedMaterial: {fileID: -4557755317545283406, guid: d6ea291f4e788d84dbca1ad85398677b, + type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4293059298 + m_fontColor: {r: 0.8867924, g: 0.8867924, b: 0.8867924, a: 1} + m_enableVertexGradient: 0 + m_colorMode: 3 + m_fontColorGradient: + topLeft: {r: 1, g: 1, b: 1, a: 1} + topRight: {r: 1, g: 1, b: 1, a: 1} + bottomLeft: {r: 1, g: 1, b: 1, a: 1} + bottomRight: {r: 1, g: 1, b: 1, a: 1} + m_fontColorGradientPreset: {fileID: 0} + m_spriteAsset: {fileID: 0} + m_tintAllSprites: 0 + m_overrideHtmlColors: 0 + m_faceColor: + serializedVersion: 2 + rgba: 4294967295 + m_outlineColor: + serializedVersion: 2 + rgba: 4278190080 + m_fontSize: 20.1 + m_fontSizeBase: 20.1 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 0 + m_textAlignment: 514 + m_characterSpacing: 0 + m_wordSpacing: 0 + m_lineSpacing: 0 + m_lineSpacingMax: 0 + m_paragraphSpacing: 0 + m_charWidthMaxAdj: 0 + m_enableWordWrapping: 1 + m_wordWrappingRatios: 0.4 + m_overflowMode: 0 + m_firstOverflowCharacterIndex: 0 + m_linkedTextComponent: {fileID: 0} + m_isLinkedTextComponent: 0 + m_isTextTruncated: 0 + m_enableKerning: 1 + m_enableExtraPadding: 0 + checkPaddingRequired: 0 + m_isRichText: 1 + m_parseCtrlCharacters: 1 + m_isOrthographic: 1 + m_isCullingEnabled: 0 + m_ignoreRectMaskCulling: 0 + m_ignoreCulling: 1 + m_horizontalMapping: 0 + m_verticalMapping: 0 + m_uvLineOffset: 0 + m_geometrySortingOrder: 0 + m_VertexBufferAutoSizeReduction: 1 + m_firstVisibleCharacter: 0 + m_useMaxVisibleDescender: 1 + m_pageToDisplay: 1 + m_margin: {x: 0, y: 0, z: 0, w: 0} + m_textInfo: + textComponent: {fileID: 1241320722} + characterCount: 1 + spriteCount: 0 + spaceCount: 0 + wordCount: 1 + linkCount: 0 + lineCount: 1 + pageCount: 1 + materialCount: 1 + m_isUsingLegacyAnimationComponent: 0 + m_isVolumetricText: 0 + m_spriteAnimator: {fileID: 0} + m_hasFontAssetChanged: 0 + m_subTextObjects: + - {fileID: 0} + - {fileID: 0} + - {fileID: 0} + - {fileID: 0} + - {fileID: 0} + - {fileID: 0} + - {fileID: 0} + - {fileID: 0} + m_baseMaterial: {fileID: 0} + m_maskOffset: {x: 0, y: 0, z: 0, w: 0} +--- !u!222 &1241320723 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1241320720} + m_CullTransparentMesh: 0 --- !u!1 &1363541043 GameObject: m_ObjectHideFlags: 0 @@ -1050,8 +1332,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 1} m_AnchorMax: {x: 0.5, y: 1} - m_AnchoredPosition: {x: 0, y: -85.45505} - m_SizeDelta: {x: 402.54, y: 170.91} + m_AnchoredPosition: {x: 0, y: -86.45} + m_SizeDelta: {x: 369.99, y: 172.72} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1363541045 MonoBehaviour: @@ -1171,7 +1453,7 @@ MonoBehaviour: m_UiScaleMode: 1 m_ReferencePixelsPerUnit: 100 m_ScaleFactor: 1 - m_ReferenceResolution: {x: 800, y: 600} + m_ReferenceResolution: {x: 1067, y: 600} m_ScreenMatchMode: 0 m_MatchWidthOrHeight: 0 m_PhysicalUnit: 3 @@ -1528,8 +1810,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -0.000010967, y: -4.2249985} - m_SizeDelta: {x: 391.99, y: 277.5} + m_AnchoredPosition: {x: -2.6, y: -15.3} + m_SizeDelta: {x: 637.4, y: 412.6} m_Pivot: {x: 0.5, y: 0.5} --- !u!132 &1872191080 GUIText: @@ -1628,8 +1910,8 @@ MonoBehaviour: m_outlineColor: serializedVersion: 2 rgba: 4278190080 - m_fontSize: 14 - m_fontSizeBase: 14 + m_fontSize: 20.7 + m_fontSizeBase: 20.7 m_fontWeight: 400 m_enableAutoSizing: 0 m_fontSizeMin: 14 @@ -1645,7 +1927,7 @@ MonoBehaviour: m_enableWordWrapping: 1 m_wordWrappingRatios: 0.4 m_overflowMode: 0 - m_firstOverflowCharacterIndex: 410 + m_firstOverflowCharacterIndex: -1 m_linkedTextComponent: {fileID: 0} m_isLinkedTextComponent: 0 m_isTextTruncated: 0 @@ -1666,7 +1948,7 @@ MonoBehaviour: m_firstVisibleCharacter: 0 m_useMaxVisibleDescender: 1 m_pageToDisplay: 1 - m_margin: {x: 6.529824, y: 0, z: 0.8162313, w: 0} + m_margin: {x: 6.529824, y: 0, z: -0.99998474, w: 0} m_textInfo: textComponent: {fileID: 1872191081} characterCount: 448 @@ -1674,7 +1956,7 @@ MonoBehaviour: spaceCount: 77 wordCount: 75 linkCount: 5 - lineCount: 16 + lineCount: 14 pageCount: 1 materialCount: 1 m_isUsingLegacyAnimationComponent: 0 @@ -1869,8 +2151,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 0, y: 143.5} - m_SizeDelta: {x: 70, y: 19} + m_AnchoredPosition: {x: 0, y: 211} + m_SizeDelta: {x: 95.68, y: 24.3} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &2098048399 MonoBehaviour: @@ -1921,8 +2203,8 @@ MonoBehaviour: m_outlineColor: serializedVersion: 2 rgba: 4278190080 - m_fontSize: 17 - m_fontSizeBase: 17 + m_fontSize: 24.1 + m_fontSizeBase: 24.1 m_fontWeight: 400 m_enableAutoSizing: 0 m_fontSizeMin: 18 diff --git a/Boids/Assets/Scripts/UIController.cs b/Boids/Assets/Scripts/UIController.cs index 4841d1b..a5ed4b8 100644 --- a/Boids/Assets/Scripts/UIController.cs +++ b/Boids/Assets/Scripts/UIController.cs @@ -4,6 +4,7 @@ using UnityEngine.UI; public class UIController : MonoBehaviour { public Canvas canvas; + public BoidController boidController; // Main Title Screen Elements @@ -12,16 +13,24 @@ public class UIController : MonoBehaviour { public Button aboutButton; public Text titleText; + // About Screen Elements public RectTransform aboutPanel; public Button aboutCloseButton; // Element Groups private GameObject[] _titleElements; - private GameObject[] _settingsElements; - private GameObject[] _aboutElements; - private GameObject[] _adjustmentElements; private UIStance _currentUI; + private CanvasScaler _scaler; + private Rect _canvasRect; + private float _scaleFactor; + + // Element Displacements + private Vector3 _aboutDiff; + private Vector3 _aboutButtonDiff; + private Vector3 _titleDiff; + private Vector3 _settingsDiff; + private Vector3 _adjustmentsDiff; private enum UIStance { Title, @@ -33,60 +42,59 @@ public class UIController : MonoBehaviour { private void Start() { // Basic variable setup _currentUI = UIStance.Title; + _scaler = canvas.GetComponent(); + _canvasRect = canvas.GetComponent().rect; + _scaleFactor = Screen.width / _scaler.referenceResolution.x; // Add event functions startButton.onClick.AddListener(OnStartButton); aboutButton.onClick.AddListener(OnAboutButton); aboutCloseButton.onClick.AddListener(OnAboutClose); - // settingsButton.onClick.AddListener(OnSettingsButton); - // Organize all UI Game Objects - _titleElements = new GameObject[] - {titleText.gameObject, startButton.gameObject, settingsButton.gameObject}; - _settingsElements = new GameObject[] - { }; - _aboutElements = new GameObject[] { }; - _adjustmentElements = new GameObject[] { }; + // Calculate UI position deltas + _aboutDiff = new Vector3(_canvasRect.size.x * _scaleFactor, 0, 0); + _aboutButtonDiff = new Vector3(75 * _scaleFactor, 0, 0); + _titleDiff = new Vector3(0, 450 * _scaleFactor, 0); + + // Move UI elements into position + aboutPanel.transform.position = canvas.transform.position + _aboutDiff; + + // Group Element Instantiation + _titleElements = new[] {titleText.gameObject, startButton.gameObject, settingsButton.gameObject}; } - // Handle Start Button Clicking - private void OnStartButton() { - switch (_currentUI) { - case UIStance.Title: { - Debug.Log("Switching to Play Screen"); - MoveTitleElements(true); - break; - } - // Shouldn't be processed - case UIStance.Play: - case UIStance.Settings: - case UIStance.About: - Debug.LogWarning($"User clicked Start Button out of Title Screen ({_currentUI})"); - break; - } - } // Move Title Elements In/Out private void MoveTitleElements(bool away) { + // Main Title and Start/Settings Buttons foreach (GameObject element in _titleElements) { LeanTween - .move(element, element.transform.position + new Vector3(0, 350 * (away ? 1 : -1), 0), away ? 0.75f : 1.15f) + .move(element, element.transform.position + _titleDiff * (away ? 1 : -1), away ? 0.65f : 1.15f) .setDelay(away ? 0f : 0.35f) .setEase(away ? LeanTweenType.easeInCubic : LeanTweenType.easeOutCubic); } // Bottom Right About Button LeanTween - .move(aboutButton.gameObject, aboutButton.transform.position + new Vector3(100 * (away ? 1 : -1), 0, 0), 0.75f) - .setEase(LeanTweenType.easeInCubic); + .move(aboutButton.gameObject, aboutButton.transform.position + _aboutButtonDiff * (away ? 1 : -1), 0.55f) + .setEase(LeanTweenType.easeInOutCubic); } // Move About Elements In/Out private void MoveAboutElements(bool away) { LeanTween - .move(aboutPanel.gameObject, aboutPanel.transform.position + new Vector3(750 * (away ? 1 : -1), 0, 0), away ? 0.6f : 0.8f) - .setEase(LeanTweenType.easeInCubic); + .move(aboutPanel.gameObject, aboutPanel.transform.position + _aboutDiff * (away ? 1 : -1), away ? 0.6f : 1f) + .setDelay(away ? 0f : 0.40f) + .setEase(away ? LeanTweenType.easeInCubic : LeanTweenType.easeOutCubic); + } + + // Handle switching to the Play Screen + private void OnStartButton() { + if (_currentUI == UIStance.Title) { + Debug.Log($"UI Transition: {_currentUI} -> {UIStance.About}"); + MoveTitleElements(true); + } } // Handle switching to the About Screen @@ -108,20 +116,4 @@ public class UIController : MonoBehaviour { _currentUI = UIStance.Title; } } - - private void SwitchToTitle() { - _currentUI = UIStance.Title; - } - - private void SwitchToAbout() { - _currentUI = UIStance.About; - } - - private void SwitchToSettings() { - _currentUI = UIStance.Settings; - } - - private void SwitchToPlay() { - _currentUI = UIStance.Play; - } } \ No newline at end of file diff --git a/Boids/Assets/Scripts/Util.cs b/Boids/Assets/Scripts/Util.cs index 749cacf..d859b41 100644 --- a/Boids/Assets/Scripts/Util.cs +++ b/Boids/Assets/Scripts/Util.cs @@ -8,7 +8,7 @@ public class Util { return new Vector2((float) rx, (float) (v.x * sa + v.y * ca)); } - + // Returns a velocity (Vector2) at a random angle with a specific overall magnitude public static Vector2 GetRandomVelocity(float magnitude) { var vector = new Vector2(magnitude, magnitude); @@ -30,4 +30,21 @@ public class Util { public static Vector2 AbsVector(Vector2 vector) { return new Vector2(vector.x, vector.y); } +} + +public class Scale { + private Vector2 _original; + private Vector2 _new; + private Vector2 _ratio; + + public float X => _ratio.x; + public float Y => _ratio.y; + + public Scale(Vector2 original, Canvas canvas) : this(original, canvas.pixelRect.size) { } + + public Scale(Vector2 original, Vector2 resized) { + _original = original; + _new = resized; + _ratio = _original / _new; + } } \ No newline at end of file