void UpdateAnimationState() { Initialize(); if (clipNameToClip.Count == 0 || animComponent == null) { return; } Model model = (Model)this.model; if (model.states == null || model.states.Length == 0) { return; } for (int i = 0; i < model.states.Length; i++) { Model.DCLAnimationState state = model.states[i]; if (clipNameToClip.ContainsKey(state.clip)) { AnimationState unityState = animComponent[state.clip]; unityState.weight = state.weight; unityState.wrapMode = state.looping ? WrapMode.Loop : WrapMode.ClampForever; unityState.clip.wrapMode = unityState.wrapMode; unityState.speed = state.speed; state.clipReference = unityState.clip; if (state.shouldReset) { ResetAnimation(state); } if (state.playing) { if (!animComponent.IsPlaying(state.clip)) { animComponent.Play(state.clip); } } else { if (animComponent.IsPlaying(state.clip)) { animComponent.Stop(state.clip); } } } } }
public void ResetAnimation(Model.DCLAnimationState state) { if (state == null || state.clipReference == null) { Debug.LogError("Clip not found"); return; } animComponent.Stop(state.clip); //Manually sample the animation. If the reset is not played again the frame 0 wont be applied state.clipReference.SampleAnimation(animComponent.gameObject, 0); }