/// <summary> /// Sets a component's enabled state to a specified state. /// </summary> /// <param name="component">Component to set.</param> /// <param name="state">State to set the component to (true, false, or flip).</param> public static void SetComponentEnabled(Component component, Toggle state) { bool newValue; if (component == null) { return; } if (component is Renderer) { Renderer targetRenderer = component as Renderer; newValue = ToggleTools.GetNewValue(targetRenderer.enabled, state); targetRenderer.enabled = newValue; } else if (component is Collider) { Collider targetCollider = component as Collider; newValue = ToggleTools.GetNewValue(targetCollider.enabled, state); targetCollider.enabled = newValue; } else if (component is Animation) { Animation animationComponent = component as Animation; newValue = ToggleTools.GetNewValue(animationComponent.enabled, state); animationComponent.enabled = newValue; } else if (component is Animator) { Animator animator = component as Animator; newValue = ToggleTools.GetNewValue(animator.enabled, state); animator.enabled = newValue; } else if (component is AudioSource) { AudioSource audioSource = component as AudioSource; newValue = ToggleTools.GetNewValue(audioSource.enabled, state); audioSource.enabled = newValue; } else if (component is Behaviour) { Behaviour behaviour = component as Behaviour; newValue = ToggleTools.GetNewValue(behaviour.enabled, state); behaviour.enabled = newValue; } else { if (DialogueDebug.LogWarnings) { Debug.LogWarning(string.Format("{0}: Don't know how to enable/disable {1}.{2}", new System.Object[] { DialogueDebug.Prefix, component.name, component.GetType().Name })); } return; } if (DialogueDebug.LogInfo) { Debug.Log(string.Format("{0}: {1}.{2}.enabled = {3}", new System.Object[] { DialogueDebug.Prefix, component.name, component.GetType().Name, newValue })); } }
public void DoAction(SetEnabledAction action, Transform actor) { if (action != null) { MonoBehaviour target = Tools.Select(action.target, this); bool newValue = ToggleTools.GetNewValue(target.enabled, action.state); if (DialogueDebug.LogInfo) { Debug.Log(string.Format("{0}: Trigger: {1}.{2}.enabled = {3}", new System.Object[] { DialogueDebug.Prefix, target.name, target.GetType().Name, newValue })); } target.enabled = newValue; } }
public void DoAction(SetActiveAction action, Transform actor) { if (action != null) { Transform target = Tools.Select(action.target, this.transform); bool newValue = ToggleTools.GetNewValue(target.gameObject.activeSelf, action.state); if (DialogueDebug.LogInfo) { Debug.Log(string.Format("{0}: Trigger: {1}.SetActive({2})", new System.Object[] { DialogueDebug.Prefix, target.name, newValue })); } target.gameObject.SetActive(newValue); } }