Advertisement
uurha

Untitled

Sep 9th, 2022 (edited)
986
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using System.Linq;
  6. using Object = UnityEngine.Object;
  7.  
  8. public class InventoryManager : MonoBehaviour
  9. {
  10.     private Dictionary<Type, List<Ingredient>> items = new Dictionary<Type, List<Ingredient>>();
  11.  
  12.     [SerializeField] private List<Ingredient> _ingredient = new List<Ingredient>();
  13.  
  14.     private WobblingConnector _wobblingConnector;
  15.  
  16.     private void Start()
  17.     {
  18.         _wobblingConnector = FindObjectOfType<WobblingConnector>(); //Better rework this, because it's not so good.
  19.  
  20.         SearchAllAndAddToDictionary();
  21.     }
  22.  
  23.     private void SearchAllAndAddToDictionary()
  24.     {
  25.         foreach (Ingredient item in _wobblingConnector._itemsInBackpack)
  26.         {
  27.             AddToDictionary(item);
  28.         }
  29.     }
  30.  
  31.     public void AddToDictionary(Ingredient item)
  32.     {
  33.         _ingredient.Add(item);
  34.         var type = item.GetType();
  35.             if(!items.ContainsKey(type))
  36.             {
  37.                 items.Add(type , new List<Ingredient>(){item});
  38.             }
  39.             else
  40.             {
  41.                 items[type].Add(item);
  42.             }
  43.             Debug.Log(ingredient);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement