diff --git a/Runtime/Data/Overridable/ImplementationOverridable.cs b/Runtime/Data/Overridable/ImplementationOverridable.cs index 0ade1ad..9e64b7a 100644 --- a/Runtime/Data/Overridable/ImplementationOverridable.cs +++ b/Runtime/Data/Overridable/ImplementationOverridable.cs @@ -1,11 +1,13 @@ using System; using Better.Attributes.Runtime.Select; +using Better.Commons.Runtime.Interfaces; using UnityEngine; namespace Better.Tweens.Runtime.Data { [Serializable] - public class ImplementationOverridable : OverridableData + public class ImplementationOverridable : OverridableData, ICloneable> + where TValue : ICloneable { [Select] [SerializeReference] private TValue _overridenValue; @@ -16,9 +18,19 @@ protected override TValue OverridenValue set => _overridenValue = value; } - public ImplementationOverridable(TValue overridenValue) + public ImplementationOverridable(TValue sourceValue, TValue overridenValue, bool overriden) : base(sourceValue, overriden) { _overridenValue = overridenValue; } + + public ImplementationOverridable(TValue overridenValue) : this(default, overridenValue, false) + { + } + + public ImplementationOverridable Clone() + { + var overridenClone = _overridenValue == null ? default : _overridenValue.Clone(); + return new ImplementationOverridable(overridenClone, SourceValue, Overriden); + } } } \ No newline at end of file diff --git a/Runtime/Data/Overridable/OverridableData.cs b/Runtime/Data/Overridable/OverridableData.cs index 135b9b1..5ed595b 100644 --- a/Runtime/Data/Overridable/OverridableData.cs +++ b/Runtime/Data/Overridable/OverridableData.cs @@ -7,11 +7,10 @@ namespace Better.Tweens.Runtime.Data public abstract class OverridableData { [SerializeField] private bool _overriden; - - private TValue _sourceValue; - - public TValue Value => Overriden ? OverridenValue : _sourceValue; + + public TValue Value => Overriden ? OverridenValue : SourceValue; protected abstract TValue OverridenValue { get; set; } + protected TValue SourceValue { get; private set; } public bool Overriden { @@ -19,9 +18,19 @@ public bool Overriden set => _overriden = value; } + protected OverridableData() + { + } + + protected OverridableData(TValue sourceValue, bool overriden) + { + SourceValue = sourceValue; + _overriden = overriden; + } + public void SetSource(TValue value) { - _sourceValue = value; + SourceValue = value; } public void Override(TValue value) diff --git a/Runtime/Data/Overridable/Simples.meta b/Runtime/Data/Overridable/Simples.meta deleted file mode 100644 index 3ad4bfe..0000000 --- a/Runtime/Data/Overridable/Simples.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: 5dc0411367e14bdd9aee469d9883ad24 -timeCreated: 1715670843 \ No newline at end of file diff --git a/Runtime/Data/Overridable/Simples/SleepingDurationOverridable.cs b/Runtime/Data/Overridable/SleepingDurationOverridable.cs similarity index 50% rename from Runtime/Data/Overridable/Simples/SleepingDurationOverridable.cs rename to Runtime/Data/Overridable/SleepingDurationOverridable.cs index 4dc4c25..38d32af 100644 --- a/Runtime/Data/Overridable/Simples/SleepingDurationOverridable.cs +++ b/Runtime/Data/Overridable/SleepingDurationOverridable.cs @@ -1,11 +1,10 @@ using System; -using Better.Attributes.Runtime.Select; -using UnityEngine; +using Better.Commons.Runtime.Interfaces; namespace Better.Tweens.Runtime.Data { [Serializable] - public class SleepingDurationOverridable : SimpleOverridable + public class SleepingDurationOverridable : ImplementationOverridable, ICloneable { public float Duration => Value.Value; public bool Infinity => Value.Infinity; @@ -14,6 +13,10 @@ public SleepingDurationOverridable(SleepingDuration overridenValue) : base(overr { } + public SleepingDurationOverridable(SleepingDuration overridenValue, SleepingDuration sourceValue, bool overriden) : base(overridenValue) + { + } + public void OverrideDuration(float value) { Overriden = true; @@ -25,5 +28,11 @@ public void OverrideInfinity() Overriden = true; OverridenValue.MakeInfinity(); } + + public new SleepingDurationOverridable Clone() + { + var overridenClone = OverridenValue?.Clone(); + return new SleepingDurationOverridable(overridenClone, SourceValue, Overriden); + } } } \ No newline at end of file diff --git a/Runtime/Data/Overridable/Simples/SleepingDurationOverridable.cs.meta b/Runtime/Data/Overridable/SleepingDurationOverridable.cs.meta similarity index 100% rename from Runtime/Data/Overridable/Simples/SleepingDurationOverridable.cs.meta rename to Runtime/Data/Overridable/SleepingDurationOverridable.cs.meta diff --git a/Runtime/Data/Overridable/Simples/SimpleOverridable.cs b/Runtime/Data/Overridable/ValueOverridable.cs similarity index 51% rename from Runtime/Data/Overridable/Simples/SimpleOverridable.cs rename to Runtime/Data/Overridable/ValueOverridable.cs index 8187123..dfe0a90 100644 --- a/Runtime/Data/Overridable/Simples/SimpleOverridable.cs +++ b/Runtime/Data/Overridable/ValueOverridable.cs @@ -1,11 +1,12 @@ using System; -using Better.Attributes.Runtime.Select; +using Better.Commons.Runtime.Interfaces; using UnityEngine; namespace Better.Tweens.Runtime.Data { [Serializable] - public class SimpleOverridable : OverridableData + public class ValueOverridable : OverridableData, ICloneable> + where TValue : struct { [SerializeField] private TValue _overridenValue; @@ -15,9 +16,14 @@ protected override TValue OverridenValue set => _overridenValue = value; } - public SimpleOverridable(TValue overridenValue) + public ValueOverridable(TValue overridenValue) { _overridenValue = overridenValue; } + + public ValueOverridable Clone() + { + return new ValueOverridable(OverridenValue); + } } } \ No newline at end of file diff --git a/Runtime/Data/Overridable/Simples/SimpleOverridable.cs.meta b/Runtime/Data/Overridable/ValueOverridable.cs.meta similarity index 100% rename from Runtime/Data/Overridable/Simples/SimpleOverridable.cs.meta rename to Runtime/Data/Overridable/ValueOverridable.cs.meta diff --git a/Runtime/Extensions/TweenCoreExtensions.cs b/Runtime/Extensions/TweenCoreExtensions.cs index 89bebf8..9f367c8 100644 --- a/Runtime/Extensions/TweenCoreExtensions.cs +++ b/Runtime/Extensions/TweenCoreExtensions.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; +using Better.Commons.Runtime.Extensions; using Better.Tweens.Runtime.Actions; using Better.Tweens.Runtime.Triggers; using Better.Tweens.Runtime.Utility; @@ -967,7 +968,7 @@ public static IEnumerable AddTrigger(this IEnumerable self return self; } - + public static TweenCore AddTrigger(this TweenCore self, TweenCoreAction action, CancellationToken cancellationToken, string id = Trigger.UndefinedId) { if (!ValidationUtility.ValidateNullReference(self)) @@ -984,14 +985,13 @@ public static TweenCore AddTrigger(this TweenCore self, TweenCoreAction action, return self.AddTrigger(trigger); } - public static TweenCore AddTrigger(this TweenCore self, CancellationToken cancellationToken, string id = Trigger.UndefinedId) where TAction : TweenCoreAction, new() { var action = new TAction(); return self.AddTrigger(action, cancellationToken, id); } - + #if BETTER_CONDITIONS public static TweenCore AddTrigger(this TweenCore self, TweenCoreAction action, Condition condition, string id = Trigger.UndefinedId) @@ -1039,6 +1039,62 @@ public static TweenCore AddTrigger(this TweenCore self, str #endif + public static TweenCore SetTrigger(this TweenCore self, Trigger value) + { + return self.ClearTriggers().AddTrigger(value); + } + + public static IEnumerable SetTrigger(this IEnumerable self, Trigger value) + { + if (!ValidationUtility.ValidateNullReference(self)) + { + return self; + } + + foreach (var tweenCore in self) + { + tweenCore.SetTrigger(value); + } + + return self; + } + + public static TweenCore SetTriggers(this TweenCore self, IEnumerable values) + { + if (!ValidationUtility.ValidateNullReference(values)) + { + return self; + } + + self.ClearTriggers(); + foreach (var value in values) + { + self.AddTrigger(value); + } + + return self; + } + + public static IEnumerable SetTriggers(this IEnumerable self, IEnumerable values) + { + if (!ValidationUtility.ValidateNullReference(self)) + { + return self; + } + + if (!ValidationUtility.ValidateNullReference(values)) + { + return self; + } + + foreach (var tweenCore in self) + { + tweenCore.SetTriggers(values); + } + + return self; + } + public static IEnumerable RemoveTriggers(this IEnumerable self, Predicate predicate) { if (!ValidationUtility.ValidateNullReference(self)) @@ -1069,6 +1125,21 @@ public static IEnumerable RemoveTriggers(this IEnumerable return self; } + public static IEnumerable ClearTriggers(this IEnumerable self) + { + if (!ValidationUtility.ValidateNullReference(self)) + { + return self; + } + + foreach (var tweenCore in self) + { + tweenCore.ClearTriggers(); + } + + return self; + } + public static TweenCore AddTags(this TweenCore self, IEnumerable values) { if (!ValidationUtility.ValidateNullReference(values)) @@ -1165,6 +1236,62 @@ public static IEnumerable AddTags(this IEnumerable self, I return self; } + public static TweenCore SetTag(this TweenCore self, object value) + { + return self.ClearTags().AddTag(value); + } + + public static IEnumerable SetTag(this IEnumerable self, object value) + { + if (!ValidationUtility.ValidateNullReference(self)) + { + return self; + } + + foreach (var tweenCore in self) + { + tweenCore.SetTag(value); + } + + return self; + } + + public static TweenCore SetTags(this TweenCore self, IEnumerable values) + { + if (!ValidationUtility.ValidateNullReference(values)) + { + return self; + } + + self.ClearTags(); + foreach (var value in values) + { + self.AddTag(value); + } + + return self; + } + + public static IEnumerable SetTags(this IEnumerable self, IEnumerable values) + { + if (!ValidationUtility.ValidateNullReference(self)) + { + return self; + } + + if (!ValidationUtility.ValidateNullReference(values)) + { + return self; + } + + foreach (var tweenCore in self) + { + tweenCore.SetTags(values); + } + + return self; + } + public static IEnumerable RemoveTag(this IEnumerable self, object value) { if (!ValidationUtility.ValidateNullReference(self)) @@ -1180,6 +1307,36 @@ public static IEnumerable RemoveTag(this IEnumerable self, return self; } + public static IEnumerable ClearTags(this IEnumerable self) + { + if (!ValidationUtility.ValidateNullReference(self)) + { + return self; + } + + foreach (var tweenCore in self) + { + tweenCore.ClearTags(); + } + + return self; + } + + public static IEnumerable As(this IEnumerable self, TweenCore source) + { + if (!ValidationUtility.ValidateNullReference(self)) + { + return self; + } + + foreach (var tweenCore in self) + { + tweenCore.As(source); + } + + return self; + } + #endregion #region Validation @@ -2232,5 +2389,68 @@ public static IEnumerable TweensLocalTimeScale(this IEn } #endregion + + #region Clonning + + public static TCore Clone(this TCore self) + where TCore : TweenCore, new() + { + if (!ValidationUtility.ValidateNullReference(self)) + { + return null; + } + + var clone = new TCore(); + clone.As(self); + + return clone; + } + + public static IEnumerable Clone(this IEnumerable self) + where TCore : TweenCore, new() + { + if (!ValidationUtility.ValidateNullReference(self)) + { + return Enumerable.Empty(); + } + + return self.Select(Clone); + } + + public static TCore CloneByActivator(this TCore self) + where TCore : TweenCore + { + if (!ValidationUtility.ValidateNullReference(self)) + { + return null; + } + + var type = self.GetType(); + if (!type.HasParameterlessConstructor()) + { + var message = $"{nameof(self)}({type}) must have parameterless constructor, was returned null"; + LogUtility.LogException(message); + + return null; + } + + var clone = (TCore)Activator.CreateInstance(type); + clone.As(self); + + return clone; + } + + public static IEnumerable CloneByActivator(this IEnumerable self) + where TCore : TweenCore + { + if (!ValidationUtility.ValidateNullReference(self)) + { + return Enumerable.Empty(); + } + + return self.Select(CloneByActivator); + } + + #endregion } } \ No newline at end of file diff --git a/Runtime/Extensions/Tweens/TargetTweenExtensions.cs b/Runtime/Extensions/Tweens/TargetTweenExtensions.cs index c3dd146..a880c18 100644 --- a/Runtime/Extensions/Tweens/TargetTweenExtensions.cs +++ b/Runtime/Extensions/Tweens/TargetTweenExtensions.cs @@ -14,7 +14,6 @@ internal static TTween Tween(this TTarge { if (!ValidationUtility.ValidateNullReference(self)) { - return null; } diff --git a/Runtime/Extensions/Tweens/VectorTweenExtensions.cs b/Runtime/Extensions/Tweens/VectorTweenExtensions.cs index cad9e8e..a0257df 100644 --- a/Runtime/Extensions/Tweens/VectorTweenExtensions.cs +++ b/Runtime/Extensions/Tweens/VectorTweenExtensions.cs @@ -6,6 +6,8 @@ namespace Better.Tweens.Runtime public static class VectorTweenExtensions { public static IEnumerable> SetSpherical(this IEnumerable> self, bool spherical = true) + where TVector : struct + where TConstraint : struct { if (!ValidationUtility.ValidateNullReference(self)) { @@ -37,6 +39,8 @@ public static IEnumerable> SetSpheric } public static IEnumerable> AddConstraint(this IEnumerable> self, TConstraint constraint) + where TVector : struct + where TConstraint : struct { if (!ValidationUtility.ValidateNullReference(self)) { @@ -68,6 +72,8 @@ public static IEnumerable> AddConstra } public static IEnumerable> RemoveConstraint(this IEnumerable> self, TConstraint constraint) + where TVector : struct + where TConstraint : struct { if (!ValidationUtility.ValidateNullReference(self)) { diff --git a/Runtime/Implementations/Core/TweenCore.Building.cs b/Runtime/Implementations/Core/TweenCore.Building.cs index af6ac0a..06f21f7 100644 --- a/Runtime/Implementations/Core/TweenCore.Building.cs +++ b/Runtime/Implementations/Core/TweenCore.Building.cs @@ -96,7 +96,7 @@ public TweenCore SetRewoundAction(TweenCoreAction value) } #endregion - + #region Triggers public TweenCore AddTrigger(Trigger trigger) @@ -120,6 +120,12 @@ public TweenCore RemoveTriggers(Predicate predicate) return this; } + public TweenCore ClearTriggers() + { + _triggers?.Clear(); + return this; + } + #endregion #region Tags @@ -146,6 +152,37 @@ public TweenCore RemoveTag(object value) return this; } + public TweenCore ClearTags() + { + _tags?.Clear(); + return this; + } + + #endregion + + #region Misc + + public virtual TweenCore As(TweenCore source) + { + if (!ValidateMutable(true, false)) + { + return this; + } + + _localTimeScale = source._localTimeScale; + _loopCount = source._loopCount.Clone(); + _dependUnityTimeScale = source._dependUnityTimeScale.Clone(); + _dependGlobalTimeScale = source._dependGlobalTimeScale.Clone(); + _sleepingDuration = source._sleepingDuration.Clone(); + _completionAction = source._completionAction.Clone(); + _rewoundAction = source._rewoundAction.Clone(); + + this.SetTags(source._tags); + this.SetTriggers(source._triggers); + + return this; + } + #endregion } } \ No newline at end of file diff --git a/Runtime/Implementations/Core/TweenCore.cs b/Runtime/Implementations/Core/TweenCore.cs index 7ead741..e0209a5 100644 --- a/Runtime/Implementations/Core/TweenCore.cs +++ b/Runtime/Implementations/Core/TweenCore.cs @@ -12,7 +12,6 @@ namespace Better.Tweens.Runtime [Serializable] public abstract partial class TweenCore { - protected const float MinTime = 0f; private const int OverLoopsThreshold = Data.LoopCount.MaxValue; public event Action StateChanged; @@ -33,11 +32,11 @@ public abstract partial class TweenCore public event Action LoopRewound; public event Action Broken; - [Min(MinTime)] + [Min(TweensSettings.MinTime)] [SerializeField] private float _localTimeScale; [SerializeField] private LoopCount _loopCount; - [SerializeField] private SimpleOverridable _dependUnityTimeScale; - [SerializeField] private SimpleOverridable _dependGlobalTimeScale; + [SerializeField] private ValueOverridable _dependUnityTimeScale; + [SerializeField] private ValueOverridable _dependGlobalTimeScale; [SerializeField] private SleepingDurationOverridable _sleepingDuration; [SerializeField] private ImplementationOverridable _completionAction; [SerializeField] private ImplementationOverridable _rewoundAction; diff --git a/Runtime/Implementations/Progressable/ProgressableCore.Building.cs b/Runtime/Implementations/Progressable/ProgressableCore.Building.cs index 1a18134..0f53dbc 100644 --- a/Runtime/Implementations/Progressable/ProgressableCore.Building.cs +++ b/Runtime/Implementations/Progressable/ProgressableCore.Building.cs @@ -12,11 +12,11 @@ public TweenCore SetLoopDelay(float value) { if (ValidateMutable(true)) { - if (value < MinTime) + if (value < TweensSettings.MinTime) { - var message = $"{nameof(LoopDelay)} cannot be less of {nameof(MinTime)}({MinTime}), was clamped"; + var message = $"{nameof(LoopDelay)} cannot be less of {nameof(TweensSettings.MinTime)}({TweensSettings.MinTime}), was clamped"; LogUtility.LogWarning(message); - value = MinTime; + value = TweensSettings.MinTime; } _loopDelay = value; @@ -29,11 +29,11 @@ public TweenCore SetStartDelay(float value) { if (ValidateMutable(true)) { - if (value < MinTime) + if (value < TweensSettings.MinTime) { - var message = $"{nameof(StartDelay)} cannot be less of {nameof(MinTime)}({MinTime}), was clamped"; + var message = $"{nameof(StartDelay)} cannot be less of {nameof(TweensSettings.MinTime)}({TweensSettings.MinTime}), was clamped"; LogUtility.LogWarning(message); - value = MinTime; + value = TweensSettings.MinTime; } _startDelay = value; @@ -87,11 +87,11 @@ public TweenCore SetDuration(float value) { if (ValidateMutable(true)) { - if (value < MinTime) + if (value < TweensSettings.MinTime) { - var message = $"{nameof(Duration)} cannot be less of {nameof(MinTime)}({MinTime}), was clamped"; + var message = $"{nameof(Duration)} cannot be less of {nameof(TweensSettings.MinTime)}({TweensSettings.MinTime}), was clamped"; LogUtility.LogWarning(message); - value = MinTime; + value = TweensSettings.MinTime; } _duration = value; @@ -110,6 +110,21 @@ public TweenCore SetLoopMode(LoopMode value) return this; } + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is ProgressableCore progressableSource) + { + _duration = progressableSource._duration; + _startDelay = progressableSource._startDelay; + _loopDelay = progressableSource._loopDelay; + _loopMode = progressableSource._loopMode; + _ease = progressableSource._ease.Clone(); + } + + return base.As(source); + } + #endregion } } \ No newline at end of file diff --git a/Runtime/Implementations/Progressable/ProgressableCore.States.cs b/Runtime/Implementations/Progressable/ProgressableCore.States.cs index e37e401..59ab43d 100644 --- a/Runtime/Implementations/Progressable/ProgressableCore.States.cs +++ b/Runtime/Implementations/Progressable/ProgressableCore.States.cs @@ -12,9 +12,9 @@ protected internal override void OnStarted() base.OnStarted(); - if (IsRunning() && InfinityLoops && Duration <= MinTime) + if (IsRunning() && InfinityLoops && Duration <= TweensSettings.MinTime) { - var message = $"Cannot started with {nameof(InfinityLoops)} and {nameof(Duration)} less of {nameof(MinTime)}({MinTime}), will be {nameof(Stop)}"; + var message = $"Cannot started with {nameof(InfinityLoops)} and {nameof(Duration)} less of {nameof(TweensSettings.MinTime)}({TweensSettings.MinTime}), will be {nameof(Stop)}"; LogUtility.LogWarning(message); Stop(); @@ -27,7 +27,7 @@ protected internal override void OnPlay() base.OnPlay(); - if (IsPlaying() && Duration <= MinTime) + if (IsPlaying() && Duration <= TweensSettings.MinTime) { InstantComplete(); } @@ -39,7 +39,7 @@ protected internal override void OnRewind() base.OnRewind(); - if (IsRewinding() && Duration <= MinTime) + if (IsRewinding() && Duration <= TweensSettings.MinTime) { InstantRewound(); } diff --git a/Runtime/Implementations/Progressable/ProgressableCore.cs b/Runtime/Implementations/Progressable/ProgressableCore.cs index 2a1be39..a89d40f 100644 --- a/Runtime/Implementations/Progressable/ProgressableCore.cs +++ b/Runtime/Implementations/Progressable/ProgressableCore.cs @@ -12,13 +12,13 @@ public abstract partial class ProgressableCore : TweenCore [SerializeField] private ImplementationOverridable _ease; - [Min(MinTime)] + [Min(TweensSettings.MinTime)] [SerializeField] private float _duration; - [Min(MinTime)] + [Min(TweensSettings.MinTime)] [SerializeField] private float _startDelay; - [Min(MinTime)] + [Min(TweensSettings.MinTime)] [SerializeField] private float _loopDelay; [SerializeField] private LoopMode _loopMode; diff --git a/Runtime/Implementations/Sequence/Channels/GroupChannel.cs b/Runtime/Implementations/Sequence/Channels/GroupChannel.cs index 26871f0..8cac625 100644 --- a/Runtime/Implementations/Sequence/Channels/GroupChannel.cs +++ b/Runtime/Implementations/Sequence/Channels/GroupChannel.cs @@ -5,13 +5,14 @@ using System.Threading.Tasks; using Better.Attributes.Runtime.Misc; using Better.Commons.Runtime.Extensions; +using Better.Commons.Runtime.Interfaces; using UnityEngine; namespace Better.Tweens.Runtime.Sequences.Channels { [Serializable] - public class GroupChannel : Channel - where TChannel : Channel, new() + public class GroupChannel : Channel, ICloneable> + where TChannel : Channel, ICloneable, new() { [HideLabel] [SerializeField] private List _channels; @@ -181,5 +182,19 @@ private Channel GetOrAddEditingChannel() return _channels.Last(); } + + public GroupChannel Clone() + { + var clone = new GroupChannel(); + foreach (var channel in _channels) + { + var channelClone = channel.Clone(); + clone._channels.Add(channelClone); + } + + return clone; + + return clone; + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Sequence/Channels/StageableChannel.cs b/Runtime/Implementations/Sequence/Channels/StageableChannel.cs index b9e102a..61c7f31 100644 --- a/Runtime/Implementations/Sequence/Channels/StageableChannel.cs +++ b/Runtime/Implementations/Sequence/Channels/StageableChannel.cs @@ -4,13 +4,14 @@ using System.Threading; using System.Threading.Tasks; using Better.Attributes.Runtime.Select; +using Better.Commons.Runtime.Interfaces; using Better.Tweens.Runtime.Sequences.Stages; using UnityEngine; namespace Better.Tweens.Runtime.Sequences.Channels { [Serializable] - public class StageableChannel : Channel + public class StageableChannel : Channel, ICloneable { [Select] [SerializeReference] private List _stages; @@ -253,5 +254,17 @@ private void MovePreviousStage() _currentStageIndex--; _currentStageIndex = Mathf.Max(_currentStageIndex, 0); } + + public StageableChannel Clone() + { + var clone = new StageableChannel(); + foreach (var stage in _stages) + { + var stageClone = stage.Clone(); + clone._stages.Add(stageClone); + } + + return clone; + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Sequence/Sequence.Building.cs b/Runtime/Implementations/Sequence/Sequence.Building.cs index 5f7cb61..5559378 100644 --- a/Runtime/Implementations/Sequence/Sequence.Building.cs +++ b/Runtime/Implementations/Sequence/Sequence.Building.cs @@ -4,6 +4,17 @@ namespace Better.Tweens.Runtime { public partial class Sequence { + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is Sequence sequenceSource) + { + _rootChannel = sequenceSource._rootChannel.Clone(); + } + + return base.As(source); + } + public Sequence AddChannel() { if (ValidateMutable(true)) diff --git a/Runtime/Implementations/Sequence/Stages/ActionStage.cs b/Runtime/Implementations/Sequence/Stages/ActionStage.cs index 2c3e89f..a3ee0f2 100644 --- a/Runtime/Implementations/Sequence/Stages/ActionStage.cs +++ b/Runtime/Implementations/Sequence/Stages/ActionStage.cs @@ -16,5 +16,13 @@ protected override void Execute() { ActionUtility.TryInvokeBySafeMode(_action); } + + public override Stage Clone() + { + var clone = new ActionStage(); + clone._action = _action; + + return clone; + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Sequence/Stages/DebugStage.cs b/Runtime/Implementations/Sequence/Stages/DebugStage.cs index bb6c7b6..537f6f8 100644 --- a/Runtime/Implementations/Sequence/Stages/DebugStage.cs +++ b/Runtime/Implementations/Sequence/Stages/DebugStage.cs @@ -22,5 +22,12 @@ protected override void Execute() { Debug.Log(_message); } + + public override Stage Clone() + { + var clone = new DebugStage(); + + return clone; + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Sequence/Stages/IntervalStage.cs b/Runtime/Implementations/Sequence/Stages/IntervalStage.cs index 08ca0de..ffa0016 100644 --- a/Runtime/Implementations/Sequence/Stages/IntervalStage.cs +++ b/Runtime/Implementations/Sequence/Stages/IntervalStage.cs @@ -84,5 +84,13 @@ public override bool IsRewound() { return _leftDuration >= _duration; } + + public override Stage Clone() + { + var clone = new IntervalStage(); + clone._duration = _duration; + + return clone; + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Sequence/Stages/Stage.cs b/Runtime/Implementations/Sequence/Stages/Stage.cs index 6c4bab9..6c9d168 100644 --- a/Runtime/Implementations/Sequence/Stages/Stage.cs +++ b/Runtime/Implementations/Sequence/Stages/Stage.cs @@ -1,11 +1,12 @@ using System; using System.Threading; using System.Threading.Tasks; +using Better.Commons.Runtime.Interfaces; namespace Better.Tweens.Runtime.Sequences.Stages { [Serializable] - public abstract class Stage + public abstract class Stage : ICloneable { public virtual void Start() { @@ -39,5 +40,6 @@ public virtual void Stop() public abstract bool IsCompleted(); public abstract bool IsRewound(); + public abstract Stage Clone(); } } \ No newline at end of file diff --git a/Runtime/Implementations/Sequence/Stages/TweensStage.cs b/Runtime/Implementations/Sequence/Stages/TweensStage.cs index 3f02907..a788ad7 100644 --- a/Runtime/Implementations/Sequence/Stages/TweensStage.cs +++ b/Runtime/Implementations/Sequence/Stages/TweensStage.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading; using System.Threading.Tasks; using Better.Attributes.Runtime.Select; @@ -91,5 +92,13 @@ public override bool IsRewound() { return _tweens.AllRewound(); } + + public override Stage Clone() + { + var clone = new TweensStage(); + clone._tweens = _tweens.CloneByActivator().ToList(); + + return clone; + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/AudioSource/PlayAudioSourceTween.cs b/Runtime/Implementations/Tweens/AudioSource/PlayAudioSourceTween.cs index aa640d2..aa12fb4 100644 --- a/Runtime/Implementations/Tweens/AudioSource/PlayAudioSourceTween.cs +++ b/Runtime/Implementations/Tweens/AudioSource/PlayAudioSourceTween.cs @@ -37,5 +37,16 @@ protected override void SetCurrentValue(bool value) if (value) Target.Play(); else Target.Pause(); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is PlayAudioSourceTween audioSource) + { + _once = audioSource._once; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/Debug/DebugTween.cs b/Runtime/Implementations/Tweens/Debug/DebugTween.cs index 3559679..8ebda04 100644 --- a/Runtime/Implementations/Tweens/Debug/DebugTween.cs +++ b/Runtime/Implementations/Tweens/Debug/DebugTween.cs @@ -14,7 +14,7 @@ public class DebugTween : Tween private const string DefaultId = nameof(DebugTween); public int CurrentValue; - + [SerializeField] private string _id = DefaultId; [SerializeField] private bool _lowLevel; @@ -237,6 +237,18 @@ public override void CollectInfo(ref StringBuilder stringBuilder) stringBuilder.AppendLine() .AppendFieldLine(nameof(CurrentValue), CurrentValue); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is DebugTween debugSource) + { + _id = debugSource._id; + _lowLevel = debugSource._lowLevel; + } + + return base.As(source); + } private StringBuilder PrebuildLog(string operationName) { diff --git a/Runtime/Implementations/Tweens/Material/PropertyColorMaterialTween.cs b/Runtime/Implementations/Tweens/Material/PropertyColorMaterialTween.cs index 7cbfe10..d2472bc 100644 --- a/Runtime/Implementations/Tweens/Material/PropertyColorMaterialTween.cs +++ b/Runtime/Implementations/Tweens/Material/PropertyColorMaterialTween.cs @@ -24,5 +24,16 @@ protected override void SetCurrentValue(Color value) { Target.SetColor(PropertyName, value); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is PropertyColorMaterialTween propertySource) + { + _propertyName = propertySource._propertyName; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/Material/PropertyFloatMaterialTween.cs b/Runtime/Implementations/Tweens/Material/PropertyFloatMaterialTween.cs index 6c65aa4..2ce681c 100644 --- a/Runtime/Implementations/Tweens/Material/PropertyFloatMaterialTween.cs +++ b/Runtime/Implementations/Tweens/Material/PropertyFloatMaterialTween.cs @@ -24,5 +24,16 @@ protected override void SetCurrentValue(float value) { Target.SetFloat(PropertyName, value); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is PropertyFloatMaterialTween propertySource) + { + _propertyName = propertySource._propertyName; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/Material/PropertyIntegerMaterialTween.cs b/Runtime/Implementations/Tweens/Material/PropertyIntegerMaterialTween.cs index 39315ca..f3ed263 100644 --- a/Runtime/Implementations/Tweens/Material/PropertyIntegerMaterialTween.cs +++ b/Runtime/Implementations/Tweens/Material/PropertyIntegerMaterialTween.cs @@ -24,5 +24,16 @@ protected override void SetCurrentValue(int value) { Target.SetInteger(PropertyName, value); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is PropertyIntegerMaterialTween propertySource) + { + _propertyName = propertySource._propertyName; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/Material/PropertyTextureOffsetMaterialTween.cs b/Runtime/Implementations/Tweens/Material/PropertyTextureOffsetMaterialTween.cs index 1f778e6..949bca7 100644 --- a/Runtime/Implementations/Tweens/Material/PropertyTextureOffsetMaterialTween.cs +++ b/Runtime/Implementations/Tweens/Material/PropertyTextureOffsetMaterialTween.cs @@ -24,5 +24,16 @@ protected override void SetCurrentValue(Vector2 value) { Target.SetTextureOffset(PropertyName, value); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is PropertyTextureOffsetMaterialTween propertySource) + { + _propertyName = propertySource._propertyName; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/Material/PropertyTextureScaleMaterialTween.cs b/Runtime/Implementations/Tweens/Material/PropertyTextureScaleMaterialTween.cs index caa8e79..6dc3482 100644 --- a/Runtime/Implementations/Tweens/Material/PropertyTextureScaleMaterialTween.cs +++ b/Runtime/Implementations/Tweens/Material/PropertyTextureScaleMaterialTween.cs @@ -24,5 +24,16 @@ protected override void SetCurrentValue(Vector2 value) { Target.SetTextureScale(PropertyName, value); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is PropertyTextureScaleMaterialTween propertySource) + { + _propertyName = propertySource._propertyName; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/Material/PropertyVectorMaterialTween.cs b/Runtime/Implementations/Tweens/Material/PropertyVectorMaterialTween.cs index 5f1b5b1..b7c4711 100644 --- a/Runtime/Implementations/Tweens/Material/PropertyVectorMaterialTween.cs +++ b/Runtime/Implementations/Tweens/Material/PropertyVectorMaterialTween.cs @@ -24,5 +24,16 @@ protected override void SetCurrentValue(Vector4 value) { Target.SetVector(PropertyName, value); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is PropertyVectorMaterialTween propertySource) + { + _propertyName = propertySource._propertyName; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/Primitives/ColorTween.cs b/Runtime/Implementations/Tweens/Primitives/ColorTween.cs index a144f70..7f87aa2 100644 --- a/Runtime/Implementations/Tweens/Primitives/ColorTween.cs +++ b/Runtime/Implementations/Tweens/Primitives/ColorTween.cs @@ -62,6 +62,17 @@ public override void CollectInfo(ref StringBuilder stringBuilder) stringBuilder.AppendLine() .AppendFieldLine(nameof(IgnoreAlpha), IgnoreAlpha); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is ColorTween colorTween) + { + _ignoreAlpha = colorTween._ignoreAlpha; + } + + return base.As(source); + } } [Serializable] @@ -121,5 +132,16 @@ public override void CollectInfo(ref StringBuilder stringBuilder) stringBuilder.AppendLine() .AppendFieldLine(nameof(IgnoreAlpha), IgnoreAlpha); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is ColorTween colorTween) + { + _ignoreAlpha = colorTween._ignoreAlpha; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/Primitives/QuaternionTween.cs b/Runtime/Implementations/Tweens/Primitives/QuaternionTween.cs index 6931085..62bac1e 100644 --- a/Runtime/Implementations/Tweens/Primitives/QuaternionTween.cs +++ b/Runtime/Implementations/Tweens/Primitives/QuaternionTween.cs @@ -56,6 +56,17 @@ public override void CollectInfo(ref StringBuilder stringBuilder) stringBuilder.AppendLine() .AppendFieldLine(nameof(Spherical), Spherical); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is QuaternionTween quaternionTween) + { + _spherical = quaternionTween._spherical; + } + + return base.As(source); + } } [Serializable] @@ -110,5 +121,16 @@ public override void CollectInfo(ref StringBuilder stringBuilder) stringBuilder.AppendLine() .AppendFieldLine(nameof(Spherical), Spherical); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is QuaternionTween quaternionTween) + { + _spherical = quaternionTween._spherical; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/Primitives/Vectors/VectorTween.cs b/Runtime/Implementations/Tweens/Primitives/Vectors/VectorTween.cs index 7315a84..ce95e5c 100644 --- a/Runtime/Implementations/Tweens/Primitives/Vectors/VectorTween.cs +++ b/Runtime/Implementations/Tweens/Primitives/Vectors/VectorTween.cs @@ -8,6 +8,8 @@ namespace Better.Tweens.Runtime { [Serializable] public abstract class VectorTween : Tween + where TVector : struct + where TConstraint : struct { [SerializeField] private List _axisConstraints; [SerializeField] private bool _spherical; @@ -67,6 +69,18 @@ public override void CollectInfo(ref StringBuilder stringBuilder) stringBuilder.AppendFieldLine(nameof(Constraints), constrainsValue); } } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is VectorTween vectorTween) + { + _spherical = vectorTween._spherical; + _axisConstraints = vectorTween._axisConstraints; + } + + return base.As(source); + } } [Serializable] @@ -131,5 +145,17 @@ public override void CollectInfo(ref StringBuilder stringBuilder) stringBuilder.AppendFieldLine(nameof(Constraints), constrainsValue); } } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is VectorTween vectorTween) + { + _spherical = vectorTween._spherical; + _axisConstraints = vectorTween._axisConstraints; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/Renderer/ColorPropertyBlockRendererTween.cs b/Runtime/Implementations/Tweens/Renderer/ColorPropertyBlockRendererTween.cs index 2dba3dc..90c2fa4 100644 --- a/Runtime/Implementations/Tweens/Renderer/ColorPropertyBlockRendererTween.cs +++ b/Runtime/Implementations/Tweens/Renderer/ColorPropertyBlockRendererTween.cs @@ -35,5 +35,16 @@ protected override void SetCurrentValue(Color value) PropertyBlock.SetColor(PropertyName, value); Target.SetPropertyBlock(PropertyBlock); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is ColorPropertyBlockRendererTween propertySource) + { + _propertyName = propertySource._propertyName; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/Renderer/FloatPropertyBlockRendererTween.cs b/Runtime/Implementations/Tweens/Renderer/FloatPropertyBlockRendererTween.cs index f5a802a..9425168 100644 --- a/Runtime/Implementations/Tweens/Renderer/FloatPropertyBlockRendererTween.cs +++ b/Runtime/Implementations/Tweens/Renderer/FloatPropertyBlockRendererTween.cs @@ -35,5 +35,16 @@ protected override void SetCurrentValue(float value) PropertyBlock.SetFloat(PropertyName, value); Target.SetPropertyBlock(PropertyBlock); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is FloatPropertyBlockRendererTween propertySource) + { + _propertyName = propertySource._propertyName; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/Renderer/IntegerPropertyBlockRendererTween.cs b/Runtime/Implementations/Tweens/Renderer/IntegerPropertyBlockRendererTween.cs index 27e7ca1..5f3a1e5 100644 --- a/Runtime/Implementations/Tweens/Renderer/IntegerPropertyBlockRendererTween.cs +++ b/Runtime/Implementations/Tweens/Renderer/IntegerPropertyBlockRendererTween.cs @@ -35,5 +35,16 @@ protected override void SetCurrentValue(int value) PropertyBlock.SetInteger(PropertyName, value); Target.SetPropertyBlock(PropertyBlock); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is IntegerPropertyBlockRendererTween propertySource) + { + _propertyName = propertySource._propertyName; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/Renderer/VectorPropertyBlockRendererTween.cs b/Runtime/Implementations/Tweens/Renderer/VectorPropertyBlockRendererTween.cs index d0e6bac..4b21b99 100644 --- a/Runtime/Implementations/Tweens/Renderer/VectorPropertyBlockRendererTween.cs +++ b/Runtime/Implementations/Tweens/Renderer/VectorPropertyBlockRendererTween.cs @@ -35,5 +35,16 @@ protected override void SetCurrentValue(Vector4 value) PropertyBlock.SetVector(PropertyName, value); Target.SetPropertyBlock(PropertyBlock); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is VectorPropertyBlockRendererTween propertySource) + { + _propertyName = propertySource._propertyName; + } + + return base.As(source); + } } } \ No newline at end of file diff --git a/Runtime/Implementations/Tweens/TargetTween.cs b/Runtime/Implementations/Tweens/TargetTween.cs index ec2cc3a..217354e 100644 --- a/Runtime/Implementations/Tweens/TargetTween.cs +++ b/Runtime/Implementations/Tweens/TargetTween.cs @@ -60,6 +60,17 @@ public override bool IsBroken() { return base.IsBroken() || Target == null; } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is TargetTween targetTween) + { + _target = targetTween._target; + } + + return base.As(source); + } } [Serializable] diff --git a/Runtime/Implementations/Tweens/Tween.cs b/Runtime/Implementations/Tweens/Tween.cs index 40aeaa4..99875fd 100644 --- a/Runtime/Implementations/Tweens/Tween.cs +++ b/Runtime/Implementations/Tweens/Tween.cs @@ -187,6 +187,20 @@ public override void CollectInfo(ref StringBuilder stringBuilder) .AppendFieldLine(nameof(FromValue), FromValue) .AppendFieldLine(nameof(ToValue), ToValue); } + + public override TweenCore As(TweenCore source) + { + if (ValidateMutable(true, false) + && source is Tween tweenSource) + { + _fromMode = tweenSource._fromMode; + _fromValue = tweenSource._fromValue; + _optionsMode = tweenSource._optionsMode; + _options = tweenSource._options; + } + + return base.As(source); + } } [Serializable] diff --git a/Runtime/TweensSettings.cs b/Runtime/TweensSettings.cs index 261c453..d2a3024 100644 --- a/Runtime/TweensSettings.cs +++ b/Runtime/TweensSettings.cs @@ -8,6 +8,7 @@ namespace Better.Tweens.Runtime [ScriptableCreate(Path)] public class TweensSettings : ScriptableSettings { + public const float MinTime = 0f; public const string Path = PrefixConstants.BetterPrefix + "/" + nameof(Tweens); } } \ No newline at end of file diff --git a/package.json b/package.json index a716ab2..77b4ac0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.tdw.better.tweens", "displayName": "Better Tweens", - "version": "0.0.3", + "version": "0.0.4", "unity": "2021.3", "description": " ", "dependencies": {