public void DoWatch(object target, string targetName, bool shouldUseWeakReference)
{
Type targetType = target.GetType();
int watcherTypeCount = _watcherTypes.Count;
bool wasWatcherTypeFound = false;
GameObject ownerGO = new GameObject(targetName);
ownerGO.transform.parent = _gameObject.transform;
//for(int w = watcherTypeCount-1; w >= 0; w--) //notice the reverse order, so we check against newer stuff first
for(int w = 0; w < watcherTypeCount; w++)
{
FWatcherType watcherType = _watcherTypes[w];
if(watcherType.targetType.IsAssignableFrom(targetType))
{
FWatcherLink link = ownerGO.AddComponent(watcherType.linkType) as FWatcherLink;
link.Init(target, shouldUseWeakReference);
wasWatcherTypeFound = true;
}
}
if(!wasWatcherTypeFound)
{
ownerGO.transform.parent = null; //remove the gameobject
}
}