// 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 System;
using Doozy.Runtime.Reactor.Internal;
using UnityEngine;
namespace Doozy.Runtime.Reactor.Animations
{
///
/// Data class used to store settings for an .
/// This class is also used for presets.
///
[Serializable]
public class UIAnimationSettings
{
[SerializeField] private UIAnimationType AnimationType;
/// Type of UI animation
public UIAnimationType animationType => AnimationType;
/// Enabled state for the Move reaction
public bool MoveEnabled;
/// Setting for the 'From' reference value
public ReferenceValue MoveFromReferenceValue;
/// Setting for the 'To' reference value
public ReferenceValue MoveToReferenceValue;
/// Setting for the 'From' custom value
public Vector3 MoveFromCustomValue;
/// Setting for the 'To' custom value
public Vector3 MoveToCustomValue;
/// Setting for the 'From' offset
public Vector3 MoveFromOffset;
/// Setting for the 'To' offset
public Vector3 MoveToOffset;
/// Setting for the 'From' direction
public MoveDirection MoveFromDirection;
/// Setting for the 'To' direction
public MoveDirection MoveToDirection;
/// Reaction setting for the Move reaction
public ReactionSettings MoveReactionSettings;
/// Enabled state for the Rotate reaction
public bool RotateEnabled;
/// Setting for the 'From' reference value
public ReferenceValue RotateFromReferenceValue;
/// Setting for the 'To' reference value
public ReferenceValue RotateToReferenceValue;
/// Setting for the 'From' custom value
public Vector3 RotateFromCustomValue;
/// Setting for the 'To' custom value
public Vector3 RotateToCustomValue;
/// Setting for the 'From' offset
public Vector3 RotateFromOffset;
/// Setting for the 'To' offset
public Vector3 RotateToOffset;
/// Reaction setting for the Rotate reaction
public ReactionSettings RotateReactionSettings;
/// Enabled state for the Scale reaction
public bool ScaleEnabled;
/// Setting for the 'From' reference value
public ReferenceValue ScaleFromReferenceValue;
/// Setting for the 'To' reference value
public ReferenceValue ScaleToReferenceValue;
/// Setting for the 'From' custom value
public Vector3 ScaleFromCustomValue;
/// Setting for the 'To' custom value
public Vector3 ScaleToCustomValue;
/// Setting for the 'From' offset
public Vector3 ScaleFromOffset;
/// Setting for the 'To' offset
public Vector3 ScaleToOffset;
/// Reaction setting for the Scale reaction
public ReactionSettings ScaleReactionSettings;
/// Enabled state for the Fade reaction
public bool FadeEnabled;
/// Setting for the 'From' reference value
public ReferenceValue FadeFromReferenceValue;
/// Setting for the 'To' reference value
public ReferenceValue FadeToReferenceValue;
/// Setting for the 'From' custom value
public float FadeFromCustomValue;
/// Setting for the 'To' custom value
public float FadeToCustomValue;
/// Setting for the 'From' offset
public float FadeFromOffset;
/// Setting for the 'To' offset
public float FadeToOffset;
/// Reaction setting for the Fade reaction
public ReactionSettings FadeReactionSettings;
/// Construct a new UIAnimationSettings (with the default animation type set to custom)
public UIAnimationSettings() : this(UIAnimationType.Custom) {}
/// Construct a new UIAnimationSettings with the given animation type;
/// Animation type
public UIAnimationSettings(UIAnimationType animationType)
{
AnimationType = animationType;
MoveReactionSettings = new ReactionSettings();
RotateReactionSettings = new ReactionSettings();
ScaleReactionSettings = new ReactionSettings();
FadeReactionSettings = new ReactionSettings();
}
/// Construct a new UIAnimationSettings with the settings of the given source
/// Other UIAnimationSettings used as a source for the settings
public UIAnimationSettings(UIAnimation source) =>
GetAnimationSettings(source);
/// Apply the settings to the target UIAnimation (copy the setting to the target)
/// Target UIAnimation
public void SetAnimationSettings(UIAnimation target)
{
_ = target ?? throw new NullReferenceException(nameof(target));
target.animationType = AnimationType;
target.Move.enabled = MoveEnabled;
target.Move.animationType = AnimationType;
target.Move.fromReferenceValue = MoveFromReferenceValue;
target.Move.toReferenceValue = MoveToReferenceValue;
target.Move.fromCustomValue = MoveFromCustomValue;
target.Move.toCustomValue = MoveToCustomValue;
target.Move.fromOffset = MoveFromOffset;
target.Move.toOffset = MoveToOffset;
target.Move.fromDirection = target.animationType == UIAnimationType.Show ? MoveFromDirection : MoveDirection.CustomPosition;
target.Move.toDirection = target.animationType == UIAnimationType.Hide ? MoveToDirection : MoveDirection.CustomPosition;
target.Move.ApplyReactionSettings(MoveReactionSettings);
target.Rotate.enabled = RotateEnabled;
target.Rotate.fromReferenceValue = RotateFromReferenceValue;
target.Rotate.toReferenceValue = RotateToReferenceValue;
target.Rotate.fromCustomValue = RotateFromCustomValue;
target.Rotate.toCustomValue = RotateToCustomValue;
target.Rotate.fromOffset = RotateFromOffset;
target.Rotate.toOffset = RotateToOffset;
target.Rotate.ApplyReactionSettings(RotateReactionSettings);
target.Scale.enabled = ScaleEnabled;
target.Scale.fromReferenceValue = ScaleFromReferenceValue;
target.Scale.toReferenceValue = ScaleToReferenceValue;
target.Scale.fromCustomValue = ScaleFromCustomValue;
target.Scale.toCustomValue = ScaleToCustomValue;
target.Scale.fromOffset = ScaleFromOffset;
target.Scale.toOffset = ScaleToOffset;
target.Scale.ApplyReactionSettings(ScaleReactionSettings);
target.Fade.enabled = FadeEnabled;
target.Fade.fromReferenceValue = FadeFromReferenceValue;
target.Fade.toReferenceValue = FadeToReferenceValue;
target.Fade.fromCustomValue = FadeFromCustomValue;
target.Fade.toCustomValue = FadeToCustomValue;
target.Fade.fromOffset = FadeFromOffset;
target.Fade.toOffset = FadeToOffset;
target.Fade.ApplyReactionSettings(FadeReactionSettings);
}
/// Get the settings from a source UIAnimation (copy the settings from the source)
/// Source UIAnimation
public void GetAnimationSettings(UIAnimation source)
{
_ = source ?? throw new NullReferenceException(nameof(source));
AnimationType = source.animationType;
MoveEnabled = source.Move.enabled;
MoveFromReferenceValue = source.Move.fromReferenceValue;
MoveToReferenceValue = source.Move.toReferenceValue;
MoveFromCustomValue = source.Move.fromCustomValue;
MoveToCustomValue = source.Move.toCustomValue;
MoveFromOffset = source.Move.fromOffset;
MoveToOffset = source.Move.toOffset;
MoveFromDirection = source.animationType == UIAnimationType.Show ? source.Move.fromDirection : MoveDirection.CustomPosition;
MoveToDirection = source.animationType == UIAnimationType.Hide ? source.Move.toDirection : MoveDirection.CustomPosition;;
MoveReactionSettings = new ReactionSettings(source.Move.settings);
RotateEnabled = source.Rotate.enabled;
RotateFromReferenceValue = source.Rotate.fromReferenceValue;
RotateToReferenceValue = source.Rotate.toReferenceValue;
RotateFromCustomValue = source.Rotate.fromCustomValue;
RotateToCustomValue = source.Rotate.toCustomValue;
RotateFromOffset = source.Rotate.fromOffset;
RotateToOffset = source.Rotate.toOffset;
RotateReactionSettings = new ReactionSettings(source.Rotate.settings);
ScaleEnabled = source.Scale.enabled;
ScaleFromReferenceValue = source.Scale.fromReferenceValue;
ScaleToReferenceValue = source.Scale.toReferenceValue;
ScaleFromCustomValue = source.Scale.fromCustomValue;
ScaleToCustomValue = source.Scale.toCustomValue;
ScaleFromOffset = source.Scale.fromOffset;
ScaleToOffset = source.Scale.toOffset;
ScaleReactionSettings = new ReactionSettings(source.Scale.settings);
FadeEnabled = source.Fade.enabled;
FadeFromReferenceValue = source.Fade.fromReferenceValue;
FadeToReferenceValue = source.Fade.toReferenceValue;
FadeFromCustomValue = source.Fade.fromCustomValue;
FadeToCustomValue = source.Fade.toCustomValue;
FadeFromOffset = source.Fade.fromOffset;
FadeToOffset = source.Fade.toOffset;
FadeReactionSettings = new ReactionSettings(source.Fade.settings);
}
///
/// Apply the settings from the source UIAnimationSettings to the target UIAnimation
/// (copy the settings from the source to the target)
/// FROM UIAnimationSettings TO UIAnimation
///
/// Source UIAnimationSettings
/// Target UIAnimation
public static void SetAnimationSettings(UIAnimationSettings source, UIAnimation target)
{
_ = source ?? throw new NullReferenceException(nameof(source));
_ = target ?? throw new NullReferenceException(nameof(target));
source.SetAnimationSettings(target);
}
///
/// Get the settings from the source UIAnimation to the target UIAnimationSettings
/// (copy the settings from the source to the target)
/// FROM UIAnimation TO UIAnimationSettings
///
/// Source UIAnimation
/// Target UIAnimationSettings
public static void GetAnimationSettings(UIAnimation source, UIAnimationSettings target)
{
_ = source ?? throw new NullReferenceException(nameof(source));
_ = target ?? throw new NullReferenceException(nameof(target));
target.GetAnimationSettings(source);
}
}
}