Advertisement
evelynshilosky

CampfireUIManager - Part 35

Mar 19th, 2024
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.58 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7.  
  8. public class CampfireUIManager : MonoBehaviour
  9. {
  10.     public static CampfireUIManager Instance { get; set; }
  11.  
  12.     public Button cookButton;
  13.     public Button exitButton;
  14.  
  15.     public GameObject foodSlot;
  16.     public GameObject fuelSlot;
  17.  
  18.     public GameObject campfirePanel;
  19.     public bool isUIOpen;
  20.  
  21.     public Campfire selectedCampfire;
  22.  
  23.     public CookingData cookingData;
  24.  
  25.     private void Awake()
  26.     {
  27.         if (Instance != null && Instance != this)
  28.         {
  29.             Destroy(gameObject);
  30.         }
  31.         else
  32.         {
  33.             Instance = this;
  34.         }
  35.     }
  36.  
  37.     private void Update()
  38.     {
  39.         if (FuelAndFoodAreValid())
  40.             cookButton.interactable = true;
  41.         else
  42.             cookButton.interactable = false;
  43.     }
  44.  
  45.     private bool FuelAndFoodAreValid()
  46.     {
  47.         InventoryItem fuel = fuelSlot.GetComponentInChildren<InventoryItem>();
  48.         InventoryItem food = foodSlot.GetComponentInChildren<InventoryItem>();
  49.  
  50.         if (fuel != null && food != null)
  51.         {
  52.             if (cookingData.validFuels.Contains(fuel.thisName) &&
  53.                 cookingData.validFoods.Any(CookableFood => CookableFood.name == food.thisName))
  54.             {
  55.                 return true;
  56.             }
  57.             else
  58.             {
  59.                 return false;
  60.             }
  61.         }
  62.         return false;
  63.     }
  64.  
  65.     public void CookButtonPressed()
  66.     {
  67.         InventoryItem food = foodSlot.GetComponentInChildren<InventoryItem>();
  68.         selectedCampfire.StartCooking(food);
  69.  
  70.         InventoryItem fuel = fuelSlot.GetComponentInChildren<InventoryItem>();
  71.  
  72.         Destroy(food.gameObject);
  73.         Destroy(fuel.gameObject);
  74.  
  75.         CloseUI();
  76.     }
  77.  
  78.  
  79.  
  80.     public void OpenUI()
  81.     {
  82.         campfirePanel.SetActive(true);
  83.         isUIOpen = true;
  84.        
  85.         Cursor.lockState = CursorLockMode.None;
  86.         Cursor.visible = true;
  87.        
  88.         SelectionManager.Instance.DisableSelection();
  89.         SelectionManager.Instance.GetComponent<SelectionManager>().enabled = false;
  90.        
  91.         InventorySystem.Instance.OpenUI();
  92.     }
  93.  
  94.     public void CloseUI()
  95.     {
  96.         campfirePanel.SetActive(false);
  97.         isUIOpen = false;
  98.  
  99.         Cursor.lockState = CursorLockMode.Locked;
  100.         Cursor.visible = false;
  101.  
  102.         SelectionManager.Instance.EnableSelection();
  103.         SelectionManager.Instance.GetComponent<SelectionManager>().enabled = true;
  104.     }
  105.  
  106.  
  107. }
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement