Coder Social home page Coder Social logo

annulusgames / magictween Goto Github PK

View Code? Open in Web Editor NEW
453.0 10.0 25.0 9.67 MB

Extremely fast, GC-free and customizable tween library implemented with Unity ECS

License: MIT License

C# 88.38% ShaderLab 9.90% HLSL 1.72%
animation easing tween unity ecs ease tweening

magictween's Introduction

Stats

stats-dark stats-light

magictween's People

Contributors

annulusgames avatar potistudio avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

magictween's Issues

Error after import the package

I just import the package and appeared this errors

Unity Version: 2023.2.19
Entities: 1.2.0
Burst: 1.8.13

Error 1)
Library\PackageCache\com.annulusgames.magic-tween@0a5b840044\Runtime\Core\Systems\PathTweenSystems.cs(60,92): error CS8377: The type 'TweenDelegates<float3>' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'T' in the generic type or method 'InternalCompilerInterface.GetComponentTypeHandle<T>(ref ComponentTypeHandle<T>, ref SystemState)'

Error 2)
Library\PackageCache\com.annulusgames.magic-tween@0a5b840044\Runtime\Core\Systems\TweenDelegateTranslationSystemBase.cs(46,93): error CS8377: The type 'TweenDelegates<TValue>' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'T' in the generic type or method 'InternalCompilerInterface.GetComponentTypeHandle<T>(ref ComponentTypeHandle<T>, ref SystemState)'

Error 3)
Library\PackageCache\com.annulusgames.magic-tween@0a5b840044\Runtime\Core\Systems\TweenDelegateTranslationSystemBase.cs(47,99): error CS8377: The type 'TweenDelegatesNoAlloc<TValue>' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'T' in the generic type or method 'InternalCompilerInterface.GetComponentTypeHandle<T>(ref ComponentTypeHandle<T>, ref SystemState)'

Error 4)
Library\PackageCache\com.annulusgames.magic-tween@0a5b840044\Runtime\Core\Systems\StringTweenSystems.cs(89,92): error CS8377: The type 'TweenDelegates<string>' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'T' in the generic type or method 'InternalCompilerInterface.GetComponentTypeHandle<T>(ref ComponentTypeHandle<T>, ref SystemState)'

Error 5)
Library\PackageCache\com.annulusgames.magic-tween@0a5b840044\Runtime\Core\Transforms\TransformTranslationSystemBase.cs(123,99): error CS8377: The type 'TweenTargetTransform' must be a non-nullable value type, along with all fields at any level of nesting, in order to use it as parameter 'T' in the generic type or method 'InternalCompilerInterface.GetComponentTypeHandle<T>(ref ComponentTypeHandle<T>, ref SystemState)'

TextMeshProのアニメーションで、テキストを変更し再度アニメーションを生成してもうまく生成されない不具合

概要

以下のコードを再生すると、2回目のアニメーションが上手く作成されません。

        var list = new List<Tween>();
        for(var i = 0; i < text.GetCharCount(); i++)
        {
	    var tween = text.TweenCharColorAlpha(i, 0, 0.2f).SetInvert().SetDelay(i * 0.2f);
              tween.Play();
              list.Add(tween);
	}
        
	await UniTask.WaitUntil(() => !list.Exists(x => x.IsPlaying()));

	text.text = "123456789123456789";
	for (var i = 0; i < text.GetCharCount(); i++)
	{
		var tween = text.TweenCharColorAlpha(i, 0, 0.2f).SetInvert().SetDelay(i * 0.2f);
		tween.Play();
	}

※ textはTextMeshProUGUIのインスタンスです。
※ textの既存の文字列は「New Text」です。新しく代入するものよりも短いと2度目がバグるようです。

試したこと

  • テキストを変更したのち、UniTask.Delayで少し遅延させてからアニメーションを生成する。
  • 異なるプロジェクトで同じコードを利用する。

コメント

さきほど、メンションさせていただいたものです。

もし、そもそもコードが間違っていたらすみません。
ご指導ください。

(2023/10/25 20:42 追記)

It seems that the 0.20.0 package is missing TweenWorld.cs

This is the first time I've asked a issue on github, so please correct me if I've made any mistakes.
It seems that the 0.20.0 package is missing some file ? For example TweenWorld.cs.
Because when I installed it in unity via git url, it reported some errors.
githubissue
githubissue

SequenceでAppendを二個以上連続した場合に正しく再生されない

var seq = Sequence.Create()
seq.Append(transform.TweenLocalScale(new Vector3(1.2f, 1.2f, 1.2f), 0.5).SetEase(Ease.OutCubic));
seq.Append(transform.TweenLocalScale(new Vector3(0, 0, 0), 0.1).SetEase(Ease.OutCubic));

上記のようにした場合、二個目のTweenの再生開始時に、繋ぎの部分で1フレームだけ表示がおかしくなります。

二個目のTweenが、一個目のTweenが終了しきってない状態の値から始めてしまうのかもしれません。

ちなみに、二個目を

seq.Append(transform.TweenLocalScale(new Vector3(1.2f, 1.2f, 1.2f), new Vector3(0, 0, 0), 0.1).SetEase(Ease.OutCubic));

のようにして、startValueを明示的に与えてやると正しい結果になります。

id指定ありのTween.KillAll()を使用すると例外が発生する

こんにちは。

id付きのTween.KillAll()を使用すると以下のような例外が発生し、正常に動作しません。

  • Tween.KillAll(int id)
InvalidOperationException: Trying to get iterator for MagicTween.Core.Components.TweenIdInt but the required component type was not declared in the EntityQuery.
Unity.Entities.EntityQueryImpl.GetIndexInEntityQuery (Unity.Entities.TypeIndex componentType) (at ./Library/PackageCache/[email protected]/Unity.Entities/Iterators/EntityQuery.cs:759)
Unity.Entities.EntityQueryImpl.ToComponentDataArray[T] (Unity.Collections.AllocatorManager+AllocatorHandle allocator, Unity.Entities.EntityQuery outer) (at ./Library/PackageCache/[email protected]/Unity.Entities/Iterators/EntityQuery.cs:1077)
Unity.Entities.EntityQuery.ToComponentDataArray[T] (Unity.Collections.AllocatorManager+AllocatorHandle allocator) (at ./Library/PackageCache/[email protected]/Unity.Entities/Iterators/EntityQuery.cs:2587)
MagicTween.Tween.KillAll (System.Int32 id) (at ./Library/PackageCache/com.annulusgames.magic-tween@687bc3cfb7/Runtime/Tween.All.cs:252)
  • Tween.KillAll(string id)
InvalidOperationException: Trying to get iterator for MagicTween.Core.Components.TweenIdString but the required component type was not declared in the EntityQuery.
Unity.Entities.EntityQueryImpl.GetIndexInEntityQuery (Unity.Entities.TypeIndex componentType) (at ./Library/PackageCache/[email protected]/Unity.Entities/Iterators/EntityQuery.cs:759)
Unity.Entities.EntityQueryImpl.ToComponentDataArray[T] (Unity.Collections.AllocatorManager+AllocatorHandle allocator, Unity.Entities.EntityQuery outer) (at ./Library/PackageCache/[email protected]/Unity.Entities/Iterators/EntityQuery.cs:1077)
Unity.Entities.EntityQuery.ToComponentDataArray[T] (Unity.Collections.AllocatorManager+AllocatorHandle allocator) (at ./Library/PackageCache/[email protected]/Unity.Entities/Iterators/EntityQuery.cs:2587)
MagicTween.Tween.KillAll (System.String id) (at ./Library/PackageCache/com.annulusgames.magic-tween@687bc3cfb7/Runtime/Tween.All.cs:266)

環境
MagicTween 0.1.3
Unity 2022.3.5f1
Entities 1.0.16
Burst 1.8.8

ArchetypeStore is Disposed when new World is destoryed.

In MagicTweenInitializationSystem, ArchetypeStore.Initialize() and ArchetypeStore.Dispose(), is calling when any World is created and disposed.

It cause the NativeArry coreComponentTypes disposed, after any World disposed. This will cause the following error when using MagicTween later:
ObjectDisposedException: The Unity.Collections.NativeArray`1[Unity.Entities.ComponentType] has been deallocated, it is not allowed to access it

Suggestion:

  1. Add a checking for the World created and disposed.
  2. Don't use static for coreComponentTypes, created it in every World.
  3. Make Initialize() and Dispose() public to users.

BTW, good job for the library. I like it very much.

プレイモード終了時に例外が発生することがある

こんにちは。

SetLink()したTweenをawaitし、その後にSetLinkに渡したgameObjectを非表示化すると、Unityエディタからプレイモードを終了した際に以下のような例外が発生します。

ObjectDisposedException: The Unity.Entities.EntityManager has been deallocated, it is not allowed to access it
Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndThrowNoEarlyOut (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <56073df97ede4f769c2cc45d546d986d>:0)
Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle.CheckWriteAndThrow (Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle handle) (at <56073df97ede4f769c2cc45d546d986d>:0)
Unity.Entities.EntityManager.GetCheckedEntityDataAccess () (at ./Library/PackageCache/[email protected]/Unity.Entities/EntityManager.cs:86)
Unity.Entities.EntityManager.Exists (Unity.Entities.Entity entity) (at ./Library/PackageCache/[email protected]/Unity.Entities/EntityManager.cs:4424)
MagicTween.TweenStatusExtensions.IsActive[T] (T self) (at ./Library/PackageCache/com.annulusgames.magic-tween@078cb46f9e/Runtime/TweenStatusExtensions.cs:19)
MagicTween.TweenLinkTrigger.OnDestroy () (at ./Library/PackageCache/com.annulusgames.magic-tween@078cb46f9e/Runtime/Core/TweenLinkTrigger.cs:72)

また、このような例外が発生するということは、どこかでメモリリークが発生しているのではないかという事が気になりました。
私はTweenのawaitが終わり、メソッドを抜けた時点で作成したTweenはどこからも参照されなくなると想定していました。

以下の最小コードで再現する事を確認しています。
ただし、私が作っているプロジェクトでは毎回発生しますが、以下のコード単体で動かした場合は発生確率が低いです。

using Cysharp.Threading.Tasks;
using MagicTween;
using UnityEngine;

public class MagicTweenDebug : MonoBehaviour
{
    private void Start()
    {
        _ = TestAsync();
    }

    private async UniTaskVoid TestAsync()
    {
        var tween = gameObject.transform.TweenPositionX(1f, 1f).SetLink(gameObject);

        await tween;

        gameObject.SetActive(false);
    }
}

環境
MagicTween 0.1.6
Unity 2022.3.5f1
Entities 1.0.16
Burst 1.8.8

An error occurs if you await twice in a row

Overview

If you wait twice in one method as shown in the source code below, the following error will occur.

Operating environment

Unity 2022.3.7f1
Entities 1.0.16
Magic Tween 0.1.5

SourceCode

    private async UniTask MagicTween()
    {
        float x = 0;
        await Tween.To(
            () => 0,
            currentValue1 => x = currentValue1,
            1,
            1
        );
        Debug.Log(x);

        float y = 0;
        await Tween.To(
            () => 1,
            currentValue2 => x = currentValue2,
            0,
            1
        );
        Debug.Log(y);
    }

ErrorLog

InvalidOperationException: Structural changes are not allowed while iterating over entities. Please use EntityCommandBuffer instead.
Unity.Entities.EntityDataAccess.CheckIsStructuralChange () (at ./Library/PackageCache/[email protected]/Unity.Entities/EntityDataAccess.cs:342)
Unity.Entities.EntityDataAccess.BeforeStructuralChange () (at ./Library/PackageCache/[email protected]/Unity.Entities/EntityDataAccess.cs:416)
Unity.Entities.EntityDataAccess.BeginStructuralChanges () (at ./Library/PackageCache/[email protected]/Unity.Entities/EntityDataAccess.cs:426)
Unity.Entities.EntityManager.AddComponent (Unity.Entities.Entity entity, Unity.Entities.ComponentType componentType) (at ./Library/PackageCache/[email protected]/Unity.Entities/EntityManager.cs:1465)
Unity.Entities.EntityManagerManagedComponentExtensions.AddComponentData[T] (Unity.Entities.EntityManager manager, Unity.Entities.Entity entity, T componentData) (at ./Library/PackageCache/[email protected]/Unity.Entities/EntityManager.cs:5808)
MagicTween.TweenCallbackExtensions.GetOrAddComponent (Unity.Entities.Entity& entity) (at ./Library/PackageCache/com.annulusgames.magic-tween@e04fe40e25/Runtime/TweenCallbackExtensions.cs:20)
MagicTween.TweenCallbackExtensions.GetOrAddCallbackActions[T] (T self) (at ./Library/PackageCache/com.annulusgames.magic-tween@e04fe40e25/Runtime/TweenCallbackExtensions.cs:27)
MagicTween.TweenUniTaskExtensions+TweenAwaiter.UnsafeOnCompleted (System.Action continuation) (at ./Library/PackageCache/com.annulusgames.magic-tween@e04fe40e25/Runtime/External/UniTask/TweenUniTaskExtensions.cs:115)
Cysharp.Threading.Tasks.CompilerServices.AsyncUniTaskMethodBuilder.AwaitUnsafeOnCompleted[TAwaiter,TStateMachine] (TAwaiter& awaiter, TStateMachine& stateMachine) (at ./Library/PackageCache/com.cysharp.unitask@b992a061fb/Runtime/CompilerServices/AsyncUniTaskMethodBuilder.cs:102)
StarView.MagicTween () (at Assets/**************)
Cysharp.Threading.Tasks.UniTaskCompletionSourceCore`1[TResult].GetResult (System.Int16 token) (at ./Library/PackageCache/com.cysharp.unitask@b992a061fb/Runtime/UniTaskCompletionSource.cs:244)
Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask`1[TStateMachine].GetResult (System.Int16 token) (at ./Library/PackageCache/com.cysharp.unitask@b992a061fb/Runtime/CompilerServices/StateMachineRunner.cs:218)
Cysharp.Threading.Tasks.UniTask+Awaiter.GetResult () (at ./Library/PackageCache/com.cysharp.unitask@b992a061fb/Runtime/UniTask.cs:312)
Cysharp.Threading.Tasks.UniTaskExtensions+<>c.<Forget>b__16_0 (System.Object state) (at ./Library/PackageCache/com.cysharp.unitask@b992a061fb/Runtime/UniTaskExtensions.cs:572)
UnityEngine.Debug:LogException(Exception)
Cysharp.Threading.Tasks.UniTaskScheduler:PublishUnobservedTaskException(Exception) (at ./Library/PackageCache/com.cysharp.unitask@b992a061fb/Runtime/UniTaskScheduler.cs:90)
Cysharp.Threading.Tasks.<>c:<Forget>b__16_0(Object) (at ./Library/PackageCache/com.cysharp.unitask@b992a061fb/Runtime/UniTaskExtensions.cs:576)
Cysharp.Threading.Tasks.UniTaskCompletionSourceCore`1:TrySetException(Exception) (at ./Library/PackageCache/com.cysharp.unitask@b992a061fb/Runtime/UniTaskCompletionSource.cs:167)
Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask`1:SetException(Exception) (at ./Library/PackageCache/com.cysharp.unitask@b992a061fb/Runtime/CompilerServices/StateMachineRunner.cs:210)
Cysharp.Threading.Tasks.CompilerServices.AsyncUniTaskMethodBuilder:SetException(Exception) (at ./Library/PackageCache/com.cysharp.unitask@b992a061fb/Runtime/CompilerServices/AsyncUniTaskMethodBuilder.cs:59)
<MagicTween>d__7:MoveNext() (at Assets/*************)
Cysharp.Threading.Tasks.CompilerServices.AsyncUniTask`1:Run() (at ./Library/PackageCache/com.cysharp.unitask@b992a061fb/Runtime/CompilerServices/StateMachineRunner.cs:189)
MagicTween.PooledTweenCallback:Run() (at ./Library/PackageCache/com.annulusgames.magic-tween@e04fe40e25/Runtime/External/UniTask/TweenUniTaskExtensions.cs:420)
MagicTween.Core.SystemJob:TryInvoke(Action) (at ./Library/PackageCache/com.annulusgames.magic-tween@e04fe40e25/Runtime/Core/Systems/TweenCallbackSystem.cs:46)
MagicTween.Core.SystemJob:Execute(TweenCallbackActions, TweenCallbackFlags&) (at ./Library/PackageCache/com.annulusgames.magic-tween@e04fe40e25/Runtime/Core/Systems/TweenCallbackSystem.cs:40)
MagicTween.Core.SystemJob:Execute(ArchetypeChunk&, Int32, Boolean, v128&) (at ./Unity.Entities.SourceGen.JobEntityGenerator/Unity.Entities.SourceGen.JobEntity.JobEntityGenerator/Temp/GeneratedCode/MagicTween/TweenCallbackSystem__JobEntity_2559358350.g.cs:30)
MagicTween.Core.SystemJob:Unity.Entities.IJobChunk.Execute(ArchetypeChunk&, Int32, Boolean, v128&)
Unity.Entities.JobChunkExtensions:RunByRefWithoutJobs(SystemJob&, EntityQuery) (at ./Library/PackageCache/[email protected]/Unity.Entities/IJobChunk.cs:271)
Unity.Entities.Internal.JobChunkInterface:RunByRefWithoutJobs(SystemJob&, EntityQuery) (at ./Library/PackageCache/[email protected]/Unity.Entities/Internal/InternalCompilerInterface.cs:264)
MagicTween.Core.InternalCompilerQueryAndHandleData:Run(SystemJob&, EntityQuery) (at ./Unity.Entities.SourceGen.JobEntityGenerator/Unity.Entities.SourceGen.JobEntity.JobEntityGenerator/Temp/GeneratedCode/MagicTween/TweenCallbackSystem__JobEntity_2559358350.g.cs:193)
MagicTween.Core.TweenCallbackSystem:__ScheduleViaJobChunkExtension_0(SystemJob, EntityQuery, JobHandle, SystemState&, Boolean) (at ./Library/PackageCache/com.annulusgames.magic-tween@e04fe40e25/Runtime/Core/Systems/TweenCallbackSystem.cs:37)
MagicTween.Core.TweenCallbackSystem:OnUpdate() (at ./Library/PackageCache/com.annulusgames.magic-tween@e04fe40e25/Runtime/Core/Systems/TweenCallbackSystem.cs:26)
Unity.Entities.SystemBase:Update() (at ./Library/PackageCache/[email protected]/Unity.Entities/SystemBase.cs:418)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at ./Library/PackageCache/[email protected]/Unity.Entities/ComponentSystemGroup.cs:739)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at ./Library/PackageCache/[email protected]/Unity.Entities/ComponentSystemGroup.cs:697)
Unity.Entities.SystemBase:Update() (at ./Library/PackageCache/[email protected]/Unity.Entities/SystemBase.cs:418)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at ./Library/PackageCache/[email protected]/Unity.Entities/ComponentSystemGroup.cs:739)
Unity.Entities.ComponentSystemGroup:OnUpdate() (at ./Library/PackageCache/[email protected]/Unity.Entities/ComponentSystemGroup.cs:697)
Unity.Entities.SystemBase:Update() (at ./Library/PackageCache/[email protected]/Unity.Entities/SystemBase.cs:418)
Unity.Entities.ComponentSystemGroup:UpdateAllSystems() (at ./Library/PackageCache/[email protected]/Unity.Entities/ComponentSystemGroup.cs:739

日本語をTweenTextでアニメーションさせた際のdurationが正しく反映されない

概要

日本語をTweenTextでアニメーションさせた際、指定のdurationよりも短い時間(半分以下ぐらい?)でアニメーションが完了する

再現手順

以下のソースコードを実行すると、durationが2fにも関わらず0.5fくらいの時間でアニメーションが完了する

tmpText.TweenText("あのイーハトーヴォのすきとおった風", 2f);

動作環境

Unity 2022.3.7f1
Entities 1.0.16
Magic Tween 0.1.5

How to Tween from the middle?

Is there a way to start from a time in the middle of defining Tween?
For example, I want to start from the 0.5 second point in the code below (currentValue==0.5f) and transition to 1 in the remaining 0.5 seconds.

        float x = 0;
        await Tween.To(
            () => 0,
            currentValue1 => x = currentValue1,
            1,
            1
        );

GetCharCount at TMPTweenAnimator.cs sometimes crashes.

When it crashes, textInfo returns null.
Therefore, I changed it like below, and seems working fine.

public int GetCharCount()
{
var info = tmpText.textInfo;
return info == null ?
0 : math.min(info.characterCount, info.characterInfo.Length);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.