Adventure Creator Wikia
Advertisement

When Menus are directly-controlled, elements are selected automatically when they turn on. As this is a property set in the Menu Manager, the same element will always be selected each time.

This script alters the behaviour of Conversation menus, so that the last-chosen option is selected automatically when re-shown. To use it:

  1. Create a new C# file named ReselectLastDialogueOption, and copy/paste in the code below.
  2. Attach the new Reselect Last Dialogue Option component to a GameObject in the scene.
  3. Update the Inspector fields with the name of your Conversation menu, and DialogueList element, if they differ from what's shown.

ReselectLastDialogueOption.cs:

using System.Collections.Generic;
using UnityEngine;
using AC;

public class ReselectLastDialogueOption : MonoBehaviour
{

	public string menuName = "Conversation";
	public string elementName = "DialogueList";
	private Dictionary<Conversation, int> lastChosenDict = new Dictionary<Conversation, int> ();

	void OnEnable ()
	{
		EventManager.OnClickConversation += OnClickConversation;
		EventManager.OnMenuTurnOn += OnMenuTurnOn;
	}

	void OnDisable ()
	{
		EventManager.OnClickConversation -= OnClickConversation;
		EventManager.OnMenuTurnOn -= OnMenuTurnOn;
	}

	void OnClickConversation (Conversation conversation, int optionID)
	{
		if (lastChosenDict.ContainsKey (conversation))
		{
			lastChosenDict[conversation] = optionID;
		}
		else
		{
			lastChosenDict.Add (conversation, optionID);
		}
	}

	void OnMenuTurnOn (Menu menu, bool isInstant)
	{
		if (menu.title != menuName) return;

		Conversation conversation = KickStarter.playerInput.activeConversation;
		if (conversation == null || !lastChosenDict.ContainsKey (conversation)) return;

		int optionID = lastChosenDict[conversation];

		ButtonDialog lastChosenOption = KickStarter.playerInput.activeConversation.GetOptionWithID (optionID);
		if (lastChosenOption == null || !lastChosenOption.isOn) return;

		MenuDialogList dialogList = menu.GetElementWithName (elementName) as MenuDialogList;
		for (int i = 0; i < dialogList.GetNumSlots (); i++)
		{
			if (dialogList.GetDialogueOption (i) == lastChosenOption)
			{
				menu.Select (dialogList, i);
				return;
			}
		}
	}
	
}
Advertisement