Skip to content

Commit 2fc034a

Browse files
committed
Keep timeline viz datetime in view
1 parent fbf83c8 commit 2fc034a

File tree

6 files changed

+109
-7
lines changed

6 files changed

+109
-7
lines changed

Assets/_Project/Prefabs/UI/TimelineVizCanvas.prefab

Lines changed: 19 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/_Project/Scenes/tally-viz-master.unity

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+

2+
using UnityEngine;
3+
using System.Collections;
4+
public class KeepInCameraView : MonoBehaviour {
5+
6+
Camera cam;
7+
public Vector2 topLeftOffset;
8+
public Vector2 bottomRightOffset;
9+
10+
private void Awake ()
11+
{
12+
cam = Camera.main;
13+
}
14+
15+
void Update ()
16+
{
17+
Vector3 pos = cam.WorldToViewportPoint (transform.position);
18+
19+
Debug.Log (pos);
20+
21+
pos.x = Mathf.Clamp01 (pos.x);
22+
pos.y = Mathf.Clamp01 (pos.y);
23+
24+
//if (pos.x < topLeftOffset.x) pos.x = topLeftOffset.x;
25+
//if (pos.y < topLeftOffset.y) pos.y = topLeftOffset.y;
26+
27+
//if (pos.x > bottomRightOffset.x) pos.x = bottomRightOffset.x;
28+
//if (pos.y > bottomRightOffset.y) pos.y = bottomRightOffset.y;
29+
30+
transform.position = cam.ViewportToWorldPoint (pos);
31+
}
32+
}

Assets/_Project/Scripts/Movement/KeepInCameraView.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+

2+
using UnityEngine;
3+
using System.Collections;
4+
public class KeepUIInCameraView : MonoBehaviour {
5+
6+
public Canvas canvas;
7+
RectTransform rect;
8+
RectTransform parentRect;
9+
10+
private void Awake ()
11+
{
12+
rect = GetComponent<RectTransform> ();
13+
parentRect = rect.parent.GetComponent<RectTransform> ();
14+
}
15+
16+
void Update ()
17+
{
18+
19+
Vector2 thisPos = rect.anchoredPosition;
20+
Vector2 parentPos = parentRect.anchorMax;
21+
22+
if (parentPos.x < 0.05f) {
23+
thisPos = new Vector3 (100, thisPos.y);
24+
} else if (parentPos.x > 0.95f) {
25+
thisPos = new Vector3 (-100, thisPos.y);
26+
} else {
27+
thisPos = new Vector3 (0, thisPos.y);
28+
}
29+
//Debug.Log (parentPos.x.ToString ());
30+
//Debug.Log (RectTransformUtility.PixelAdjustPoint (parentPos, parentRect, canvas));
31+
32+
rect.anchoredPosition = thisPos;
33+
}
34+
}

Assets/_Project/Scripts/Movement/KeepUIInCameraView.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)