// Copyright (c) 2015 - 2023 Doozy Entertainment. All Rights Reserved. // This code can only be used under the standard Unity Asset Store End User License Agreement // A Copy of the EULA APPENDIX 1 is available at http://unity3d.com/company/legal/as_terms using Doozy.Runtime.Reactor.Easings; using Doozy.Runtime.Reactor.Ticker; using UnityEngine; // ReSharper disable UnusedMember.Global // ReSharper disable MemberCanBePrivate.Global namespace Doozy.Runtime.Reactor.Internal { public static class ReactionExtensions { public static T SetDirection(this T target, PlayDirection playDirection) where T : Reaction { target.direction = playDirection; return target; } public static T SetTargetObject(this T target, object targetObject) where T : Reaction { if (target.hasTargetObject) Reaction.ReactionByTargetObject.RemoveReaction(target.targetObject, target); target.targetObject = targetObject; target.hasTargetObject = targetObject != null; if (target.hasTargetObject) Reaction.ReactionByTargetObject.AddReaction(targetObject, target); return target; } public static T ClearTargetObject(this T target) where T : Reaction => target.SetTargetObject(null); public static T SetObjectId(this T target, object objectId) where T : Reaction { if (target.hasObjectId) Reaction.ReactionByObjectId.RemoveReaction(target.objectId, target); target.objectId = objectId; target.hasObjectId = objectId != null; if (target.hasObjectId) Reaction.ReactionByObjectId.AddReaction(objectId, target); return target; } public static T ClearObjectId(this T target) where T : Reaction => target.SetObjectId(null); public static T SetStringId(this T target, string stringId) where T : Reaction { if (target.hasStringId) Reaction.ReactionByStringId.RemoveReaction(target.stringId, target); target.stringId = stringId; target.hasStringId = !string.IsNullOrEmpty(stringId); if (target.hasStringId) Reaction.ReactionByStringId.AddReaction(stringId, target); return target; } public static T ClearStringId(this T target) where T : Reaction => target.SetStringId(string.Empty); public static T SetIntId(this T target, int intId) where T : Reaction { if (target.hasIntId) Reaction.ReactionByIntId.RemoveReaction(target.intId, target); target.intId = intId; target.hasIntId = true; if (target.hasIntId) Reaction.ReactionByIntId.AddReaction(intId, target); return target; } public static T ClearIntId(this T target) where T : Reaction { if (target.hasIntId) Reaction.ReactionByIntId.RemoveReaction(target.intId, target); target.intId = Reaction.k_DefaultIntId; target.hasIntId = false; return target; } public static T ClearAllIds(this T target) where T : Reaction => target .ClearTargetObject() .ClearObjectId() .ClearStringId() .ClearIntId(); public static T SetRuntimeHeartbeat(this T target) where T : Reaction { target.SetHeartbeat(new RuntimeHeartbeat()); return target; } public static T SetPlayMode(this T target, PlayMode playMode) where T : Reaction { target.settings.playMode = playMode; return target; } public static T SetEaseMode(this T target, EaseMode easeMode) where T : Reaction { target.settings.easeMode = easeMode; return target; } public static T SetEase(this T target, Ease ease) where T : Reaction { target.settings.ease = ease; return target; } public static T SetAnimationCurve(this T target, AnimationCurve curve) where T : Reaction { target.settings.curve = curve; return target; } public static T SetReactionSettings(this T target, ReactionSettings settings) where T : Reaction { target.settings = settings ?? new ReactionSettings(); target.RefreshSettings(); return target; } public static T ApplyReactionSettings(this T target, ReactionSettings settings) where T : Reaction { target.settings = new ReactionSettings(settings); target.RefreshSettings(); return target; } public static T SetStartDelay(this T target, float startDelay) where T : Reaction { target.settings.useRandomStartDelay = false; target.settings.startDelay = startDelay; target.settings.Validate(); target.startDelay = target.settings.GetStartDelay(); return target; } public static T SetRandomStartDelay(this T target, float min, float max, bool useRandomValue = true) where T : Reaction { target.settings.SetRandomStartDelay(min, max, useRandomValue); target.settings.Validate(); target.startDelay = target.settings.GetStartDelay(); return target; } public static T SetDuration(this T target, float duration) where T : Reaction { target.settings.useRandomDuration = false; target.settings.duration = duration; target.settings.Validate(); target.duration = target.settings.GetDuration(); return target; } public static T SetRandomDuration(this T target, float min, float max, bool useRandomValue = true) where T : Reaction { target.settings.SetRandomDuration(min, max, useRandomValue); target.settings.Validate(); target.duration = target.settings.GetDuration(); return target; } public static T SetLoops(this T target, int numberOfLoops) where T : Reaction { target.settings.useRandomLoops = false; target.settings.loops = numberOfLoops; target.settings.Validate(); target.loops = target.settings.GetLoops(); return target; } public static T SetRandomLoops(this T target, int min, int max, bool useRandomValue = true) where T : Reaction { target.settings.SetRandomLoops(min, max, useRandomValue); target.settings.Validate(); target.loops = target.settings.GetLoops(); return target; } public static T SetLoopDelay(this T target, float loopDelay) where T : Reaction { target.settings.useRandomLoopDelay = false; target.settings.loopDelay = loopDelay; target.settings.Validate(); target.loopDelay = target.settings.GetLoopDelay(); return target; } public static T SetRandomLoopDelay(this T target, float min, float max, bool useRandomValue = true) where T : Reaction { target.settings.SetRandomLoopDelay(min, max, useRandomValue); target.settings.Validate(); target.loopDelay = target.settings.GetLoopDelay(); return target; } #region OnPlayCallback public static T SetOnPlayCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnPlayCallback = callback; return target; } public static T AddOnPlayCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnPlayCallback += callback; return target; } public static T ClearOnPlayCallback(this T target) where T : Reaction { target.OnPlayCallback = null; return target; } #endregion #region OnStopCallback public static T SetOnStopCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnStopCallback = callback; return target; } public static T AddOnStopCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnStopCallback += callback; return target; } public static T ClearOnStopCallback(this T target) where T : Reaction { target.OnStopCallback = null; return target; } #endregion #region OnFinishCallback public static T SetOnFinishCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnFinishCallback = callback; return target; } public static T AddOnFinishCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnFinishCallback += callback; return target; } public static T ClearOnFinishCallback(this T target) where T : Reaction { target.OnFinishCallback = null; return target; } #endregion #region OnLoopCallback public static T SetOnLoopCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnLoopCallback = callback; return target; } public static T AddOnLoopCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnLoopCallback += callback; return target; } public static T ClearOnLoopCallback(this T target) where T : Reaction { target.OnLoopCallback = null; return target; } #endregion #region OnPauseCallback public static T SetOnPauseCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnPauseCallback = callback; return target; } public static T AddOnPauseCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnPauseCallback += callback; return target; } public static T ClearOnPauseCallback(this T target) where T : Reaction { target.OnPauseCallback = null; return target; } #endregion #region OnResumeCallback public static T SetOnResumeCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnResumeCallback = callback; return target; } public static T AddOnResumeCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnResumeCallback += callback; return target; } public static T ClearOnResumeCallback(this T target) where T : Reaction { target.OnResumeCallback = null; return target; } #endregion #region OnUpdateCallback public static T SetOnUpdateCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnUpdateCallback = callback; return target; } public static T AddOnUpdateCallback(this T target, ReactionCallback callback) where T : Reaction { if (callback == null) return target; target.OnUpdateCallback += callback; return target; } public static T ClearOnUpdateCallback(this T target) where T : Reaction { target.OnUpdateCallback = null; return target; } #endregion public static T ClearCallbacks(this T target) where T : Reaction => target.ClearOnFinishCallback() .ClearOnLoopCallback() .ClearOnPauseCallback() .ClearOnPlayCallback() .ClearOnResumeCallback() .ClearOnStopCallback() .ClearOnUpdateCallback(); } }