Here is preview. You can customize it to fit your project.
class SelectableRealWorldSample : MonoBehaviour, ISelectable
{
[field: SerializeField] public ObjectData Data { get; private set; }
[field: SerializeField] public Forceable Forceable { get; private set; }
[field: SerializeField] public bool CanBeSelected { get; private set; } = true;
[field: SerializeField] public UnityEvent<bool> OnSelectChanged { get; private set; } = new();
[field: SerializeField] public UnityEvent<bool> OnHoverChanged { get; private set; } = new();
public bool IsLocalPlayer => Forceable.forceId == Forceable.LocalPlayerId;
public Sprite Icon => Data.icon;
// Primary selection priority
// Returns 0 for local player objects, 1 for others
// Used to prioritize selecting player's own units first
public int SelectionPriority1
{
get
{
if (IsLocalPlayer) return 0;
return 1;
}
}
// Secondary selection priority
// Prioritizes units (0) over structures (1) and other types (2)
public int SelectionPriority2
{
get
{
if (Data.type == ObjectType.Unit) return 0;
else if (Data.type == ObjectType.Structure) return 1;
return 2;
}
}
// Tertiary selection priority
// For units, returns 0
// For other types, uses the Order value
public int SelectionPriority3
{
get
{
if (Data.type == ObjectType.Unit) return 0;
return Order;
}
}
// Determines the ordering within selection groups
// Units get a higher base order (10000 + ID)
// Other types just use their ID
public int Order
{
get
{
int order = 0;
if (Data.type == ObjectType.Unit)
{
order += 10000;
}
order += Data.id;
return order;
}
}
// SubGroupId uses the object's ID for grouping related selectables
public int SubGroupId => Data.id;
// Only local player objects can be multi-selected
public bool CanBeMultiSelected => IsLocalPlayer;
// Only local player objects can be grouped
public bool CanBeGrouped => IsLocalPlayer;
}