/************************************************************************************************************************/ /// <summary> /// Adds a menu function which passes the result of <see cref="CalculateEditorFadeDuration"/> into `startFade`. /// </summary> public static void AddFadeFunction(GenericMenu menu, string label, bool isEnabled, AnimancerNode node, Action <float> startFade) { // Fade functions need to be delayed twice since the context menu itself causes the next frame delta // time to be unreasonably high (which would skip the start of the fade). AddMenuItem(menu, label, isEnabled, () => EditorApplication.delayCall += () => EditorApplication.delayCall += () => { startFade(node.CalculateEditorFadeDuration()); }); }
/// <summary> /// Returns the duration of the `node`s current fade (if any), otherwise returns the `defaultDuration`. /// </summary> public static float CalculateEditorFadeDuration(this AnimancerNode node, float defaultDuration = 1) => node.FadeSpeed > 0 ? 1 / node.FadeSpeed : defaultDuration;
/************************************************************************************************************************/ /// <summary> /// Returns true if the `node` is not null and <see cref="AnimancerNode.IsValid"/>. /// </summary> /// <remarks> /// Normally a method can't have the same name as a property, but an extension method can. /// </remarks> public static bool IsValid(this AnimancerNode node) { return(node != null && node.IsValid); }