Questions regarding TooltipSpawner and IItemHolder

Hello, I have two questions,

  1. What was the reason to not define CanCreateTooltip() and UpdateTooltip() in the TooltipSpawner.cs script itself? (all other methods in that script were defined).

  2. Instead of using the IItemHolder interface, why dont we just use IDragContainer interface which also has the GetItem() method in it?

The base TooltipSpawner does not know the conditions for which the tooltip can be created, as it’s generic… It doesn’t even know that it’s an IItemHolder… all it knows is that it’s going to spawn a GameObject and try to place it at the right location, that’s all.

This is best handled by the child class which has more information about whether or not the tooltip can be generated… For example, you might have a tooltip spawner on an enemy that spawns a tooltip describing the enemy and it’s strengths and weaknesses. IItemHolder is for InventoryItems, so that wouldn’t work. If the character is in combat (like you’re actively fighting it), a tooltip could get in the way, so we don’t want to display it then. So for an Enemy Tooltip, you might have

[RequireComponent(typeof(EnemyInformationHolder))]
public class EnemyTooltipSpawner : TooltipSpawner
{
    public override bool CanCreateTooltip()
    {
         if(GetComponent<Fighter>().IsInCombat()) return false;
         return true;
     }
}

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms