113 lines
3.1 KiB
C#
113 lines
3.1 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.Localization;
|
|
|
|
public class ExaminableItemInputEvent : MonoBehaviour
|
|
{
|
|
[SerializeField] UnityEvent unityEventToTrigger;
|
|
|
|
[Header("Key to Press")]
|
|
public KeyCode keyboardKey;
|
|
public KeyCode ControllerKey;
|
|
|
|
public bool DoOnce;
|
|
[HideInInspector] public bool invokedOnce;
|
|
|
|
[HideInInspector] public bool isOnTrigger;
|
|
|
|
[Header("UI")]
|
|
private bool shouldUpdateButtonPrompt = true;
|
|
[SerializeField] private string keyboardInteractionUIPrompt;
|
|
[SerializeField] private string xboxControllerInteractionUIPrompt;
|
|
|
|
public LocalizedString localizedPCUI;
|
|
public LocalizedString localizedXBOXUI;
|
|
|
|
private void OnEnable()
|
|
{
|
|
shouldUpdateButtonPrompt = true;
|
|
}
|
|
|
|
//private void OnTriggerEnter(Collider other)
|
|
//{
|
|
// if (other.gameObject.CompareTag("Player"))
|
|
// {
|
|
// isOnTrigger = true;
|
|
// StartCoroutine(UpdateInput());
|
|
// }
|
|
//}
|
|
|
|
//private void OnTriggerExit(Collider other)
|
|
//{
|
|
// if (other.gameObject.CompareTag("Player"))
|
|
// {
|
|
// isOnTrigger = false;
|
|
// InteractionManager.GetInstance().HideInteractionUIButtonOnlyCanvas();
|
|
// }
|
|
//}
|
|
|
|
public void UpdateEventInput()
|
|
{
|
|
isOnTrigger = true;
|
|
if (invokedOnce == false)
|
|
{
|
|
StartCoroutine(UpdateInput());
|
|
}
|
|
}
|
|
|
|
public void StopUpdatingEventInput()
|
|
{
|
|
ExaminableItemData.GetInstance().CleanItemInteractionMessage();
|
|
isOnTrigger = false;
|
|
}
|
|
|
|
IEnumerator UpdateInput()
|
|
{
|
|
while (isOnTrigger)
|
|
{
|
|
if (shouldUpdateButtonPrompt)
|
|
{
|
|
//InteractionManager.GetInstance().DisplayInteractionUIButtonOnlyCanvas(keyboardInteractionUIPrompt, xboxControllerInteractionUIPrompt);
|
|
if (InputControlManager.Getinstance().IsUsingJoystick == false)
|
|
{
|
|
ExaminableItemData.GetInstance().DisplayItemInteractionMessage(localizedPCUI);
|
|
}
|
|
else
|
|
{
|
|
ExaminableItemData.GetInstance().DisplayItemInteractionMessage(localizedXBOXUI);
|
|
}
|
|
}
|
|
if (Input.GetKeyDown(keyboardKey) || Input.GetKeyDown(ControllerKey))
|
|
{
|
|
InvokeEvent();
|
|
}
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
public void InvokeEvent()
|
|
{
|
|
if (!invokedOnce)
|
|
{
|
|
unityEventToTrigger.Invoke();
|
|
if (DoOnce)
|
|
{
|
|
//InteractionManager.GetInstance().HideInteractionUIButtonOnlyCanvas();
|
|
StopUpdatingEventInput();
|
|
print("Did event once");
|
|
invokedOnce = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
///// <summary>
|
|
///// Call from unityEvents if you have to.
|
|
///// </summary>
|
|
//public void HideInteractionUI()
|
|
//{
|
|
// InteractionManager.GetInstance().HideInteractionUIButtonOnlyCanvas();
|
|
//}
|
|
}
|