Adventure Creator is a hefty framework and another big tool to learn, but it's really handy for the tasks you asked about. The Dialogue System has pretty good Adventure Creator integration, too. It's still possible to do this without Adventure Creator, of course, but it requires some scripting. The first one's pretty easy, but most of the work of the second one is outside of the Dialogue System's scope and will require more code.
To change the cursor, hook into the Selector's OnSelectedUsable() and OnDeselectedUsable() UnityEvents, or the SelectedUsableObject and DeselectedUsableObject C# events. For example, add this script to the Usable object:
UsableCursor.cs
Code: Select all
using UnityEngine;
public class UsableCursor : MonoBehaviour
{
public Texture2D cursor;
public Vector2 hotspot = Vector2.zero;
public CursorMode cursorMode = CursorMode.Auto;
}
And this script on the GameObject (e.g., player) that has the Selector:
SelectorCursor.cs
Code: Select all
using UnityEngine;
using PixelCrushers.DialogueSystem;
[RequireComponent(typeof(Selector))]
public class SelectorCursor : MonoBehaviour
{
public Texture2D defaultCursor;
public Vector2 hotspot = Vector2.zero;
public CursorMode cursorMode = CursorMode.Auto;
private void Start()
{
Cursor.SetCursor(defaultCursor, hotspot, cursorMode);
}
void OnEnable()
{
var selector = GetComponent<Selector>();
selector.SelectedUsableObject += OnSelectedUsable;
selector.DeselectedUsableObject += OnDeselectedUsable;
}
void OnDisable()
{
var selector = GetComponent<Selector>();
selector.SelectedUsableObject -= OnSelectedUsable;
selector.DeselectedUsableObject -= OnDeselectedUsable;
}
private void OnSelectedUsable(Usable usable)
{
var usableCursor = usable.GetComponent<UsableCursor>();
if (usableCursor != null)
{
Cursor.SetCursor(usableCursor.cursor, usableCursor.hotspot, usableCursor.cursorMode);
}
}
private void OnDeselectedUsable(Usable usable)
{
Cursor.SetCursor(defaultCursor, hotspot, cursorMode);
}
}
If you want to use two different cursors for a Usable target -- one when it's in range, one when it's too far to use -- then you can add two cursor variables to UsableCursor.cs. In SelectorCursor, add an Update method or coroutine to OnSelectedUsable that checks if the selector's CurrentDistance is under the usable's maxUseDistance.
To register a click when too far away, hook into the TooFarEvent() UnityEvent. You can use UnityEvent.AddListener to hook into this in a C# script if you don't want to assign it in the inspector. Your code that handles this event is responsible for moving the player within range and then sending OnUse to the usable:
Code: Select all
usable.SendMessage("OnUse", player.transform);