private void ListenInteraction() { // MISE A JOUR DE LA SELECTION // On cherche l'objet intéractif le plus proche float distanceMin = float.PositiveInfinity; GameObject nearest = null; foreach (GameObject go in actionsInRange) { float distance = (go.transform.position - transform.position).magnitude; if (distance < distanceMin) { distanceMin = distance; nearest = go; } } // On désélectionne l'objet sélectionné auparavant if (selection != null) { selection.GetComponent <Interactable>().Deselect(); } selection = nearest; // Si l'interactive le plus proche a une action disponible, alors on la selectionne if (nearest != null) { Interactable interactive = selection.GetComponent <Interactable>(); interactive.Select(); } // ECOUTE DE L'INTERACTION if (selection != null) { if (inputManager.GetButtonDown("Interact") && canMove) { if (currentPopup != null) { currentPopup.Hide(); } // Start interaction Interactable script = selection.GetComponent <Interactable>(); if (script is ChoicesSenderBehaviour) { ChoicesSenderBehaviour iObj = script as ChoicesSenderBehaviour; currentPopup = choicePopup; choicePopup.SetChoices(iObj.GetChoices(this)); } else if (script is QTEBehaviour) { UserAction action = (script as QTEBehaviour).GetAction(this); if (action == null) { return; } if (!(action is ComboAction)) { action.DoAction(); } currentPopup = QTEPopup; QTEPopup.SetAction(action); } // Set static player canMove = false; _animator.SetBool("IsWalkingUp", false); _animator.SetBool("IsWalkingRight", false); _animator.SetBool("IsWalkingDown", false); _animator.SetBool("IsWalkingLeft", false); _animator.SetBool("IsRunningLeft", false); _animator.SetBool("IsRunningRight", false); if (currentPopup != null) { // Display popup currentPopup.Display(); currentPopup.onClose.RemoveAllListeners(); currentPopup.onClose.AddListener(() => { canMove = true; currentPopup = null; }); } else { canMove = true; } } else if (inputManager.GetButtonDown("Cancel")) { HideCurrentPopup(); } else if (currentPopup == null || currentPopup == LabelPopup) { string text = selection.GetComponent <Interactable>().GetDecription(this); if (string.IsNullOrWhiteSpace(text)) { if (currentPopup != null) { HideCurrentPopup(); } return; } LabelPopup.SetText(text); if (currentPopup == null) { LabelPopup.Display(); } currentPopup = LabelPopup; } } else if (currentPopup != null) { HideCurrentPopup(); } }
public void HideCurrentPopup() { currentPopup.Hide(); currentPopup = null; }