heya @Brian_Trotter @bixarrio (mainly bixarrio for this one)
OK so… I’ve spent the past couple of hours digging deep into the EBS Code, trying to figure out where in the world does the code go to, when it’s executing the function to select a building part to construct… After about 3 hours of searching, I finally found this in a script called ‘UICircularBuildingMenu.cs’:
public void SelectBuildingPart(string buildingName)
{
BuildingPlacer.Instance.SelectBuildingPart(BuildingManager.Instance.GetBuildingPartByName(buildingName));
BuildingPlacer.Instance.ChangeBuildMode(BuildingPlacer.BuildMode.PLACE);
CloseMenu();
}
Basically if the content of this function is commented out, the player is unable to click on that option. He can hover over it, but can’t click on it, which is perfect for what I want
Alongside, the developer provided me the code that he used to implement that function above for the “RPGBuilder” Unity Asset, as follows (if that helps):
CircularButtonSettings m_selectedButtonSettings;
m_selectedButtonSettings = circularButtonSettings;
public void SelectBuilding(string name)
{
if (m_SelectedButtonSettings.BuildingEntity != null &&
m_SelectedButtonSettings.BuildingEntity.RequiredItems != null)
{
if (!HasAllRequiredItems(m_SelectedButtonSettings.BuildingEntity.RequiredItems))
{
return;
}
}
BuildingPlacer.Instance.SelectBuildingPart(m_SelectedButtonSettings.BuildingEntity.GetComponent<BuildingPart>());
BuildingPlacer.Instance.ChangeBuildMode(BuildingPlacer.BuildMode.PLACE);
CloseMenu();
}
I also copied a bit from ‘Recipe.cs’ (our Crafting System) to create a new script I called ‘buildingRecipe.cs’, as follows:
// Similar to the 'RPGBuilderBuildingEntity.cs', this
// is my version of my own Building Recipe
using System;
using System.Collections.Generic;
using RPG.Crafting;
using UnityEngine;
namespace EasyBuildSystem.Features.Runtime.Buildings.Recipe
{
[CreateAssetMenu(menuName = "Construction/Recipe", order = 0)]
public class BuildingRecipe : ScriptableObject, ISerializationCallbackReceiver
{
// Unique ID for recipes
[SerializeField] string recipeID;
// Building Ingredients
[SerializeField] CraftingItem[] ingredients;
// Resulting Item
[SerializeField] CraftingItem resultingItem;
// Level required
[SerializeField] int levelRequired;
// XP Reward
[SerializeField] int XPReward;
static Dictionary<string, BuildingRecipe> recipeLookupCache = default;
public static BuildingRecipe GetFromID(string recipeID)
{
if (recipeLookupCache == null)
{
recipeLookupCache = new Dictionary<string, BuildingRecipe>();
var recipeList = Resources.LoadAll<BuildingRecipe>("Recipes");
foreach (var buildingRecipe in recipeList)
{
if (recipeLookupCache.ContainsKey(buildingRecipe.recipeID))
{
Debug.LogError($"Duplicate found: {recipeLookupCache[buildingRecipe.recipeID]} and {buildingRecipe}");
continue;
}
recipeLookupCache[buildingRecipe.recipeID] = buildingRecipe;
}
}
if (string.IsNullOrWhiteSpace(recipeID) || !recipeLookupCache.ContainsKey(recipeID))
{
return null;
}
return recipeLookupCache[recipeID];
}
public string GetRecipeID()
{
return recipeID;
}
public CraftingItem[] GetIngredients()
{
return ingredients;
}
public void OnAfterDeserialize()
{
if (string.IsNullOrWhiteSpace(recipeID))
{
recipeID = Guid.NewGuid().ToString();
}
}
public float GetRequiredLevel()
{
return levelRequired;
}
public int GetXPReward()
{
return XPReward;
}
public void OnBeforeSerialize()
{
// Empty function, needed for Interface to be quiet
}
}
}
Where “BuildingEntity.cs” is his equivalent of my “BuildingRecipe.cs” script, but each one of us took a slightly different direction with variable names I suppose
(I figured ‘CraftingItem.cs’ has sufficient information, so I copied a little bit from it, rather than developing a new ‘BuildingItem.cs’ script)
I seek help today for the final step, which is to blend these two scripts into one, so that if my player doesn’t have enough inventory resources in his inventory, he won’t be able to construct whatever the item he’s hovering over (and I’ll also throw in a level checker in the future, but that’s not for now… although I’m sure it’s literally only 3 lines of code at max)
Any other information you might seek? (I’m mainly asking because I can’t find the code in the Crafting System where the crafting operation of consuming stuff and all that happens, so I’m lowkey stuck and confessing that I forgot some stuff)