Dimensions for all screen sizes

main
Benjamin Kraft 1 year ago
parent 32eaec7c21
commit f985b5cf6b
  1. 79
      Assets/Scenes/Game.unity
  2. 96
      Assets/Scripts/Dimensions.cs
  3. 4
      Assets/Scripts/Game/AIPlayer.cs
  4. 2
      Assets/Scripts/Game/GameManager.cs
  5. 10
      Assets/Scripts/Game/Player.cs
  6. 4
      Assets/Scripts/GameUI.cs
  7. 11
      Assets/UI Toolkit/player_panel.uss
  8. 6
      ProjectSettings/ProjectSettings.asset
  9. 1
      README.md

@ -148,7 +148,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 132613872}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -12.6, y: 0, z: 0}
m_LocalPosition: {x: -10, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@ -171,8 +171,8 @@ EdgeCollider2D:
m_Offset: {x: 0, y: 0}
m_EdgeRadius: 0
m_Points:
- {x: 0, y: 21}
- {x: 0, y: -21}
- {x: 0, y: 17.5}
- {x: 0, y: -17.5}
m_AdjacentStartPoint: {x: 0, y: 0}
m_AdjacentEndPoint: {x: 0, y: 0}
m_UseAdjacentStartPoint: 0
@ -299,6 +299,14 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 948416251}
m_Modifications:
- target: {fileID: 786906420117163282, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_Points.Array.data[0].x
value: -10
objectReference: {fileID: 0}
- target: {fileID: 786906420117163282, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_Points.Array.data[1].x
value: 10
objectReference: {fileID: 0}
- target: {fileID: 786906420117163283, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: side
value: 1
@ -317,7 +325,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 786906420117163285, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_LocalPosition.y
value: -21
value: -17.5
objectReference: {fileID: 0}
- target: {fileID: 786906420117163285, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_LocalPosition.z
@ -357,7 +365,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 3154833278331422328, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_Positions.Array.data[0].x
value: -12.6
value: -10
objectReference: {fileID: 0}
- target: {fileID: 3154833278331422328, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_Positions.Array.data[0].y
@ -365,7 +373,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 3154833278331422328, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_Positions.Array.data[1].x
value: 12.6
value: 10
objectReference: {fileID: 0}
- target: {fileID: 3154833278331422328, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_Positions.Array.data[1].y
@ -446,7 +454,7 @@ SpriteRenderer:
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 2
m_Size: {x: 42, y: 25.2}
m_Size: {x: 35, y: 20}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
@ -640,7 +648,7 @@ SpriteRenderer:
m_FlipX: 0
m_FlipY: 0
m_DrawMode: 2
m_Size: {x: 36, y: 42}
m_Size: {x: 28.636364, y: 35}
m_AdaptiveModeThreshold: 0.5
m_SpriteTileMode: 0
m_WasSpriteAssigned: 1
@ -714,9 +722,10 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 572c5b8dd6a94b3585befaa50a883755, type: 3}
m_Name:
m_EditorClassIdentifier:
panelHeightPercentage: 15
emptySpacePercentage: 5
playGroundAspect: 0.6
isUpdating: 1
panelHeightPixelsMinimum: 200
playGroundSize: {x: 20, y: 35}
emptySpaceHeight: 3
mainCamera: {fileID: 1698696476}
topC: {fileID: 1166615027}
bottomC: {fileID: 238423618}
@ -726,12 +735,12 @@ MonoBehaviour:
playerPanelTop: {fileID: 738870617}
playerPanelBottom: {fileID: 2108734120}
background: {fileID: 712762093}
top: 21
bottom: -21
left: -12.6
right: 12.6
boardTop: 18.9
boardBottom: -18.9
top: 17.5
bottom: -17.5
left: -10
right: 10
boardTop: 14.5
boardBottom: -14.5
--- !u!1001 &1166615026
PrefabInstance:
m_ObjectHideFlags: 0
@ -739,6 +748,14 @@ PrefabInstance:
m_Modification:
m_TransformParent: {fileID: 948416251}
m_Modifications:
- target: {fileID: 786906420117163282, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_Points.Array.data[0].x
value: -10
objectReference: {fileID: 0}
- target: {fileID: 786906420117163282, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_Points.Array.data[1].x
value: 10
objectReference: {fileID: 0}
- target: {fileID: 786906420117163284, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_Name
value: TopGate
@ -753,7 +770,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 786906420117163285, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_LocalPosition.y
value: 21
value: 17.5
objectReference: {fileID: 0}
- target: {fileID: 786906420117163285, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_LocalPosition.z
@ -793,7 +810,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 3154833278331422328, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_Positions.Array.data[0].x
value: -12.6
value: -10
objectReference: {fileID: 0}
- target: {fileID: 3154833278331422328, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_Positions.Array.data[0].y
@ -801,7 +818,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 3154833278331422328, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_Positions.Array.data[1].x
value: 12.6
value: 10
objectReference: {fileID: 0}
- target: {fileID: 3154833278331422328, guid: 00ae6168f2c5cea79ba751265a06d0ae, type: 3}
propertyPath: m_Positions.Array.data[1].y
@ -852,7 +869,7 @@ Transform:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1462314553}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 12.6, y: 0, z: 0}
m_LocalPosition: {x: 10, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children: []
@ -875,8 +892,8 @@ EdgeCollider2D:
m_Offset: {x: 0, y: 0}
m_EdgeRadius: 0
m_Points:
- {x: 0, y: 21}
- {x: 0, y: -21}
- {x: 0, y: 17.5}
- {x: 0, y: -17.5}
m_AdjacentStartPoint: {x: 0, y: 0}
m_AdjacentEndPoint: {x: 0, y: 0}
m_UseAdjacentStartPoint: 0
@ -926,7 +943,7 @@ Camera:
far clip plane: 1000
field of view: 60
orthographic: 1
orthographic size: 30
orthographic size: 25.454546
m_Depth: 0
m_CullingMask:
serializedVersion: 2
@ -981,7 +998,7 @@ MonoBehaviour:
m_VolumeTrigger: {fileID: 0}
m_VolumeFrameworkUpdateModeOption: 2
m_RenderPostProcessing: 1
m_Antialiasing: 0
m_Antialiasing: 1
m_AntialiasingQuality: 2
m_StopNaN: 0
m_Dithering: 0
@ -999,11 +1016,11 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 4540566536649322900, guid: b4033513367475439bfcd048b5d376a6, type: 3}
propertyPath: m_Size.x
value: 36
value: 28.636364
objectReference: {fileID: 0}
- target: {fileID: 4540566536649322900, guid: b4033513367475439bfcd048b5d376a6, type: 3}
propertyPath: m_Size.y
value: 9
value: 7.954546
objectReference: {fileID: 0}
- target: {fileID: 4540566536649322901, guid: b4033513367475439bfcd048b5d376a6, type: 3}
propertyPath: m_Name
@ -1019,7 +1036,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4540566536649322903, guid: b4033513367475439bfcd048b5d376a6, type: 3}
propertyPath: m_LocalPosition.y
value: -25.5
value: -21.477272
objectReference: {fileID: 0}
- target: {fileID: 4540566536649322903, guid: b4033513367475439bfcd048b5d376a6, type: 3}
propertyPath: m_LocalPosition.z
@ -1138,11 +1155,11 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 4540566536649322900, guid: b4033513367475439bfcd048b5d376a6, type: 3}
propertyPath: m_Size.x
value: 36
value: 28.636364
objectReference: {fileID: 0}
- target: {fileID: 4540566536649322900, guid: b4033513367475439bfcd048b5d376a6, type: 3}
propertyPath: m_Size.y
value: 9
value: 7.954546
objectReference: {fileID: 0}
- target: {fileID: 4540566536649322901, guid: b4033513367475439bfcd048b5d376a6, type: 3}
propertyPath: m_Name
@ -1158,7 +1175,7 @@ PrefabInstance:
objectReference: {fileID: 0}
- target: {fileID: 4540566536649322903, guid: b4033513367475439bfcd048b5d376a6, type: 3}
propertyPath: m_LocalPosition.y
value: 25.5
value: 21.477272
objectReference: {fileID: 0}
- target: {fileID: 4540566536649322903, guid: b4033513367475439bfcd048b5d376a6, type: 3}
propertyPath: m_LocalPosition.z

@ -1,14 +1,23 @@
using System;
using UnityEngine;
using UnityEngine.Serialization;
[ExecuteInEditMode]
public class Dimensions : MonoBehaviour {
[Tooltip("How much height for player panels")]
public float panelHeightPercentage;
[Tooltip("How much height is the empty space between board and death zone")]
public float emptySpacePercentage;
[Tooltip("Aspect ratio of the playground")]
public float playGroundAspect;
public bool isUpdating;
[FormerlySerializedAs("panelHeightPixels")]
[Tooltip("Player panels height")]
public float panelHeightPixelsMinimum;
[Tooltip("Size in Unity units")]
public Vector2 playGroundSize;
[Tooltip("Height of the empty space between board and death zone")]
public float emptySpaceHeight;
public Camera mainCamera;
public EdgeCollider2D topC, bottomC, leftC, rightC;
public SpriteRenderer playGround;
@ -20,56 +29,56 @@ public class Dimensions : MonoBehaviour {
private void Awake() {
Singleton = this;
GetComponents();
}
private void OnValidate() {
GetComponents();
SetDimensions();
if (Application.isPlaying)
isUpdating = false;
}
private void GetComponents() {
topL = topC.GetComponent<LineRenderer>();
bottomL = bottomC.GetComponent<LineRenderer>();
}
public Vector2 PlaySize { get; private set; }
public Vector2 PlaySizeBoards { get; private set; }
public float top, bottom, left, right;
public float boardTop, boardBottom;
public float Width => right * 2;
public float Height => top * 2;
public float PanelHeightPixels { get; private set; }
private LineRenderer topL, bottomL;
private void Update() {
float height = mainCamera.orthographicSize * 2;
float allWidth = mainCamera.aspect * height;
float panelHeight = height * panelHeightPercentage / 100f;
float playGroundHeight = height - 2 * panelHeight;
float playGroundWidth = playGroundHeight * playGroundAspect;
float emptySpaceHeight = playGroundHeight * emptySpacePercentage / 100f;
top = playGroundHeight / 2;
bottom = -top;
right = playGroundWidth / 2;
left = -right;
private void SetDimensions() {
float heightByPanels = 1 / (1 - 2 * panelHeightPixelsMinimum / mainCamera.pixelHeight) * playGroundSize.y;
float heightByPlayground = playGroundSize.x / mainCamera.aspect;
float height = Mathf.Max(heightByPanels, heightByPlayground);
float width = mainCamera.aspect * height;
float panelHeight = (height - playGroundSize.y) / 2;
mainCamera.orthographicSize = height / 2;
float top = playGroundSize.y / 2;
float right = playGroundSize.x / 2;
boardTop = top - emptySpaceHeight;
boardBottom = -boardTop;
PanelHeightPixels = panelHeight / height * mainCamera.pixelHeight;
PlaySize = playGroundSize;
PlaySizeBoards = playGroundSize - new Vector2(0, emptySpaceHeight * 2);
Vector2 v1 = new Vector3(left, 0);
Vector2 v1 = new Vector3(-right, 0);
Vector2 v2 = new Vector3(right, 0);
Vector2 v3 = new Vector3(0, top);
Vector2 v4 = new Vector3(0, bottom);
Vector2 v4 = new Vector3(0, -top);
topC.transform.position = new Vector2(0, top);
bottomC.transform.position = new Vector2(0, bottom);
leftC.transform.position = new Vector2(left, 0);
bottomC.transform.position = new Vector2(0, -top);
leftC.transform.position = new Vector2(-right, 0);
rightC.transform.position = new Vector2(right, 0);
topC.points = new[] {v1, v2};
bottomC.points = new[] {v1, v2};
leftC.points = new[] {v3, v4};
rightC.points = new[] {v3, v4};
playGround.transform.rotation = Quaternion.Euler(0, 0, 90);
playGround.size = new Vector2(playGroundSize.y, playGroundSize.x);
const float lineWidth = 0.5f;
Vector3 offset = Vector3.up * lineWidth / 2;
@ -79,14 +88,17 @@ public class Dimensions : MonoBehaviour {
v12 = new[] {(Vector3) v1 + offset, (Vector3) v2 + offset};
bottomL.SetPositions(v12);
playGround.transform.rotation = Quaternion.Euler(0, 0, 90);
playGround.size = new Vector2(playGroundHeight, playGroundWidth);
playerPanelTop.transform.position = new Vector2(0, (height + Height) / 4);
playerPanelBottom.transform.position = new Vector2(0, -(height + Height) / 4);
playerPanelTop.transform.position = new Vector2(0, (height + PlaySize.y) / 4);
playerPanelBottom.transform.position = new Vector2(0, -(height + PlaySize.y) / 4);
playerPanelTop.size = playerPanelBottom.size = new Vector2(allWidth, panelHeight);
playerPanelTop.size = playerPanelBottom.size = new Vector2(width, panelHeight);
background.size = new Vector2(allWidth, playGroundHeight);
background.size = new Vector2(width, playGroundSize.y);
}
private void Update() {
if (!isUpdating)
return;
SetDimensions();
}
}

@ -78,8 +78,8 @@ namespace Game {
private float Simulate(Vector2 origin, Vector2 velocity, float radius, float secondsLeft, float secondsUsed, out bool ignore) {
ignore = false;
Vector2 r = new Vector2(radius, radius);
Vector2 validAreaOrigin = new Vector2(Dimensions.Singleton.left, Dimensions.Singleton.boardBottom) + r;
Vector2 validAreaSize = new Vector2(Dimensions.Singleton.Width, Dimensions.Singleton.boardTop * 2) - r * 2;
Vector2 validAreaOrigin = -Dimensions.Singleton.PlaySizeBoards / 2 + r;
Vector2 validAreaSize = Dimensions.Singleton.PlaySizeBoards - r * 2;
Rect area = new Rect(validAreaOrigin, validAreaSize);
// Try to follow this line from origin -> end

@ -77,7 +77,7 @@ namespace Game {
}
private void SpawnModification() {
Vector2 pos = new Vector2(Random.Range(Dimensions.Singleton.left, Dimensions.Singleton.right), Random.Range(-2, 2));
Vector2 pos = new Vector2(Random.Range(0, Dimensions.Singleton.PlaySize.x) - Dimensions.Singleton.PlaySize.x / 2, Random.Range(-2, 2));
ModificationProperties properties = modifications[Random.Range(0, modifications.Length)];
var mod = Instantiate(modificationPrefab, pos, Quaternion.identity).GetComponent<Modification>();
mod.Properties = properties;

@ -37,8 +37,8 @@ namespace Game {
}
// Unit distance from zero
private readonly float baseBorder = Dimensions.Singleton.Width / 2 * 0.9f;
private readonly float borderSummand = Dimensions.Singleton.Width / 2 * 0.1f;
private readonly float baseBorder = Dimensions.Singleton.PlaySize.x / 2 * 0.9f;
private readonly float borderSummand = Dimensions.Singleton.PlaySize.x / 2 * 0.1f;
protected float Border {
get {
return Mathf.Min(Modifications.Where(m => m.Properties.effect == ModEffect.Border)
@ -47,7 +47,7 @@ namespace Game {
ModType.Nerf => -borderSummand,
_ => throw new ArgumentOutOfRangeException()
}),
Dimensions.Singleton.Width / 2
Dimensions.Singleton.PlaySize.x / 2
);
}
}
@ -86,8 +86,8 @@ namespace Game {
private void Start() {
float y = Side switch {
Side.Bottom => Dimensions.Singleton.boardBottom,
Side.Top => Dimensions.Singleton.boardTop,
Side.Bottom => -Dimensions.Singleton.PlaySizeBoards.y / 2,
Side.Top => Dimensions.Singleton.PlaySizeBoards.y / 2,
_ => throw new ArgumentOutOfRangeException()
};
transform.position = new Vector2(0, y);

@ -47,8 +47,8 @@ public class GameUI : MonoBehaviour {
}
private void PreparePlayerPanels() {
float heightPercentage = Dimensions.Singleton.panelHeightPercentage;
PlayerPanel(Side.Top).style.height = PlayerPanel(Side.Bottom).style.height = Length.Percent(heightPercentage);
float pixelHeight = Dimensions.Singleton.PanelHeightPixels;
PlayerPanel(Side.Top).style.height = PlayerPanel(Side.Bottom).style.height = new Length(pixelHeight, LengthUnit.Pixel);
SetupGoButton(Side.Top, "left");
SetupGoButton(Side.Top, "right");

@ -1,7 +1,6 @@
.go {
flex-shrink: 1;
width: auto;
font-size: 50px;
font-size: 80px;
-unity-text-align: middle-center;
border-left-color: rgb(141, 157, 255);
border-right-color: rgb(141, 157, 255);
@ -11,10 +10,10 @@
border-right-width: 3px;
border-top-width: 3px;
border-bottom-width: 3px;
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
border-top-left-radius: 15px;
border-bottom-left-radius: 15px;
border-top-right-radius: 15px;
border-bottom-right-radius: 15px;
margin-left: 10px;
margin-right: 10px;
margin-top: 10px;

@ -135,9 +135,7 @@ PlayerSettings:
16:9: 1
Others: 1
bundleVersion: 1.0.2
preloadedAssets:
- {fileID: 1441689946358639501, guid: d3ba8f6dacc9c5d199124c512efea75f, type: 2}
- {fileID: 11400000, guid: b9344a9885130f6b6af43d2d0e72c9c8, type: 2}
preloadedAssets: []
metroInputSource: 0
wsaTransparentSwapchain: 0
m_HolographicPauseOnTrackingLoss: 1
@ -167,7 +165,7 @@ PlayerSettings:
iPhone: 0
tvOS: 0
overrideDefaultApplicationIdentifier: 0
AndroidBundleVersionCode: 4
AndroidBundleVersionCode: 5
AndroidMinSdkVersion: 22
AndroidTargetSdkVersion: 33
AndroidPreferredInstallLocation: 1

@ -5,7 +5,6 @@
- Collectables:
- NewBall
- Wormhole
- Ball delayed Spawn with direction indicator
- Border visuals
- Ball visuals

Loading…
Cancel
Save