597 lines
24 KiB
C#
597 lines
24 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using System;
|
|
using System.Reflection;
|
|
|
|
[System.Serializable]
|
|
public class TemporarilySavedInventoryItemsData
|
|
{
|
|
public List<KeyPickupData> temporarilySavedKeysInventoryItemsData;
|
|
public List<IndividualBatteriesPickupData> temporarilySavedBatteriesInventoryItemsData;
|
|
public List<IndividualPillsPickupData> temporarilySavedPillsInventoryItemsData;
|
|
public List<ObtainedItemsData> temporarilyObtainedItemsData;
|
|
public PocketWatchInventoryItemData temporarilySavedPocketWatchInventoryItemData;
|
|
public CandleHolderItemData temporarilySavedCandleHolderItemData;
|
|
public List<DiaryEntryData> temporarilySavedDiaryEntryInventoryData;
|
|
public List<RegularItemData> temporarilySavedRegularItemsInventoryData;
|
|
}
|
|
|
|
//[System.Serializable]
|
|
//public class TemporarilySavedKeysInventoryItemsData
|
|
//{
|
|
// [Tooltip("How the key prefab is named in the inventoryManager field to access it")]
|
|
// public string KeyNameID;
|
|
// public string KeyModelForKeyHole;
|
|
// public string KeyModelNameInInventoryManager;
|
|
//}
|
|
|
|
public class InventoryManager : MonoBehaviour
|
|
{
|
|
public TemporarilySavedInventoryItemsData temporarilySavedInventoryItemsData;
|
|
|
|
public GameObject inventoryCanvas;
|
|
public Animator inventoryAnimator;
|
|
public bool inventoryIsOpen;
|
|
public bool canPressButton = true;
|
|
public bool shouldTakeInput = true;
|
|
|
|
public AudioSource inventoryAudioSource;
|
|
[SerializeField] private AudioClip inventoryOpenAudioClip;
|
|
[SerializeField] private AudioClip inventoryCloseAudioClip;
|
|
|
|
public AudioSource itemObtainedAudioSource;
|
|
[SerializeField] private AudioClip itemObtainedAudioClip;
|
|
|
|
public Animator itemAddedToInventoryPanelAnimator;
|
|
public TextMeshProUGUI itemAddedText;
|
|
|
|
|
|
public Transform itemsToAddTransform;
|
|
public Transform TransformWithPosRotForItemsToAdd;
|
|
|
|
[Header("Inventory Categories")]
|
|
public GameObject inventoryKeysAndItemsCategoryGO;
|
|
public GameObject inventoryCollectablesCategoryGO;
|
|
|
|
[Header("Inventory Button Prompts")]
|
|
public GameObject inventoryButtonPromptsPanel;
|
|
|
|
[Header("Items on ring Inventory")]
|
|
public GameObject pillsOnRingInventory;
|
|
public GameObject batteryOnRingInventory;
|
|
public GameObject oilOnRingInventory;
|
|
public GameObject pocketWatchOnRingInventory;
|
|
public GameObject candleHolderOnRingInventory;
|
|
|
|
public MainHousePart1ItemsOnRingInventory mainHousePart1ItemsOnRingInventory;
|
|
|
|
public GameObject mannequinHeadBodyPart;
|
|
public GameObject mannequinRightArmBodyPart;
|
|
public GameObject mannequinLeftArmBodyPart;
|
|
public GameObject mannequinRightFootBodyPart;
|
|
public GameObject mannequinLeftFootBodyPart;
|
|
|
|
public MedallionsForLibraryPuzzleInventoryItems medallionsForLibraryPuzzleInventoryItems;
|
|
|
|
public ChildrenLoopsItemsOnRingInventory childrenLoopInventoryItems;
|
|
|
|
[Header("Keys")]
|
|
public GameObject keyTypeA;
|
|
public GameObject keyTypeB;
|
|
public GameObject keyTypeC;
|
|
|
|
[Header("Items on CollectablesInventory")]
|
|
public GameObject medeaDiary;
|
|
public GameObject danielDiary;
|
|
|
|
[Header("Items To display")]
|
|
public GameObject largeMedipackGo;
|
|
public GameObject smallMedipackGo;
|
|
public GameObject flarePackGo;
|
|
|
|
[Header("Items")]
|
|
//public float flashlightBatteryPercentage;
|
|
public int batteries = 7;
|
|
public int pills = 1;
|
|
//public int medipackLarge = 2;
|
|
//public int medipackSmall = 1;
|
|
//public int flaresAmount = 0;
|
|
|
|
public bool canChangeInventoryState = true;
|
|
|
|
[Header("Ring Inventory")]
|
|
public RingInventory ringInventoryGear;
|
|
|
|
private static InventoryManager _instance;
|
|
public static InventoryManager GetInstance() { return _instance; }
|
|
|
|
private void Awake()
|
|
{
|
|
if (!_instance)
|
|
{
|
|
_instance = this;
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
StartCoroutine(RemoveItemsFromRingInventoryAfterStart());
|
|
}
|
|
|
|
IEnumerator RemoveItemsFromRingInventoryAfterStart()
|
|
{
|
|
yield return new WaitForSecondsRealtime(0.01f);
|
|
//Disable those items if the count is equal or below zero
|
|
if (batteryOnRingInventory.activeSelf == true && BatteryManager.GetInstance().batteriesCollected <= 0)
|
|
{
|
|
RingInventory.GetInstance().RemoveItemByNameToKeysAndItemsInventory("Battery");
|
|
}
|
|
if (pillsOnRingInventory.activeSelf == true && PlayerHealthManager.GetInstance().pillsCollected == 0)
|
|
{
|
|
RingInventory.GetInstance().RemoveItemByNameToKeysAndItemsInventory("Pills");
|
|
}
|
|
}
|
|
|
|
public void SaveTemporarilyObtainedItemsData(string ObtainedItemName)
|
|
{
|
|
ObtainedItemsData temporarilyObtainedItemsData = new ObtainedItemsData();
|
|
temporarilyObtainedItemsData.obtainedItemName = ObtainedItemName;
|
|
temporarilySavedInventoryItemsData.temporarilyObtainedItemsData.Add(temporarilyObtainedItemsData);
|
|
}
|
|
|
|
public void SaveTemporarilyRegularItemsData(string ItemName, string ItemNameInInventory, string ItemModelNameInInventoryManager, bool AddToKeysAndItemsInventory)
|
|
{
|
|
if (ItemName != null &&
|
|
ItemModelNameInInventoryManager != null &&
|
|
ItemNameInInventory != null
|
|
//ObtainedKeyItemName != null
|
|
)
|
|
{
|
|
RegularItemData temporarilyRegularItemsData = new RegularItemData();
|
|
temporarilyRegularItemsData.ItemName = ItemName;
|
|
temporarilyRegularItemsData.ItemNameInInventory = ItemNameInInventory;
|
|
temporarilyRegularItemsData.ItemModelNameInInventoryManager = ItemModelNameInInventoryManager;
|
|
temporarilyRegularItemsData.AddToKeysAndItemsInventory = AddToKeysAndItemsInventory;
|
|
temporarilySavedInventoryItemsData.temporarilySavedRegularItemsInventoryData.Add(temporarilyRegularItemsData);
|
|
}
|
|
}
|
|
|
|
public void SaveTemporarilyPocketWatchInventoryItemData(bool pocketWatchCollected)
|
|
{
|
|
temporarilySavedInventoryItemsData.temporarilySavedPocketWatchInventoryItemData.pocketWatchCollected = pocketWatchCollected;
|
|
}
|
|
|
|
public void SaveTemporarilyCandleHolderInventoryItemData(bool candleHolderCollected, bool hasCandle, float candleLife)
|
|
{
|
|
temporarilySavedInventoryItemsData.temporarilySavedCandleHolderItemData.candleHolderIsCollected = candleHolderCollected;
|
|
temporarilySavedInventoryItemsData.temporarilySavedCandleHolderItemData.hasCandle = hasCandle;
|
|
temporarilySavedInventoryItemsData.temporarilySavedCandleHolderItemData.candleLife = candleLife;
|
|
}
|
|
|
|
public void SaveTemporarilySavedPillsInventoryItemsData(string ObtainedPillsItemName, string ObtainedPillsItemUniqueID)
|
|
{
|
|
IndividualPillsPickupData temporarilyObtainedPillsPickupData = new IndividualPillsPickupData();
|
|
temporarilyObtainedPillsPickupData.obtainedPillsItemName = ObtainedPillsItemName;
|
|
temporarilyObtainedPillsPickupData.obtainedPillsItemUniqueID = ObtainedPillsItemUniqueID;
|
|
temporarilySavedInventoryItemsData.temporarilySavedPillsInventoryItemsData.Add(temporarilyObtainedPillsPickupData);
|
|
}
|
|
|
|
public void SaveTemporarilySavedBatteriesInventoryItemsData(string ObtainedBatteryItemName, string ObtainedBatteryItemUniqueID)
|
|
{
|
|
IndividualBatteriesPickupData temporarilyObtainedBatteriesPickupData = new IndividualBatteriesPickupData();
|
|
temporarilyObtainedBatteriesPickupData.obtainedBatteryItemName = ObtainedBatteryItemName;
|
|
temporarilyObtainedBatteriesPickupData.obtainedBatteryItemUniqueID = ObtainedBatteryItemUniqueID;
|
|
temporarilySavedInventoryItemsData.temporarilySavedBatteriesInventoryItemsData.Add(temporarilyObtainedBatteriesPickupData);
|
|
}
|
|
|
|
public void SaveTemporarilyKeyInventoryItemData(string KeyNameID/*, string keyModelForKeyHole*/, string KeyModelNameInInventoryManager, string keyNameInInventory, string ObtainedKeyItemName, bool IsReusable)
|
|
{
|
|
if (KeyNameID != null &&
|
|
KeyModelNameInInventoryManager != null &&
|
|
keyNameInInventory != null &&
|
|
ObtainedKeyItemName != null)
|
|
{
|
|
KeyPickupData temporarilySavedKeysInventoryItemsData = new KeyPickupData();
|
|
temporarilySavedKeysInventoryItemsData.KeyNameID = KeyNameID;
|
|
temporarilySavedKeysInventoryItemsData.KeyModelNameInInventoryManager = KeyModelNameInInventoryManager;
|
|
temporarilySavedKeysInventoryItemsData.keyNameInInventory = keyNameInInventory;
|
|
temporarilySavedKeysInventoryItemsData.obtainedKeyItemName = ObtainedKeyItemName;
|
|
temporarilySavedKeysInventoryItemsData.IsReusable = IsReusable;
|
|
|
|
temporarilySavedInventoryItemsData.temporarilySavedKeysInventoryItemsData.Add(temporarilySavedKeysInventoryItemsData);
|
|
print("Temporarily saved key Inventory Item");
|
|
}
|
|
else
|
|
{
|
|
print("One or more fields are null. Item not saved.");
|
|
}
|
|
}
|
|
|
|
public void SaveTemporarilyDiaryEntryInventoryItemData(string DiaryEntryModelNameInInventoryManager,string ObtainedDiartEntryItemName)
|
|
{
|
|
DiaryEntryData temporarilySavedDiaryEntryInventoryItemsData = new DiaryEntryData();
|
|
|
|
temporarilySavedDiaryEntryInventoryItemsData.diaryEntryModelNameInInventoryManager = DiaryEntryModelNameInInventoryManager;
|
|
temporarilySavedDiaryEntryInventoryItemsData.obtainedDiaryEntryItemName = ObtainedDiartEntryItemName;
|
|
temporarilySavedInventoryItemsData.temporarilySavedDiaryEntryInventoryData.Add(temporarilySavedDiaryEntryInventoryItemsData);
|
|
print("Temporarily saved Diary Entry Inventory Item");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Call from when you're saving the game to delete the diary entries you already obtained before the save.
|
|
/// </summary>
|
|
/// <param name="DiaryEntryModelNameInInventoryManager"></param>
|
|
/// <param name="ObtainedDiartEntryItemName"></param>
|
|
public void DeleteTemporarilyDiaryEntryInventoryItemData()
|
|
{
|
|
foreach (var temporarilySavedDiaryEntryInventoryItemsData in temporarilySavedInventoryItemsData.temporarilySavedDiaryEntryInventoryData)
|
|
{
|
|
temporarilySavedInventoryItemsData.temporarilySavedDiaryEntryInventoryData.Remove(temporarilySavedDiaryEntryInventoryItemsData);
|
|
}
|
|
}
|
|
|
|
public void DeleteTemporarilySavedKeyInventoryItemData(string KeyNameID)
|
|
{
|
|
|
|
for (int i = temporarilySavedInventoryItemsData.temporarilySavedKeysInventoryItemsData.Count - 1; i >= 0; i--)
|
|
{
|
|
if (temporarilySavedInventoryItemsData.temporarilySavedKeysInventoryItemsData[i].KeyNameID == KeyNameID)
|
|
{
|
|
temporarilySavedInventoryItemsData.temporarilySavedKeysInventoryItemsData.RemoveAt(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void DeleteTemporarilySavedRegularItemData(string ItemName)
|
|
{
|
|
for (int i = temporarilySavedInventoryItemsData.temporarilySavedRegularItemsInventoryData.Count - 1; i >= 0; i--)
|
|
{
|
|
if (temporarilySavedInventoryItemsData.temporarilySavedRegularItemsInventoryData[i].ItemName == ItemName)
|
|
{
|
|
temporarilySavedInventoryItemsData.temporarilySavedRegularItemsInventoryData.RemoveAt(i);
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum State
|
|
{
|
|
Gameplay,
|
|
InventoryMenu,
|
|
CollectablesMenu
|
|
}
|
|
|
|
public State currentInventoryState = State.Gameplay;
|
|
|
|
|
|
private void Update()
|
|
{
|
|
switch (currentInventoryState)
|
|
{
|
|
case State.Gameplay:
|
|
if ((Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.JoystickButton6)) && canPressButton && !LoadManager.GetInstance().LoadingGame)
|
|
{
|
|
if (!GameplayController.GetInstance().IsOnState(GameplayController.State.PauseMenu) && !GameplayController.GetInstance().IsOnState(GameplayController.State.MainMenu)
|
|
&& ClockController.GetInstance().isUsingPocketWatch == false && !ExaminableItemData.GetInstance().IsExamining)
|
|
{
|
|
if (!inventoryIsOpen)
|
|
{
|
|
OpenInventory();
|
|
}
|
|
else
|
|
{
|
|
CloseInventory();
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case State.InventoryMenu:
|
|
if ((Input.GetKeyDown(KeyCode.Tab)
|
|
|| Input.GetKeyDown(KeyCode.JoystickButton6)
|
|
|| Input.GetKeyDown(KeyCode.Escape)
|
|
|| Input.GetKeyDown(KeyCode.Mouse1)
|
|
|| Input.GetKeyDown(KeyCode.JoystickButton7)
|
|
|| Input.GetKeyDown(KeyCode.JoystickButton1)) && canPressButton)
|
|
{
|
|
CloseInventory();
|
|
}
|
|
|
|
float DpadVertical = Input.GetAxis("DpadVertical");
|
|
|
|
if (Input.GetKeyDown(KeyCode.W) || Input.GetKeyDown(KeyCode.S)
|
|
|| DpadVertical > 0 || DpadVertical < 0)
|
|
{
|
|
if (shouldTakeInput)
|
|
{
|
|
if (RingInventory.GetInstance().IsOnState(RingInventory.InventoryState.KeysAndItemsInventory) && canChangeInventoryState)
|
|
{
|
|
RingInventory.GetInstance().ResetInventoryValuesOnClose();
|
|
inventoryCollectablesCategoryGO.SetActive(false);
|
|
inventoryCanvas.SetActive(false);
|
|
inventoryCanvas.transform.SetParent(RingInventory.GetInstance().inventoryOriginalParent);
|
|
inventoryCanvas.transform.localPosition = Vector3.zero;
|
|
inventoryCanvas.transform.rotation = new Quaternion(0, 0, 0, 0);
|
|
OpenCollectablesInventory();
|
|
StartCoroutine(InputUpdate());
|
|
}
|
|
else if (RingInventory.GetInstance().IsOnState(RingInventory.InventoryState.CollectablesInventory) && canChangeInventoryState)
|
|
{
|
|
RingInventory.GetInstance().ResetInventoryValuesOnClose();
|
|
inventoryCollectablesCategoryGO.SetActive(false);
|
|
inventoryCanvas.SetActive(false);
|
|
inventoryCanvas.transform.SetParent(RingInventory.GetInstance().inventoryOriginalParent);
|
|
inventoryCanvas.transform.localPosition = Vector3.zero;
|
|
inventoryCanvas.transform.rotation = new Quaternion(0, 0, 0, 0);
|
|
OpenKeysAndItemsInventory();
|
|
StartCoroutine(InputUpdate());
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case State.CollectablesMenu:
|
|
//In this state you have selected a collectable item and You are doing stuff from there. (SEE InventoryCollectablesMenuManager)
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
//if ((Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.JoystickButton6) && canPressButton))
|
|
//{
|
|
// if (!inventoryIsOpen)
|
|
// {
|
|
// OpenInventory();
|
|
// }
|
|
// else
|
|
// {
|
|
// CloseInventory();
|
|
// }
|
|
//}
|
|
}
|
|
|
|
IEnumerator InputUpdate()
|
|
{
|
|
RingInventory.GetInstance().shouldTakeInput = false;
|
|
shouldTakeInput = false;
|
|
yield return new WaitForSecondsRealtime(0.5f);
|
|
shouldTakeInput = true;
|
|
RingInventory.GetInstance().shouldTakeInput = true;
|
|
}
|
|
|
|
public void InventoryInputIsEnabled()
|
|
{
|
|
canPressButton = true;
|
|
}
|
|
|
|
public void InventoryInputIsDisabled()
|
|
{
|
|
canPressButton = false;
|
|
}
|
|
|
|
public bool IsOnState(State checkState)
|
|
{
|
|
return currentInventoryState == checkState;
|
|
}
|
|
|
|
public void GoToInventoryMenuState()
|
|
{
|
|
currentInventoryState = State.InventoryMenu;
|
|
}
|
|
|
|
public void GoToCollectablesMenuState()
|
|
{
|
|
currentInventoryState = State.CollectablesMenu;
|
|
}
|
|
|
|
public void OpenInventory()
|
|
{
|
|
#region NEW BUT TESTING COLLECTABLES INVENTORY
|
|
//GameplayController.GetInstance().GoToInventoryMenuState();
|
|
//RingInventory.GetInstance().GoToKeysAndItemsInventory();
|
|
//RingInventory.GetInstance().RefreshItemsToKeysAndItemsInventory();
|
|
////inventoryCanvas.transform.SetParent(RingInventory.GetInstance().inventoryParentAfterOpening);
|
|
////inventoryCanvas.transform.localPosition = Vector3.zero;
|
|
////inventoryCanvas.transform.rotation = new Quaternion(0, 0, 0, 0);
|
|
//ringInventoryGear.UpdateUIElementsForKeysAndItemsInventory();
|
|
//inventoryAudioSource.PlayOneShot(inventoryOpenAudioClip);
|
|
//currentInventoryState = State.InventoryMenu;
|
|
//Time.timeScale = 0f;
|
|
//inventoryIsOpen = true;
|
|
//inventoryKeysAndItemsCategoryGO.SetActive(true);
|
|
//inventoryCanvas.SetActive(true);
|
|
////inventoryAnimator.SetBool("InventoryIsOpen", true);
|
|
////StartCoroutine(inventoryIsOpening());
|
|
///
|
|
#endregion
|
|
OpenKeysAndItemsInventory();
|
|
}
|
|
|
|
public void OpenKeysAndItemsInventory()
|
|
{
|
|
RingInventory.GetInstance().shouldTakeInput = true;
|
|
UIManager.GetInstance().userInterfaceIsOnScreen = true;
|
|
UIManager.GetInstance().customPassUIRenderOnTop_UIAndModels.gameObject.SetActive(true);
|
|
UIManager.GetInstance().CustomPassUIRenderOnTop_UIOnly.gameObject.SetActive(false);
|
|
GameplayController.GetInstance().GoToInventoryMenuState();
|
|
RingInventory.GetInstance().GoToKeysAndItemsInventory();
|
|
RingInventory.GetInstance().RefreshItemsToKeysAndItemsInventory();
|
|
ringInventoryGear.UpdateUIElementsForKeysAndItemsInventory();
|
|
inventoryAudioSource.PlayOneShot(inventoryOpenAudioClip);
|
|
currentInventoryState = State.InventoryMenu;
|
|
Time.timeScale = 0f;
|
|
inventoryIsOpen = true;
|
|
inventoryKeysAndItemsCategoryGO.SetActive(true);
|
|
inventoryCollectablesCategoryGO.SetActive(false);
|
|
inventoryCanvas.SetActive(true);
|
|
UIManager.GetInstance().DisableUIItemIconVisibility();
|
|
}
|
|
|
|
public void OpenCollectablesInventory()
|
|
{
|
|
GameplayController.GetInstance().GoToInventoryMenuState();
|
|
RingInventory.GetInstance().GoToCollectablesInventory();
|
|
RingInventory.GetInstance().RefreshItemsToCollectablesInventory();
|
|
ringInventoryGear.UpdateUIElementsForCollectablesInventory();
|
|
inventoryAudioSource.PlayOneShot(inventoryOpenAudioClip);
|
|
currentInventoryState = State.InventoryMenu;
|
|
Time.timeScale = 0f;
|
|
inventoryIsOpen = true;
|
|
inventoryKeysAndItemsCategoryGO.SetActive(false);
|
|
inventoryCollectablesCategoryGO.SetActive(true);
|
|
inventoryCanvas.SetActive(true);
|
|
}
|
|
|
|
public void CloseInventory()
|
|
{
|
|
inventoryAudioSource.PlayOneShot(inventoryCloseAudioClip);
|
|
canPressButton = false;
|
|
inventoryIsOpen = false;
|
|
//inventoryAnimator.SetBool("InventoryIsOpen", false);
|
|
StartCoroutine(inventoryIsClosing());
|
|
}
|
|
|
|
IEnumerator inventoryIsOpening()
|
|
{
|
|
inventoryCanvas.SetActive(true);
|
|
foreach (var inventoryMeshRenderers in inventoryCanvas.GetComponentsInChildren<MeshRenderer>())
|
|
{
|
|
inventoryMeshRenderers.enabled = false;
|
|
}
|
|
yield return new WaitForSecondsRealtime(0.1f);
|
|
foreach (var inventoryMeshRenderers in inventoryCanvas.GetComponentsInChildren<MeshRenderer>())
|
|
{
|
|
inventoryMeshRenderers.enabled = true;
|
|
}
|
|
//inventoryAnimator.SetBool("InventoryIsOpen", true);
|
|
}
|
|
|
|
IEnumerator inventoryIsClosing()
|
|
{
|
|
yield return new WaitForSecondsRealtime(0.5f);
|
|
//RingInventory.GetInstance().currentIndex = 0;
|
|
RingInventory.GetInstance().ResetInventoryValuesOnClose();
|
|
RingInventory.GetInstance().GoToNone();
|
|
inventoryCollectablesCategoryGO.SetActive(false);
|
|
inventoryCanvas.SetActive(false);
|
|
inventoryCanvas.transform.SetParent(RingInventory.GetInstance().inventoryOriginalParent);
|
|
inventoryCanvas.transform.localPosition = Vector3.zero;
|
|
inventoryCanvas.transform.rotation = new Quaternion(0, 0, 0, 0);
|
|
canPressButton = true;
|
|
currentInventoryState = State.Gameplay;
|
|
GameplayController.GetInstance().GoToGameplayState();
|
|
ringInventoryGear.canPressButton = true;
|
|
Time.timeScale = 1f;
|
|
UIManager.GetInstance().EnableUIItemIconVisibility();
|
|
UIManager.GetInstance().userInterfaceIsOnScreen = false;
|
|
}
|
|
|
|
public void ItemPickupUpdateCanvas(string itemDescription, GameObject itemToDisplay)
|
|
{
|
|
itemAddedText.text = itemDescription;
|
|
itemObtainedAudioSource.PlayOneShot(itemObtainedAudioClip);
|
|
StartCoroutine(UpdateItemAddedCanvasAnimations(itemToDisplay));
|
|
}
|
|
|
|
IEnumerator UpdateItemAddedCanvasAnimations(GameObject itemToDisplay)
|
|
{
|
|
itemToDisplay.SetActive(true);
|
|
itemAddedToInventoryPanelAnimator.Play("ItemAddedToInventoryPanelPopUp");
|
|
yield return new WaitForSeconds(5f);
|
|
itemAddedToInventoryPanelAnimator.Play("ItemAddedToInventoryPanelPopOut");
|
|
yield return new WaitForSeconds(3f);
|
|
itemToDisplay.SetActive(false);
|
|
|
|
}
|
|
|
|
|
|
public GameObject AccessFieldInInventoryManager(string fieldName)
|
|
{
|
|
if (InventoryManager.GetInstance() == null)
|
|
{
|
|
Debug.LogWarning("InventoryManager instance not found.");
|
|
return null;
|
|
}
|
|
|
|
// Get the InventoryManager instance
|
|
InventoryManager inventoryManager = InventoryManager.GetInstance();
|
|
|
|
// Start a recursive search for the field in InventoryManager
|
|
return FindFieldRecursively(inventoryManager, fieldName);
|
|
}
|
|
|
|
private GameObject FindFieldRecursively(object currentObject, string fieldName)
|
|
{
|
|
if (currentObject == null)
|
|
return null;
|
|
|
|
// Get the type of the current object
|
|
Type type = currentObject.GetType();
|
|
|
|
// First, check if the field exists at the current level
|
|
FieldInfo field = type.GetField(fieldName, BindingFlags.Public | BindingFlags.Instance);
|
|
if (field != null)
|
|
{
|
|
// If the field exists and is a GameObject, return it
|
|
return field.GetValue(currentObject) as GameObject;
|
|
}
|
|
|
|
// If the field is not found, search all public instance fields of the current object
|
|
FieldInfo[] allFields = type.GetFields(BindingFlags.Public | BindingFlags.Instance);
|
|
foreach (FieldInfo subField in allFields)
|
|
{
|
|
// Get the value of the subfield (e.g., a nested class or struct)
|
|
object subFieldValue = subField.GetValue(currentObject);
|
|
|
|
if (subFieldValue == null)
|
|
continue;
|
|
|
|
// Recursively search within this subfield
|
|
GameObject result = FindFieldRecursively(subFieldValue, fieldName);
|
|
if (result != null)
|
|
{
|
|
return result; // If found in the nested field, return it
|
|
}
|
|
}
|
|
|
|
// If the field is not found in this object or its nested fields, return null
|
|
return null;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
[Serializable]
|
|
public class MedallionsForLibraryPuzzleInventoryItems
|
|
{
|
|
public GameObject MedallionA;
|
|
public GameObject MedallionB;
|
|
public GameObject MedallionC;
|
|
public GameObject MedallionD;
|
|
}
|
|
|
|
[Serializable]
|
|
public class MainHousePart1ItemsOnRingInventory
|
|
{
|
|
public GameObject BilliardBall;
|
|
public GameObject TeddyBear;
|
|
public GameObject KitchenRecipe;
|
|
}
|
|
|
|
[Serializable]
|
|
public class ChildrenLoopsItemsOnRingInventory
|
|
{
|
|
public GameObject DrawingTopLeft;
|
|
public GameObject DrawingTopRight;
|
|
public GameObject DrawingBottomLeft;
|
|
public GameObject DrawingBottomRight;
|
|
public GameObject BabyDollHeadPiece;
|
|
[Header("Loop 5")]
|
|
public GameObject BookA;
|
|
public GameObject BookB;
|
|
public GameObject BookC;
|
|
public GameObject BookD;
|
|
[Header("Loop 6")]
|
|
public GameObject ConfessKnife;
|
|
public GameObject RemainSilentKnife;
|
|
public GameObject BetrayKnife;
|
|
} |