/// <summary> /// The extension to easy create <see cref="MotionPlayer"/> with <paramref name="view"/> /// </summary> /// <param name="model">The l2d model</param> /// <param name="millsec">Fade millsecond</param> /// <exception cref="ArgumentNullException">When <paramref name="model"/>, <paramref name="view"/> or <paramref name="key"/> <see langword="null"/></exception> /// <exception cref="KeyNotFoundException">When given key <paramref name="key"/> not in <see cref="L2DModel.Motion"/></exception> public static MotionPlayer CreatePlayer(this L2DModel model, L2DView view, string key) { if (model is null) { throw new ArgumentNullException(nameof(model)); } if (view is null) { throw new ArgumentNullException(nameof(view)); } if (key is null) { throw new ArgumentNullException(nameof(key)); } var val = model.Motion[key]; return(new MotionPlayer(view, val)); }
/// <summary> /// Do when motion finished changed. /// <para> /// It is dependency <see cref="L2DView.IsMotionFinishedChanged"/> event. When the motion status changed, /// the action <paramref name="action"/> will be call once. /// </para> /// </summary> /// <param name="view">The l2d view, it can't be <see langword="null"/></param> /// <param name="action">The action, it can't be <see langword="null"/></param> /// <exception cref="ArgumentNullException">When arguments <paramref name="view"/> or <paramref name="action"/> is <see langword="null"/></exception> public static void DoWhenMotionFinishedChanged(this L2DView view, Action <L2DView, bool> action) { if (view is null) { throw new ArgumentNullException(nameof(view)); } if (action is null) { throw new ArgumentNullException(nameof(action)); } Action <L2DView, bool> doSomething = null; doSomething = (v, value) => { action?.Invoke(view, value); //Only once v.IsMotionFinishedChanged -= doSomething; }; view.IsMotionFinishedChanged += doSomething; }