294 lines
13 KiB
C#
294 lines
13 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Localization;
|
|
|
|
namespace InfallibleCode
|
|
{
|
|
public class ExaminableItem : MonoBehaviour, IInteractable
|
|
{
|
|
public ExamineItem examineItem;
|
|
//public Transform ItemDefaultPosition;
|
|
|
|
//public bool CanInteractWithInteractableItem;
|
|
#region DoAction Accessibility
|
|
[Tooltip("Accesible from ExaminableItemDoAction script")]
|
|
[HideInInspector] public bool HasInteractedWithItem;
|
|
[HideInInspector] public bool IsInteractingWithItem;
|
|
#endregion
|
|
|
|
public ExaminableItemScaler examinableItemScaler;
|
|
public ExaminableItemInputEvent examinableItemInputEvent;
|
|
public ExaminableItemRegularEvent examinableItemRegularEvent;
|
|
|
|
//Maybe?
|
|
public CollectibleEntry examinableItemCollectibleEntry;
|
|
|
|
public Quaternion transformItem3DPOS;
|
|
|
|
void Start()
|
|
{
|
|
if(examineItem._item3dToExam == null)
|
|
{
|
|
examineItem._item3dToExam = transform.gameObject;
|
|
}
|
|
|
|
if(examineItem._item3dToExam.transform.parent != null)
|
|
{
|
|
examineItem.ItemHasParent = true;
|
|
examineItem._item3DParent = examineItem._item3dToExam.transform.parent;
|
|
//transformItem3DPOS = Quaternion.Euler(examineItem._item3dToExam.transform.localRotation.x, examineItem._item3dToExam.transform.localRotation.y, examineItem._item3dToExam.transform.localRotation.z);
|
|
}
|
|
else
|
|
{
|
|
examineItem._item3DParent = null;
|
|
//transformItem3DPOS = new Quaternion(examineItem._item3dToExam.transform.localRotation.x, examineItem._item3dToExam.transform.localRotation.y, examineItem._item3dToExam.transform.localRotation.z, 0f);
|
|
}
|
|
|
|
examineItem._Item3DDefaultPos = new Vector3(examineItem._item3dToExam.transform.localPosition.x, examineItem._item3dToExam.transform.localPosition.y, examineItem._item3dToExam.transform.localPosition.z);
|
|
//examineItem._Item3DDefaultPos = new Vector3(examineItem._item3dToExam.transform.localEulerAngles.x, examineItem._item3dToExam.transform.localEulerAngles.y, examineItem._item3dToExam.transform.localEulerAngles.z);
|
|
//float item3DDefaultPosX = examineItem._Item3DDefaultPos.x;
|
|
//float item3DDefaultPosY = examineItem._Item3DDefaultPos.y;
|
|
//float item3DDefaultPosZ = examineItem._Item3DDefaultPos.z;
|
|
transformItem3DPOS = new Quaternion(examineItem._item3dToExam.transform.localRotation.x, examineItem._item3dToExam.transform.localRotation.y, examineItem._item3dToExam.transform.localRotation.z, examineItem._item3dToExam.transform.localRotation.w);
|
|
|
|
//// Store the original renderingLayerMask value
|
|
//if (examineItem._item3dToExam.GetComponent<Renderer>() != null)
|
|
//{
|
|
// examineItem.originalRenderingLayerMask = (int)examineItem._item3dToExam.GetComponent<Renderer>().renderingLayerMask;
|
|
//}
|
|
//else
|
|
//{
|
|
// foreach (Renderer itemsRenderers in examineItem._item3dToExam.GetComponents<Renderer>())
|
|
// {
|
|
// examineItem.originalRenderingLayerMask = (int)itemsRenderers.renderingLayerMask;
|
|
// }
|
|
//}
|
|
|
|
if (TryGetComponent<ExaminableItemScaler>(out ExaminableItemScaler examinableItemScaler))
|
|
{
|
|
this.examinableItemScaler = examinableItemScaler;
|
|
this.examinableItemScaler.itemOriginalScale = examineItem._item3dToExam.transform.localScale;
|
|
}
|
|
|
|
if(TryGetComponent<ExaminableItemInputEvent>(out ExaminableItemInputEvent examinableItemEvent))
|
|
{
|
|
this.examinableItemInputEvent = examinableItemEvent;
|
|
}
|
|
|
|
if (TryGetComponent<ExaminableItemRegularEvent>(out ExaminableItemRegularEvent examinableItemRegularEvent))
|
|
{
|
|
this.examinableItemRegularEvent = examinableItemRegularEvent;
|
|
}
|
|
|
|
if (TryGetComponent<CollectibleEntry>(out CollectibleEntry examinableItemCollectibleEntry))
|
|
{
|
|
this.examinableItemCollectibleEntry = examinableItemCollectibleEntry;
|
|
}
|
|
|
|
}
|
|
|
|
public void AddExaminableItemInputEvent(ExaminableItemInputEvent examinableItemInputEventToAdd)
|
|
{
|
|
examinableItemInputEvent = examinableItemInputEventToAdd;
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
#region No Interface
|
|
//UpdateInteractableItem();
|
|
#endregion
|
|
|
|
if (examineItem.CurrenltyExaminingObj) //If is currently examining item:
|
|
{
|
|
examineItem.ItemRotation(); //You can rotate the item.
|
|
}
|
|
if (examineItem.IsExitingItemExamination) //If is exiting the examination:
|
|
{
|
|
IEnumerator lerpItemInCamera = LerpItemInCamera();
|
|
StopAllCoroutines();
|
|
StartCoroutine(LerpItemInDefaultPlace());
|
|
Debug.Log("AHA!");
|
|
|
|
HasInteractedWithItem = true; //for DoAction In script: "ExaminableItemDoAction" if used.
|
|
IsInteractingWithItem = false;
|
|
}
|
|
}
|
|
|
|
public void UpdateInteractableItem()
|
|
{
|
|
if (examineItem.CanExamineObject)
|
|
{
|
|
#region No Interface
|
|
//if (ExaminableItemData.GetInstance().CanInteractWithInteractableItem)
|
|
//{
|
|
|
|
//}
|
|
//CanInteractWithInteractableItem = true;
|
|
#endregion
|
|
print("UpdateInteractable item");
|
|
examineItem.CurrenltyExaminingObj = true; //Sets the bool to true for the game to know that you examine an object now.
|
|
IsInteractingWithItem = true;
|
|
examineItem.DisplayItem3D();
|
|
StopAllCoroutines();
|
|
StartCoroutine(LerpItemInCamera());
|
|
if (examineItem.CanGetItem) //If you can get the item you are examining:
|
|
{
|
|
UpdateInputToGetItem(); //Starts coroutine to let you press the button to get the item.
|
|
}
|
|
}
|
|
}
|
|
|
|
public void UpdateInputToGetItem()
|
|
{
|
|
examineItem.CanGetItem = true;
|
|
|
|
#region UI Can Get Item
|
|
ExaminableItemData.GetInstance().pressEToGetItemUI.SetActive(true);
|
|
Debug.Log("Press E to get item");
|
|
#endregion
|
|
|
|
StartCoroutine(CanPressButtonDownToGetItemTRUE()); //Starts coroutine to let you press the button to get the item.
|
|
}
|
|
|
|
IEnumerator UpdateInputForGettingItem()
|
|
{
|
|
while (examineItem.CanPressButtonToGetItem && examineItem.CurrenltyExaminingObj)
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.E) || Input.GetKeyDown(KeyCode.JoystickButton0))
|
|
{
|
|
//_canPressButtonDown = false;
|
|
StartCoroutine(PickingUpObject());
|
|
examineItem.CanPressButtonToGetItem = false;
|
|
}
|
|
yield return null;
|
|
}
|
|
}
|
|
|
|
IEnumerator PickingUpObject()
|
|
{
|
|
examineItem._item3dToExam.transform.GetComponent<PickupInventoryItem>().ItemPickup();
|
|
print("kalamaris");
|
|
yield return new WaitForSecondsRealtime(0.1f);
|
|
UIManager.GetInstance().userInterfaceIsOnScreen = false;
|
|
examineItem.GotItemExitDisplayingItem3d();
|
|
//yield return new WaitForSecondsRealtime(0.1f);
|
|
print("got item");
|
|
Destroy(gameObject);
|
|
}
|
|
|
|
public IEnumerator CanPressButtonDownToGetItemTRUE()
|
|
{
|
|
yield return new WaitForSecondsRealtime(0.5f);
|
|
examineItem.CanPressButtonToGetItem = true;
|
|
StartCoroutine(UpdateInputForGettingItem());
|
|
}
|
|
|
|
public IEnumerator LerpItemInCamera()
|
|
{
|
|
if (examinableItemCollectibleEntry != null)
|
|
{
|
|
examinableItemCollectibleEntry.DisplayEntryText();
|
|
}
|
|
examineItem.CanPressButton = false;
|
|
examineItem._item3dToExam.transform.parent = ExaminableItemData.GetInstance().ItemsExaminationPos.transform;
|
|
yield return new WaitForSecondsRealtime(0.1f);
|
|
examineItem.CanPressButton = true;
|
|
while (examineItem._lerpItem <= 1.0f)
|
|
{
|
|
examineItem._lerpItem += 0.8f * Time.unscaledDeltaTime;
|
|
examineItem._item3dToExam.transform.localPosition = Vector3.Lerp(examineItem._item3dToExam.transform.localPosition, ExaminableItemData.GetInstance().ItemLerpPosition.localPosition, examineItem._lerpItem);
|
|
examineItem._item3dToExam.transform.rotation = Quaternion.Lerp(examineItem._item3dToExam.transform.rotation, ExaminableItemData.GetInstance().ItemLerpPosition.rotation, examineItem._lerpItem);
|
|
|
|
//ItemScale if needed:
|
|
if(examinableItemScaler != null)
|
|
{
|
|
examineItem._item3dToExam.transform.localScale = Vector3.Lerp(examineItem._item3dToExam.transform.localScale, examinableItemScaler.itemScaleInFrontOfCamera, examineItem._lerpItem);
|
|
}
|
|
|
|
//DrawerIsOpen = true;
|
|
Debug.Log("Is lerping item in front of camera");
|
|
yield return null;
|
|
}
|
|
if(examinableItemInputEvent != null)
|
|
{
|
|
examinableItemInputEvent.UpdateEventInput();
|
|
}
|
|
if(examinableItemRegularEvent != null)
|
|
{
|
|
examinableItemRegularEvent.InvokeWhenStartExamining();
|
|
}
|
|
yield return null;
|
|
}
|
|
|
|
public IEnumerator LerpItemInDefaultPlace()
|
|
{
|
|
examineItem.IsExitingItemExamination = false;
|
|
if (examineItem.ItemHasParent)
|
|
{
|
|
examineItem._item3dToExam.transform.parent = examineItem._item3DParent;
|
|
Debug.Log("PWWWWWWWWW");
|
|
}
|
|
else
|
|
{
|
|
examineItem._item3dToExam.transform.parent = null;
|
|
}
|
|
if (examinableItemInputEvent != null)
|
|
{
|
|
examinableItemInputEvent.StopUpdatingEventInput();
|
|
}
|
|
if (examinableItemRegularEvent != null)
|
|
{
|
|
examinableItemRegularEvent.InvokeWhenStopExamining();
|
|
}
|
|
yield return new WaitForSeconds(0.1f);
|
|
UIManager.GetInstance().userInterfaceIsOnScreen = false;
|
|
//ExaminableItemData.GetInstance().ExamineCamera.SetActive(false);
|
|
while (examineItem._lerpItem <= 1.0f)
|
|
{
|
|
examineItem._lerpItem += 0.8f * Time.deltaTime;
|
|
examineItem._item3dToExam.transform.localPosition = Vector3.Lerp(examineItem._item3dToExam.transform.localPosition, examineItem._Item3DDefaultPos /*ItemDefaultPosition.localPosition*/, examineItem._lerpItem);
|
|
//examineItem._item3dToExam.transform.localEulerAngles = Vector3.Lerp(examineItem._item3dToExam.transform.localEulerAngles, IDKENTAKSI.localEulerAngles, examineItem._lerpItem);
|
|
examineItem._item3dToExam.transform.localRotation = Quaternion.Lerp(examineItem._item3dToExam.transform.localRotation, transformItem3DPOS /*ItemDefaultPosition.localRotation*/, examineItem._lerpItem);
|
|
//DrawerIsOpen = true;
|
|
|
|
//ItemScale if needed:
|
|
if (examinableItemScaler != null)
|
|
{
|
|
examineItem._item3dToExam.transform.localScale = Vector3.Lerp(examineItem._item3dToExam.transform.localScale, examinableItemScaler.itemOriginalScale, examineItem._lerpItem);
|
|
}
|
|
|
|
Debug.Log("Is lerping item in default");
|
|
yield return null;
|
|
}
|
|
|
|
Debug.Log("IsLerpingInDefaultPlace");
|
|
examineItem.CanExamineObject = true;
|
|
examineItem._lerpItem = 0f;
|
|
yield return null;
|
|
}
|
|
|
|
public void Interact()
|
|
{
|
|
UpdateInteractableItem();
|
|
}
|
|
|
|
public void RefreshItemDescription(LocalizedString description)
|
|
{
|
|
examineItem.sentences = description.GetLocalizedString();
|
|
ExaminableItemData.GetInstance().sentencesText.text = examineItem.localizedSentences.GetLocalizedString();
|
|
}
|
|
|
|
public void UpdateItemStartPosition(Transform newPosition)
|
|
{
|
|
examineItem._Item3DDefaultPos = newPosition.localPosition;
|
|
transformItem3DPOS = newPosition.localRotation;
|
|
}
|
|
|
|
public void CanGetItemNow()
|
|
{
|
|
examineItem.CanGetItem = true;
|
|
}
|
|
}
|
|
}
|