Search Unity

LEAN ⚡️ Touch / GUI / Texture / Localization / Transition / Pool

Discussion in 'Assets and Asset Store' started by Darkcoder, Aug 1, 2019.

  1. senfit

    senfit

    Joined:
    Nov 21, 2019
    Posts:
    3
    Hi Carlos,

    thank you for your amazing asset. I'm working with lt+ and am currently struggling with a very basic feature.

    I want to replicate an animation I was using before lt+. When the finger touches an object the object gets smaller and gets back to its initial size as soon as so stop touching it and triggers an action (e.g. open window).
    So basically an animated button.

    Before lt+ I was using OnMouseDown() and OnMouseUpAsButton() to trigger the animations and trigger an action.
    To make it work I had to check for various special scenarios, especially when the whole world was able to pan and zoom. Therefore I would like to migrate it to lt+.

    In lt+ I tried to replicate this feature with OnSelect() and OnSelectUp() but it doesn't get called early enough.
    I've checked the documentation and read through this thread but didn't find a solution. If I missed something a hint would be great :)

    How would you replicate OnMouseDown() and OnMouseUpAsButton() lt+ ?

    Thank you!
     
  2. JohnnyFactor

    JohnnyFactor

    Joined:
    May 18, 2018
    Posts:
    343
    I'm using LeanTransition with some audio sources. I found volumeTransition but no pitchTransition. It would be great if you could add that to the package.
     
  3. ina

    ina

    Joined:
    Nov 15, 2010
    Posts:
    1,085
    So I've looked at lean docs and cannot seem to figure out how to use Use.GetFingers() in order to supply proper zoom values to GetPinchRatio() ...

    Trying to supply a zoom in/out value to a device camera zoom. What is needed to GetPinchRatio() to supply anything but 1?
     
  4. cihad_unity

    cihad_unity

    Joined:
    Dec 27, 2019
    Posts:
    35
    Hello Carlos,
    I'm using LeanTouch. First of all, amazing asset! Although I realize I don't need, I bought the LeanTouch+ just to support.

    I have an issue and so surprised no one here mentioned it.

    I develop mobile apps and games so I always use Device Simulator package by Unity and it's awesome. I can define different phones with different DPIs and point sizes. It makes mobile development easy.

    Screen Shot 2021-03-15 at 12.02.51 PM.png
    However, I can't simulate multiple touches with it (e.g rotate and scale) I guess it behaves like a real phone but maybe there is a workaround.
    Is there a way to solve this?
     
  5. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I sent you a private message with a new build!


    Try the attached package.


    I've never used this package. If the touch simulator that comes with LeanTouch doesn't work with it then I imagine this package is actually changing the input data to make it seem like it's coming from a real touch device. In this case it wouldn't work without drastically changing the code, since I would have to bypass the data coming from Unity itself. I have plans in the future to decouple the touch simulation into its own component, and at this point it would be possible to implement this kind of input bypass code. I'm a little too busy right now to write such code though.
     

    Attached Files:

  6. kypronite

    kypronite

    Joined:
    Apr 15, 2013
    Posts:
    21
    Hi, I'm using LeanTransition for UI
    (I bought other paid tweening asset but since I'm using Lean Pool, i was like might as well used Lean Transition altogether.So far,I'm impressed by the clean api:))

    Okay, currently I'm using filled image for my mana bar that automatically refilled over time.
    However adding LeanImageFillAmount component to my image, I notice I CANNOT change duration in script (only in editor).

    Reason I'm doing this because I want to update my mana bar over time,
    example
    if mana bar 0% filled, i passed 2 second for duration
    if mana bar 50% filled, I passed 1 second for duration
    if mana bar 25% filled,I passed .5 second for duration

    I cannot find any example for this.
    So I figure out way to do code in this
    I will be calling this method everytime my mana bar is used up.

    Code (CSharp):
    1.        
    2. manaBar.fillAmountTransition(1f, fillDuration,LeanEase.Accelerate);
    3. manaBar.GetComponent<LeanAnimation>().BeginTransitions();
    4.  
    Just curious ,is it right way coding in this manner?
     
  7. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    If your transitions are on a GameObject and you want to modify a transition duration before execution then you can just .GetComponent<whatever>().Data.Duration = 123;

    If your transitions are started from code then after you execute the transition (e.g. manaBar.fillAmountTransition(...)) you can store the LeanTransition.CurrentHead value somewhere, and modify its .Duration.

    Keep in mind the CurrentHead value will change every time you execute a transition, so if you execute multiple like on a GameObject with many transitions then you can't easily get a reference to al earlier transition since there can be an arbitrary amount. That said, you can access it via CurrentHead's .Prev list, and then .Prev on any of those, etc, it just gets difficult.
     
  8. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    I'm using Lean Pool for spawning and despawning various books. I'm getting lag spikes when spawning each one...
     
  9. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    If your prefab is heavy then you should preload it. If it's still lagging then something during the de/activation is causing the lag. In either case the profiler will give you more information.
     
    Proto-G likes this.
  10. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Thanks. I am preloading. I'll learn more about the profiler, never use it.
     
    Darkcoder likes this.
  11. kypronite

    kypronite

    Joined:
    Apr 15, 2013
    Posts:
    21
    Thanks for quick reply.
    I now added the GUI component Image.fillAmounTransition and
    set fill amount to absolute value everytime mana used and then adjust the data.duration accodingly.
    Is working and this way is much more cleaner.

    I have code running elsewhere calculating manabar fill amount, I just need to sync the gui(fillamount) with internal data.
    thanks again:D
     
    Darkcoder likes this.
  12. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Hi there!
    I just tried Unity 2021.1.0f1 tech release and it's giving me fatal errors when using Lean Pool:

    It happens consistently and crashes the editor for good.
    Everything works perfectly on Unity 2019.4.22f1 LTS
    I'll try with Unity 2020.3.1f1 LTS (which is the new current LTS version replacing the 2019.4 version) and let you know if it still happens.
     
  13. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Does this issue occur in the example scenes, or only your setup?

    All line 777 does is activate a previously despawned prefab clone, so I'm not sure what can be done.
     
  14. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Seems like it's a Unity 2021 bug with audio sources using an audio filter on them.
    Not related to your plugin. I was just spawning particle effects with sound with an audio filter.
    I still have to check it with the 2020 LTS version. (still reimporting the whole project... ASTC compression takes AGES...)
     
  15. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    It's working perfectly fine with Unity 2020.3.1f1 LTS
    For the record, the "Callback registration failed. Increase kMaxCallback." error is an Unity 2021.1 exclusive bug and it's related to using audio filter effects on audiosources.
    It seems to be fixed in 2021.2 alpha, but I'm not installing an alpha version of Unity. Regular versions are alpha enough for me :rolleyes:
    Anyway, nothing related to LeanPool, but it would be nice to know for other users.
     
    Darkcoder likes this.
  16. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Great, let me know if you encounter any other issues :D
     
  17. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Nothing to do with your plugins, but 2020.3 LTS breaks any Bakery Lightmapped scene on Android builds.
    Definitively it's not going to be a smooth upgrade from 2019.4 to 2020.3 .... :mad:

    -EDIT: actually the issue lied in the ASTC_HDR compression, not related to Bakery but still a Unity 2020.3LTS bug -
     
    Last edited: Mar 25, 2021
  18. stansison

    stansison

    Joined:
    Feb 20, 2016
    Posts:
    28
    I'm finding that Lean Camera Zoom's mousewheel functions doesn't seem to respect Ignore Started Over GUI/Ignore is Over Gui, though it works flawlessly with touch and finger control.

    You can easily see this by using the Camera2DMoveZoom example scene and adding a basic scrollview. Using the mousewheel over the scrollview will still cause the camera to zoom in and out. Is there a way to have the mousewheel inputs be also checked as the finger inputs?
     
  19. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    This is by design because the mouse wheel isn't a finger, I could add this option though. I'll send you a build by email when I can!
     
  20. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    Given a bunch of objects under a root, is there a way to animate all of them in sequence regardless of the number of o objects?
    I'm thinking of making bricks of a road fall to the ground one after the other.
     
  21. stansison

    stansison

    Joined:
    Feb 20, 2016
    Posts:
    28
    That we be very much appreciated! Thank you
     
  22. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    When you say sequence, you mean to join them all together, except without having to add the LeanJoinTransition between them? If so, you would have to do this with a custom script. First you must call GetComponentsInChildren<LeanMethod>() to get all the transition components, then run through them one at a time calling this: LeanTransition.CurrentQueue = yourMethod.Register(); Just make sure you set LeanTransition.CurrentQueue to null at the end. Setting CurrentQueue is basically the manual way of calling .JoinTransition (you could call this instead if you'd like).
     
    laurentlavigne likes this.
  23. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    I see, I'll try that. Are the components in the transform order (index)?
     
  24. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I think so.
     
    laurentlavigne likes this.
  25. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    Like this?
    Code (CSharp):
    1. public class LeanTransitionGroup : MonoBehaviour
    2. {
    3.     public float delayBetweenTransitions;
    4.     IEnumerator Start()
    5.     {
    6.         var leans = GetComponentsInChildren<LeanMethod>();
    7.         foreach (var l in leans)
    8.         {
    9.             LeanTransition.CurrentQueue = l.Register();
    10.             yield return new WaitForSeconds(delayBetweenTransitions);
    11.         }
    12.         LeanTransition.CurrentQueue = null;
    13.     }
    14. }
    15.  
    it's giving me grief.
    upload_2021-3-25_20-37-42.png
     
  26. tonygiang

    tonygiang

    Joined:
    Jun 13, 2017
    Posts:
    71
    Hi, is there a way to force Lean GUI component to reject interaction when there are multiple touch inputs (as in fingers) on the screen?

    Our tester poked around and raised this as an issue and now it's a must-fix.
     
  27. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Oops, something like this should work:

    Code (CSharp):
    1. foreach (var method in GetComponentsInChildren<LeanMethod>())
    2.         {
    3.             method.Register();
    4.  
    5.             LeanTransition.CurrentQueue = LeanTransition.CurrentHead;
    6.         }
    7.  
    8.         LeanTransition.Submit();
    If you're manually putting a delay between each method registration using WaitForSeconds then there's no need to join them together, you can just call .Register every n seconds. Doing it your way while joining them may not even work, because the previously registered transition may no longer exist or be what you expect after the WaitForSeconds.

    Which components are you referring to? LeanButton for example has the MultiDown setting which can change this behavior.
     
    laurentlavigne likes this.
  28. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    Roger that.
    I ended up using this which works but that's less flexible so I'd like to try making the next one work.
    Code (CSharp):
    1.     IEnumerator Start()
    2.     {
    3.         yield return null;
    4.         var leans = GetComponentsInChildren<Renderer>();
    5.         foreach (var l in leans)
    6.         {
    7.             l.transform.localPosition = new Vector3(0, 5, 0);
    8.             l.gameObject.SetActive(false);
    9.         }
    10.  
    11.         foreach (var l in leans)
    12.         {
    13.             l.gameObject.SetActive(true);
    14.             l.transform.localPositionTransition_Y(0, .5f, LeanEase.Accelerate);
    15.             yield return new WaitForSeconds(delayBetweenTransitions);
    16.         }
    17.     }
    This only play the last object in the queue.
    Code (CSharp):
    1.     IEnumerator Start()
    2.     {
    3.         yield return null;
    4.         var leans = GetComponentsInChildren<LeanMethod>();
    5.         foreach (var l in leans)
    6.         {
    7.             l.gameObject.SetActive(false);
    8.         }
    9.         foreach (var l in leans)
    10.         {
    11.             l.Register();
    12.             LeanTransition.CurrentQueue = LeanTransition.CurrentHead;
    13.         }
    14.         LeanTransition.Submit();
    15.     }
    edit easy solution: add a negative delay
    you thought about everything :)
    upload_2021-3-26_11-50-52.png
     
    Last edited: Mar 26, 2021
    Darkcoder likes this.
  29. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    by the way, did you move LeanAnimation & co out of the Extras namespace in version ? it's become first class citizen?
    upload_2021-3-26_12-2-5.png
    upload_2021-3-26_12-3-1.png
     
  30. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    Question: why do you use System.Action in LeanTransition when UnityEvent is what's being exposed?
     
  31. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I'm in the middle of deciding how to structure everything, so the namespaces are subject to change. Since they're all in the same assembly I figure that putting them in their own sub namespace is strange. In a perfect world Unity's package manager would be fully integrated into the store and I could make the examples a separate package, but it's not, so putting them all in the same asset and namespace seems to make the most sense right now.

    The next release will once again change many things. For LeanTransition, one nice thing I've added a tool to easily build transitions based on templates. So with just a few seconds of typing and the clicking of a button it will generate new transitions for almost any kind of property:

    upload_2021-3-27_10-16-16.png


    UnityEvent is used for the events I intend for the user to edit in the inspector. System.Action is for code-only events because it's faster, but it doesn't work in the inspector so I have to mix both.
     
    laurentlavigne likes this.
  32. tonygiang

    tonygiang

    Joined:
    Jun 13, 2017
    Posts:
    71
    The description of MultiDown reads:

    Code (csharp):
    1. If you enable this then OnDown + DownTransition be invoked once for each finger that begins touching the button.
    2. If you disable this then OnDown + DownTransition will only be invoked for the first finger that begins touching the button.
    This is not what I'm looking for. I'm looking for a method to reject OnDown altogether when there are multiple fingers touching. One of those fingers could be touching outside of the button to qualify a rejection.
     
  33. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    When I do that, leans grabs all transitions except for LeanAnimation
    it's acting weird so I'm wondering if there is a way to queue up LeanAnimation instead?
    (the goal is to grab all leananimations of dynamically created children and then queu them up so they play automatically one after the other)
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using Lean.Transition;
    5.  
    6. [DefaultExecutionOrder(9999)]
    7. public class LeanTransitionChildren : MonoBehaviour
    8. {
    9.     LeanMethod[] leans;
    10.     [ContextMenu("Init")]
    11.     public void Init()
    12.     {
    13.         leans = GetComponentsInChildren<LeanMethod>(true);
    14.         foreach (var l in leans)
    15.         {
    16.             l.gameObject.SetActive(false);
    17.         }
    18.     }
    19.     [ContextMenu("Transition")]
    20.     public void Transition()
    21.     {
    22.         if (leans == null)
    23.             Init();
    24.         foreach (var l in leans)
    25.         {
    26.             l.Register();
    27.             LeanTransition.CurrentQueue = LeanTransition.CurrentHead;
    28.         }
    29.         LeanTransition.Submit();
    30.     }
    31.  
    32.     public void ActivateAll()
    33.     {
    34.         if (leans == null)
    35.             Init();
    36.         foreach (var l in leans)
    37.         {
    38.             l.gameObject.SetActive(false);
    39.         }
    40.     }
    41. }
    42.  
     
  34. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    LeanAnimation isn't a transition, only components that implement LeanMethod are. You could just get all Component instances and check if they're a LeanMethod or LeanAnimation and register/begin them as needed.
     
  35. Prot0Type

    Prot0Type

    Joined:
    May 18, 2017
    Posts:
    4
    Hello,

    I got an issue with my object in the scene, drifting slowly after I moved it or orbited/zoomed the camera. I think the issue comes from "Lean Drag Translate Along", because when i deactivate the script the object wont drift anymore (I have set the damping of Lean Drag Translate Along to -1). Any ideas?
     
  36. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I'll send you a private message with a test fix.
     
  37. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    i use leananimation as entry point to a bunch of leanmethods so i can either beging these leananimation in a coroutine or just don't use them and queue up all 80 LeanMethod and that'll have the same effect? (looks that way)
     
  38. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    LeanAnimation is basically just a list of Transforms that begins the LeanMethod components attached to them, and with a few other things sprinkled on top like the speed setting, aliases, etc. This can all be done from code, it just depends what you want it to do exactly. Since it seems like you're trying to do some complex stuff I recommend doing it entirely from code.

    Lean Transition itself is fairly simple, at its core you just have LeanMethods that you can begin via .Register(), or via transform.localPositionTransform(...) etc. If there is a state set in LeanTransition.CurrentQueue, then that new state will only begin once the queue one finishes. After you register a transition its state will be stored in LeanTransition.CurrentHead, so you can put it in the queue to join it to the next transition, or you can store it for later use like modifying a transition state while it's running. The only thing you have to watch out for is storing that state reference longer than the transition length itself, which can lead to unexpected results.
     
    laurentlavigne likes this.
  39. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    It works well now, I simply queued up all 80 LeanMethds. Thanks.
    Brain can't parse all that :D. If you have microsoft paint, I wouldn't mind see a diagram though.
     
  40. thomas_superFASTgames

    thomas_superFASTgames

    Joined:
    Jul 15, 2017
    Posts:
    23
    Looking at all of your offerings and they look very polished and useful! Regarding LeanTransition, is there a way to "stop" a sequence, or reset it (so that it will begin at the start of the sequence)? Also, what is the best way to support your efforts since so many of your assets are free? Do you have a Patreon etc? Thanks :)
     
  41. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    I'll rename some of these methods to make this clearer!


    Thanks, you can support by writing a review, and/or buying one of my assets that you will find use for :)

    To stop a sequence you must store a reference to all its states. This can currently only be done from code, like:

    Code (csharp):
    1. var state = transform.localPositionTransition(targetPos, 1.0f).GetTransition();
    Unless you're using a coroutine or something you will want to store that state somewhere, then you can call:

    Code (CSharp):
    1. state.Skip = true;
    And that will stop it from doing anything.

    If a transition is already running and you begin the same transition on the same object, then the first one will be skipped. This means you can automatically restart an animation by just playing it at any time. However, if the animation is complex with many different transitions then you will have to 'stop' it like mentioned above by manually skipping. I could simplify this for editor animations by storing these states for you ,but that will require some code change which will take a little bit, as I'm already in the middle of making some big changes.
     

    Attached Files:

  42. Supergrubman

    Supergrubman

    Joined:
    Jan 2, 2014
    Posts:
    20
    I'm currently having some trouble getting LeanPool to work.
    Can some one tell me the equivalent of this line of code with Leanpool.
    GameObject arrow = Instantiate(Resources.Load(ArrowPrefabName, typeof(GameObject))) as GameObject;

    Can leanpool return the GameObject
     
  43. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    Instead of using that version of Resources.Load, you should use this: Resources.Load<GameObject>(ArrowPrefabName), which you can spawn without casting. The issue with your current one is you need to cast before the Instantiate call for it to work with LeanPool, but you're doing it after.
     
    laurentlavigne likes this.
  44. dead_byte_dawn

    dead_byte_dawn

    Joined:
    May 7, 2015
    Posts:
    16
    Hey Guys, I have three objects using Lean_Drag_Line, and I was wondering if there was a way (using leantouch methods) to make only one selectable at a time?
     
  45. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    LeanDragLine has the Use/RequiredSelectable setting. If you add the LeanSelectable to this GameObject and drop it into this setting, the line will only draw when this object is selected. You can copy+paste one of the selection setups from the Lean/Touch/Examples scenes like Select 3D, etc.
     
  46. dead_byte_dawn

    dead_byte_dawn

    Joined:
    May 7, 2015
    Posts:
    16
    Okay! Super easy with the LeanSelectable.IsSelected interface! thank you!
     
    Darkcoder likes this.
  47. maltakereuz

    maltakereuz

    Joined:
    Mar 29, 2015
    Posts:
    53
    Bug: LeanLocalization makes scene dirty after scene is played. It does not really breaks anything, but is very annoying because it is not clear if scene was actually changed or not. And i found the method that is called on scene start:


    Code (CSharp):
    1.  
    2. /// <summary>If you call this method, then UpdateTranslations will be called next Update.</summary>
    3. public static void DelayUpdateTranslations()
    4. {
    5.     pendingUpdates = true;
    6. #if UNITY_EDITOR
    7.     // Go through all enabled phrases
    8.     for (var i = 0; i < Instances.Count; i++)
    9.     {
    10.         EditorUtility.SetDirty(Instances[i].gameObject);
    11.         Debug.Log("set dirty " + Instances[i].gameObject);
    12.     }
    13. #endif
    14. }
    15.  
    The stacktrace of is the following:



    The easiest solution for me is just comment the set-dirty call. But i suppose this call is placed there for a reason. Why OnDisable-hook is called by start. Why LeanLocalization wants to (delayed) updated translations and should it really marks scene as dirty? That results every time i hit Play scene is dirty, even if i did not edited anything. Is it safe just to comment this code?
     
  48. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,414
    This looks like I made a mistake. Not sure why I put the dirtying code there, hmm. Commenting it out should work.

    I'm currently working on a large update to all Lean assets, and I'll test this out in more detail.
     
  49. thomas_superFASTgames

    thomas_superFASTgames

    Joined:
    Jul 15, 2017
    Posts:
    23
    Thanks for your reply. One last question... is there/will there be a way to set a transition from code? For example, set the position on a LeanTransformPosition dynamically?
     
  50. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    bizarre behaviour: this pulses (plays) even though leanAnimation.BeginTransition was never called
    upload_2021-4-4_21-53-30.png
    upload_2021-4-4_21-53-37.png
    upload_2021-4-4_21-53-44.png
    upload_2021-4-4_21-53-49.png