103 lines
4.0 KiB
C#
103 lines
4.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using System.Linq;
|
|
using UnityEngine.Events;
|
|
|
|
namespace InfallibleCode
|
|
{
|
|
public class BodyPartJointHole : MonoBehaviour, IInteractable
|
|
{
|
|
public Transform jointHolePosition;
|
|
public List<Transform> jointHolePos;
|
|
public string correctBodyPartKeyNameID;
|
|
public bool hasBodyPartInserted;
|
|
public bool hasCorrectBodyPartInserted;
|
|
public bool canTakeBodyPart = true;
|
|
KeyPickup bodyPartKeyPickup;
|
|
GameObject KeyModelForJointHole;
|
|
|
|
[Header("Events")]
|
|
public UnityEvent afterAttachOrDetachEvent;
|
|
|
|
public void Interact()
|
|
{
|
|
//If it's NOT already in the inventory menu:
|
|
switch (hasCorrectBodyPartInserted)
|
|
{
|
|
case false:
|
|
if (GameplayController.GetInstance().IsOnState(GameplayController.State.InventoryMenu) == false)
|
|
{
|
|
InventoryManager.GetInstance().OpenInventory();
|
|
//StartCoroutine(UpdateInteraction());
|
|
}
|
|
else
|
|
{
|
|
if (KeysManager.GetInstance().currentlySelectedKeyType == KeysManager.CurrentlySelectedKeyType.BodyPartKeyType)
|
|
{
|
|
//If it's in inventory menu and hits use to use the key joint item to interact:
|
|
KeysManager.GetInstance().currentlySelectedJointAndJointHoleMatch = true;
|
|
CheckBodyPartName();
|
|
print("Key type Matches!");
|
|
}
|
|
else
|
|
{
|
|
print("Key type is NOT matching!");
|
|
}
|
|
}
|
|
break;
|
|
case true:
|
|
|
|
break;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
private void CheckBodyPartName()
|
|
{
|
|
if(KeysManager.GetInstance().currentlySelectedInventoryKeyNameID == correctBodyPartKeyNameID)
|
|
{
|
|
hasCorrectBodyPartInserted = true;
|
|
}
|
|
else
|
|
{
|
|
hasCorrectBodyPartInserted = false;
|
|
}
|
|
PositionBodyPartKeyToJointHole();
|
|
hasBodyPartInserted = true;
|
|
}
|
|
|
|
public void PositionBodyPartKeyToJointHole()
|
|
{
|
|
Transform foundTransform = null;
|
|
KeyModelForJointHole = KeysManager.GetInstance().currentlySelectedKeyModelForKeyHole;
|
|
if (KeyModelForJointHole.TryGetComponent(out BodyPartKeyAdditional bodyPartKeyAdditional))
|
|
{
|
|
foundTransform = jointHolePos.FirstOrDefault(transform => transform.name == bodyPartKeyAdditional.bodyPartAttachPivotName);
|
|
KeyModelForJointHole.transform.position = foundTransform.position;
|
|
KeyModelForJointHole.transform.rotation = foundTransform.rotation;
|
|
KeyModelForJointHole.GetComponent<BodyPartKeyAdditional>().bodyPartJointHoleOfThisBodyPart = transform.GetComponent<BodyPartJointHole>();
|
|
}
|
|
Instantiate(KeyModelForJointHole, foundTransform.transform.position, foundTransform.rotation, foundTransform.transform);
|
|
|
|
KeysManager.GetInstance().currentlySelectedKeyModelForKeyHole = null;
|
|
KeyModelForJointHole = null;
|
|
|
|
afterAttachOrDetachEvent.Invoke();
|
|
|
|
//KeysManager.GetInstance().currentlySelectedKeyModelForKeyHole = null;
|
|
//KeysManager.GetInstance().currentlySelectedKeyModelForKeyHole.transform.position = jointHolePosition.position;
|
|
//KeysManager.GetInstance().currentlySelectedKeyModelForKeyHole.transform.rotation = jointHolePosition.rotation;
|
|
}
|
|
|
|
//IEnumerator UpdateInteraction()
|
|
//{
|
|
// while (GameplayController.GetInstance().IsOnState(GameplayController.State.InventoryMenu))
|
|
// {
|
|
|
|
// yield return null;
|
|
// }
|
|
//}
|
|
}
|
|
} |