Exemplo n.º 1
0
        /************************************************************************************************************************/

        /// <summary>[Pro-Only]
        /// Reconnects the input of the specified `playable` to its output.
        /// </summary>
        public static void RemovePlayable(Playable playable, bool destroy = true)
        {
            if (!playable.IsValid())
            {
                return;
            }

            Debug.Assert(playable.GetInputCount() == 1,
                         $"{nameof(RemovePlayable)} can only be used on playables with 1 input.");
            Debug.Assert(playable.GetOutputCount() == 1,
                         $"{nameof(RemovePlayable)} can only be used on playables with 1 output.");

            var input = playable.GetInput(0);

            if (!input.IsValid())
            {
                if (destroy)
                {
                    playable.Destroy();
                }
                return;
            }

            var graph  = playable.GetGraph();
            var output = playable.GetOutput(0);

            if (output.IsValid())// Connected to another Playable.
            {
                if (destroy)
                {
                    playable.Destroy();
                }
                else
                {
                    Debug.Assert(output.GetInputCount() == 1,
                                 $"{nameof(RemovePlayable)} can only be used on playables connected to a playable with 1 input.");
                    graph.Disconnect(output, 0);
                    graph.Disconnect(playable, 0);
                }

                graph.Connect(input, 0, output, 0);
            }
            else// Connected to the graph output.
            {
                Debug.Assert(graph.GetOutput(0).GetSourcePlayable().Equals(playable),
                             $"{nameof(RemovePlayable)} can only be used on playables connected to another playable or to the graph output.");

                if (destroy)
                {
                    playable.Destroy();
                }
                else
                {
                    graph.Disconnect(playable, 0);
                }

                graph.GetOutput(0).SetSourcePlayable(input);
            }
        }
Exemplo n.º 2
0
        void Restore()
        {
            if (animator != null)
            {
                animator.runtimeAnimatorController = wasController;
                animator.applyRootMotion           = wasRootMotion;
                animator.cullingMode = wasCullingMode;
                animator.enabled     = wasEnabled;
            }

#if UNITY_2017_1_OR_NEWER
            if (graph.IsValid())
            {
                graph.Destroy();
            }
#elif UNITY_5_6_OR_NEWER
            if (graph.IsValid())
            {
                graph.Destroy();
            }
#else
            mixerPlayable.Destroy();
            if (Application.isPlaying && animator.runtimeAnimatorController != null)
            {
                RestoreAnimatorInfo();
            }
#endif
        }
Exemplo n.º 3
0
        public static void DestroyPlayableRecursive(ref Playable a_playable)
        {
            int count = a_playable.GetInputCount();

            for (int i = 0; i < count; ++i)
            {
                var playable = a_playable.GetInput(i);

                if (playable.IsValid())
                {
                    a_playable.DisconnectInput(i);
                    DestroyPlayableRecursive(ref playable); //Recursion
                }
            }

            a_playable.Destroy();
        }
Exemplo n.º 4
0
        //============================================================================================
        /**
        *  @brief Recursive function which destroys a playable and any child playables
        *         
        *********************************************************************************************/
        private void ClearPlayable(ref Playable a_playable)
        {
            if (!a_playable.IsValid())
                return;

            int inputCount = a_playable.GetInputCount();

            for(int i=0; i < inputCount; ++i)
            {
                var playable = a_playable.GetInput(i);

                ClearPlayable(ref playable);

                playable.Destroy();
            }

            a_playable.Destroy();
        }