I guess a few comments.
Firstly, you can get the game object from the PointerEventData without needing your own static property. You can see how this is done in the docs: Interface IDropHandler | Unity UI | 3.0.0-exp.4
Secondly, it’s better to not use the transform heirarchy to manage your data structure. Your slot should hold onto a reference to the card dropped onto it, and not look it up via a child transform every time. On top of that, you should reference it via a component, rather than a game object.
When you want to get information about a game object, you can use GetComponent, or preferably TryGetComponent these days. So when your slot component has something dropped onto it, it can check for a particular component and go from there.
You could write your slot to either be generic and standalone for other components to hook into, or you can design it to be inherited from (or both?).
So lets imagine you have a MonoBehaviour called Card. A standalone slot might look like:
using System;
using UnityEngine;
// sealed, so no inheritance!
public sealed class Slot : MonoBehaviour, IDropHandler
{
private Card _card;
public event Action<Card> OnSlotCardChanged;
// try get pattern to get the current card
public bool TryGetCurrentCard(out Card card)
{
card = _card;
return card != null;
}
public void OnDrop (PointerEventData eventData)
{
var droppedGameObject = eventData.pointerDrag;
if (droppedGameObject == null) // do nothing if null
{
return;
}
bool isCard = droppedGameObject.TryGetComponent(out Card card) == true;
if (isCard == true)
{
_card = card;
_card.transform.SetParent(this.transform);
OnSlotCardChanged?.Invoke(_card);
}
}
}
Then you make other components that subscribe to the OnSlotCardChanged delegate.
One designed for inheritance might look like:
// lets make this abstract so only concrete derived types can be used
public abstract class Slot : MonoBehaviour, IDropHandler
{
public void OnDrop (PointerEventData eventData)
{
var droppedGameObject = eventData.pointerDrag;
if (droppedGameObject == null) // do nothing if null
{
return;
}
bool isCard = droppedGameObject.TryGetComponent(out Card card) == true;
if (isCard == true)
{
OnCardDropped(card);
}
protected abstract void OnCardDropped(Card card);
}
// usage
public sealed class CharacterSlot : Slot
{
private CharacterCard _characterCard;
protected override void OnCardDropped(Card card)
{
if (card is CharacterCard characterCard)
{
_characterCard = characterCard;
// etc etc
}
}
}
You probably want to add in some way to accept or deny a card being dropped into a slot as well.
Additionally, while I’m telling you to use GetComponent here, in your drag handler you have unnecessary uses of GetComponent. If these game objects always have a canvas group on them, then you should get the reference once in Awake, or reference it via a serialized field. No need to GetComponent for it every time.