/// <summary> /// Called by Unity. /// </summary> private void OnEnable() { _cubismFadeMotionList = GetComponent <CubismFadeController>().CubismFadeMotionList; // Fail silently... if (_cubismFadeMotionList == null) { Debug.LogError("CubismMotionController : CubismFadeMotionList doesn't set in CubismFadeController."); return; } // Get Animator. var animator = GetComponent <Animator>(); if (animator.runtimeAnimatorController != null) { Debug.LogWarning("Animator Controller was set in Animator component."); return; } _isActive = true; // Disabble animator's playablegrap. var graph = animator.playableGraph; if (graph.IsValid()) { graph.GetOutput(0).SetWeight(0); } // Create Playable Graph. _playableGrap = PlayableGraph.Create("Playable Graph : " + this.FindCubismModel().name); _playableGrap.SetTimeUpdateMode(DirectorUpdateMode.GameTime); // Create Playable Output. _playableOutput = AnimationPlayableOutput.Create(_playableGrap, "Animation", animator); _playableOutput.SetWeight(1); // Create animation layer mixer. _layerMixer = AnimationLayerMixerPlayable.Create(_playableGrap, LayerCount); // Create cubism motion layers. if (_motionLayers == null) { LayerCount = (LayerCount < 1) ? 1 : LayerCount; _motionLayers = new CubismMotionLayer[LayerCount]; } for (var i = 0; i < LayerCount; ++i) { _motionLayers[i] = CubismMotionLayer.CreateCubismMotionLayer(_playableGrap, _cubismFadeMotionList); _motionLayers[i].AnimationEndHandler += OnAnimationEnd; _layerMixer.ConnectInput(i, _motionLayers[i].PlayableOutput, 0); _layerMixer.SetInputWeight(i, 1.0f); } // Set Playable Output. _playableOutput.SetSourcePlayable(_layerMixer); }
/// <summary> /// Initialize motion layer. /// </summary> /// <param name="playableGraph">.</param> /// <param name="fadeMotionList">.</param> /// <param name="layerWeight">.</param> public static CubismMotionLayer CreateCubismMotionLayer(PlayableGraph playableGraph, CubismFadeMotionList fadeMotionList, float layerWeight = 1.0f) { var ret = new CubismMotionLayer(); ret._playableGraph = playableGraph; ret._cubismFadeMotionList = fadeMotionList; ret._layerWeight = layerWeight; ret._isFinished = false; ret._motionStates = new List <CubismMotionState>(); ret._playingMotions = new List <CubismFadePlayingMotion>(); ret.PlayableOutput = AnimationMixerPlayable.Create(playableGraph, 1); return(ret); }