예제 #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);
        }
예제 #2
0
    public override void ProcessFrame(Playable playable, FrameData info, object playerData)
    {
        Debug.Log(MethodInfo.GetCurrentMethod().Name + " Time=" + playable.GetTime());

        double preTime      = playable.GetPreviousTime();
        double timeOnClip   = playable.GetTime();
        double deltaTime    = timeOnClip - preTime;
        double durationTime = playable.GetDuration();
        double rate         = timeOnClip / durationTime;
        double rateAfter    = (timeOnClip + deltaTime) / durationTime;

        double weight = info.weight;

        int inputCount  = playable.GetInputCount();
        int outputCount = playable.GetOutputCount();

        Debug.Log(MethodInfo.GetCurrentMethod().Name + " InputCount=" + inputCount);

        // 文字列を設定
        messageDialog.SetText(textString);

        // 表示する
        messageDialog.Show();


        // ★次のフレームで完了する(クリップから抜ける)時
        // ※クリップを抜けるとProcessFrameは呼ばれず、OnBehaviourPauseが呼ばれるので、
        // ProcessFrame内で捕まえるタイミングは今しかない。
        if (rate < 1.0f && 1.0f <= rateAfter)
        {
            OnBehaviourPreFinish(playable, info, playerData);
        }
    }
예제 #3
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);
 }
예제 #5
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);
            }
예제 #6
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);
        }
    }
예제 #7
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);
            }
예제 #8
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);
            }
예제 #9
0
        private void UpdateTransition(float deltaTime)
        {
            int   inputsCount        = States.Count;
            float transitionDuration = CurrentTransition.Duration;

            if (CurrentTransition.DurationType == DurationType.SourcePercentage)
            {
                float sourceDuration = CurrentState.InputPort.Link.OutputPort.Node.Duration;
                transitionDuration *= sourceDuration == float.PositiveInfinity ? 1f : sourceDuration;
            }
            else if (CurrentTransition.DurationType == DurationType.DestinationPercentage)
            {
                float destinationDuration = NextState.InputPort.Link.OutputPort.Node.Duration;
                transitionDuration *= destinationDuration == float.PositiveInfinity ? 1f : destinationDuration;
            }

            float progressDelta         = transitionDuration != 0f ? deltaTime / transitionDuration : 1f;
            float transitionProgress    = TransitionProgress;
            float newTransitionProgress = transitionProgress + progressDelta;

            float inverseTransitionProgress = 1f - transitionProgress;

            void ResetState(State state)
            {
                state.PreviousTime.Value           = 0f;
                state.Time.Value                   = 0f;
                state.PreviousNormalizedTime.Value = 0f;
                state.NormalizedTime.Value         = 0f;
            }

            for (int i = 0; i < inputsCount; i++)
            {
                if (i == TransitionDestinationIndex)
                {
                    continue;
                }

                float inputWeight = InputPorts[i].Weight;

                if (inputWeight <= 0f)
                {
                    continue;
                }

                float newInputWeight = inputWeight - progressDelta * (inputWeight / inverseTransitionProgress);

                if (newInputWeight <= 0f)
                {
                    InputPorts[i].Weight = 0f;

                    Playable inputPlayable = Playable.GetInput(i);
                    if (!inputPlayable.IsNull() && inputPlayable.GetOutputCount() < 2)
                    {
                        //inputPlayable.Pause();
                        if (InputPorts[i].Link.OutputPort.Node.CanSetTime)
                        {
                            inputPlayable.SetTime(0f);
                        }
                    }
                    ResetState(States.At(i));

                    continue;
                }

                InputPorts[i].Weight = newInputWeight;
            }

            if (newTransitionProgress >= 1f)
            {
                for (int i = 0; i < States.Count; i++)
                {
                    if (i == TransitionDestinationIndex)
                    {
                        continue;
                    }

                    InputPorts[i].Weight = 0f;

                    Playable inputPlayable = Playable.GetInput(i);
                    if (!inputPlayable.IsNull() && inputPlayable.GetOutputCount() < 2)
                    {
                        //inputPlayable.Pause();
                        if (InputPorts[i].Link.OutputPort.Node.CanSetTime)
                        {
                            inputPlayable.SetTime(0f);
                        }
                    }
                    ResetState(States.At(i));
                }

                InputPorts[TransitionDestinationIndex].Weight = 1f;

                if (CurrentTransition.PlayAfterTransition)
                {
                    Playable.GetInput(TransitionDestinationIndex).Play();
                }

                OnTransitionFinished?.Invoke(CurrentTransition);

                CurrentState = CurrentTransition.DestinationState;
                NextState    = null;

                InTransition      = false;
                CurrentTransition = null;
            }
            else
            {
                InputPorts[TransitionDestinationIndex].Weight = newTransitionProgress;
            }
        }