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 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(""); }