FWatcher.DoWatch C# (CSharp) Method

DoWatch() public method

public DoWatch ( object target, string targetName, bool shouldUseWeakReference ) : void
target object
targetName string
shouldUseWeakReference bool
return void
    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
        }
    }

Usage Example

Exemplo n.º 1
0
    static public void Watch(object target, bool shouldShowNonPublic, string targetName)
    {
        if (target == null)
        {
            return;
        }

        if (targetName == null)
        {
            if (target is Type)
            {
                targetName = (target as Type).Name;
            }
            else
            {
                targetName = target.GetType().Name;
            }
        }

        if (_instance == null)
        {
            _instance = new FWatcher();
        }

        _instance.DoWatch(target, targetName, shouldShowNonPublic);
    }