Refresh Usable Text
-
- Posts: 113
- Joined: Sun Sep 20, 2020 8:21 pm
Refresh Usable Text
Hi Tony! Hope you're doing well.
I'd like to update the Name and UseMessage for a Usable through code and have it update live on-screen. I know how to change the text, but it only updates when the player walks away from the game object and goes back to it. Is there a way to refresh the UI without leaving the collider box? I've tried a few things, but none of them seem to be working.
Thanks as always!
I'd like to update the Name and UseMessage for a Usable through code and have it update live on-screen. I know how to change the text, but it only updates when the player walks away from the game object and goes back to it. Is there a way to refresh the UI without leaving the collider box? I've tried a few things, but none of them seem to be working.
Thanks as always!
Re: Refresh Usable Text
Hi,
Disable and re-enable the Selector or Proximity Selector. It'll refresh the display.
Disable and re-enable the Selector or Proximity Selector. It'll refresh the display.
-
- Posts: 113
- Joined: Sun Sep 20, 2020 8:21 pm
Re: Refresh Usable Text
I did that and it didn't work, and then I put it in a coroutine to wait for the frame and it didn't work. Am I missing something?
Re: Refresh Usable Text
Hi,
Does the GameObject that has the Selector/ProximitySelector have a SelectorUIStandardUIElements component?
If not, then it's using the default IMGUI method to display the usable text. If this is the case and you don't want to switch to ,SelectorUIStandardUIElements, let me know.
Does the GameObject that has the Selector/ProximitySelector have a SelectorUIStandardUIElements component?
If not, then it's using the default IMGUI method to display the usable text. If this is the case and you don't want to switch to ,SelectorUIStandardUIElements, let me know.
-
- Posts: 113
- Joined: Sun Sep 20, 2020 8:21 pm
Re: Refresh Usable Text
Morning Tony - yes, the gameobject does have the SelectorUIStandardUIElements component on it.
Re: Refresh Usable Text
Hi,
Here's an example scene:
DS_UpdateUsableTextExample_2023-11-16.unitypackage
It's DemoScene1, but if you press [F1] while targeting Private Hart, it will change his usable UI name.
Here's an example scene:
DS_UpdateUsableTextExample_2023-11-16.unitypackage
It's DemoScene1, but if you press [F1] while targeting Private Hart, it will change his usable UI name.
-
- Posts: 113
- Joined: Sun Sep 20, 2020 8:21 pm
Re: Refresh Usable Text
Thanks for the example Tony - that's basically exactly what I tried, however, I'm using a somewhat custom version of ProximitySelector, not Selector. Not sure if that makes a difference. Here is my custom class:
Code: Select all
namespace PixelCrushers.DialogueSystem
{
[AddComponentMenu("")] // Use wrapper.
public class ProximitySelectorES : ProximitySelector
{
public Usable lastUsable;
private Animator selectorAnim;
private void Start()
{
selectorAnim = GameObject.Find("Basic Standard UI Selector Elements 1").GetComponent<Animator>();
}
void OnDisable()
{
if (currentUsable != null)
{
lastUsable = currentUsable;
currentUsable.enabled = false;
selectorAnim.SetTrigger("Hide");
//currentUsable.OnDeselectUsable();
}
}
void OnEnable()
{
if (lastUsable != null && lastUsable.gameObject.activeInHierarchy)
{
//Check NPC indicator status before turning UsableES back on
if (lastUsable.GetComponent<DialogueActor>() != null)
{
if (lastUsable.GetComponentInChildren<IndicatorManager>().npcIndicatorState != NPCIndicatorState.None)
{
lastUsable.enabled = true;
selectorAnim.SetTrigger("Show");
}
}
else
{
lastUsable.enabled = true;
selectorAnim.SetTrigger("Show");
}
}
if(usablesInRange.Count == 0 && selectorAnim != null)
{
selectorAnim.SetTrigger("Hide");
}
//if (currentUsable != null) currentUsable.enabled = true; //OnSelectUsable();
}
public void ClearUsable()
{
currentUsable = null;
lastUsable = null;
}
/// <summary>
/// Calls OnUse on the current selection.
/// </summary>
public override void UseCurrentSelection()
{
//Check priority of Usable and pick the highest number
int tempUsable = 0;
foreach (var usable in usablesInRange)
{
if (usable.GetComponent<UsableES>() != null)
{
if (usable.GetComponent<UsableES>().priority > tempUsable)
{
tempUsable = usable.GetComponent<UsableES>().priority;
currentUsable = usable.GetComponent<UsableES>();
}
}
}
base.UseCurrentSelection();
}
protected override void CheckTriggerEnter(GameObject other)
{
if (other.GetComponent<UsableES>() != null)
{
if (currentUsable == null)
{
base.CheckTriggerEnter(other);
}
else
{
if (other.GetComponent<UsableES>().priority > currentUsable.GetComponent<UsableES>().priority)
{
base.CheckTriggerEnter(other);
}
}
}
}
protected override void OnUsableDisabled(Usable usable)
{
}
}
}
Re: Refresh Usable Text
Hi,
In your overridden OnEnable() and OnDisable() methods, call the base methods:
In your overridden OnEnable() and OnDisable() methods, call the base methods:
Code: Select all
void OnDisable()
{
base.OnDisable();
if (currentUsable != null) ...
}
void OnEnable()
{
base.OnEnable();
if (lastUsable != null && lastUsable.gameObject.activeInHierarchy) ...
-
- Posts: 113
- Joined: Sun Sep 20, 2020 8:21 pm
Re: Refresh Usable Text
ProximitySelector.cs doesn't have an OnEnable or OnDisable method. I'm on version 2.2.30.
Am I missing something?
Am I missing something?
Re: Refresh Usable Text
I believe it was added in 2.2.33. Can you back up your project and update to the current version?