FANDOM


This script allows you to display multiple Hotspot labels at the same time - one for each highlight Hotspot.  It works by using the Highlight component's On/Off events to control a copy of a Hotspot menu defined in the Menu Manager.

It is particularly useful when working with Touch Screen input in conjunction with Player Vicinity hotspot detection, since that involves nearby Hotspots highlighting without becoming selected.

Note that this requires AC v1.60.5 or newer.

First, create a Hotspot menu (or modify the default one) with both an Appear type and Position of On Hotspot.  To prevent it showing up normally as well, also check Start game locked off? (our copies will be unlocked through script).

Next, define a Highlight component for each Hotspot.  If you don't want the Highlight to have a visible effect on any mesh, uncheck Auto-brighten materials?.

Create a new C# script named MultiHotspotLabel, and attach it to each Highlight GameObject:

using UnityEngine;
using AC;

public class MultiHotspotLabel : MonoBehaviour
{

public Hotspot hotspotToShow;
public Highlight highlightToSync;

public string menuName = "Hotspot"; // The name of the Hotspot Menu to copy
private Menu myMenu; // Our own local Menu


private void OnEnable ()
{
// Attempt to auto-assign components if not set yet
if (highlightToSync == null)
{
highlightToSync = GetComponent <Highlight>();
hotspotToShow = GetComponent <Hotspot>();
}

// Add our own listeners to the Highlight component's onHighlightOn and onHighlightOff events
if (highlightToSync != null)
{
highlightToSync.callEvents = true;
highlightToSync.onHighlightOn.AddListener (ShowForHotspot);
highlightToSync.onHighlightOff.AddListener (Hide);
}
}


private void OnDisable ()
{
// Remove our own listeners from the Highlight component's onHighlightOn and onHighlightOff events
if (highlightToSync != null)
{
highlightToSync.onHighlightOn.RemoveListener (ShowForHotspot);
highlightToSync.onHighlightOff.RemoveListener (Hide);
}
}


private void ShowForHotspot ()
{
// Call this function to show a new Menu linked to the given Hotspot
if (myMenu == null)
{
// When run for the first time, create a new Menu and use the default Hotspot menu to copy from
Menu menuToCopy = PlayerMenus.GetMenuWithName (menuName);
myMenu = ScriptableObject.CreateInstance <Menu>();

myMenu.CreateDuplicate (menuToCopy); // Copy from the default Menu
myMenu.appearType = AppearType.Manual; // Set it to Manual so that we can control it easily
myMenu.isLocked = false; // Unlock it so that the default can remain locked if necessary
myMenu.SetHotspot (hotspotToShow, null); // Link it to the Hotspot
myMenu.title += this.name;
}

// Turn the menu on
myMenu.TurnOn ();

// Register with PlayerMenus to handle updating
KickStarter.playerMenus.RegisterCustomMenu (myMenu, true);
}


private void Hide ()
{
// Call this function to hide the Menu
if (myMenu != null)
{
myMenu.TurnOff ();
myMenu = null;
}
}

}

In its component Inspector (or by modifying the script), set the Menu Name value to the name of the Hotspot Menu listed in your Menu Manager that should be copied each time. The Hotspot To Show and Highlight To Sync values will also need to be assigned, but this is automatic if these components are already on the same GameObject as the above script.

When the game runs, the script will automatically add its own functions to the Highlight component's custom events.