Пример #1
0
    public void OnResult(MMResult result)
    {
        if (result.Clip == null)
        {
            return;
        }
        bool needBlend = m_currentClip.IsNull() == false;

        if (needBlend)
        {
            if (result.Clip == m_currentClip.GetAnimationClip())
            {
                return;
            }

            AnimationClipPlayable blendOutClip = m_currentClip;
            m_mixer.DisconnectInput(0);
            m_mixer.DisconnectInput(1);
            m_mixer.ConnectInput(1, blendOutClip, 0, 1.0f);
            m_weight = 0.0f;
            m_mixer.SetInputWeight(0, 0.0f);
            m_mixer.SetInputWeight(1, 1.0f);
        }
        else
        {
            m_mixer.SetInputWeight(0, 1.0f);
            m_mixer.SetInputWeight(1, 0.0f);
        }

        m_currentClip = AnimationClipPlayable.Create(m_graph, result.Clip);
        m_currentClip.SetTime(result.Time);

        m_mixer.DisconnectInput(0);
        m_mixer.ConnectInput(0, m_currentClip, 0, needBlend? 0.0f : 1.0f);
    }
Пример #2
0
        public void RemoveZeroWeightsInput()
        {
            int size = mixer.GetInputCount();

            for (int i = 0; i < size; i++)
            {
                if (mixer.GetInputWeight(i) <= 0)
                {
                    mixer.GetInput(i).Destroy();
                    for (int j = i + 1; j < size; j++)
                    {
                        // double localTime = ((AnimationClipPlayable)mixer.GetInput(j)).GetTime();
                        float    _weight = mixer.GetInputWeight(j);
                        Playable clip    = mixer.GetInput(j);
                        // clip.SetTime(localTime);
                        mixer.DisconnectInput(j);
                        mixer.ConnectInput(j - 1, clip, 0);
                        mixer.SetInputWeight(j - 1, _weight);
                    }
                    i--;
                    size--;
                    mixer.SetInputCount(size);
                }
            }
        }
        //===========================================================================================

        /**
         *  @brief
         *
         *********************************************************************************************/
        public void EndPreviewLocal()
        {
            if (!m_previewActive)
            {
                return;
            }

            AnimationMixerPlayable mixer = MxMPreviewScene.Mixer;

            if (mixer.IsValid())
            {
                for (int i = 0; i < mixer.GetInputCount(); ++i)
                {
                    var clipPlayable = mixer.GetInput(0);

                    if (clipPlayable.IsValid())
                    {
                        mixer.DisconnectInput(0);
                        clipPlayable.Destroy();
                    }
                }
            }

            m_previewActive     = false;
            m_previewBlendSpace = null;
        }
        public override void OnChangeClip(ClipBehaviour fromClip, float fromWeight, ClipBehaviour toClip, float toWeight)
        {
            m_Mixer.DisconnectInput(0);
            m_Mixer.DisconnectInput(1);

            if (fromClip != null)
            {
                var playable = ((AnimationClipBehaviour)fromClip).Playable;
                m_Mixer.ConnectInput(0, playable, 0, fromWeight);
            }

            if (toClip != null)
            {
                var playable = ((AnimationClipBehaviour)toClip).Playable;
                m_Mixer.ConnectInput(1, playable, 0, toWeight);
            }

            m_Mixer.SetInputWeight(0, fromWeight);
            m_Mixer.SetInputWeight(1, toWeight);
        }
 public void Disconnect(int index)
 {
     if (!Animation.IsNull() && Animation.IsValid())
     {
         Animation.DisconnectInput(index);
     }
     if (!Audio.IsNull() && Audio.IsValid())
     {
         Audio.DisconnectInput(index);
     }
 }
Пример #6
0
    /// <summary>
    /// Adds clip to Aniamtion Graph and then plays the clip.
    /// </summary>
    /// <param name="blendTime">Time taken to blend between current clip and next clip</param>
    /// <param name="clipOffset">How many seconds to offset the clip's start time</param>
    public void Play(AnimationClip clip, float blendTime = .2f, float clipOffset = 0)
    {
        if (!clip)
        {
            Debug.LogError("Cannot Play Null Clip", gameObject);
            return;
        }
        if (!playableLookup.TryGetValue(clip, out var next))
        {
            if (!graph.IsValid())
            {
                CreateGraph();
            }

            playableLookup[clip] = next = AnimationClipPlayable.Create(graph, clip);
        }

        var current = mixer.GetInput(0);

        next.SetTime(clipOffset);
        mixer.DisconnectInput(0);
        mixer.DisconnectInput(1);

        mixer.ConnectInput(0, next, 0);

        if (blendTime <= 0)
        {
            mixer.SetInputWeight(0, 1);
        }
        else
        {
            if (current.IsValid() && ((AnimationClipPlayable)current).GetAnimationClip() != ((AnimationClipPlayable)next).GetAnimationClip())
            {
                mixer.ConnectInput(1, current, 0);
            }
            mixer.SetInputWeight(0, 0);
            mixer.SetInputWeight(1, 1);
        }
        this.blendTime = blendTime;
        changeTime     = Time.time;
    }
Пример #7
0
        public void RemoveZeroWeightsInputsAnimations(
            AnimationMixerPlayable mixer,
            List <float> blendingWeights,
            List <float> currentWeights,
            List <int> curretClipsIndex,
            List <LogicAnimationsSequence> animationsSequences
            )
        {
            int size = mixer.GetInputCount();

            for (int i = 0; i < size; i++)
            {
                if (currentWeights[i] <= 0f)
                {
                    int sequenceMixerInputsCount = mixer.GetInput(i).GetInputCount();
                    if (sequenceMixerInputsCount > 0)
                    {
                        for (int mixerInputInputsIndex = 0; mixerInputInputsIndex < sequenceMixerInputsCount; mixerInputInputsIndex++)
                        {
                            mixer.GetInput(i).GetInput(mixerInputInputsIndex).Destroy();
                        }
                        for (int as_Index = 0; as_Index < animationsSequences.Count; as_Index++)
                        {
                            if (curretClipsIndex[i] == animationsSequences[as_Index].dataIndex)
                            {
                                animationsSequences.RemoveAt(as_Index);
                                break;
                            }
                        }
                    }
                    mixer.GetInput(i).Destroy();
                    blendingWeights.RemoveAt(i);
                    curretClipsIndex.RemoveAt(i);
                    currentWeights.RemoveAt(i);
                    for (int j = i + 1; j < size; j++)
                    {
                        // double localTime = ((AnimationClipPlayable)mixer.GetInput(j)).GetTime();
                        float    _weight = mixer.GetInputWeight(j);
                        Playable clip    = mixer.GetInput(j);
                        // clip.SetTime(localTime);
                        mixer.DisconnectInput(j);
                        mixer.ConnectInput(j - 1, clip, 0);
                        mixer.SetInputWeight(j - 1, _weight);
                    }
                    i--;
                    size--;
                    mixer.SetInputCount(size);
                }
            }
        }
Пример #8
0
    private void ConnectInput(int index)
    {
        StateInfo state = m_States[index];
        AnimationMixerPlayable mixer = GetMixer(state.layer);

        if (mixer.Equals(AnimationMixerPlayable.Null))
        {
            throw new Exception("Can not get mixer at layer:" + state.layer);
        }

        int stateCountByLayer = m_States.GetCountByLayer(state.layer);

        if (stateCountByLayer > mixer.GetInputCount())
        {
            mixer.SetInputCount(stateCountByLayer);
        }

        mixer.DisconnectInput(state.indexAtLayer);
        graph.Connect(state.playable, 0, mixer, state.indexAtLayer);
    }
Пример #9
0
        public void Tick(float deltaTime)
        {
            _playableGraph.Evaluate(deltaTime);

            for (int i = 0; i < AnimationPlayLayers.Length; i++)
            {
                var currLayer = AnimationPlayLayers[i];

                if (currLayer.GetWeight(out var aW, out var bW))
                {
                    mixerPlayable.SetInputWeight(currLayer.aInputIndex, aW);
                    mixerPlayable.SetInputWeight(currLayer.bInputIndex, bW);

                    if (aW <= 0)
                    {
                        mixerPlayable.DisconnectInput(currLayer.aInputIndex);
                        currLayer.EndBInput();
                    }
                }
                currLayer.Time += deltaTime;
            }
        }