Example #1
0
        public static T FindOutput <T>(Playable h, bool recursive = false) where T : PlayableBehaviour, new()
        {
            if (!h.IsValid())
            {
                return(null);
            }

            for (int port = 0; port < h.GetOutputCount(); ++port)
            {
                var playable = h.GetOutput(port);
                if (playable.IsValid())
                {
                    var type = playable.GetPlayableType();
                    if (type == typeof(T))
                    {
                        return(((ScriptPlayable <T>)playable).GetBehaviour());
                    }
                    else if (recursive)
                    {
                        return(FindOutput <T>(playable, recursive));
                    }
                }
            }
            return(null);
        }
Example #2
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);
            }
        }
 private static bool HasValidOuputs(Playable h)
 {
     for (int port = 0; port < h.GetOutputCount(); ++port)
     {
         Playable playable = h.GetOutput(port);
         if (playable.IsValid())
         {
             return(true);
         }
     }
     return(false);
 }
Example #4
0
            public static bool IsOutputtingToPlayableType(Playable playable, Type type)
            {
                int numOutputs = playable.GetOutputCount();

                for (int i = 0; i < numOutputs; i++)
                {
                    if (IsPlayableOfType(playable.GetOutput(i), type))
                    {
                        return(true);
                    }
                }

                return(false);
            }
Example #5
0
    private void RecursiveDump(Playable p)
    {
        if (!p.IsValid <Playable>())
        {
            return;
        }
        var pCount = p.GetOutputCount <Playable>();

        for (int j = 0; j < pCount; j++)
        {
            var ip = p.GetOutput <Playable>(j);
            Debug.Log(ip.ToString());
            RecursiveDump(ip);
        }
    }
    public override void OnGraphStart(Playable playable)
    {
        base.OnGraphStart(playable);

        m_fatherMixerPlayable = playable.GetOutput(0);
        if (!m_fatherMixerPlayable.IsPlayableOfType <AnimationMixerPlayable>())
        {
            Debug.LogError("Get AnimationMixerPlayable Error");
        }

        //如果是第一个Clip,直接设置权重
        if (playable.Equals(m_fatherMixerPlayable.GetInput(0)))
        {
            SetWeight();
        }
    }
        public override void OnGraphStart(Playable playable)
        {
            ActiveMixerBehaviour = ((ScriptPlayable <ActiveMixerBehaviour>)playable.GetOutput(0)).GetBehaviour();
            ActiveMixerBehaviour.ActiveBehaviourList.Add(this);
            ExposedPropertyTable = playable.GetGraph().GetResolver();
            if (!string.IsNullOrEmpty(Label) && ActiveMixerBehaviour.MarkerMap.ContainsKey(Label))
            {
                DidBehaviourStartAsObservable()
                .Subscribe(_ => SetProcessing(true));
                DidBehaviourEndAsObservable()
                .Subscribe(_ => SetProcessing(false));
                ActiveMixerBehaviour
                .TimeProperty
                // Do not use streamed value
                .Subscribe(_ => ProcessTime());
            }

            Initialize();
        }
Example #8
0
            private static PlayableBehaviour GetTrackMixer(Playable root, TrackAsset track, Type type)
            {
                int inputCount = root.GetOutputCount();

                for (int i = 0; i < inputCount; i++)
                {
                    Playable rootInput = root.GetOutput(i);

                    if (rootInput.IsValid())
                    {
                        //If this input is a T, check it matches our track
                        if (rootInput.GetPlayableType() is ITrackMixer)
                        {
                            PlayableBehaviour playableBehaviour = GetPlayableBehaviour(rootInput, type);
                            ITrackMixer       trackMixer        = playableBehaviour as ITrackMixer;

                            if (trackMixer != null && trackMixer.GetTrackAsset() == track)
                            {
                                return(playableBehaviour);
                            }
                        }

                        //Otherwise search this playable's inputs
                        {
                            PlayableBehaviour trackMixer = GetTrackMixer(rootInput, track, type);

                            if (trackMixer != null)
                            {
                                return(trackMixer);
                            }
                        }
                    }
                }

                return(null);
            }
Example #9
0
            private static T GetTrackMixer <T>(Playable root, TrackAsset track) where T : class, IPlayableBehaviour, ITrackMixer, new()
            {
                int inputCount = root.GetOutputCount();

                for (int i = 0; i < inputCount; i++)
                {
                    Playable rootInput = root.GetOutput(i);

                    if (rootInput.IsValid())
                    {
                        //If this input is a T, check it matches our track
                        if (rootInput.GetPlayableType() == typeof(T))
                        {
                            ScriptPlayable <T> scriptPlayable = (ScriptPlayable <T>)rootInput;
                            T trackMixer = scriptPlayable.GetBehaviour();

                            if (trackMixer.GetTrackAsset() == track)
                            {
                                return(trackMixer);
                            }
                        }

                        //Otherwise search this playable's inputs
                        {
                            T trackMixer = GetTrackMixer <T>(rootInput, track);

                            if (trackMixer != null)
                            {
                                return(trackMixer);
                            }
                        }
                    }
                }

                return(null);
            }
Example #10
0
 public static double GetMixerTime(this Playable mixer) =>
 mixer.GetOutput(0).GetTime();