Multiple Text Color in itemTooltip and drag drop within UI background area

I have created multiple text Colors in itemTooltip but I am not sure if this is the best practice, because I don’t want to scrap everything down the road when I realize that that this method has some major limitations.

My approach:

  1. create more [SerializeField] descriptions for other texts in InventoryItem.cs
  2. create a [SerializeField] int itemLevelTier in InventoryItem.cs
  3. create public string function GetNewDescription() in InventoryItem.cs
  4. create public int GetItemLevelTier() in InventoryItem.cs
  5. Change itemLevel from Scriptable object for certain items
  6. create new [SerializeField] textMeshProUGUI newText in ItemTooltip
  7. fetch itemLevel in public void Setup(InventoryItem item){} first then change to different newColor32 depends on the int of the itemLevel.
    My result is in the pic as below:

My second question is that it’s not user friendly to drag an item to the UI area (outside of the equipment Slot but still in the background area) and release to drop. If I want the item to get back to the slot if I release when the item is still on top of the background UI area, I can only drop an item if I drag it to open area, what approach should I take?
My question is also in the pic as below:

We’ll start wtih the second question, if I’m understanding correctly, you don’t want the character to drop the item when over any part of the Equipment or Inventory area, implement the IDragDestination interface on the Equipment and Inventory windows, but for Max Acceptable, set the value to 0 (this will always force a snapback).

Now to tackle the first question…
Your approach will work, but be sure to take advantage of inheritance.

Here’s my approach:

In InventoryItem, I made GetDescription() virtual

public virtual string GetDescription() 
{
    return $"{description}\nLevel {level}";
}

Then in each of the child classes of InventoryItem, I add on the relevant information to that class…

/// EquipableItem's override
public override GetDescription()
{
    return base.GetDescription + $"\n{allowedEquipLocation}";
}
///WeaponConfig's Description
public override GetDescription()
{
    return base.GetDescription + 
       $"/n<color=#88ff888>Weapon Damage = {baseDamage}</color>";
}

Thanks Brian. Your approach is way much simplier. I love it.

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

Privacy & Terms