예제 #1
0
    private void Serialize()
    {
        if (Settings == null)
        {
            Settings = new AnimatorGraph();
        }
        if (Settings.layers == null)
        {
            return;
        }

        int layerCount = Settings.layers.Length;

        for (int l = 0; l < layerCount; l++)
        {
            AnimatorLayer layer = Settings.layers[l];
            if (layer.states == null)
            {
                layer.states = new AnimatorState[0];
            }
            int stateCount = layer.states.Length;
            for (int s = 0; s < stateCount; s++)
            {
                AnimatorState state = layer.states[s];
                if (state.serialisedMotions == null)
                {
                    state.serialisedMotions = new List <SerializableMotion>();
                }
                state.serialisedMotions.Clear();
                SerialiseObject(state);
            }
        }
    }
예제 #2
0
    public void Deserialize()
    {
        AnimatorGraph animator   = Settings;
        int           layerCount = animator.layers.Length;

        for (int l = 0; l < layerCount; l++)
        {
            AnimatorLayer layer      = animator.layers[l];
            int           stateCount = layer.states.Length;
            for (int s = 0; s < stateCount; s++)
            {
                AnimatorState state = layer.states[s];
                if (state.serialisedMotions.Count > 0)
                {
                    state.motion = ReadNodeFromSerializedNodes(state, 0);
                }
            }
        }
    }
예제 #3
0
    void SetAnimationData(AnimatorGraph graph, List <AnimatorRuntimeBlendData> blend_data)
    {
        if (!_animator)
        {
            Log.Error("No Animator component attached to '{0}' or one of it's children, cant play animations", gameObject.name);
            return;
        }

        var blendCount = blend_data.Count;

        if (blendCount == 0)
        {
            //      Log.Warn("No blends sent");
            return;
        }

        _indexes.Clear();
        _playables.Clear();

        for (Int32 b = 0; b < blendCount; b++)
        {
            _motionData.Clear();

            var var    = blend_data[b];
            var state  = graph.GetState(var.stateId);
            var motion = state.GetMotion(var.animationIndex, _motionData) as AnimatorClip;

            if (motion != null && !String.IsNullOrEmpty(motion.clipName))
            {
                _playables.Add(AnimationClipPlayable.Create(_graph, _clips[motion.clipName]));
                _indexes.Add(b);
            }
        }

        var playableCount = _playables.Count;

        //    Debug.Log("====: "+playableCount);
        if (playableCount > 1)
        {
            _mixerPlayable = AnimationMixerPlayable.Create(_graph, playableCount);

            for (Int32 p = 0; p < playableCount; p++)
            {
                _graph.Connect(_playables[p], 0, _mixerPlayable, p);
            }
            _output.SetSourcePlayable(_mixerPlayable);

            for (Int32 p = 0; p < playableCount; p++)
            {
                var   data       = blend_data[_indexes[p]];
                float normalTime = data.normalTime.AsFloat;
                float clipLength = _playables[p].GetAnimationClip().length;
                //        float clipLength = (float)_playables[p].GetDuration();

                _playables[p].SetTime(normalTime * clipLength);//currentTime.AsFloat);

                //        _playables[p].SetTime(data.normalTime.AsFloat);
                //        Debug.Log(p + " \t " + _playables[p].GetAnimationClip().name.Substring(0,10) + " \t " + data.currentTime.AsFloat.ToString("F4") + " \t " + data.normalTime.AsFloat.ToString("F4") + " \t " + _playables[p].GetAnimationClip().length.ToString("F4") + " \t " + data.weight.AsFloat.ToString("F4") + " \t " + data.length.AsFloat.ToString("F4") + " \t " + data.calculatedLength.AsFloat.ToString("F4"));

                _playables[p].SetPlayState(PlayState.Paused);

                _mixerPlayable.SetInputWeight(p, data.weight.AsFloat);
            }
        }
        else if (playableCount == 1)
        {
            var   data       = blend_data[_indexes[0]];
            float normalTime = data.normalTime.AsFloat;
            float clipLength = _playables[0].GetAnimationClip().length;

            _playables[0].SetTime(normalTime * clipLength);
            //      Debug.Log("X \t " + _playables[0].GetAnimationClip().name.Substring(0, 10) + " \t " + data.currentTime.AsFloat.ToString("F4") + " \t " + data.normalTime.AsFloat.ToString("F4") + " \t " + _playables[0].GetAnimationClip().length.ToString("F4") + " \t " + data.weight.AsFloat.ToString("F4") + " \t " + data.length.AsFloat.ToString("F4") + " \t " + data.calculatedLength.AsFloat.ToString("F4"));

            _output.SetSourcePlayable(_playables[0]);
        }

        if (playableCount > 0)
        {
            _graph.Play();
        }
        else
        {
            _graph.Stop();
        }
    }