Add Delivery Manager UI and UI logic
This commit is contained in:
parent
8c5f4f2acf
commit
3ec46256e8
89 changed files with 14001 additions and 12 deletions
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
@ -5,6 +6,8 @@ using UnityEngine;
|
|||
public class DeliveryManager : MonoBehaviour
|
||||
{
|
||||
|
||||
public event EventHandler OnRecipeSpawned;
|
||||
public event EventHandler OnRecipeCompleted;
|
||||
public static DeliveryManager Instance { get; private set; }
|
||||
|
||||
[SerializeField] private RecipeListSO recipeListSO;
|
||||
|
@ -30,11 +33,11 @@ public class DeliveryManager : MonoBehaviour
|
|||
|
||||
if (waitingRecipeSOList.Count < waitingRecipesMax)
|
||||
{
|
||||
RecipeSO waitingRecipeSO = recipeListSO.recipeSOList[Random.Range(0, recipeListSO.recipeSOList.Count)];
|
||||
|
||||
Debug.Log(waitingRecipeSO.recipeName);
|
||||
RecipeSO waitingRecipeSO = recipeListSO.recipeSOList[UnityEngine.Random.Range(0, recipeListSO.recipeSOList.Count)];
|
||||
|
||||
waitingRecipeSOList.Add(waitingRecipeSO);
|
||||
|
||||
OnRecipeSpawned?.Invoke(this, EventArgs.Empty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -81,6 +84,8 @@ public class DeliveryManager : MonoBehaviour
|
|||
|
||||
waitingRecipeSOList.RemoveAt(i);
|
||||
|
||||
OnRecipeCompleted?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -92,4 +97,9 @@ public class DeliveryManager : MonoBehaviour
|
|||
Debug.Log("Player brought the wrong recipe!");
|
||||
}
|
||||
|
||||
public List<RecipeSO> GetWaitingRecipeSOList()
|
||||
{
|
||||
return waitingRecipeSOList;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
8
Assets/Scripts/UI.meta
Normal file
8
Assets/Scripts/UI.meta
Normal file
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cbf3102324b7bf2459ff0cc7b25c1f74
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
39
Assets/Scripts/UI/DeliveryManagerSingleUI.cs
Normal file
39
Assets/Scripts/UI/DeliveryManagerSingleUI.cs
Normal file
|
@ -0,0 +1,39 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class DeliveryManagerSingleUI : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private TextMeshProUGUI recipeNameText;
|
||||
[SerializeField] private Transform iconContainer;
|
||||
[SerializeField] private Transform iconTemplate;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
iconTemplate.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void SetRecipeSO(RecipeSO recipeSO)
|
||||
{
|
||||
recipeNameText.text = recipeSO.recipeName;
|
||||
|
||||
foreach (Transform child in iconContainer)
|
||||
{
|
||||
if (child == iconTemplate) continue;
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
foreach (KitchenObjectSO kitchenObjectSO in recipeSO.kitchenObjectSoList)
|
||||
{
|
||||
Transform iconTransform = Instantiate(iconTemplate, iconContainer);
|
||||
|
||||
iconTransform.GetComponent<Image>().sprite = kitchenObjectSO.sprite;
|
||||
|
||||
iconTransform.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/UI/DeliveryManagerSingleUI.cs.meta
Normal file
11
Assets/Scripts/UI/DeliveryManagerSingleUI.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 3099d20f5c3187d4194b982b16b8b7d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
52
Assets/Scripts/UI/DeliveryManagerUI.cs
Normal file
52
Assets/Scripts/UI/DeliveryManagerUI.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class DeliveryManagerUI : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private Transform container;
|
||||
[SerializeField] private Transform recipeTemplate;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
recipeTemplate.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
UpdateVisual();
|
||||
|
||||
DeliveryManager.Instance.OnRecipeSpawned += DeliveryManager_OnRecipeSpawned;
|
||||
DeliveryManager.Instance.OnRecipeCompleted += DeliveryManager_OnRecipeCompleted;
|
||||
}
|
||||
|
||||
private void DeliveryManager_OnRecipeSpawned(object sender, System.EventArgs e)
|
||||
{
|
||||
UpdateVisual();
|
||||
}
|
||||
|
||||
private void DeliveryManager_OnRecipeCompleted(object sender, System.EventArgs e)
|
||||
{
|
||||
UpdateVisual();
|
||||
}
|
||||
|
||||
private void UpdateVisual()
|
||||
{
|
||||
foreach (Transform child in container)
|
||||
{
|
||||
if (child == recipeTemplate) continue;
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
|
||||
foreach (RecipeSO recipeSO in DeliveryManager.Instance.GetWaitingRecipeSOList())
|
||||
{
|
||||
Transform recipeTransform = Instantiate(recipeTemplate, container);
|
||||
|
||||
recipeTransform.GetComponent<DeliveryManagerSingleUI>().SetRecipeSO(recipeSO);
|
||||
|
||||
recipeTransform.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
11
Assets/Scripts/UI/DeliveryManagerUI.cs.meta
Normal file
11
Assets/Scripts/UI/DeliveryManagerUI.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 4ef59cd396e471c4aa88b6e877446288
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -5,8 +5,8 @@ using UnityEngine.UI;
|
|||
|
||||
public class PlateIconSingleUI : MonoBehaviour
|
||||
{
|
||||
|
||||
[SerializeField] private Image image;
|
||||
// For some reason it was pulling Image from somewhere else randomly near the end of development so I had to specify UnityEngine.UI.Image??
|
||||
[SerializeField] private UnityEngine.UI.Image image;
|
||||
|
||||
public void SetKitchenObjectSO(KitchenObjectSO kitchenObjectSO)
|
||||
{
|
|
@ -34,8 +34,10 @@ public class PlateIconsUI : MonoBehaviour
|
|||
foreach (KitchenObjectSO kitchenObjectSO in plateKitchenObject.GetKitchenObjectSOList())
|
||||
{
|
||||
Transform iconTransform = Instantiate(iconTemplate, transform);
|
||||
iconTransform.gameObject.SetActive(true);
|
||||
|
||||
iconTransform.GetComponent<PlateIconSingleUI>().SetKitchenObjectSO(kitchenObjectSO);
|
||||
|
||||
iconTransform.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue