I have a list of 10 game objects and i want to compare this list to a list with clones of these game objects. I want to check if the content of the two lists are the same regardless of the order but the one contains original objects and the other contains clones of the same objects. These are my lists
public List<GameObject> Materials = new List<GameObject>();
public List<GameObject> materialsRequired = new List<GameObject>();
and this is the algorithm i use to compare them which I got from some other stackoverflow answer:
public static bool ScrambledEquals<T>(IEnumerable<T> list1, IEnumerable<T> list2)
{
var cnt = new Dictionary<T, int>();
foreach (T s in list1)
{
if (cnt.ContainsKey(s))
{
cnt[s]++;
}
else
{
cnt.Add(s, 1);
}
}
foreach (T s in list2)
{
if (cnt.ContainsKey(s))
{
cnt[s]--;
}
else
{
return false;
}
}
return cnt.Values.All(c => c == 0);
}
even though this answer works if both lists contain the original asset of the game object, it doesnt work when one contains the same objects but instead of the original game objects it contains different instances/clones of the object.
Does anyone know how I can fix this?