/************************************************************************************************************************/ #endregion /************************************************************************************************************************/ #region Initialisation /************************************************************************************************************************/ #if UNITY_EDITOR /// <summary>[Editor-Only] /// Called by the Unity Editor in edit mode whenever an instance of this script is loaded or a value is changed /// in the inspector. /// <para></para> /// Uses <see cref="ClipState.ValidateClip"/> to ensure that all of the clips in the <see cref="Animations"/> /// array are supported by the <see cref="Animancer"/> system and removes any others. /// </summary> protected virtual void OnValidate() { if (_Animations == null) { return; } for (int i = 0; i < _Animations.Length; i++) { var clip = _Animations[i]; if (clip != null) { try { ClipState.ValidateClip(clip); continue; } catch (Exception ex) { Debug.LogException(ex, clip); } } Array.Copy(_Animations, i + 1, _Animations, i, _Animations.Length - (i + 1)); Array.Resize(ref _Animations, _Animations.Length - 1); i--; } }
/// <summary> /// Creates and returns a new <see cref="ClipState"/> to play the `clip` and registers it with the `key`. /// </summary> public ClipState CreateState(object key, AnimationClip clip) { var state = new ClipState(clip) { _Key = key, }; AddChild(state); return(state); }
/************************************************************************************************************************/ /// <summary>Checks if any clip in the <see cref="Controller"/> has an animation event with the specified 'functionName'.</summary> public override bool HasEvent(string functionName) { var clips = _Controller.animationClips; var count = clips.Length; for (int i = 0; i < count; i++) { if (ClipState.HasEvent(clips[i], functionName)) { return(true); } } return(false); }