From e3abf8e1d124f1f9e6b3209de1cd01d2fa614347 Mon Sep 17 00:00:00 2001 From: hani-sayegh Date: Fri, 10 Mar 2017 16:37:42 -0600 Subject: [PATCH] simplified code --- .../Scene/Test Scenes/Networking Test.unity | 10 +++--- Assets/hanisstuff/scripts/TimeLineUI.cs | 35 +++++++------------ 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/Assets/Scene/Test Scenes/Networking Test.unity b/Assets/Scene/Test Scenes/Networking Test.unity index 7a53652..04bd87b 100644 --- a/Assets/Scene/Test Scenes/Networking Test.unity +++ b/Assets/Scene/Test Scenes/Networking Test.unity @@ -375,14 +375,14 @@ RectTransform: m_GameObject: {fileID: 202315549} 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_LocalScale: {x: 1, y: 10, z: 1} m_Children: [] m_Father: {fileID: 101545229} m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} - m_AnchorMin: {x: 0, y: 0.5} - m_AnchorMax: {x: 0, y: 0.5} - m_AnchoredPosition: {x: 0, y: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 0, y: -0.5} m_SizeDelta: {x: 1, y: 1} m_Pivot: {x: 0, y: 0.5} --- !u!114 &202315551 @@ -397,7 +397,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 1, g: 1, b: 1, a: 1} + m_Color: {r: 0, g: 0, b: 0, a: 1} m_RaycastTarget: 1 m_OnCullStateChanged: m_PersistentCalls: diff --git a/Assets/hanisstuff/scripts/TimeLineUI.cs b/Assets/hanisstuff/scripts/TimeLineUI.cs index f69ffd2..4f4f261 100644 --- a/Assets/hanisstuff/scripts/TimeLineUI.cs +++ b/Assets/hanisstuff/scripts/TimeLineUI.cs @@ -22,6 +22,8 @@ public class TimeLineUI : MonoBehaviour void Start() { playerTimeLine = GameObject.FindGameObjectWithTag("PlayerTimeLine").GetComponent(); + //once drawn the first time should never be touched again. + playerTimeLine.rectTransform.localScale = new Vector3(Screen.width, 55, 1); //thisTimeLine = GetComponent(); startTime = Time.time; latestSecond = intervalCount; @@ -54,10 +56,13 @@ void Update() playerTimeLineScale = widthBetweenSeconds * Time.time; } + foreach (var second in secondsOnScreen) + { + animate(second); + } + if (transform.anchoredPosition.x < midpoint) { - //once drawn the first time should never be touched again. - playerTimeLine.rectTransform.localScale = new Vector3(widthBetweenSeconds * Time.time, 1, 1); //transform.anchoredPosition = Vector2.right * direction * widthBetweenSeconds * (Time.time - startTime); transform.anchoredPosition += Vector2.right * direction * widthBetweenSeconds * Time.deltaTime; @@ -68,7 +73,6 @@ void Update() { foreach (var second in secondsOnScreen) { - animate(second); second.rectTransform.anchoredPosition += Vector2.left * direction * widthBetweenSeconds * Time.deltaTime; var charOrigin = second.rectTransform.anchoredPosition.x; //In pixels @@ -108,27 +112,14 @@ void Update() void animate(Text second) { var currPos = second.rectTransform.position.x; - var offsetFromMidpoint = 150; - if (currPos < midpoint + offsetFromMidpoint && currPos > midpoint) + //10 percent of the screen + var offsetFromMidpoint = Screen.width / 10; + var tickPosition = transform.position.x; + if (currPos < tickPosition + offsetFromMidpoint && currPos > tickPosition - offsetFromMidpoint) { - var distanceFromMidpoint = currPos - midpoint; - var ratio = (offsetFromMidpoint - distanceFromMidpoint) / offsetFromMidpoint; - second.fontSize = 15 + (int)(ratio * 15); - //remove this - if (second.fontSize > 30) - second.fontSize = 30; - } - else if (currPos > midpoint - offsetFromMidpoint && currPos < midpoint) - { - //take abs - var distanceFromMidpoint = midpoint - currPos; + var distanceFromMidpoint = Mathf.Abs(currPos - tickPosition); var ratio = (offsetFromMidpoint - distanceFromMidpoint) / offsetFromMidpoint; second.fontSize = 15 + (int)(ratio * 15); } } -} - - -//current + scale* 15; -//015--------------|301 -// distance = x; \ No newline at end of file +} \ No newline at end of file