Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated the UI Ticker #348

Merged
merged 2 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 74 additions & 10 deletions Assets/Prefabs/UI/Layers/LayerUI.prefab

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 8 additions & 25 deletions Assets/Scripts/UI/Components/TextTicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,27 @@ void Awake()

void Start()
{
// Get initial widths and set initial position
UpdateWidths();
SetInitialPosition();

// You can call this method to start monitoring for width changes
StartMonitoringWidth();
}

private void SetInitialPosition()
{
childWidth = childRect.rect.width;
parentWidth = parentRect.rect.width;

if (childWidth > parentWidth)
{
childRect.anchoredPosition = new Vector2(0, childRect.anchoredPosition.y);
}
}

private void UpdateWidths()


public void CheckAndStartScrolling()
{
// Get widths of parent and child RectTransforms
childWidth = childRect.rect.width;
parentWidth = parentRect.rect.width;
}

// Start monitoring for width changes
public void StartMonitoringWidth()
{
UpdateWidths(); // Initial check
CheckAndStartScrolling(); // Check and start scrolling if necessary
}

// Example event trigger method to be called when needed
public void OnWidthChange() // Call this method when a width change occurs
{
Invoke("UpdateWidths",0.1f);
Invoke("CheckAndStartScrolling",0.1f);
}

private void CheckAndStartScrolling()
{
if (childWidth > parentWidth)
{
if (scrollingCoroutine == null)
Expand All @@ -78,6 +60,7 @@ private IEnumerator ScrollChild()
{
while (true)
{

Vector2 newPosition = childRect.anchoredPosition;
newPosition.x -= scrollSpeed * Time.deltaTime;

Expand All @@ -93,7 +76,7 @@ private IEnumerator ScrollChild()
}
}

private void StopScrolling()
public void StopScrolling()
{
if (scrollingCoroutine != null)
{
Expand Down
Loading