/// <summary> /// This removes a target game object. /// </summary> /// <param name="gameObject"> /// The game object to remove. /// </param> public void RemoveGameObject(GameObject gameObject) { //make sure this game object is not null and is already in the list if (gameObject != null && targetGameObjects.Contains(gameObject) == true) { //remove the game object targetGameObjects.Remove(gameObject); //get all MonoBehavior components on this target game object MonoBehaviour[] behaviours = gameObject.GetComponents <MonoBehaviour>(); for (int j = 0; j < behaviours.Length; j++) { //make sure the found behavior is not this behavior, and it is a IVisModifierTarget if (behaviours[j] != this && behaviours[j] is IVisModifierTarget) { //get the modifier target and add to the ValueUpdate event IVisModifierTarget modifierTarget = behaviours[j] as IVisModifierTarget; if (modifierTarget != null) { ValueUpdated -= modifierTarget.OnValueUpdated; } } } } }
/// <summary> /// This destroys all of the delegates for all current target game objects. /// </summary> public void DestroyAllDelegates() { //loop through all game objects and remove delegates for (int i = 0; i < targetGameObjects.Count; i++) { //make sure this game object is not null if (targetGameObjects[i] != null) { //get all MonoBehavior components on this target game object MonoBehaviour[] behaviours = targetGameObjects[i].GetComponents <MonoBehaviour>(); for (int j = 0; j < behaviours.Length; j++) { //make sure the found behavior is not this behavior, and it is a IVisModifierTarget if (behaviours[j] != this && behaviours[j] is IVisModifierTarget) { //get the modifier target and remove from the ValueUpdate event IVisModifierTarget modifierTarget = behaviours[j] as IVisModifierTarget; if (modifierTarget != null) { ValueUpdated -= modifierTarget.OnValueUpdated; } } } } } }
/// <summary> /// This adds a new target game object. /// </summary> /// <param name="gameObject"> /// The game object to target. /// </param> public void AddGameObject(GameObject gameObject) { //make sure this game object is not null and is not already in the list if (gameObject != null && targetGameObjects.Contains(gameObject) == false) { //warn if the game object being added is the parent of this component if (gameObject == this) { Debug.LogWarning("You are adding a game object to a modifier that is the parent of this modifier. This may have unexpected results."); } //add the game object targetGameObjects.Add(gameObject); //get all MonoBehavior components on this target game object MonoBehaviour[] behaviours = gameObject.GetComponents <MonoBehaviour>(); for (int j = 0; j < behaviours.Length; j++) { //make sure the found behavior is not this behavior, and it is a IVisModifierTarget if (behaviours[j] != this && behaviours[j] is IVisModifierTarget) { //get the modifier target and add to the ValueUpdate event IVisModifierTarget modifierTarget = behaviours[j] as IVisModifierTarget; if (modifierTarget != null) { ValueUpdated += modifierTarget.OnValueUpdated; } } } } }