Adventure Creator Wikia
Register
(Initial post)
Tag: Visual edit
 
(Simpified script)
Tag: Visual edit
Line 14: Line 14:
 
{<br>
 
{<br>
 
<br>
 
<br>
    public string menuName = "Hotspot"; // The name of the Hotspot Menu to copy<br>
+
public string menuName = "Hotspot"; // The name of the Hotspot Menu to copy<br>
    private Menu myMenu; // Our own local Menu<br>
+
private Menu myMenu; // Our own local Menu<br>
 
<br>
 
<br>
 
<br>
 
<br>
    public void ShowForHotspot (Hotspot hotspot)<br>
+
public void ShowForHotspot (Hotspot hotspot)<br>
    {<br>
+
{<br>
        // Call this function to show a new Menu linked to the given Hotspot<br>
+
// Call this function to show a new Menu linked to the given Hotspot<br>
        if (myMenu == null)<br>
+
if (myMenu == null)<br>
        {<br>
+
{<br>
            // When run for the first time, create a new Menu and use the default Hotspot menu to copy from<br>
+
// When run for the first time, create a new Menu and use the default Hotspot menu to copy from<br>
            Menu menuToCopy = PlayerMenus.GetMenuWithName (menuName);<br>
+
Menu menuToCopy = PlayerMenus.GetMenuWithName (menuName);<br>
            myMenu = ScriptableObject.CreateInstance <Menu>();<br>
+
myMenu = ScriptableObject.CreateInstance <Menu>();<br>
 
<br>
 
<br>
            myMenu.CreateDuplicate (menuToCopy); // Copy from the default Menu<br>
+
myMenu.CreateDuplicate (menuToCopy); // Copy from the default Menu<br>
            myMenu.appearType = AppearType.Manual; // Set it to Manual so that we can control it easily<br>
+
myMenu.appearType = AppearType.Manual; // Set it to Manual so that we can control it easily<br>
            myMenu.isLocked = false; // Unlock it so that the default can remain locked if necessary<br>
+
myMenu.isLocked = false; // Unlock it so that the default can remain locked if necessary<br>
            myMenu.SetHotspot (hotspot, null); // Link it to the Hotspot<br>
+
myMenu.SetHotspot (hotspot, null); // Link it to the Hotspot<br>
  +
myMenu.title += this.name;<br>
        }<br>
 
 
}<br>
 
<br>
 
<br>
        // Turn the menu on<br>
+
// Turn the menu on<br>
        myMenu.TurnOn ();<br>
+
myMenu.TurnOn ();<br>
    }<br>
 
 
<br>
 
<br>
  +
// Register with PlayerMenus to handle updating<br>
 
KickStarter.playerMenus.RegisterCustomMenu (myMenu, true);<br>
 
}<br>
 
<br>
 
<br>
    public void Hide ()<br>
 
    {<br>
 
        // Call this function to hide the Menu<br>
 
        if (myMenu != null)<br>
 
        {<br>
 
            myMenu.TurnOff ();<br>
 
        }<br>
 
    }<br>
 
 
<br>
 
<br>
 
public void Hide ()<br>
<br>
 
 
{<br>
    private void Update ()<br>
 
 
// Call this function to hide the Menu<br>
    {<br>
 
 
if (myMenu != null)<br>
        // Update the Menu every frame<br>
 
 
{<br>
        if (myMenu != null)<br>
 
 
myMenu.TurnOff ();<br>
        {<br>
 
 
myMenu = null;<br>
            KickStarter.playerMenus.UpdateMenu (myMenu);<br>
 
        }<br>
+
}<br>
    }<br>
+
}<br>
<br>
 
<br>
 
    private void OnGUI ()<br>
 
    {<br>
 
        // Draw the Menu every OnGUI cycle.  This is not necessary if it is rendered with Unity UI.<br>
 
        if (myMenu != null && myMenu.menuSource == MenuSource.AdventureCreator)<br>
 
        {<br>
 
            KickStarter.playerMenus.DrawMenu (myMenu, 0);<br>
 
        }<br>
 
    }<br>
 
 
<br>
 
<br>
 
}
 
}
 
 
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.
 
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.
   

Revision as of 06:16, 26 April 2018

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.

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 string menuName = "Hotspot"; // The name of the Hotspot Menu to copy
private Menu myMenu; // Our own local Menu


public void ShowForHotspot (Hotspot hotspot)
{
// 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 (hotspot, 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);
}


public 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.

Back in each Highlight component, check Call custom events? and create new events for both the On Highlight On and On Highlight Off events.  On Highlight On should invoke its associated MultiHotspotLabel's ShowForHotspot method (setting the Hotspot parameter as appropriate), and On Highlight Off should invoke its Hide method.