You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
2.6 KiB
114 lines
2.6 KiB
10 years ago
|
using UnityEngine;
|
||
|
using UnityEngine.EventSystems;
|
||
|
using System;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
|
[CommandInfo("Dialog",
|
||
|
"Menu",
|
||
|
"Displays a multiple choice menu")]
|
||
|
[AddComponentMenu("")]
|
||
|
public class Menu : Command
|
||
|
{
|
||
|
|
||
|
// Menu displays a menu button which will execute the target sequence when clicked
|
||
|
// Menu Timeout executes a sequence if the timeout expires
|
||
|
// The 'Hide If Visited' option checks the execution count of the target sequence
|
||
|
// Hide Say dialog when finished? Let Say command handle that
|
||
|
// Can wrap in an If statement if you need a conditional option
|
||
|
|
||
10 years ago
|
public string text = "Option Text";
|
||
10 years ago
|
public Sequence targetSequence;
|
||
|
public bool hideIfVisited;
|
||
|
|
||
10 years ago
|
public MenuDialog setMenuDialog;
|
||
|
|
||
10 years ago
|
protected static bool eventSystemPresent;
|
||
|
|
||
|
public override void OnEnter()
|
||
|
{
|
||
|
CheckEventSystem();
|
||
|
|
||
10 years ago
|
if (setMenuDialog != null)
|
||
10 years ago
|
{
|
||
10 years ago
|
// Override the active menu dialog
|
||
|
MenuDialog.activeMenuDialog = setMenuDialog;
|
||
|
}
|
||
10 years ago
|
|
||
10 years ago
|
bool hideOption = (hideIfVisited && targetSequence != null && targetSequence.GetExecutionCount() > 0);
|
||
|
|
||
|
if (!hideOption)
|
||
|
{
|
||
|
MenuDialog menuDialog = MenuDialog.GetMenuDialog();
|
||
|
if (menuDialog != null)
|
||
10 years ago
|
{
|
||
10 years ago
|
menuDialog.gameObject.SetActive(true);
|
||
|
string displayText = text;
|
||
|
menuDialog.AddOption(displayText, targetSequence);
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
|
Continue();
|
||
|
}
|
||
|
|
||
|
// There must be an Event System in the scene for Menu input to work.
|
||
|
// This function will automatically instantiate one if none exists.
|
||
|
protected virtual void CheckEventSystem()
|
||
|
{
|
||
|
if (eventSystemPresent)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
EventSystem eventSystem = GameObject.FindObjectOfType<EventSystem>();
|
||
|
if (eventSystem == null)
|
||
|
{
|
||
|
// Auto spawn an Event System from the prefab
|
||
10 years ago
|
GameObject prefab = Resources.Load<GameObject>("EventSystem");
|
||
|
if (prefab != null)
|
||
10 years ago
|
{
|
||
10 years ago
|
GameObject go = Instantiate(prefab) as GameObject;
|
||
|
go.name = "EventSystem";
|
||
10 years ago
|
}
|
||
|
}
|
||
|
|
||
|
eventSystemPresent = true;
|
||
|
}
|
||
|
|
||
|
public override void GetConnectedSequences(ref List<Sequence> connectedSequences)
|
||
|
{
|
||
|
if (targetSequence != null)
|
||
|
{
|
||
|
connectedSequences.Add(targetSequence);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public override string GetSummary()
|
||
|
{
|
||
|
if (targetSequence == null)
|
||
|
{
|
||
|
return "Error: No target sequence selected";
|
||
|
}
|
||
|
|
||
|
if (text == "")
|
||
|
{
|
||
|
return "Error: No button text selected";
|
||
|
}
|
||
|
|
||
|
return text + " : " + targetSequence.sequenceName;
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(184, 210, 235, 255);
|
||
|
}
|
||
|
|
||
|
public override bool RunSlowInEditor()
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|