Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
aprius committed Dec 10, 2023
2 parents 38cc222 + 86285f2 commit 681163a
Show file tree
Hide file tree
Showing 17 changed files with 245 additions and 154 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
using System.Collections.Generic;
using PrimeTween;
using UnityEditor;
using UnityEngine;

[CustomEditor(typeof(PrimeTweenManager))]
internal class PrimeTweenManagerInspector : Editor {
SerializedProperty tweensProp;
SerializedProperty fixedUpdateTweensProp;
GUIContent aliveTweenGuiContent;
const string aliveTweensLabel = "Alive tweens";
GUIContent fixedUpdateTweenGuiContent;

void OnEnable() {
tweensProp = serializedObject.FindProperty(nameof(PrimeTweenManager.tweens));
fixedUpdateTweensProp = serializedObject.FindProperty(nameof(PrimeTweenManager.fixedUpdateTweens));
Assert.IsNotNull(tweensProp);
aliveTweenGuiContent = new GUIContent(aliveTweensLabel);
aliveTweenGuiContent = new GUIContent("Tweens");
fixedUpdateTweenGuiContent = new GUIContent("Fixed update tweens");
}

public override void OnInspectorGUI() {
Expand All @@ -23,8 +27,8 @@ public override void OnInspectorGUI() {
Assert.IsNotNull(manager);

GUILayout.BeginHorizontal();
GUILayout.Label(aliveTweensLabel, EditorStyles.label);
GUILayout.Label(manager.tweens.Count.ToString(), EditorStyles.boldLabel);
GUILayout.Label("Alive tweens", EditorStyles.label);
GUILayout.Label(manager.tweensCount.ToString(), EditorStyles.boldLabel);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();

Expand All @@ -42,15 +46,19 @@ public override void OnInspectorGUI() {
EditorGUILayout.HelpBox("Use " + Constants.setTweensCapacityMethod + " to set tweens capacity.\n" +
"To prevent memory allocations during runtime, choose the value that is greater than the maximum number of simultaneous tweens in your game.", MessageType.None);

if (tweensProp.isExpanded) {
foreach (var tween in manager.tweens) {
if (tween != null && string.IsNullOrEmpty(tween.debugDescription)) {
tween.debugDescription = tween.GetDescription();
drawList(tweensProp, manager.tweens, aliveTweenGuiContent);
drawList(fixedUpdateTweensProp, manager.fixedUpdateTweens, fixedUpdateTweenGuiContent);
void drawList(SerializedProperty tweensProp, List<ReusableTween> list, GUIContent guiContent) {
if (tweensProp.isExpanded) {
foreach (var tween in list) {
if (tween != null && string.IsNullOrEmpty(tween.debugDescription)) {
tween.debugDescription = tween.GetDescription();
}
}
}
}
using (new EditorGUI.DisabledScope(true)) {
EditorGUILayout.PropertyField(tweensProp, aliveTweenGuiContent);
using (new EditorGUI.DisabledScope(true)) {
EditorGUILayout.PropertyField(tweensProp, guiContent);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ internal static float getPropHeight([NotNull] SerializedProperty property) {
count++; // startDelay
count++; // endDelay
count++; // useUnscaledTime
count++; // useFixedUpdate
var result = singleLineHeight * count + standardVerticalSpacing * (count - 1);
result += standardVerticalSpacing * 2; // extra spacing
return result;
Expand Down Expand Up @@ -108,6 +109,11 @@ internal static void drawStartDelayTillEnd(ref Rect rect, [NotNull] SerializedPr
PropertyField(rect, property);
moveToNextLine(ref rect);
}
{ // useFixedUpdate
property.NextVisible(true);
PropertyField(rect, property);
moveToNextLine(ref rect);
}
}

internal static int drawCycles(Rect rect, [NotNull] SerializedProperty property) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public override float GetPropertyHeight([NotNull] SerializedProperty property, G
count++; // startDelay
count++; // endDelay
count++; // useUnscaledTime
count++; // useFixedUpdate
var result = singleLineHeight * count + standardVerticalSpacing * (count - 1);
result += standardVerticalSpacing * 2; // extra space
return result;
Expand Down
21 changes: 16 additions & 5 deletions Assets/Heart/Modules/PrimeTween/Runtime/Easing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
using UnityEngine;

namespace PrimeTween {
/// <summary>
/// A wrapper struct that encapsulates three available easing methods: standard Ease, AnimationCurve, or Parametric Easing.<br/>
/// Use static methods to create an Easing struct, for example: Easing.Standard(Ease.OutBounce), Easing.Curve(animationCurve),
/// Easing.Elastic(strength, period), etc.
/// </summary>
[PublicAPI]
public readonly struct Easing {
internal readonly Ease ease;
Expand All @@ -27,7 +32,8 @@ public readonly struct Easing {
}

public static implicit operator Easing(Ease ease) => Standard(ease);
/// <summary>Standard Robert Penner's easing methods. Or simply use Ease enum instead of this method.</summary>

/// <summary>Standard Robert Penner's easing method. Or simply use Ease enum instead.</summary>
public static Easing Standard(Ease ease) {
Assert.AreNotEqual(Ease.Custom, ease);
if (ease == Ease.Default) {
Expand All @@ -37,21 +43,26 @@ public static Easing Standard(Ease ease) {
}

public static implicit operator Easing([NotNull] AnimationCurve curve) => Curve(curve);
/// <summary>AnimationCurve to use an easing function. Or simply use AnimationCurve instead of this method.</summary>

/// <summary>AnimationCurve to use as an easing function. Or simply use AnimationCurve instead.</summary>
public static Easing Curve([NotNull] AnimationCurve curve) => new Easing(Ease.Custom, curve);

#if PRIME_TWEEN_EXPERIMENTAL
/// <summary>Customizes the bounce <see cref="strength"/> of Ease.OutBounce.</summary>
public static Easing Bounce(float strength) => new Easing(ParametricEase.Bounce, strength);
/// <summary>The first bounce will have the exact <see cref="amplitude"/> measured in meters/angles.</summary>

/// <summary>Customizes the exact <see cref="amplitude"/> of the first bounce in meters/angles.</summary>
public static Easing BounceExact(float amplitude) => new Easing(ParametricEase.BounceExact, amplitude);

/// <summary>Customizes the overshoot <see cref="strength"/> of Ease.OutBack.</summary>
public static Easing Overshoot(float strength) => new Easing(ParametricEase.Overshoot, strength * StandardEasing.backEaseConst);

/// <summary>Customizes the <see cref="strength"/> and oscillation <see cref="period"/> of Ease.OutElastic.</summary>
public static Easing Elastic(float strength, float period = 0.3f) {
if (strength < 1) {
strength = Mathf.Lerp(0.2f, 1f, strength); // remap strength to limit decayFactor
}
return new Easing(ParametricEase.Elastic, strength, Mathf.Max(0.1f, period));
}
#endif

internal static float Evaluate(float t, [NotNull] ReusableTween tween) {
var settings = tween.settings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static string buildWarningCanBeDisabledMessage(string settingName) {
internal const string endDelayTooltip = "Delays the completion of a tween.\n\n" +
"For example, can be used to add the delay between cycles.\n\n" +
"Or can be used to postpone the execution of the onComplete callback.";
internal const string infiniteTweenInSequenceError = "It's not allowed to have infinite tweens (cycles == -1) in a sequence. If you want the sequence to repeat forever, " + nameof(Sequence.SetRemainingCycles) + "(-1) on the parent sequence instead."; // todoo error instead of exception?
internal const string infiniteTweenInSequenceError = "It's not allowed to have infinite tweens (cycles == -1) in a sequence. If you want the sequence to repeat forever, " + nameof(Sequence.SetRemainingCycles) + "(-1) on the parent sequence instead.";
internal const string customTweensDontSupportStartFromCurrentWarning =
"Custom tweens don't support the '" + nameof(T.startFromCurrent) + "' because they don't know the current value of animated property.\n" +
"This means that the animated value will be changed abruptly if a new tween is started mid-way.\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// todo add Sequence.SetEase()
// ReSharper disable UnusedMember.Global
// ReSharper disable UnusedType.Global
// ReSharper disable UnusedParameter.Local
Expand Down Expand Up @@ -133,6 +134,7 @@ public Sequence AppendCallback([NotNull] Action callback) {
}

public Sequence SetLoops(int loops) {
// todo add LoopType parameter
Assert.IsTrue(isAlive);
SetRemainingCycles(loops);
return this;
Expand Down Expand Up @@ -242,7 +244,6 @@ public Tween SetEase(Ease ease, float? amplitude = null, float? period = null) {
}

static Easing getParametricEasing(Ease ease, float? maybeStrength, float? maybePeriod) {
#if PRIME_TWEEN_EXPERIMENTAL
var strength = maybeStrength ?? 1;
switch (ease) {
case Ease.OutBack:
Expand All @@ -253,8 +254,6 @@ static Easing getParametricEasing(Ease ease, float? maybeStrength, float? maybeP
case Ease.OutElastic:
return Easing.Elastic(strength, maybePeriod ?? 0.3f);
}
#endif
Debug.LogWarning($"Custom amplitude/period is not supported for {ease} ease. Consider using custom ease curve instead.");
return Easing.Standard(ease);
}

Expand Down
32 changes: 32 additions & 0 deletions Assets/Heart/Modules/PrimeTween/Runtime/Internal/ITween.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*// ReSharper disable UnusedMemberInSuper.Global
using System;
using JetBrains.Annotations;
namespace PrimeTween {
// ReSharper disable once TypeParameterCanBeVariant
internal interface ITween<TResult> {
bool isAlive { get; }
void Stop();
void Complete();
TResult OnComplete([NotNull] Action onComplete, bool warnIfTargetDestroyed = true);
TResult OnComplete<T>([NotNull] T target, [NotNull] Action<T> onComplete, bool warnIfTargetDestroyed = true) where T : class;
Sequence Group(Tween tween);
Sequence Chain(Tween tween);
Sequence Group(Sequence sequence);
Sequence Chain(Sequence sequence);
void SetRemainingCycles(int cycles);
void SetRemainingCycles(bool stopAtEndValue);
int cyclesDone { get; }
int cyclesTotal { get; }
bool isPaused { get; set; }
float timeScale { get; set; }
float duration { get; }
float durationTotal { get; }
float elapsedTime { get; set; }
float elapsedTimeTotal { get; set; }
float progress { get; set; }
float progressTotal { get; set; }
// K OnUpdate<T>(T target, Action<T, Tween> onUpdate) where T : class; // Sequence doesn't support OnUpdate because its root updates before all children tweens, but it's reasonable that OnUpdate() should be called AFTER all sequence children are updated
}
}*/

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 681163a

Please sign in to comment.