This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
project-undercover/Project Undercover/Assets/Scripts/UI/InteractionPanelController.cs

115 lines
3.1 KiB
C#
Raw Permalink Normal View History

2017-10-03 04:15:13 -05:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class InteractionPanelController : MonoBehaviour {
// One choice vars
[SerializeField]
GameObject oneChoicePanel;
[SerializeField]
InteractionButtonProperties interactionButton;
// two choices vars
[SerializeField]
GameObject choicePanel;
[SerializeField]
InteractionButtonProperties spyButton;
[SerializeField]
InteractionButtonProperties npcButton;
2017-10-03 04:15:13 -05:00
private static InteractionPanelController activePanel;
private StateController _controller;
2017-10-03 04:15:13 -05:00
void Start()
{
ActivePanel = this;
Hide();
}
public void SelectInteractionReveal(StateController controller)
2017-10-03 04:15:13 -05:00
{
_controller = controller;
if (oneChoicePanel.activeInHierarchy || choicePanel.activeInHierarchy)
return;
2017-10-10 12:43:11 -05:00
int randomInt = (int)(Random.value * controller.SelectedObject.interactions.Length);
Interaction randomNpcInteraction = controller.SelectedObject.interactions[randomInt];
if (controller.SelectedObject.spyInteractions.Length == 0)
{
oneChoicePanel.SetActive(true);
interactionButton.SetInteraction(randomNpcInteraction);
}
else
{
choicePanel.SetActive(true);
Interaction spyInteraction = controller.SelectedObject.spyInteractions[0];
spyButton.SetInteraction(spyInteraction);
npcButton.SetInteraction(randomNpcInteraction);
}
}
public void AcceptInteractionReveal(StateController controller)
{
_controller = controller;
oneChoicePanel.SetActive(true);
choicePanel.SetActive(false);
string description = controller.Interactor.SelectedInteraction.receiverDescription;
interactionButton.text.text = description;
interactionButton.SetInteraction(controller.Interactor.SelectedInteraction);
}
public void Hide()
2017-10-03 04:15:13 -05:00
{
choicePanel.SetActive(false);
oneChoicePanel.SetActive(false);
2017-10-03 04:15:13 -05:00
}
public static InteractionPanelController ActivePanel
{
get
{
if (activePanel)
return activePanel;
Debug.LogError("No interaction panels in scene");
return null;
}
set
{
if (!activePanel)
activePanel = value;
else
{
Debug.LogError("More than one interaction panel currently exists in the scene");
}
}
}
public static bool InteractionPrompted()
{
return ActivePanel.choicePanel.activeInHierarchy || ActivePanel.oneChoicePanel.activeInHierarchy;
}
public void SetInteraction(Interaction interaction)
{
_controller.SelectedInteraction = interaction;
}
/*
public bool WasInteractionInitiated()
{
if (_initiatedInteraction)
{
_initiatedInteraction = false;
return _initiatedInteraction;
}
return false;
}
public void InitiatedInteraction()
{
_initiatedInteraction = true;
}*/
2017-10-03 04:15:13 -05:00
}