Skip to content

fix new input system #20

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
24 changes: 11 additions & 13 deletions Assets/FancyTextRendering/Scripts/Links/TextLinkHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using JimmysUnityUtilities;
using JimmysUnityUtilities;
using System;
using TMPro;
using UnityEngine;
Expand All @@ -10,7 +10,7 @@ namespace LogicUI.FancyTextRendering
/// Allows links in TextMeshPro text objects to be clicked on, and gives them custom colors when they are hovered or clicked.
/// </summary>
[RequireComponent(typeof(TMP_Text))]
public class TextLinkHelper : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler
public class TextLinkHelper : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, IPointerMoveHandler
{
private TMP_Text _Text;
public TMP_Text Text
Expand All @@ -35,15 +35,15 @@ private void OnEnable()

// I'm not sure why the frame delay is necessary, but it is.
// I suspect that TMP changes the colors in LateUpdate or something
Dispatcher.EnsureInitialized();
CoroutineUtility.RunAfterOneFrame(SetAllLinksToNormalColor);
}

private void OnDisable()
{
HoverEnded();
}



[ColorUsage(showAlpha: false), SerializeField]
Color32 LinkNormalColor = new Color32(29, 124, 234, 255);

Expand All @@ -67,8 +67,7 @@ public void LinkDataUpdated()
previouslyHoveredLinkIndex = -1;
SetAllLinksToNormalColor();
}



public event Action<string> OnLinkClicked;

void IPointerClickHandler.OnPointerClick(PointerEventData eventData)
Expand All @@ -80,9 +79,7 @@ void IPointerClickHandler.OnPointerClick(PointerEventData eventData)
OnLinkClicked?.Invoke(link.GetLinkID());
}
}




void IPointerDownHandler.OnPointerDown(PointerEventData eventData)
{
PointerIsDown = true;
Expand All @@ -93,7 +90,7 @@ void IPointerUpHandler.OnPointerUp(PointerEventData eventData)
{
PointerIsDown = false;
SetLinkToColor(previouslyHoveredLinkIndex, LinkNormalColor);
previouslyHoveredLinkIndex = -1; // Reset the link hovered caching so that in Update() it's set back to the hovered color
previouslyHoveredLinkIndex = -1; // Reset the link hovered caching so that it's set back to the hovered color in the move event
}

void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
Expand All @@ -115,7 +112,8 @@ void IPointerExitHandler.OnPointerExit(PointerEventData eventData)

bool CurrentlyHoveredOver;
bool PointerIsDown;
void Update()

public void OnPointerMove(PointerEventData eventData)
{
if (!CurrentlyHoveredOver)
return;
Expand All @@ -124,7 +122,7 @@ void Update()
return;


int linkIndex = TMP_TextUtilities.FindIntersectingLink(Text, Input.mousePosition, cachedCamera);
int linkIndex = TMP_TextUtilities.FindIntersectingLink(Text, eventData.position, cachedCamera);
if (linkIndex < 0)
HoverEnded();
else
Expand Down Expand Up @@ -204,4 +202,4 @@ private void SetLinkToColor(int linkIndex, Color32 color)
Text.UpdateVertexData(TMP_VertexDataUpdateFlags.All);
}
}
}
}