-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathScreenBorders.cs
60 lines (54 loc) · 2.13 KB
/
ScreenBorders.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using UnityEngine;
namespace Wrj
{
[ExecuteInEditMode]
public class ScreenBorders : MonoBehaviour
{
[SerializeField] private ScreenBorder leftBorder;
[SerializeField] private ScreenBorder rightBorder;
[SerializeField] private ScreenBorder ground;
[SerializeField] private ScreenBorder ceiling;
void Start()
{
if (Application.isPlaying)
{
Wrj.ScreenSizeNotifier.Instance.OnScreenChangeWorld += SetBorders;
}
}
#if UNITY_EDITOR
void Update()
{
SetBorders(ScreenSizeNotifier.WorldDimensions);
}
#endif
void SetBorders(Vector3 worldDimensions)
{
if (leftBorder.transform != null)
{
leftBorder.transform.localScale = transform.localScale.With(y: worldDimensions.y * 2f);
leftBorder.transform.position = Vector3.zero.With(x: (-worldDimensions.x - (leftBorder.transform.lossyScale.x * .5f)) + leftBorder.offset);
}
if (rightBorder.transform != null)
{
rightBorder.transform.localScale = transform.localScale.With(y: worldDimensions.y * 2f);
rightBorder.transform.position = Vector3.zero.With(x: (worldDimensions.x + (rightBorder.transform.lossyScale.x * .5f)) + rightBorder.offset);
}
if (ground.transform != null)
{
ground.transform.localScale = transform.localScale.With(x: worldDimensions.x * 2f);
ground.transform.position = Vector3.zero.With(y: (-worldDimensions.y - (ground.transform.lossyScale.y * .5f)) + ground.offset);
}
if (ceiling.transform != null)
{
ceiling.transform.localScale = transform.localScale.With(x: worldDimensions.x * 2f);
ceiling.transform.position = Vector3.zero.With(y: (worldDimensions.y + (ceiling.transform.lossyScale.y * .5f)) + ceiling.offset);
}
}
[System.Serializable]
protected class ScreenBorder
{
public Transform transform;
public float offset;
}
}
}