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.
99 lines
2.9 KiB
99 lines
2.9 KiB
8 years ago
|
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
|
||
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
|
||
9 years ago
|
|
||
9 years ago
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using System.Collections.Generic;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
8 years ago
|
/// Set the interactable state of selectable objects.
|
||
8 years ago
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("UI",
|
||
|
"Set Interactable",
|
||
|
"Set the interactable sate of selectable objects.")]
|
||
|
public class SetInteractable : Command
|
||
|
{
|
||
|
[Tooltip("List of objects to be affected by the command")]
|
||
8 years ago
|
[SerializeField] protected List<GameObject> targetObjects = new List<GameObject>();
|
||
9 years ago
|
|
||
8 years ago
|
[Tooltip("Controls if the selectable UI object be interactable or not")]
|
||
8 years ago
|
[SerializeField] protected BooleanData interactableState = new BooleanData(true);
|
||
9 years ago
|
|
||
8 years ago
|
public override void OnEnter()
|
||
|
{
|
||
|
if (targetObjects.Count == 0)
|
||
|
{
|
||
|
Continue();
|
||
|
return;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
foreach (GameObject targetObject in targetObjects)
|
||
|
{
|
||
|
foreach (Selectable selectable in targetObject.GetComponents<Selectable>())
|
||
|
{
|
||
|
selectable.interactable = interactableState.Value;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Continue();
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
public override string GetSummary()
|
||
|
{
|
||
|
if (targetObjects.Count == 0)
|
||
|
{
|
||
|
return "Error: No targetObjects selected";
|
||
|
}
|
||
|
else if (targetObjects.Count == 1)
|
||
|
{
|
||
|
if (targetObjects[0] == null)
|
||
|
{
|
||
|
return "Error: No targetObjects selected";
|
||
|
}
|
||
|
return targetObjects[0].name + " = " + interactableState.Value;
|
||
|
}
|
||
|
|
||
|
string objectList = "";
|
||
|
foreach (GameObject gameObject in targetObjects)
|
||
|
{
|
||
|
if (gameObject == null)
|
||
|
{
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
if (objectList == "")
|
||
|
{
|
||
|
objectList += gameObject.name;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
objectList += ", " + gameObject.name;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return objectList + " = " + interactableState.Value;
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(180, 250, 250, 255);
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
public override void OnCommandAdded(Block parentBlock)
|
||
|
{
|
||
|
targetObjects.Add(null);
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
public override bool IsReorderableArray(string propertyName)
|
||
|
{
|
||
|
if (propertyName == "targetObjects")
|
||
|
{
|
||
|
return true;
|
||
|
}
|
||
9 years ago
|
|
||
8 years ago
|
return false;
|
||
|
}
|
||
|
}
|
||
9 years ago
|
}
|