I know this has nothing to do with the RPG Course, and please ignore if you wish to do so, but I was just wondering if anyone ever attempted and successfully implemented a grid-based construction system for their game? (I’m trying to implement this ON A COPY OF THE MASTER RPG PROJECT REPO, as I wait for Brian to release a new chapter of his series). I recently purchased the ‘Easy Build System’ from the Unity Asset Store by PolarInt, and the developer takes a while to respond to my questions, so I’m seeking help here (even though I know this is not the right place to be, but something is better than nothing…)
If anyone purchased that system and managed to integrate it into their game, or knows how to integrate one, that would be amazing
For context, here is what he told me about trying to integrate his system into my game:
To start, in your inventory system, create a new "string" variable in your "item.cs" script or something similar.
// by 'item.cs', I assumed he meant my 'InventoryItem.cs' script, but that didn't work too well for me...
This variable should contain the same identifier as the Building Part that will be placed when you use the item in question.
--
Next, you need to create a new method that you'll call when using your item from the inventory to preview the Building Part.
Example: "TryUseBuildingItem(string identifier)". Add your identifier, which you added earlier, as an argument.
This method will allow you to preview the desired building without actually using the item.
For example, if the player cancels the placement with a right-click, it would be silly to use the item.
--
Now, here's where the integration happens:
When you call the method you previously created (TryUseBuildingItem), you can enter preview mode by calling these following methods:
// Here, we directly take the "identifier" argument we passed. This will allow us to reference the Building Part in question.
BuildingPart partReference = BuildingManager.Instance.GetBuildingPartByIdentifier(string identifier);
// Now that we have the reference, we select it in the Building Placer.
BuildingPlacer.Instance.SelectBuildingPart(partReference);
// Here, we switch into placement mode to preview the Building Part.
BuildingPlacer.Instance.ChangeBuildMode(BuildMode mode);
--
When this is done, you just need to use an event from the system to detect if a Building Part has been placed:
BuildingManager.Instance.OnPlacingBuildingPartEvent.AddListener((BuildingPart part) => { });
Of course, inside this event, you check that the placed Building Part's identifier is the same as the one used by your item.
Then, you can delete the item or decrease the amount by 1, depending on the item type.
I hope this isn't too confusing. This is the approach I used for integrating the system with RPGBuilder, so if you have the asset, you can take a look at it; it will make things easier for you.
and here is what I attempted to code, following his instructions (in my ‘InventorySlotUI.cs’ script). I’m not sure why I chose “InventorySlotUI.cs” instead of “InventoryItem.cs”:
// EASY Build System Integration:
public string buildingPartIdentifier;
public void TryUseBuildingItem(string identifier)
{
// Retrieve the BuildingPart reference based on the identifier:
BuildingPart partReference = BuildingManager.Instance.GetBuildingPartByIdentifier(identifier);
// Check if the reference is valid:
if (partReference != null)
{
// Select the building part in the Building Placer:
BuildingPlacer.Instance.SelectBuildingPart(partReference);
// Switch to placement mode, for previewing the Building Part:
BuildingPlacer.Instance.ChangeBuildMode(BuildingPlacer.BuildMode.EDIT);
}
}
void Start()
{
BuildingManager.Instance.OnPlacingBuildingPartEvent.AddListener((BuildingPart part) =>
{
if (part.GetGeneralSettings.Identifier == buildingPartIdentifier)
{
if (item.IsStackable())
{
Inventory inventory = Inventory.GetPlayerInventory();
RemoveItems(1); // kinda clueless of how to get a count on that
}
}
});
}
Any help or leads on this would be appreciated (but please keep the language simple), I’m willing to try program it on my own, or even try code my own from scratch, but I’m struggling to get any further directions.