255 lines
11 KiB
C#
255 lines
11 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using UnityEngine.Localization;
|
|
|
|
[System.Serializable]
|
|
public class ExamineItem
|
|
{
|
|
[Header("Items to examine")]
|
|
public string objectName; //The name of the object that you examine.
|
|
//public TextMeshProUGUI nameText;
|
|
public LocalizedString localizedObjName;
|
|
|
|
[TextArea(3/*min lines*/, 10/*max lines*/)]
|
|
public string sentences;
|
|
//public TextMeshProUGUI sentencesText;
|
|
public LocalizedString localizedSentences;
|
|
|
|
[Tooltip("You can declare the item you want to examine here. " +
|
|
"(If you don't want to declare the object don't worry because the script will declare as the object the gameobject that this script is on)")]
|
|
public GameObject _item3dToExam; //The one 3d model that you can examine.
|
|
[Tooltip("The rotation speed when the player examines the item.")]
|
|
public float RotationSpeed = 1f; //The rotation speed of the 3d model.
|
|
|
|
public bool Examine3dObject; //Examine object up close.
|
|
public bool CanGetItem;
|
|
|
|
//public LayerMask newRenderingLayerMask;
|
|
//[HideInInspector] public LayerMask originalRenderingLayerMask;
|
|
|
|
[Header("Debugging")]
|
|
public bool CanPressButtonToGetItem;
|
|
public bool CurrenltyExaminingObj;
|
|
public bool IsExitingItemExamination;
|
|
[HideInInspector] public bool ItemHasParent;
|
|
[HideInInspector] public bool CanPressButton;
|
|
[HideInInspector] public bool CanExamineObject = true;
|
|
|
|
/*[HideInInspector]*/ public Transform _item3DParent;
|
|
|
|
//[HideInInspector] public GameObject _ChloeCameraBlur;
|
|
//[HideInInspector] public GameObject _MaxCameraBlur;
|
|
|
|
[HideInInspector] public Vector3 _Item3DDefaultPos;
|
|
/* [HideInInspector]*/ public float _lerpItem;
|
|
|
|
#region Item3D Stuff
|
|
public void DisplayItem3D()
|
|
{
|
|
UIManager.GetInstance().userInterfaceIsOnScreen = true;
|
|
CanExamineObject = false;
|
|
_lerpItem = 0f;
|
|
#region Layer change
|
|
if (_item3dToExam.GetComponent<Renderer>() != null)
|
|
{
|
|
_item3dToExam.gameObject.GetComponent<Renderer>().renderingLayerMask = 2;
|
|
}
|
|
if(_item3dToExam.GetComponentsInChildren<Renderer>() != null)
|
|
{
|
|
foreach (var renderers in _item3dToExam.GetComponentsInChildren<Renderer>())
|
|
{
|
|
renderers.renderingLayerMask = ExaminableItemData.GetInstance().renderingLayerMask;
|
|
}
|
|
}
|
|
var itemChildren = _item3dToExam.GetComponentsInChildren<Transform>(true);
|
|
for(int i = 0, max = itemChildren.Length; i <max; i++)
|
|
{
|
|
Transform child = itemChildren[i];
|
|
//Only change layers that are not called: "WorldUI"
|
|
if (child.gameObject.layer != LayerMask.NameToLayer("WorldUI"))
|
|
{
|
|
child.gameObject.layer = LayerMask.NameToLayer("ExaminableItem");
|
|
}
|
|
//if (child.GetComponent<Renderer>() != null)
|
|
//{
|
|
// child.gameObject.GetComponent<Renderer>().renderingLayerMask = 2;
|
|
//}
|
|
}
|
|
#endregion
|
|
ExaminableItemData.GetInstance().examinationPointLight.gameObject.SetActive(true);
|
|
//ExaminableItemData.GetInstance().ExamineCamera.SetActive(true);
|
|
ExaminableItemData.GetInstance().EnableBlur();
|
|
CameraMovement.GetInstance().enabled = false;
|
|
CurrenltyExaminingObj = true;
|
|
//InventoryManager.GetInstance().enabled = false; //You can't access inventory because you examine an object.
|
|
//_item3dToExam.SetActive(true);
|
|
//_item3dToExam.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
|
|
Time.timeScale = 0f;
|
|
//ExaminableItemData.GetInstance().nameText.gameObject.SetActive(true);
|
|
ExaminableItemData.GetInstance().nameText.text = localizedObjName.GetLocalizedString();
|
|
//ExaminableItemData.GetInstance().sentencesText.gameObject.SetActive(true);
|
|
ExaminableItemData.GetInstance().sentencesText.text = localizedSentences.GetLocalizedString();
|
|
ExaminableItemData.GetInstance().examinationUIAnimator.SetBool("IsOpen", true);
|
|
ExaminableItemData.GetInstance().IsExamining = true;
|
|
|
|
UIManager.GetInstance().DisableUIItemIconVisibility();
|
|
|
|
#region MouseUI
|
|
if (Examine3dObject)
|
|
{
|
|
UIManager.GetInstance().MouseUILeftDisplay(UIManager.GetInstance().localizedMouseUILeftLabel);
|
|
UIManager.GetInstance().MouseUIRightDisplay(UIManager.GetInstance().localizedMouseUIRightLabel);
|
|
UIManager.GetInstance().MouseUIMiddleDisplay(UIManager.GetInstance().localizedMouseUIMiddleLabel);
|
|
}
|
|
else
|
|
{
|
|
UIManager.GetInstance().MouseUIRightDisplay(UIManager.GetInstance().localizedMouseUIRightLabel);
|
|
}
|
|
#endregion
|
|
//#region UI Can Get Item
|
|
//if (CanGetItem)
|
|
//{
|
|
// ExaminableItemData.GetInstance().pressEToGetItemUI.SetActive(true);
|
|
// Debug.Log("Press E to get item");
|
|
//}
|
|
//#endregion
|
|
}
|
|
|
|
public void ExitDisplayingItem3D()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.Mouse1) || Input.GetKeyDown(KeyCode.JoystickButton1) && CanPressButton)
|
|
{
|
|
_lerpItem = 0f;
|
|
#region Layer change
|
|
var itemChildren = _item3dToExam.GetComponentsInChildren<Transform>(true);
|
|
for (int i = 0, max = itemChildren.Length; i < max; i++)
|
|
{
|
|
Transform child = itemChildren[i];
|
|
//Only change layers that are not called: "WorldUI"
|
|
if (child.gameObject.layer != LayerMask.NameToLayer("WorldUI"))
|
|
{
|
|
child.gameObject.layer = LayerMask.NameToLayer("Interactable");
|
|
}
|
|
}
|
|
#endregion
|
|
ExaminableItemData.GetInstance().examinationPointLight.gameObject.SetActive(false);
|
|
IsExitingItemExamination = true;
|
|
//ExaminableItemData.GetInstance().ExamineCamera.SetActive(false);
|
|
ExaminableItemData.GetInstance().DisableBlur();
|
|
CurrenltyExaminingObj = false;
|
|
//InventoryManager.GetInstance().enabled = true; //You can access inventory because you don't examine an object.
|
|
//_item3dToExam.SetActive(false);
|
|
Time.timeScale = 1f;
|
|
//ExaminableItemData.GetInstance().nameText.gameObject.SetActive(false);
|
|
//ExaminableItemData.GetInstance().sentencesText.gameObject.SetActive(false);
|
|
ExaminableItemData.GetInstance().pressEToGetItemUI.SetActive(false);
|
|
|
|
UIManager.GetInstance().EnableUIItemIconVisibility();
|
|
|
|
#region MouseUI
|
|
UIManager.GetInstance().MouseUILeftDisable();
|
|
UIManager.GetInstance().MouseUIRightDisable();
|
|
UIManager.GetInstance().MouseUIMiddleDisable();
|
|
#endregion
|
|
ExaminableItemData.GetInstance().examinationUIAnimator.SetBool("IsOpen", false);
|
|
CameraMovement.GetInstance().enabled = true;
|
|
|
|
ExaminableItemData.GetInstance().IsExamining = false;
|
|
|
|
CanPressButtonToGetItem = false; //In case that there is an item to get it resets the bool for the input delay.
|
|
}
|
|
}
|
|
|
|
public void GotItemExitDisplayingItem3d()
|
|
{
|
|
_lerpItem = 0f;
|
|
#region Layer change
|
|
var itemChildren = _item3dToExam.GetComponentsInChildren<Transform>(true);
|
|
for (int i = 0, max = itemChildren.Length; i < max; i++)
|
|
{
|
|
Transform child = itemChildren[i];
|
|
child.gameObject.layer = LayerMask.NameToLayer("Interactable");
|
|
}
|
|
#endregion
|
|
ExaminableItemData.GetInstance().examinationPointLight.gameObject.SetActive(false);
|
|
IsExitingItemExamination = true;
|
|
//ExaminableItemData.GetInstance().ExamineCamera.SetActive(false);
|
|
ExaminableItemData.GetInstance().DisableBlur();
|
|
CurrenltyExaminingObj = false;
|
|
//InventoryManager.GetInstance().enabled = true; //You can access inventory because you don't examine an object.
|
|
//_item3dToExam.SetActive(false);
|
|
Time.timeScale = 1f;
|
|
//ExaminableItemData.GetInstance().nameText.gameObject.SetActive(false);
|
|
//ExaminableItemData.GetInstance().sentencesText.gameObject.SetActive(false);
|
|
ExaminableItemData.GetInstance().pressEToGetItemUI.SetActive(false);
|
|
|
|
UIManager.GetInstance().EnableUIItemIconVisibility();
|
|
|
|
#region MouseUI
|
|
UIManager.GetInstance().MouseUILeftDisable();
|
|
UIManager.GetInstance().MouseUIRightDisable();
|
|
UIManager.GetInstance().MouseUIMiddleDisable();
|
|
#endregion
|
|
#region Audio Clip Play
|
|
AudioManager.GetInstance().PickUpItemSoundPlay();
|
|
#endregion
|
|
ExaminableItemData.GetInstance().examinationUIAnimator.SetBool("IsOpen", false);
|
|
CameraMovement.GetInstance().enabled = true;
|
|
ExaminableItemData.GetInstance().IsExamining = false;
|
|
}
|
|
|
|
#endregion
|
|
|
|
public void ItemRotation()
|
|
{
|
|
#region Item examination rotation
|
|
if (Examine3dObject == true && CurrenltyExaminingObj == true) //If there is an object to examin:
|
|
{
|
|
float rotX;
|
|
float rotY;
|
|
if (!InputControlManager.Getinstance().IsUsingJoystick)
|
|
{
|
|
rotX = Input.GetAxis("Mouse X") * RotationSpeed * Mathf.Deg2Rad;
|
|
rotY = Input.GetAxis("Mouse Y") * RotationSpeed * Mathf.Deg2Rad;
|
|
}
|
|
else
|
|
{
|
|
rotX = Input.GetAxis("Joystick X") * RotationSpeed * 10f /*Because it's too slow *10f*/ * Mathf.Deg2Rad;
|
|
rotY = Input.GetAxis("Joystick Y") * RotationSpeed * 10f /*Because it's too slow *10f*/ * Mathf.Deg2Rad;
|
|
Debug.Log("Rotate item joystick");
|
|
}
|
|
|
|
if (!InputControlManager.Getinstance().IsUsingJoystick)
|
|
{
|
|
if (Input.GetMouseButton(0)) //While you are holding down the left mouse:
|
|
{
|
|
_item3dToExam.transform.RotateAroundLocal(Vector3.up, -rotX);
|
|
_item3dToExam.transform.RotateAroundLocal(Vector3.right, rotY);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_item3dToExam.transform.RotateAroundLocal(Vector3.up, -rotX);
|
|
_item3dToExam.transform.RotateAroundLocal(Vector3.right, rotY);
|
|
}
|
|
|
|
if (Input.GetMouseButtonDown(2)/*Mouse Wheel*/ || Input.GetKeyDown(KeyCode.JoystickButton9)) //Default Rotation:
|
|
{
|
|
Debug.Log("Mouse wheel pressed");
|
|
//_item3dToExam.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
|
|
_item3dToExam.transform.localEulerAngles = ExaminableItemData.GetInstance().ItemLerpPosition.localEulerAngles;
|
|
}
|
|
ExitDisplayingItem3D(); //Disable the Item.
|
|
}
|
|
else if(!Examine3dObject && CurrenltyExaminingObj) //Not rotatable item.
|
|
{
|
|
ExitDisplayingItem3D(); //Disable the Item.
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
}
|