public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("You need to specify a game object.", this);
        }

        UTTypeInfo theComponentInfo = component.EvaluateIn(context);

        if (theComponentInfo == null)
        {
            throw new UTFailBuildException("You need to specify a component that should be removed.", this);
        }

        Type theComponent = theComponentInfo.Type;

        if (theComponent == null)
        {
            throw new UTFailBuildException("There is no component of type " + theComponentInfo.TypeName + " in the current project. Did you delete it accidently?", this);
        }

        var doRemoveAll = removeAll.EvaluateIn(context);


        Component[] toRemove;
        if (doRemoveAll)
        {
            toRemove = theGameObject.GetComponents(theComponent);
        }
        else
        {
            toRemove = new Component[] { theGameObject.GetComponent(theComponent) };
        }

        foreach (var comp in toRemove)
        {
            if (comp != null)
            {
                if (UTPreferences.DebugMode)
                {
                    Debug.Log("Removing component " + comp.name + ".", this);
                }
                UObject.DestroyImmediate(comp);
            }
        }

        yield return("");
    }
 public UTComponentFilter(UTTypeInfo[] componentTypes)
 {
     if (componentTypes != null) {
         List<Type> finalTypes = new List<Type> ();
         foreach (var componentType in componentTypes) {
             var finalType = componentType.Type;
             if (finalType == null) {
                 Debug.LogWarning("There is no component of type " + componentType.TypeName + " in the current project. Did you delete it accidently?");
             }
             else {
                 finalTypes.Add(finalType);
             }
         }
         this.componentTypes = finalTypes.ToArray();
     }
 }
    public override IEnumerator Execute(UTContext context)
    {
        var theGameObject = gameObject.EvaluateIn(context);

        if (theGameObject == null)
        {
            throw new UTFailBuildException("You need to specify a game object.", this);
        }

        UTTypeInfo theComponentInfo = component.EvaluateIn(context);

        if (theComponentInfo == null)
        {
            throw new UTFailBuildException("You need to specify a component that should be added.", this);
        }

        Type theComponent = theComponentInfo.Type;

        if (theComponent == null)
        {
            throw new UTFailBuildException("There is no component of type " + theComponentInfo.TypeName + " in the current project. Did you delete it accidently?", this);
        }

        var doOnlyIfNotExists = onlyIfNotExists.EvaluateIn(context);
        var doAdd             = true;

        if (doOnlyIfNotExists)
        {
            if (theGameObject.GetComponent(theComponent) != null)
            {
                if (UTPreferences.DebugMode)
                {
                    Debug.Log("Component of type " + theComponent.Name + " already exists at game object " + theGameObject);
                }
                doAdd = false;
            }
        }

        if (doAdd)
        {
            theGameObject.AddComponent(theComponent);
        }

        yield return("");
    }