Search Unity

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

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

  1. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    612
    Just discovered Lean GUI, very nice components! Thanks

    I am using the tool tip component and was wondering if you have any suggestions on creating a tool tip with pop-up modal behaviour.

    The tool tips work great on keyboard/mouse, but for mobile I want to press the icon to show the tooltip, click elsewhere to "close" the tooltip.

    So it's basically like the pop up but instead of having it centered all the time, it would be nice to be re-positioned and re-sized as a tooltip.
     
  2. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    This can be done by making your modal a child of your tooltip, then it will automatically be placed under the mouse. You can then trigger it with the LeanTooltip.OnShow event. See the attached scene :)
     

    Attached Files:

    xjjon likes this.
  3. xjjon

    xjjon

    Joined:
    Apr 15, 2016
    Posts:
    612
    Thank you, that works very well!

    One another thing, for my `LeanButton` certain fields from the underlying `Selectable` are not visible in the inspector (unless in debug mode). Is this intentional? For example, I want to set color transition and target graphic.

    lean_button.png


    I am using 2019 LTS
     
  4. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    I think Unity's built in transition system is poop, so I made LeanTransition and integrated it into LeanButton and others. It requires some extra work to understand and isn't quite as 'instant' to set up, but it allows you to transition anything.
     
    xjjon likes this.
  5. pradf4i

    pradf4i

    Joined:
    Nov 7, 2017
    Posts:
    39
    I am trying to detect swipe on a gameobject (cube) using ‘ lean finger swipe’ and having a selectable component on the cube. However, the event just does not get triggered. Is there an example that shows swipe wit’required selectable option’?
     

    Attached Files:

  6. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Seems to work as expected (see attached packaged scene).
     

    Attached Files:

  7. pradf4i

    pradf4i

    Joined:
    Nov 7, 2017
    Posts:
    39
    Thanks @Darkcoder. I was sure I was missing something basic. It works once you start the swipe from the gameobject itself. Is there a setting to detect 10-20 pixels earlier?
    Anyways, got Leantouch+ as well now and will look in to your other products.
     
  8. tonygiang

    tonygiang

    Joined:
    Jun 13, 2017
    Posts:
    71
    Hi, somebody has collected your free assets on GitHub and packaged them up into UPM format. I hope using these assets via this repo does not raise a licensing issue because UPM format is now my preferred way to install packages.

    (I'm not using this specific repo because it is several updates behind the official Asset Store versions)
     
  9. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    You can adjust the minimum distance required for a swipe to trigger with the LeanTouch component's SwipeThreshold setting.


    I also like UPM, but I don't want to deal with uploading my assets twice. The main challenge here is that UPM packages have a different structure to asset store packages, so my workflow will become very complex if I have to constantly switch between them to upload. My main repository also contains paid assets, and cleanly separating these while still keeping an efficient workflow is difficult. Unity has plans to move assets to UPM, so when that happens all my assets will go there too, but not now.
     
    pradf4i likes this.
  10. Bazzajunior

    Bazzajunior

    Joined:
    May 23, 2015
    Posts:
    20
    I'm having one of those days where I've been looking at code and I'm sure I'm making things harder than they need to be, so I'm going to ask before I go a bit crazy.

    I'm looking at replacing
    Input.GetAxis("Horizontal")
    with a simple swipe left and right of the screen; i.e. if you swipe on the left it's -1 and on the right it's 1 (and 0 when released). I want it to be continuous so I'm guessing it's LeanFingerDown and LeanFingerSwipe that I need to use, but for the life of me, I can't think how to employ this.

    I don't need fractions of numbers (i.e. if you're just over the middle of the screen it'll be 0.001) just two whole numbers in the same way that a keyboard only registers 'Left Arrow Key' or 'Right Arrow Key'. If the player drags their finger from one side of the screen to the other, it'll update instantly without having to lift their finger.

    I think I've just been going at this project for too many hours :confused:

    My current code is (I've deleted parts for torque which aren't relevant here):

    Code (CSharp):
    1.  
    2. public void FixedUpdate()
    3.     {
    4.         float steeringWheel = maxSteeringAngle * Input.GetAxis("Horizontal");
    5.      
    6.         foreach (AxleInfo axleInfo in axleInfos)
    7.         {
    8.             if (axleInfo.steering)
    9.             {
    10.                 axleInfo.leftWheel.steerAngle = steeringWheel;
    11.                 axleInfo.rightWheel.steerAngle = steeringWheel;
    12.             }
    13.         }
    14.     }
    15.  
     
    Last edited: Jul 2, 2020
  11. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    You can get a similar value using code like this:

    Code (csharp):
    1. var fingers    = LeanTouch.GetFingers(true, false);
    2. var delta      = LeanGesture.GetScreenDelta(fingers);
    3. var horizontal = Mathf.Sign(delta.x);
    or

    Code (csharp):
    1. var fingers    = LeanTouch.GetFingers(true, false);
    2. var delta      = LeanGesture.GetStartScreenCenter(fingers) - LeanGesture.GetScreenCenter(fingers);
    3. var horizontal = Mathf.Sign(delta.x);
    Where horizontal will be -1, 0, or 1.

    Keep in mind the first one will give 0 if your finger(s) don't move between frames. If your game is running at a high framerate then this may happen unexpectedly since fingers can only move one pixel per frame minimum. Also, since the inputs are updated in Update, you may 'miss' some inputs if this code is in FixedUpdate, or even get multiple of the same input data. Therefore it's a better idea to handle the inputs in Update, and instead of directly using the finger position changes, you should use some kind of velocity value that works across several frames to mitigate any framerate-dependent effects. This is why many mobile games use the second version, which acts more like a joystick.
     
    Last edited: Jul 2, 2020
    Bazzajunior likes this.
  12. Bazzajunior

    Bazzajunior

    Joined:
    May 23, 2015
    Posts:
    20
    First off @Dark-Coder, thanks for this - it's now far clearer and I've got a working version that detects when a finger is placed and dragged left or right to enable a '-1' or '1' :D

    ...but I've realised that if the player clicks on the left of the screen first, the middle position is re-defined where each new touch commences. This means the middle of the screen (0) is not permanent and the player has to swipe left to make the steering turn left.

    I also now realise too that players may click and hold to make a turn but this would mean that the centre must always be in the middle of the physical screen for this to work. Is there a way to define that '0' is always in the centre of the screen?

    Code (CSharp):
    1.    
    2.     public float horizontal = 0f;
    3.     public bool fingerDown;
    4.  
    5.     public void Update()
    6.     {
    7.         var fingers = LeanTouch.GetFingers(true, false);
    8.         var delta = LeanGesture.GetScreenCenter(fingers) - LeanGesture.GetStartScreenCenter(fingers);
    9.  
    10.         if (fingerDown)
    11.         {
    12.             horizontal = Mathf.Sign(delta.x);
    13.             steeringWheel = maxSteeringAngle * horizontal;
    14.         }
    15.         else
    16.         {
    17.             steeringWheel = 0f;
    18.         }
    19.  
    20.         foreach (AxleInfo axleInfo in axleInfos)
    21.         {
    22.             if (axleInfo.steering)
    23.             {
    24.                 axleInfo.leftWheel.steerAngle = steeringWheel;
    25.                 axleInfo.rightWheel.steerAngle = steeringWheel;
    26.             }
    27.             if (axleInfo.motor)
    28.             {
    29.                 axleInfo.leftWheel.motorTorque = engine;
    30.                 axleInfo.rightWheel.motorTorque = engine;
    31.             }
    32.         }
    33.     }
    34.  
    35.     //Apply the following to detect if a LeanFingerDown or LeanFingerUp component is in use
    36.     public void OnSwipeHeld()
    37.     {
    38.         fingerDown = true;
    39.     }
    40.     public void OnSwipeReleased()
    41.     {
    42.         fingerDown = false;
    43.     }
    44.  
     
    Last edited: Jul 2, 2020
  13. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    As you can see, the delta there is calculated between the current center (average) screen point of all fingers, and the start center (average) screen point of all fingers:

    Code (csharp):
    1. var delta = LeanGesture.GetScreenCenter(fingers) - LeanGesture.GetStartScreenCenter(fingers);
    I'll leave it up to you to figure out how to change this to be relative to the screen center.
     
    Bazzajunior likes this.
  14. IceTrooper

    IceTrooper

    Joined:
    Jul 19, 2015
    Posts:
    36
    Hi, firstly thank you for your asset LeanTouch and LeanTouch+. I bought LeanTouch+ to support the idea of making great, production-ready, free assets (i.e. LeanTouch) and of course to check out new features in Plus. I'm quite new trying out and checking all examples with Touch, but I've already used it in my current project.
    I got one issue and one question for now:

    1. Every time when I install a new package in a serious project I import all folders, but also I add all Examples/Demos folders to .gitignore. Unfortunately, my colleague who cloned a project report me that the project is missing scripts in Lean->Touch->Examples->Scripts. I think those scripts should be moved to Lean->Touch->Scripts and example scenes should stay in Examples. It's the first time when I removed Examples folder and got errors. I think this should be fixed to avoid misunderstanding when you have to get examples to work with the package.

    2. More difficult problem:
    I was disappointed when I tried to use LeanFingerSet and OnFinger event was raised every time except when the finger was going to Up. Is it a feature or a bug? I expected all finger moves/translations are fired in OnFinger but I couldn't check if finger is up in this event handler. Now I had to use 3 components: LeanFingerDown (to do something on down), LeanFingerUp (to do something on up) and LeanFingerSet (to check delta).

    What I wanted to achieve: Player touch screen anywhere on screen (except buttons so IgnoresStartedOverGUI: true) and then something happens (plant is growing) until he raise finger up. At the same time if player when touching the screen moves finger to left or right I react to those moves (plant starts to fall on left or right direction). Is there easier way to do that?

    Anyway, thank you very much for the asset.

    EDIT: btw, is there any helper function, event or component to react on only first finger down and last finger up?
     
    Last edited: Jul 4, 2020
  15. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    1 - The 'core' of LeanTouch is LeanTouch+LeanFinger+LeanGesture+LeanSnapshot, which provide the C# API to do everything. The other components are basically wrappers around this so you don't have to write any code. I agree that most of these components are very useful to all LeanTouch projects without code, though it's difficult to draw the line between a purely example component and one that would be useful in most projects. I do want to change the way the components are organized though, so I'll have to think about it.

    2 - Good point, I'll rename this to OnFingerUpdate, and add a setting to LeanFingerUpdate that allows you to toggle this behaviour.

    3 - There's no such component yet, you can check it like this though:

    Code (csharp):
    1.  
    2. var fingers   = Lean.Touch.LeanTouch.GetFingers(true, false);
    3. var firstDown = fingers.Count > 0 && fingers.TrueForAll(f => f.Down);
    4. var lastUp    = fingers.Count > 0 && fingers.TrueForAll(f => f.Up);
    Thanks for the suggestions, I'll send you an updated build soon :)
     
    IceTrooper likes this.
  16. Bazzajunior

    Bazzajunior

    Joined:
    May 23, 2015
    Posts:
    20
    That's it fixed :cool:

    I've used the premise of just clicking/tapping on the relevant side of the screen rather than continually swiping and the centre of the screen is just worked out from screen width halved. If there IS a way to keep a finger held down, and simply swipe to the left or right of the screen, it would still be interesting to see how it could be done.

    Here's the final code (less the variables) just for reference and if anyone else needs something similar :D

    Code (CSharp):
    1.     public void HandleFingerDown(LeanFinger finger)
    2.     {
    3.         var fingerPositionOnScreen = finger.ScreenPosition.x; //This detects the 'Lean Touch' placement on the screen only in the X axis
    4.         var screenWidth = Screen.width; //This is the screen width (e.g. 480px)
    5.         clickOnLeft = fingerPositionOnScreen < screenWidth / 2; //This the finger position less than half screen width (e.g. 0px - 240px)
    6.         clickOnRight = fingerPositionOnScreen > screenWidth / 2; // This the finger position more than half screen width(e.g. 240px - 480px)
    7.     }
    8.  
    9.     public void Update()
    10.     {
    11.  
    12.         if (steeringOccurring)
    13.         {
    14.             if (clickOnRight)
    15.             {
    16.                 steeringRight = 1f;
    17.                 steeringWheel = maxSteeringAngle * steeringRight;
    18.                 Debug.Log("Steering Right");
    19.             }
    20.         }
    21.         if (steeringOccurring)
    22.         {
    23.             if (clickOnLeft)
    24.             {
    25.                 steeringLeft = -1f;
    26.                 steeringWheel = maxSteeringAngle * steeringLeft;
    27.                 Debug.Log("Steering Left");
    28.             }
    29.         }
    30.         else
    31.         {
    32.             steeringWheel = 0f;
    33.             Debug.Log("Steering neutral");
    34.         }
    There's a boolean for the Lean Finger Down and Lean Finger Up in the inspector that refers to the 'steeringOccurring' variable.
     
    Darkcoder likes this.
  17. IceTrooper

    IceTrooper

    Joined:
    Jul 19, 2015
    Posts:
    36
    Whoa, it was fast reply, thank you :) Great! I will be waiting for an update ^.^
     
  18. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Sent :)
     
    IceTrooper likes this.
  19. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    331
    Hello, I have a question about Lean Pool

    I have a functionality in a component OnEnable

    When Lean Pool preload the instances, it creates the instances of the prefab, and after this, it disables the instances. So, when they are preloaded, OnEnable is triggered

    I know I can use either IPoolable interface or I can disable the prefab directly. The problem is that this prefab is not only used with the pool, it is used in other parts.

    I think the prefab should be disabled before is preloaded. Thus, OnEnable wouldn't be triggered because the instances are created disabled.

    I don't know if this feature is available.I have added this functionality to PreloadAll method with a new flag, DisablePrefabOnPreload flag, but I'd rather not touch the original code

    Code (CSharp):
    1.         [ContextMenu("Preload All")]
    2.         public void PreloadAll()
    3.         {
    4.             if (Preload > 0)
    5.             {
    6.                 if (prefab != null)
    7.                 {
    8.                     bool cacheState = prefab.activeSelf;
    9.                     if (DisablePrefabOnPreload)
    10.                     {
    11.                       //disabling the prefab before preloading
    12.                         prefab.SetActive(false);
    13.                     }
    14.                     for (var i = Total; i < Preload; i++)
    15.                     {
    16.                         PreloadOneMore();
    17.                     }
    18.  
    19.                     prefab.SetActive(cacheState);
    20.                 }
    21.                 else if (Warnings == true)
    22.                 {
    23.                     if (Warnings == true) Debug.LogWarning("Attempting to preload a null prefab", this);
    24.                 }
    25.             }
    26.         }
    Thank you
     
  20. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Your solution works, and this is something I do in my own projects for setting component data before spawning, but there are some scenarios where it can lead to issues that may be hard to track down.

    A better idea is to just deactivate your prefab, then it will remain deactivated when preloaded (thus not triggering OnEnable/OnDisable), and it will activate as normal when spawned. The only downside is that editing the prefab might be more difficult because for some components you have to activate it to be able to edit or visualize them.
     
  21. Maeslezo

    Maeslezo

    Joined:
    Jun 16, 2015
    Posts:
    331
    Yes, I know the disabled prefab approach, but as I said, I can not do this because I use this prefab outside the pool as well.

    If that is the way to go, maybe I can create a disabled prefab variant or something like this.

    Thank you for your help
     
    Darkcoder likes this.
  22. adamq_q

    adamq_q

    Joined:
    Oct 16, 2017
    Posts:
    4
    What would be the easiest way to ensure that a LeanSpawn upon a LeanTap only has the ability to spawn one GameObject. I'd like for each time a tap happens, the previous GameObject gets removed, and a new one gets spawned. Would it be best to use a custom script here?
     
  23. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    A custom script is probably best, but if you don't want to write one you can get LeanPool. This allows you to make a pool of your prefab, and you can call its Spawn function from your UI button. Using the LeanGameObjectPool component settings you can set the Capacity to 1, and enable the Recycle setting to ensure the previously spawned prefab gets replaced.
     
  24. vonchor

    vonchor

    Joined:
    Jun 30, 2009
    Posts:
    249
    I scanned thru the forum, but can't find any info about whether or not LeanTouch+ will support the "new" input system. I tried a clean project with only the new input system activated and then installed LeanTouch+ to test and:

    InvalidOperationException: You are trying to read Input using the UnityEngine.Input class, but you have switched active Input handling to Input System package in Player Settings.
    Lean.Touch.LeanTouch.PollFingers () (at Assets/Lean/Touch/Scripts/LeanTouch.cs:618)
    Lean.Touch.LeanTouch.Update () (at Assets/Lean/Touch/Scripts/LeanTouch.cs:466)

    Any plans to update? It's a verified package at this point. It's easy to do a few simple things but I really would like to avoid rewriting (or hacking-up) LeanTouch to make it work. I'd know one can have both the old and new input systems at the same time, so that's a "stopgap" I can use during dev but eventually I want to just use the new input system.

    Appreciate any info you have on plans regarding this.
     
  25. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    A new version will be out within a few days with support for the new InputSystem. The biggest challenge was that InputSystem has its own asmdef, so to compile properly LeanTouch must reference this, but since all Lean assets are built with Unity 2018.4.0, it's not possible to reference an assembly that doesn't exist in the project without errors (not everyone has InputSystem installed). Additionally, all Lean assets use a UI canvas with EventSystem for the example scenes, which will throw an error due to not using the new input module. To fix this I had to add a component to LeanCommon that can automatically upgrade this to fix any errors, and so all Lean assets must come with this. Luckily there are solutions to all of these, but it means I have to update all Lean assets at the same time and make sure there's no issues otherwise I'll have to update them all at the same time. It's almost ready though :)
     
    IceTrooper likes this.
  26. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Hey everyone,

    I've just updated ALL lean assets to support the new InputSystem (optional). If you switch to the new InputSystem then it should automatically work with LeanTouch/etc, and your EventSystem should automatically get upgraded.

    One thing to keep in mind is that this required moving from Unity 2018.4.0f1 to 2018.4.13f1. It should still work in older versions, but you may get console errors about the LeanCommon.asmdef referencing a missing Unity.InputSystem.asmdef. If so, you must find the Lean/Common/LeanCommon.asmdef, and manually remove this missing assembly reference and hit apply.

    Let me know if you encounter any issues!

    Enjoy :)
     
  27. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Hey everyone,


    LeanTouch+ is part of the latest Power Tools mega bundle, you can get it HERE.

    Someone also pointed out a bug with LeanSelectable in the latest version. I'll have that fixed ASAP!
     
  28. chgeorgiadis

    chgeorgiadis

    Joined:
    Jan 30, 2018
    Posts:
    51
    Hello. I am using lean touch in a project with vuforia. I have an object that i want to move it around. I am adding an animator and it works fine having just an idle state at the beginning. But when i add a second triggered animation my object can not be moved. I want to move the specific object to another one and when these is a collision to start this animation. Is that possible? Thank you :)
     
  29. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Which components are you using the move your object? I can't think of why it would stop moving, because the animation should have no relation to the movement, unless by movement you mean animation? Also, how are you triggering the animation to play? Lean Touch doesn't have any components to detect collisions (it's not really related to touch).
     
  30. ricke44654

    ricke44654

    Joined:
    May 8, 2016
    Posts:
    8
    Update: I deleted the Lean Touch / Lean Touch+ from my test project, then imported Lean Touch by itself, which worked fine and had no errors. Then I imported Lean Touch+, which also worked fine. Then I deleted both again and did a reimport of Lean Touch+ with Lean Touch included... and it worked fine. So it must have had a grumpy load the first time for some reason. At this point, I'm good to go without any issues. Thanks for the great assets, keep up the good work!

    --------------------------------------

    Good evening. I've been using your Lean Pool asset and really like it a lot! So I picked up the Lean Touch+ asset in the Power Tools sale on the Asset Store to include in my project as well. However, after importing it into my test project (I'm using Unity 2019.4.1f1), I'm getting several errors in the DrawInspector and DrawScene methods of the LeanCircuit.cs script with the following message:

    Assets\Standard Assets\Lean\Common\Examples\Scripts\LeanCircuit.cs(16,8): error CS0103: The name 'Target' does not exist in the current context

    A look at the code doesn't show any reference to Target as a class variable or any other clues where it could come from. Any thoughts? Thanks for your help. :)
     
    Last edited: Jul 22, 2020
  31. AndrewStyan

    AndrewStyan

    Joined:
    Apr 6, 2020
    Posts:
    14
    Hi,
    I attempting to use Touch but can't get multi finger touch working.

    Using the LeanTouchEvents component, no multi-finger events show up, ie gesture events list in the console but as if only one finger is in use - pinch is always 1.0 twist is always 0 regardless of whether 1 or 2 finger used. Using single finger and left-Ctrl twist and pinch work correctly.

    This is on a Mac, OS10.14, Unity 2019.4, Logitech Touchpad or MacPro touchpad (neither work). Pinch to zoom works correctly at the OS level.

    I am a Unity beginner :). Am I doing something wrong?
    Thanks,
    Andrew
     
  32. crackoder

    crackoder

    Joined:
    Jun 11, 2017
    Posts:
    7
    Hey I'm using Lean Localization, and I'm reallly liking it so far, but right now I've encountered an issue and I hope someone can help me find the problem, I have set up the options for a dropdown like this:

    LL.PNG

    and since I'm using a Text Mesh pro dropdown, I was thinking on adding the values in C#, so I did this:

    Code (CSharp):
    1. qualityDropOptions.Add(Lean.Localization.LeanLocalization.GetTranslationText("Menu/Quality Opt/Ultra"));
    2.         qualityDropOptions.Add(Lean.Localization.LeanLocalization.GetTranslationText("Menu/Quality Opt/Very High"));
    3.         qualityDropOptions.Add(Lean.Localization.LeanLocalization.GetTranslationText("Menu/Quality Opt/High"));
    4.         qualityDropOptions.Add(Lean.Localization.LeanLocalization.GetTranslationText("Menu/Quality Opt/Medium"));
    5.         qualityDropOptions.Add(Lean.Localization.LeanLocalization.GetTranslationText("Menu/Quality Opt/Low"));
    6.         qualityDropOptions.Add(Lean.Localization.LeanLocalization.GetTranslationText("Menu/Quality Opt/Very Low"));
    now, what's happening is that Very High and Very Low are populated, but the rest returns null and I have no idea why it works only for those two, they all seem to be correctly configured.

    Thanks in advance!
     
  33. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    LeanCircuit was removed in the latest version, so to update you have to either delete that file, or delete the /Lean folder and reinstall. Hopefully one day Unity will make assets packages to make file removal easier to handle!



    Lean Touch uses the touch data sent from Unity, and Unity may not properly support your touchpad devices. You can try using the new InputSystem package, which may support them.


    Do you see these translations in the LeanLocalization component's inspector?

    If so, your script may be running before these translations have been registered. You can hook into LeanLocalization.OnLocalizationChanged to make sure you have the latest values. You can also call LeanLocalization.GetTranslation to see what has been registered for that particular translation name, and see which language Entries exist for it.
     
    dominguez-n-3 likes this.
  34. skytow2003

    skytow2003

    Joined:
    Feb 9, 2014
    Posts:
    30
    Hi.
    Today I downloaded Lean Pool in a project that already had installed older versions of Lean Touch+ ,Lean Localization and Lean Gui.
    I received a lot of errors about a Target Script. I Deleted Lean Pool and Lean Gui and then installed again Lean Gui.
    I now receive these errors on Lean Localization.
    Assets\Lean\Localization\Scripts\LeanTranslationNameAttribute.cs(9,15): error CS0101: The namespace 'Lean.Localization' already contains a definition for 'LeanTranslationNameAttribute'
    Assets\Lean\Localization\Scripts\LeanTranslationNameAttribute.cs(18,15): error CS0101: The namespace 'Lean.Localization' already contains a definition for 'LeanTranslationNameDrawer'
    Assets\Lean\Localization\Scripts\LeanTranslationNameAttribute.cs(20,24): error CS0111: Type 'LeanTranslationNameDrawer' already defines a member called 'OnGUI' with the same parameter types

    can you tell me how I could fix them ?
    thanks
     
  35. tonygiang

    tonygiang

    Joined:
    Jun 13, 2017
    Posts:
    71
    Hi. Some of the scripts in Examples folder of some Lean assets are causing compile error as of the 2020 July 13 update. I am using Lean Transition and Lean GUI in my project. There might be more in other Lean assets but that is what I can observe so far.
     
  36. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    I recently updated all Lean assets with new demo scenes, new folder structures, etc. If you want to update these then you must delete your existing /Lean folder, download the latest versions of all Lean assets, then import them again.

    Sometimes Unity fails to detect that there is a new version available, so you may have to delete the cached download package. On my PC these are located in: C:\Users\<USERNAME>\AppData\Roaming\Unity\Asset Store-5.x\Carlos Wilkes\

    If you've done all this and still get errors then let me know what the errors are, and your Unity version.
     
  37. crackoder

    crackoder

    Joined:
    Jun 11, 2017
    Posts:
    7
    Thanks a lot!, that was the issue, LeanLocalization.OnLocalizationChanged worked perfectly for me!
     
    Darkcoder likes this.
  38. skytow2003

    skytow2003

    Joined:
    Feb 9, 2014
    Posts:
    30
    Hi.
    I have a question about translation of a gameobject using LeanTranslate or TranslateAlong. Looking at your code I see that you check for the presence of the camera every frame in the UpdateLoop with var camera = LeanTouch.GetCamera(Camera, gameObject);
    Is there a more optimized way then creating a variable every frame or am I missing something. (intermediate coder here :) )
    thanks for your response.
    Pietro
     
  39. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    These components were designed with ease of use and modification as the priority, not maximum performance. You can always modify the code to cache the result or something, but I don't think one GetComponent and Camera.main call will impact performance in any noticeable way.
     
  40. MaxKMadiath

    MaxKMadiath

    Joined:
    Dec 10, 2016
    Posts:
    69
    Hi I am new to Lean+.
    I want the player to follow the path as I swipe on the screen, how I can do that.
    is it possible to know when the player reach the swipe end location( navmesh).
    I am using playmaker.
    Thanks
     
  41. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    The demo scenes in the Touch+/Examples/Follow folder show you how to make objects follow the finger using different methods.

    Although there's no nav mesh example, you can use the same ideas as these examples. For example, the LeanMultiUpdate component has the OnWorldTo event, which can send a Vector3 position to a NavMeshAgent's destination value:

    upload_2020-8-5_13-20-33.png

    This will move your agent to the position every frame your fingers touch the screen to a point defined by the ScreenDepth settings (you may want to change it to PhysicsRaycast or something).

    There's no component to detect when the agent has reached the destination though, as that's outside the scope of what LeanTouch is designed to do. Perhaps PlayMaker has an action for this though?
     
  42. skytow2003

    skytow2003

    Joined:
    Feb 9, 2014
    Posts:
    30
    Thanks for the quick response.
    I had tried to cache the camera in a couple of ways but I was getting errors. I retried today and this is what I get,
    - If I put in awake the declaration of a private variable of type Camera and then try to assign the camera with the LeanTouch GetCamera() as such
    protected void Awake() {
    Camera camera = LeanTouch.GetCamera(ScreenDepth.Camera, gameObject);
    }
    I get a... Failed to find camera. Either tag your cameras MainCamera, or set one in this component.

    - If I create a public Camera camera , tag it as maincamera and assign it through the inspector and change all the GetComponent<Camera> calls with the variable camera I get the same error.

    - If I move the TranslateAlong script to another object from the one I want to move and I add a Camera component to it and assign it in the inspector again same error.

    Could you help me in solving this issue.
    best regards
    Pietro
     
  43. MaxKMadiath

    MaxKMadiath

    Joined:
    Dec 10, 2016
    Posts:
    69
    Thanks for quick support.
     
  44. NoConscience

    NoConscience

    Joined:
    Mar 16, 2019
    Posts:
    14
    Hi, I'm trying to pause my game but the time.timescale does not working. How can I pause all transition??
     
  45. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    You're not assigning any field here:

    Code (csharp):
    1. Camera camera = LeanTouch.GetCamera(ScreenDepth.Camera, gameObject);
    Keep in mind a lot of components use this pattern:

    Code (csharp):
    1. var camera = LeanTouch.GetCamera(Camera, gameObject);
    So to to optimize this you would have to replace the 'camera' local variables with the 'Camera' field, (optionally) delete that specific line, and then add something like this:

    Code (csharp):
    1. Camera = LeanTouch.GetCamera(Camera, gameObject);
    to Awake/OnEnable. It should then work, if you still get errors then look at the stack trace to see which line is triggering it, as you probably missed something.

    If your scene doesn't already, make a new GameObject with the LeanTransition component, and change the DefaultTiming.

    You can also change the time of a specific transition by adding the Time Transition (LeanTime) component at the top.
     
  46. UnbridledGames

    UnbridledGames

    Joined:
    May 12, 2020
    Posts:
    139
    Just wanted to give a heads up about an odd "bug" I found. Might be more related to base Unity code. I also have no tried to reproduce it, as since I fixed it in my app, trying to figure out "why" - eeh.

    I noticed my app was chewing up a ton of canvas processing time... a static UI with nothing animating was running at best 30 fps in Play mode. Trying to profile it, I noticed that when I swiped off the main screen, the CPU use dropped dramatically, settling to just over 100fps.

    The app uses Lean Drag Translate, which is restricted by constrain to collider, to handle swiping left/right through multiple UI screens. Long story short, after a LOT of banging my head against the wall seeing how seemingly minor changes that made zero sense whatsoever would reduce the CPU usage (like, while in play mode, changing the main panel's RectTransform from stretch mode to anchored in the center), I noticed the one factor in common:

    Through various edits, my main panels top/left/right/bottom numbers had some very odd floats in them... like Left was 0.017263 and Top was 2.9176113 (not exact numbers, but way higher precision that necessary). This was causing Constrain To Collider to lose it's mind. I'm not sure if it's an issue in the unity code for
    Collider.ClosestPoint(transform.position) or if it has something to do with setting the transform.position of the attached gameobject to a weird result from that, or a combo of the issue being called in LateUpdate, but by fixing my object's transform numbers to even 0's, the app started up super fast again.

    I suspect it has SOMETHING to do with LateUpdate... the slowdown was in PostLateUpdate.PlayerUpdateCanvases. And in fact I was able to make the error re-appear (so I could look up what method the slowdown was in) by typing some random numbers into the Left field for the panel: 0.018233, which then caused the Right field to auto-update to 4.549045e-05.

    With those very small numbers in the rect transform, Constrain To Collider was spending 28.63ms in that PlayerUpdateCanvas.

    Like I said, not sure if it's a Unity issue or not, but since a Lean Touch component was causing the issue, thought I'd report it here.

    (Quick note after re-reading this: The reason why the issue stopped after swiping the screen is the code I wrote to 'finish' the swipe over to the next panel translated the ending location to an integer number for the X coordinate, 'fixing' the super-small float location)
     
  47. ZoidbergForPresident

    ZoidbergForPresident

    Joined:
    Dec 15, 2015
    Posts:
    157
    Just got this for the localization (lean localization) and it's pretty cool but I have an issue.

    The first time I launch the app, no texts are found. I first need to click on a button to change the language so that it actually find the resources. Shouldn't there be a default language? I let mine to "system" (using english) and one of the language is "english" so it should be fine no?
     
  48. Volkerku

    Volkerku

    Joined:
    Nov 23, 2016
    Posts:
    114
    LeanTouch+
    How can I constrain the twist/rotation of a 3D object to only the y axis?
    Thx
     
  49. Darkcoder

    Darkcoder

    Joined:
    Apr 13, 2011
    Posts:
    3,412
    Is your UI very complex? Moving a UI element requires rebuilding the UI, which can be expensive, even if the 'movement' is so small you can't see it. I imagine Unity only updates the element you move and its children, but perhaps there's some interplay between components that cause your whole canvas to update or something, it's hard to say. This could probably be fixed by adding some movement threshold to LeanConstrainToCollider.


    The LeanLocalization component has the DefaultLanguage setting, which will be used on first app load if DetectLanguage fails, or as a fallback if you haven't localized a specific text. Also keep in mind if you're reading the localizations directly then you may want to hook into OnLocalizationChanged, otherwise your code that loads localizations may run before LeanLocalization, and thus you miss their activation.

    If you mean point down the Y axis and roll around then you can use the LeanConstrainToDirection with a Direction = 0,1,0. If you mean rotate around the Y axis then you can use the LeanPitchYaw component with the specified Pitch, and adjust the Yaw (e.g. call the RotateYaw function from another event).
     
  50. UnbridledGames

    UnbridledGames

    Joined:
    May 12, 2020
    Posts:
    139
    It is complex, but the point was the constrain to collider was causing constant refreshes even when the window wasn't moving, if the current position had some very small fractional number in it. When I set the X/Y localPosition of the RectTransform, the window didn't cause any excess lag. When the X position was something like 0.00182732 (because thats where it settled after moving, or if thats where it started due to an odd math issue in the Inspector) the window would be updating every frame and causing an absurd number of rebuilds.