Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Optimized ScrollView Adapter + Playmaker support

Discussion in 'Assets and Asset Store' started by xucian, Apr 1, 2016.

  1. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Hey,
    Again I didn't see any notifications for your post. Sorry for replying this late.
    You can use a separate instance of the prefab (not in the scrollview) just to get the right size of the image through a content size fitter, and then manually call RequestChangeItemSizeAndUpdateLayout on it (or call it directly, if you know how to approximate the size once the image is downloaded). Call this from MonoBehaviour.Update. Be careful of how you manage those calls. Async flows is very tricky if you didn't do them before. The grid scene has a good-enough example of managing asynchronous downloading of images in the context of a scrollview (by the time an image finishes downloading, maybe it's not needed anymore because it may have been replaced with another image which was downloaded faster. happens when scrolling relatively fast)

    Thank you very much for noticing this!
    Noted.

    Replied to your email :)
     
  2. neosca

    neosca

    Joined:
    Jul 1, 2014
    Posts:
    11
    Hi,
    Can you help me with cell group prefab. I can't seem to find from where they are managed. Basically I want to set their RectTransform as stretched, I can't seem to find the original or where in code it is being instantiated.
    asfasf.PNG
     
  3. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Hey,

    They should be managed by the adapter exclusively, that's why there's no obvious way of modifying them. But you can achieve almost any effect nonetheless. Can you look deeper into the GridAdapter's "Grid" property in the inspector and see if you can find there what you want?
    If not, let me know exactly what effect do you need and we'll see from there.

    Lucian
     
  4. Airship

    Airship

    Joined:
    Sep 10, 2011
    Posts:
    260
    Thanks, I ended up just caching ahead of time the dimensions of the images since I could do that in my database. I'll have to try out your suggestion sometime
     
    xucian likes this.
  5. laythra

    laythra

    Joined:
    May 10, 2018
    Posts:
    7
    Hello,

    I was just wondering about the use of the Canvas.ForceUpdateCanvases() in the init function in the OSA.cs script?

    When calling the ForceUpdateCanvases(), sometimes it conflicts with the text field components we have in our scene and causes an exception, and what i also noticed is that when i tried commenting out that function call, nothing changed at all and every list view we have in our project kept working perfectly, which made me wonder about the use of that function call. i do understand what the actual function does, but what i don't get is why do we need to call it over there?

    Thanks!
     

    Attached Files:

  6. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Hey,
    In some scenes, or if the OSA scrollview is instantiated at runtime, the rect transforms are not correctly scaled according to their anchors immediately (in case you want bigger items on bigger screens, you want the item prefab to have a size dependent on the screen size).
    It's a way of assuring that the size reported by the item prefab is the real one, in all scenarios. If you're sure you have absolutely no problem on any target screen size/density, and also you won't update to next versions, you may comment that line. The only problem with that is if this causes a subtle bug that only appears after 1 month from now, no one will remember that you made this change, and it may take some time to track the issue back.

    Can you fix the text-related stuff instead? If so, I'll definitely recommend that.

    Hopefully this was useful :)
    Lucian
     
  7. laythra

    laythra

    Joined:
    May 10, 2018
    Posts:
    7

    Hello,
    Thank you for the fast and useful response,

    What we are fully encountering is that we have some text mesh pro components in our scene that also contains a horizontal OSA scrollview, and when entering the scene upon calling the Cavnas.ForceUpdateCanvases() from the init function, the rebuild function for those text fields get triggered, and causes the following exception:

    Non-fatal Exception: java.lang.Exception: IndexOutOfRangeException :  Index was outside the bounds of the array.
    at TMPro.TMP_Text.StringToCharArray(TMPro.TMP_Text)
    at TMPro.TMP_Text.ParseInputText(TMPro.TMP_Text)
    at TMPro.TextMeshProUGUI.OnPreRenderCanvas(TMPro.TextMeshProUGUI)
    at TMPro.TextMeshProUGUI.Rebuild(TMPro.TextMeshProUGUI)
    at UnityEngine.UI.CanvasUpdateRegistry.PerformUpdate(UnityEngine.UI.CanvasUpdateRegistry)
    at UnityEngine.Canvas:ForceUpdateCanvases(UnityEngine)
    at Com.TheFallenGames.OSA.Core.OSA`2:Init(Com.TheFallenGames.OSA.Core)
    at Com.TheFallenGames.OSA.Core.OSA`2:Start(Com.TheFallenGames.OSA.Core)


    We had no luck whatsoever in reproducing this bug, it would be great if you have any idea why does this exception get caused sometimes, and if you have any idea about the correlation between the Cavnas.ForceUpdateCanvases() and the text field rebuild function.

    Thank you so much, Lucian.
     
  8. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Hey,

    Is it feasible to start the scene with the problematic TMPros disabled and then enable them after the OSA initializes?
     
  9. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Hi there! I'm now on 3.0 version, is it possible to migrate to 4 with no pain?))
     
  10. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Hey,

    There will be pain :)

    Do a backup, download the current 4.1 version, use the migration guide. Pray. Test every aspect of your scroll views.
    If any issue appears that really breaks big parts of the projects, the only solution is to revert to your backup project, remove the SRIA package, import the latest version and replace the SRIA refs with OSA (SRIA was renamed to OSA and any related component was also renamed). Params should be tweaked too, since there's a chance they'll revert to defaults
     
  11. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    If i only need sub folders, may be it would be better to switch to 3.2 not 4?
     
  12. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    If you successfully switch to 3.2, you can then switch to 4 using the migration guide.
    What you mean by "I only need sub folders"?
     
  13. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    I mean this is single feature that i need to add to current project
     
  14. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    I don't know what "sub folders" mean. Hierarchy structure?
     
  15. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Yes
     
  16. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    You can download the package in an empty project and just copy the code from there. You can also import the hierarchy scene directly from there, so you won't need to create the UI yourself, and you'll just need to re-link stuff in inspector. Doable
     
  17. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
  18. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Seems that update works fine, but it breaks a little old feature wich you help me to implement in this post
    There are two bugs
    1)
    Code (CSharp):
    1.  
    2. ...
    3.  
    4. vh.contentSizeFitter.enabled = false;
    5.  
    6. if (model.descExpanded)
    7. {
    8.   SmoothScrollTo(vh.ItemIndex, 0.2f);
    9. }
    10.  
    as you can see after expanding description i smoothly put element to the top of the list by scrolling. And now it works, but somehow flashes while scrolling.



    2) If i fold it behaves strangely



    3) What params should i tweak to see "normal" scrollrect behaviour with smooth speed lowering ?

     
    Last edited: Nov 24, 2018
  19. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Maybe microsoft word online was down at the moment you accessed it?
    What message do you get? A screenshot would be helpful


    Oh, so it worked pretty well. The problems that you get are most probably related to the params not being identical with the previous version. My suggestion is to open your 100% fully working project in a separate unity instance and this new upgraded project in another, and make sure the params in the inspector in the new project are identical to those in your 100% working project.
    If you can't open 2 unity instances at once, try recording your screen while you browse all params in the inspector in the older project so you can refer to them after :)

    Write here if you solved it
     
  20. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    I copied my project and make all stuff in it. So old params in inspector stayed the same and new ones was added with default values.
     
  21. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    OK. Let me know if you tweaked those new params to be identical and if it worked
     
  22. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    There are identical already. i think problem in code (explanding feature from this post)
    May be it somehow related to the new system without ScrollRect

    Here is my old inspector and expanding without scrollTo



    and new


     
  23. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Hmm, this seems odd. The current default code doesn't allow both the above and the below items to be pushed, like in your gif. Did you modify the OSA's source code somewhere?

    If you're using RequestChangeItemSizeAndUpdateLayout, make sure you're calling it with itemEndEdgeStationary=false, and computeVisibility=true. They already have these default values, but maybe you changed them.

    If you're using ScheduleComputeVisibilityTwinPass, make sure to call it with preferContentEndEdgeStationaryIfSizeChanges=false. Also the default

    Make sure the content RectTransform's pivot is set to center-top (0.5, 1.0) at runtime. This is equivalent to setting Gravity (in inspector) to START, which you already have. Don't change the pivot yourself. It's already set for you at runtime depending on the Gravity property.

    If you're using ScrollTo to scroll to your item (though it's not necessary), describe how exactly you're doing it, which values do you pass to the function. We'll work up from there.

    If the above are fine but still the problem persists, I can only help if you send me the project via email(specify the Unity version).

    Lucian
     
  24. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    PMed you =)
     
  25. Player7

    Player7

    Joined:
    Oct 21, 2015
    Posts:
    1,533
    This doesn't have any support for table view and column headers does it?

    And if you want to remove an item out of the list..on the content size fitter demo.. does that work fine?
     
  26. apaix

    apaix

    Joined:
    Aug 10, 2017
    Posts:
    21
    You can customize the objects however you wish but it takes an understanding of the core mechanics. For example your list could have a header and then 5 objects. Its all about how you populate the data and tie it back to your UI components.

    But if you're looking for sticky table header behavior similar to native iOS, you'll likely have to add some pieces to keep the headers in place.
     
    xucian likes this.
  27. apaix

    apaix

    Joined:
    Aug 10, 2017
    Posts:
    21
    I'm wanting to upgrade to 4.2 but I'm sitting on 3.2. What's my best path here? I don't see the 4.1 download.
     
  28. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Hey,

    If you can code, you can do 99% of the things you can imagine.
    Playmaker support includes some basic functionality for common cases. Of course, by avoiding code you'll reach some limitations at some point, but that's valid for most visual scripting tools in general.

    The short answer for all of the question is yes, you can, whether using Playmaker or code.

    Table view, list view, grid view, list box: these are just terms used by different frameworks to refer to the same base concept. The only distinction that OSA does is that grids are treated different than lists (even though a list is a particular case of a grid with one column or row), for optimization purposes.
    Although the term "table view" is not standardized (it can mean a list of different item types or identical item types), I'm sure you can implement it, whatever your definition of a table view may be. You're creating your own item prefab, so it can be arbitrarily complex.

    Edit: If you code, you can create the header UI and code its behavior, relying the logic on the ScrollPositionChanged event, the Velocity property and methods like this
     
    Last edited: Nov 27, 2018
  29. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Hey,
    Email me with your invoice code and I'll give you the 4.1.

    Lucian
     
  30. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Also replying here so others can see.
    In this particular scenario, he uses this code to expand/collapse an item that contains a variable-sized Text component:

    Code (CSharp):
    1.  
    2.         void OnItemClicked(MyItemViewsHolder vh)
    3.         {
    4.             Debug.Log("vh.ItemIndex " + vh.ItemIndex);
    5.             Debug.Log("LazyData.Count " + LazyData.Count);
    6.             //var model = _Params.Data[vh.ItemIndex];
    7.             var model = LazyData.GetOrCreate(vh.ItemIndex);  
    8.  
    9.             Debug.Log(model.expanded);      
    10.             model.expanded = !model.expanded;
    11.             Debug.Log(model.expanded);
    12.  
    13.             // No need to set HasPendingSizeChange=true, since the rectTransform will be updated immediately
    14.             vh.UpdateExpandedState(model.expanded);
    15.  
    16.             // If you're enabling/disabling children that can have an impact on the item's size (as opposed to just changing their content - like the Text.text property),
    17.             // this is he only reliable way of dynamically changing an item's size through SRIA v3.2 or lower.
    18.  
    19.  
    20.             // The size changed. Enable the CSF component
    21.             // This is not needed here in the current case (replace it with vh.contentSizeFitter.enabled=true if you want),
    22.             // since we're using the "ForceXXX" version of the layout rebuilding function,
    23.             // but we should do it in general, in case your viewholder has some own logic to be executed right before a rebuild event.
    24.             vh.MarkForRebuild();
    25.  
    26.             // The CSF component will resize the root accordingly
    27.             // Use Canvas.ForceUpdateCanvases() instead, if on old unity version
    28.             LayoutRebuilder.ForceRebuildLayoutImmediate(vh.root);
    29.  
    30.             // The CSF component was used to estimate the item's size, but the adapter itself
    31.             // should set it (along with correctly setting the item's position, shifting other items, updating sizes cache etc.)
    32.             RequestChangeItemSizeAndUpdateLayout(vh, vh.root.rect.height);
    33.  
    34.             // MarkForRebuild has set it to true; We used it, now set it back to false - not too important,
    35.             // because it'll be disabled anyway next time it's recycled, but it's nice to clean after ourselves:)
    36.             vh.contentSizeFitter.enabled = false;
    37.         }
    The issue is solved by bringing the item's pivot to upper-center (0.5, 1.0).
    If you want the end edge to be stationary (by calling
    RequestChangeItemSizeAndUpdateLayout with
    itemEndEdgeStationary=true), it needs to be lower-center (0.5, 0.0).

    In v4.2.1 the RequestChangeItemSizeAndUpdateLayout method
    will have a correctItemPosition parameter which you can set to true, in case not only the item's size has changed externaly but also its local position, which is often the case with ContentSizeFitter.
    If you want to have this change now, make sure these methods in OSA.cs contain this code:
    Code (CSharp):
    1.  
    2.         public float RequestChangeItemSizeAndUpdateLayout(TItemViewsHolder withVH, float requestedSize, bool itemEndEdgeStationary = false, bool computeVisibility = true, bool correctItemPosition = false)
    3.         { return RequestChangeItemSizeAndUpdateLayout(withVH.ItemIndex, requestedSize, itemEndEdgeStationary, computeVisibility, correctItemPosition); }
    4.  
    5.         public float RequestChangeItemSizeAndUpdateLayout(int itemIndex, float requestedSize, bool itemEndEdgeStationary = false, bool computeVisibility = true, bool correctItemPosition = false)
    6.         {
    7.             CancelAnimationsIfAny();
    8.  
    9.             var skipCompute_oldValue = _SkipComputeVisibilityInUpdateOrOnScroll;
    10.             _SkipComputeVisibilityInUpdateOrOnScroll = true;
    11.  
    12.             StopMovement(); // we don't want a ComputeVisibility() during changing an item's size, so we cut off any inertia
    13.  
    14.             int itemIndexInView = _ItemsDesc.GetItemViewIndexFromRealIndexChecked(itemIndex);
    15.             var viewsHolderIfVisible = GetItemViewsHolderIfVisible(itemIndex);
    16.             bool vrtContentPanelIsAtOrBeforeEnd = _InternalState.CTVirtualInsetFromVPE_Cached >= 0d;
    17.  
    18.             double curSize = _ItemsDesc[itemIndexInView];
    19.             double resolvedSize =
    20.                 ChangeItemSizeAndUpdateContentSizeAccordingly(
    21.                     viewsHolderIfVisible,
    22.                     itemIndexInView,
    23.                     curSize,
    24.                     requestedSize,
    25.                     itemEndEdgeStationary
    26.                 );
    27.  
    28.             double reportedScrollDelta;
    29.             if (itemEndEdgeStationary)
    30.                 reportedScrollDelta = .1d;
    31.             else
    32.             {
    33.                 // If start edge is stationary, either if the item shrinks or expands the reportedDelta should be negative,
    34.                 // indicating that a fake "slight scroll towards end" was done. This triggers a virtualization of the the content's position correctly to compensate for the new ctEnd
    35.                 // and makes any item after it be visible again (in the shirnking case) if it was after viewport
    36.                 reportedScrollDelta = -.1d;
    37.  
    38.                 // ..but if the ctEnd is fully visible, the items will act as if they're shrinking with itemEndEdgeStationary=true, because the content's end can't exceed the vpEnd
    39.                 if (vrtContentPanelIsAtOrBeforeEnd)
    40.                     reportedScrollDelta = .1d;
    41.             }
    42.  
    43.             if (correctItemPosition)
    44.                 CorrectPositionsOfVisibleItems(!computeVisibility, false);
    45.  
    46.             if (computeVisibility)
    47.                 ComputeVisibilityForCurrentPositionRawParams(true, false, reportedScrollDelta);
    48.  
    49.             _SkipComputeVisibilityInUpdateOrOnScroll = skipCompute_oldValue;
    50.  
    51.             return (float)resolvedSize;
    52.         }
    And you'd call RequestChangeItemSizeAndUpdateLayout(vh=..., size=..., itemEndEdgeStationary=..., computeVisibility=true, correctItemPosition=true);

    Edit: After more testing, I've found that the pivot still needs to be set as described above. This function change is not necessary anymore for this particular case. You can pass correctItemPosition=false for this case. The method will be kept for other uses where the positioning problem won't be caused by the pivot.
     
    Last edited: Dec 2, 2018
  31. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Hi! It's works fine besides one moment when element is not fully visible in list



    And also please explain one moment. What if i need to sort(and may be filter) all currently visible child "files" in hierarchy example (by title for example). How i can do this?
     
  32. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Hey, thanks for reporting this. It helps a lot finding these issues as early as possible.
    I edited my previous answer and actually for this case you don't need correctItemPosition=true. Only by setting the pivot accordingly you can solve it.
    We've done some optimizations and now can't guess the item's positions that easily, so we must rely on the users setting the pivot in a way that doesn't move the item's edge when manually resizing it with a content size fitter.

    About the hierarchy, I'll reply you in a day or two via email. Please send me a message there

    Lucian
     
    Last edited: Dec 2, 2018
    justtime likes this.
  33. LordBelasco

    LordBelasco

    Joined:
    May 1, 2017
    Posts:
    29
    I have installed Unity 2018.3 and the GridAdapter doesn't work with the stripping code set to High or Medium, only the low level works
    I get this error :
    2018-12-14 19:30:36.879 6180-6251/com.DavydeoGamesStudio.DavydeoTest E/Unity: UnityException: OSA: Com.TheFallenGames.OSA.CustomAdapters.GridView.GridParams: the prefab was not set. Please set it through inspector or in code
    at Com.TheFallenGames.OSA.CustomAdapters.GridView.GridParams.InitIfNeeded (Com.TheFallenGames.OSA.Core.IOSA iAdapter) [0x00000] in <00000000000000000000000000000000>:0
    at Assets.Scripts.UI.WorldManagement.LevelsGridAdapter.Start () [0x00000] in <00000000000000000000000000000000>:0
    But the prefab is set and all works fine with low stripping code
     
  34. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Hi! Can't send you email, so i wrote a PM!
     
  35. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    In a few days I'll test and submit a version with 2018.3.
    See this post by Eric.
    Unity can't always know whether a piece of code is used or not and thus it can't do code stripping correctly.
    I've worked on several complex projects and only none supported code stripping higher than "assembly" level (first/lowest one).
    As a matter of fact, I checked the "grid_plus_horizontal..." scene with maximum stripping level on android, with Unity 2018.2, and it worked. YMMV
    Make sure there's no error that precedes the "prefab was not set" one. Otherwise you should stick with the first level of code stripping

    Lucian
     
  36. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Replying here to potentially help other users needing the same info.
    BTW you should be able to send emails (tested all of them).

    The summarized question was "How do I use different sizes in a hierarchy-like ScrollView?".
    The easiest and the most convenient solution is to specify the height for each item in the CollectItemsSizes callback.
    Example code on its usage can be found in the IncrementalItemFetchExample.cs demo script.
    On @justtime's case, there were folders and files only, but folders had size A while files had size B. This can be easily implemented by checking in CollectItemsSizes whether the added items (this method is called on any modification, but we ignore the REMOVE modification, since no new sizes are to be collected at that moment) are folders or files and supply one of the possible corresponding sizes (again, IncrementalItemFetchExample.cs contains full exampel code for this).
    Also, when doing this on a ScrollView similar to the provided hierarchy template, use _Params.flattenedVisibleHierarchy to get the inserted items' data.

    Good to know: each time you collapse/expand an item in the hierarchy example, its children are removed/inserted, which also modifies the _Params.flattenedVisibleHierarchy list (which is where its name comes from)

    Other approaches exist, but it's not worth it unless you have 10-50k+ items and/or the lag when adding/removing items becomes unacceptable
     
  37. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Hi! Just faced one issue, that i never saw before. Elements in list somehow hide but after scrolling reveal.
     
  38. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Thanks! I am trying to combine expand example with this one. So when my sub-element(aka fille in hierarchy example) is visible, but his desc is not expanded all seems fine. If desc is expanded, then list twitches.
    GIF


    Also, what if the proper way to use sizes in CollectItemsSizes, if my elements can have different height depending screen size and depending description expanded status? May be i need get them from recttransform, but in which callback ?
     
    Last edited: Dec 19, 2018
  39. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Will reply to the first part of your post in a day or 2 (busy schedule), after I'll inspect the code you've sent.

    As for manually setting the sizes in CollectItemsSizes and using different ones per screen size, an easy way is to have some invisible items (as many as the number of different sizes thah you have) added to the RectTransform that scale with the screen and just use their sizes (if they don't report the correct sizes, call Canvas.ForceUpdate - but only do it once, the first time). What this approach lacks in elegance gains in simplicity so it's a good trade-off IMO.
    There are other ways that take more time, but they make sense to approach only if the above doesn't prove suitable
     
  40. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Hi! Correct me please, if i wrong. You mean that, if i have 100 elements with differents sizes i need to instantiate all of them in some hidden parent object, connect them with models, and use their sizes when i need to expand models?
     
  41. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Hey. Welcome to 2019!

    For that many different sizes (I suppose you want to use variable-sized text or similar), this method doesn't work.
    You mentioned you have a description that expands for each item, so I assumed having a fixed-height description would be acceptable, in which case you'd only have 2 sizes to manage. If you want to support an arbitrary number of sizes, you need to work with content size fitter.

    So you want to have hierarchy + expandable + content size fitter. Correct?
    I'll assume so. First think if there's a way of removing 2nd or 3rd ones. Then it'll be much easier to implement.
    If you really need all of the 3:
    - create 1 hidden item (detached from the scroll view), identical with the prefab, except that you'll add a CSF component to it
    - when the "expand" happens, bind the model of the expanded item to this hidden one and call ForceRebuildLayoutImmediate on it to trigger the CSF to resize it. then get its size and call RequestChangeItemSizeAndUpdateLayout on it to inform the adapter about the size that you want to be set to it
    - using the included ExpandCollapseOnClick script in this case will make it very unreadable and much less maintainable, so I advice you to create a new one for this specific case, which will be 10x shorter and straightforward. Maybe include all of this CSF logic into it directly.

    Holidays are over here, so expect more frequent replies :)
    Feel free to ask more questions, if needed.

    Also, about your project that you've sent via PM, if it's another one, please send it to me via email if you still need help with it, and specify exactly what should I look for and what you want to achieve.
     
  42. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Hi!
    1)I need to call ForceRebuildLayoutImmediate on temp prefab ?
    2)But RequestChangeItemSizeAndUpdateLayout on the actual VH ?

    So my case is "hierarchy + expandable + content size fitter"
    1)I have folders with same height. But it depends on the screen. So i use aspect ration filter to calc height relative to width (for saving my folder's images proportions) and then set it to layoutelement minHeight and rect height (of the VH's root). I did this in CreateViesHolder.
    2)When user click folder, then i show not expanded elements with different to folders height. And they heights not related to screen cause they don't have images. Then user click expand and i show expanded state. Each element has unique height in this mode.

    I did what you write, but can't handle moment when i open folder. So i need to change height from folder state to element, but in OnFolderClick method i have just current folder VH reference, but revealed elements will be stored in another VH's. So, i have sizes from my tempPrefab(hidden), but don't know how to get newly revealed elements VH's to set this sizes.

    Also i don't understand do i need to use code from these examples(csf, expand), i.e. ScheduleComputeVisibilityTwinPass, RebuildLayoutDueToScrollViewSizeChange and other ? I am totally confused (
     
    Last edited: Jan 4, 2019
  43. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Let's do it over skype since we'll most probably write here forever. Email me your current project and your skype id.

    --Lucian
     
  44. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Hi there! Sometimes i got this error
    Code (CSharp):
    1. UnityException: itemIndexInView=7, while the expected one is 6. Sizes can only be changed for items one by one, one after another(e.g. 3,4,5,6,7..), starting with the one passed to BeginChangingItemsSizes(int)!
    2. Com.TheFallenGames.OSA.Core.ItemsDescriptor.set_Item (System.Int32 itemIndexInView, System.Double value) (at Assets/Standard Assets/OSA/Scripts/Core/ItemsDescriptor.cs:42)
    3. Com.TheFallenGames.OSA.Core.OSA`2[TParams,TItemViewsHolder].OnItemsSizesChangedExternally (System.Collections.Generic.List`1[T] vhs, System.Double[] sizes, System.Boolean itemEndEdgeStationary) (at Assets/Standard Assets/OSA/Scripts/Core/OSAInternal.cs:2473)
    4. Com.TheFallenGames.OSA.Core.OSA`2[TParams,TItemViewsHolder].ComputeVisibilityTwinPass (System.Boolean contentEndEdgeStationary) (at Assets/Standard Assets/OSA/Scripts/Core/OSAInternal.cs:1919)
    5. Com.TheFallenGames.OSA.Core.OSA`2[TParams,TItemViewsHolder].ChangeItemsCountInternal (Com.TheFallenGames.OSA.Core.ItemCountChangeMode changeMode, System.Int32 count, System.Int32 indexIfInsertingOrRemoving, System.Boolean contentPanelEndEdgeStationary, System.Boolean keepVelocity, System.Boolean stealInsteadOfRecycle) (at Assets/Standard Assets/OSA/Scripts/Core/OSAInternal.cs:1290)
    6. Com.TheFallenGames.OSA.Core.OSA`2[TParams,TItemViewsHolder].ChangeItemsCount (Com.TheFallenGames.OSA.Core.ItemCountChangeMode changeMode, System.Int32 itemsCount, System.Int32 indexIfInsertingOrRemoving, System.Boolean contentPanelEndEdgeStationary, System.Boolean keepVelocity) (at Assets/Standard Assets/OSA/Scripts/Core/OSA.cs:454)
    7. JamPacksScrollRectItemsAdapter.ChangeItemsCount (Com.TheFallenGames.OSA.Core.ItemCountChangeMode changeMode, System.Int32 itemsCount, System.Int32 indexIfInsertingOrRemoving, System.Boolean contentPanelEndEdgeStationary, System.Boolean keepVelocity) (at Assets/Scripts/JamPacksScrollRectItemsAdapter.cs:289)
    8. Com.TheFallenGames.OSA.Core.OSA`2[TParams,TItemViewsHolder].InsertItems (System.Int32 index, System.Int32 itemsCount, System.Boolean contentPanelEndEdgeStationary, System.Boolean keepVelocity) (at Assets/Standard Assets/OSA/Scripts/Core/OSA.cs:441)
    9. JamPacksScrollRectItemsAdapter.OnDirectoryFoldOutClicked (JamPacksViewsHolder vh) (at Assets/Scripts/JamPacksScrollRectItemsAdapter.cs:572)
    10. JamPacksScrollRectItemsAdapter+<CreateViewsHolder>c__AnonStorey7.<>m__0 () (at Assets/Scripts/JamPacksScrollRectItemsAdapter.cs:496)
    11. UnityEngine.Events.InvokableCall.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:165)
    12. UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58)
    13. UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:36)
    14. UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:45)
    15. UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
    16. UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
    17. UnityEngine.EventSystems.EventSystem:Update()
    18.  
    Can i somehow prevent it?
     
  45. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Also i am using script for left right swap, which in general just doing this
    Code (CSharp):
    1. ExecuteEvents.ExecuteHierarchy(m_VerticalTargetObject, eventData, ExecuteEvents.endDragHandler);
    Full source
    And as you can see in this gif with this code osa scroll on every click/touch somekind of instantly scrolling down. With normal ScrollRect this component works fine.


    This script on Viewport which is child of OSA scrollrect, and m_VerticalTargetObject is OSA scrollrect.
     
    Last edited: Jan 30, 2019
  46. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Of course.
    Just make sure you remove the item from your data list before calling OSA.RemoveItems(index, 1/*the removed count*/). Or if you're using a DataHelper (which is mostly the case, as it's in most scenes), a single call to RemoveItem prior the swipe should do it, along with preventing the view from actually being removed externally. OSA will remove the view itself after this call. If however it's hard to prevent the external removal of the view, use RemoveItemWithViewsHolder with stealViewsHolderInsteadOfRecycle set to true, which would detach that view from OSA completely and the caller will be responsible for it from then on.

    Update: I initially thought your both replies are for the same issue, the one with sliding.
    I'll test the sliding script and will see what makes it incompatible. I'll try to reply soon
     
    Last edited: Jan 30, 2019
  47. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Can I have the code in "JamPacksScrollRectItemsAdapter" and any other relevant classes it uses that are not in OSA package?
     
  48. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Back on the DragEventSender script:

    The script doesn't dispatch the OnInitializePotentialDrag event, which is pretty essential. Please message the original author and tell him/her to add this, as it's an important inconsistency. All the ScrollRects that may receive drag events should be notified about the possibility that a drag could occur on them shortly. This allows them to prepare.
    Unity's ScrollRect doesn't care too much for this event. It only sets velocity to 0 when it receives it (which I'm sure you noticed that it doesn't happen, since it doesn't receive it).
    But OSA relies on this event to initialize a lot of stuff for its internal dragging system.


    How to:
    1. make it implemnent IInitializePotentialDragHandler
    2. add this:
    Code (CSharp):
    1.  
    2.     /// <summary>
    3.     /// When draging is occuring this will be called every time the cursor is moved.
    4.     /// </summary>
    5.     /// <param name="eventData">Current event data.</param>
    6.     public void OnInitializePotentialDrag(PointerEventData eventData)
    7.     {
    8.         if (m_HorizontalTargetObject != null)
    9.             ExecuteEvents.ExecuteHierarchy(m_HorizontalTargetObject, eventData, ExecuteEvents.initializePotentialDrag);
    10.         if (m_LeftTargetObject != null)
    11.             ExecuteEvents.ExecuteHierarchy(m_LeftTargetObject, eventData, ExecuteEvents.initializePotentialDrag);
    12.         if (m_RightTargetObject != null)
    13.             ExecuteEvents.ExecuteHierarchy(m_RightTargetObject, eventData, ExecuteEvents.initializePotentialDrag);
    14.         if (m_VerticalTargetObject != null)
    15.             ExecuteEvents.ExecuteHierarchy(m_VerticalTargetObject, eventData, ExecuteEvents.initializePotentialDrag);
    16.         if (m_UpTargetObject != null)
    17.             ExecuteEvents.ExecuteHierarchy(m_UpTargetObject, eventData, ExecuteEvents.initializePotentialDrag);
    18.         if (m_DownTargetObject != null)
    19.             ExecuteEvents.ExecuteHierarchy(m_DownTargetObject, eventData, ExecuteEvents.initializePotentialDrag);
    20.  
    21.         if (m_AnyDirectionTargetObject != null)
    22.             ExecuteEvents.ExecuteHierarchy(m_AnyDirectionTargetObject, eventData, ExecuteEvents.initializePotentialDrag);
    23.     }
     
    Last edited: Jan 31, 2019
    justtime likes this.
  49. justtime

    justtime

    Joined:
    Oct 6, 2013
    Posts:
    424
    Hi! Should i update to from 4.1 to 4.2 ? Or it's not neccesary if it's works now?
     
  50. xucian

    xucian

    Joined:
    Mar 7, 2016
    Posts:
    836
    Hey,
    If you afford to test your entire application for OSA usages and make sure they behave, sure, it's not a major upgrade. We'll release 4.2.1 soon and you'd then have less to do to upgrade. But please make backups before upgrading. Good practice.

    -- Lucian