Hello everyone.
How would i go if i want to open a panel with code?
I managed to do this below. And i can then attach OpenPanel() to a custom button. That when clicked will OpenMainMenu.
If i click the OpenCraftingMenu() it will open crafting menu.
But is this the correct way? It seems wrong to do it like this.
Can i please get some help here?
Also what is the correct way to code a close button via code? Is there something i need to handle inside the code? Like events or update inventory??
How would i go if i want to open a panel with code?
I managed to do this below. And i can then attach OpenPanel() to a custom button. That when clicked will OpenMainMenu.
If i click the OpenCraftingMenu() it will open crafting menu.
But is this the correct way? It seems wrong to do it like this.
Can i please get some help here?
Also what is the correct way to code a close button via code? Is there something i need to handle inside the code? Like events or update inventory??
C#:
using Opsive.UltimateInventorySystem.Demo.UI.Menus.Crafting;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Opsive.UltimateInventorySystem.Demo.Interaction.Interactables
{
using Opsive.Shared.Utility;
using Opsive.UltimateInventorySystem.Core;
using Opsive.UltimateInventorySystem.Core.InventoryCollections;
using Opsive.UltimateInventorySystem.Crafting;
using Opsive.UltimateInventorySystem.Demo.UI.Menus.Crafting;
using Opsive.UltimateInventorySystem.Interactions;
using Opsive.UltimateInventorySystem.Storage;
using Opsive.UltimateInventorySystem.UI;
using Opsive.UltimateInventorySystem.UI.Panels;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI.Extensions.Examples;
public class testscr : MonoBehaviour
{
[Tooltip("The crafting menu.")]
[SerializeField] protected CraftingMenu m_CraftingMenu;
[Tooltip("The recipes to display in the menu.")]
[SerializeField] protected CraftingRecipe[] m_MiscellanousRecipes;
[Tooltip("The recipes with the categories specified will be visible in the menu.")]
[SerializeField] protected CraftingCategory[] m_RecipeCategories;
[SerializeField] protected DisplayPanelManager m_DisplayPanelManager;
protected CraftingRecipe[] m_Recipes;
public Inventory Inventory;
public GameObject DMP;
public DisplayPanelManager _DPM;
// Start is called before the first frame update
void Start()
{
var recipeList = new List<CraftingRecipe>(m_MiscellanousRecipes);
for (int i = 0; i < m_RecipeCategories.Length; i++)
{
var pooledArray = GenericObjectPool.Get<CraftingRecipe[]>();
var recipesCount = m_RecipeCategories[i].GetAllChildrenElements(ref pooledArray);
for (int j = 0; j < recipesCount; j++)
{
recipeList.Add(pooledArray[j]);
}
GenericObjectPool.Return(pooledArray);
}
m_Recipes = recipeList.ToArray();
}
public void OpenPanel() {
_DPM.OpenMainMenu();
}
public void OpenCraftingMenu() {
m_CraftingMenu.SetClientInventory(Inventory);
m_CraftingMenu.SetRecipes(m_Recipes);
m_CraftingMenu.Open(m_CraftingMenu);
}
}
}