Пример #1
0
        /// <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 = ToggleUtility.GetNewValue(targetRenderer.enabled, state);
                targetRenderer.enabled = newValue;
            }
            else if (component is Collider)
            {
                Collider targetCollider = component as Collider;
                newValue = ToggleUtility.GetNewValue(targetCollider.enabled, state);
                targetCollider.enabled = newValue;
            }
            else if (component is Animation)
            {
                Animation animationComponent = component as Animation;
                newValue = ToggleUtility.GetNewValue(animationComponent.enabled, state);
                animationComponent.enabled = newValue;
            }
            else if (component is Animator)
            {
                Animator animator = component as Animator;
                newValue         = ToggleUtility.GetNewValue(animator.enabled, state);
                animator.enabled = newValue;
            }
            else if (component is AudioSource)
            {
                AudioSource audioSource = component as AudioSource;
                newValue            = ToggleUtility.GetNewValue(audioSource.enabled, state);
                audioSource.enabled = newValue;
            }
            else if (component is Behaviour)
            {
                Behaviour behaviour = component as Behaviour;
                newValue          = ToggleUtility.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 }));
            }
        }
Пример #2
0
 public void DoAction(SetActiveAction action, Transform actor)
 {
     if (action != null)
     {
         Transform target   = Tools.Select(action.target, this.transform);
         bool      newValue = ToggleUtility.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);
     }
 }
Пример #3
0
 protected virtual void DoSetActiveActions(Transform actor)
 {
     for (int i = 0; i < setActiveActions.Length; i++)
     {
         var action = setActiveActions[i];
         if (action != null && action.condition != null && action.condition.IsTrue(actor))
         {
             var  target   = Tools.Select(action.target, this.transform);
             bool newValue = ToggleUtility.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);
         }
     }
 }
 public void DoAction(SetEnabledAction action, Transform actor)
 {
     if (action != null)
     {
         MonoBehaviour target = Tools.Select(action.target, this);
         if (target == null)
         {
             return;
         }
         bool newValue = ToggleUtility.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;
     }
 }