Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

[RELEASED] [Free] Better Streaming Assets

Discussion in 'Assets and Asset Store' started by gwiazdorrr, Dec 12, 2017.

  1. gwiazdorrr

    gwiazdorrr

    Joined:
    Sep 29, 2014
    Posts:
    102
    Errrrr there's no
    BetterStreamingAssets.GetFilesAsync
    . Also, direct synchronous access to streaming assets is impossible on webgl.

    EDIT: It would be possible if you were willing to download all the streaming assets prior to using them, which in my opinion is not worth it.
     
  2. ickydime

    ickydime

    Joined:
    Nov 20, 2012
    Posts:
    110
    I have a project where there is HTML pages being shown within Unity. Those HTML pages load image/css/js/etc.

    So I could use BetterStreamingAssets to grab the main html page but then the rest will fail because the html page will be pointing to assets that are still in the android jar://

    My current thought is to grab everything and put it into persistent data. Is there a way to do that using BetterStreamingAssets rather than www/asset bundles? Basically grab everything from the jar and move it over to persistentPath?
     
    Last edited: Mar 21, 2021
  3. gwiazdorrr

    gwiazdorrr

    Joined:
    Sep 29, 2014
    Posts:
    102
    It can easily be done with BSA and will certainly be a lot faster than alternatives. The easiest way is to use
    BetterStreamingAssets.ReadAllBytes
    and then
    File.WriteAllBytes
    , but using a combination of
    BetterStreamingAssets.OpenRead
    ,
    File.Create
    and
    Stream.CopyTo
    should be better when it comes to memory allocation.

    To list Streaming Assets use
    BetterStreamingAssets.GetFiles
    .
     
  4. ickydime

    ickydime

    Joined:
    Nov 20, 2012
    Posts:
    110
    Wow, thanks for the super quick and helpful response. Greatly appreciate it.
     
    gwiazdorrr likes this.
  5. zz00

    zz00

    Joined:
    Nov 8, 2019
    Posts:
    2
    Hi I am trying to open local files in Android. I was wondering how I can use your plugin to do it?

    Code (CSharp):
    1.     private void Awake()
    2.     {
    3.        
    4.         BetterStreamingAssets.Initialize();
    5.     }
    6.  
    7.     public void Open_PDF()
    8.     {
    9.         var paths = BetterStreamingAssets.GetFiles("/", "documentation.pdf", SearchOption.AllDirectories);
    10.        
    11.  
    12.     }
     
  6. thexdd

    thexdd

    Joined:
    Mar 20, 2013
    Posts:
    18
    Does not work in edit mode.
     
  7. gwiazdorrr

    gwiazdorrr

    Joined:
    Sep 29, 2014
    Posts:
    102
    @thexdd Make sure
    BetterStreamingAssets.Initialize();
    is called before any other call.

    @zz00 BSA works with StreamingAssets only, not local Android files.
     
  8. nonlin

    nonlin

    Joined:
    Dec 12, 2013
    Posts:
    46
    Why is it that the root directory in streaming assets has spaces but packaged up in the .apk the spaces are gone?
    Does that mean I should rename the folder with no spaces?
     
  9. gwiazdorrr

    gwiazdorrr

    Joined:
    Sep 29, 2014
    Posts:
    102
    @nonlin Can you elaborate and give an example, please?
     
  10. RS_Pereira_Ryu

    RS_Pereira_Ryu

    Joined:
    Aug 16, 2023
    Posts:
    2
    hello, awesome plugin wwhat ive readed so far, I have a questionm there is any way you can read how many folders there are in certain place?
     
  11. gwiazdorrr

    gwiazdorrr

    Joined:
    Sep 29, 2014
    Posts:
    102
    @RS_Pereira_Ryu The reason there's no
    GetDirectories 
    is that behaviour for empty folders varies from platform to platform. For instance, Windows builds preserve empty folders, while Android builds do not.

    You can however get a list of non-empty folders yourself by parsing the output of
    GetFiles
    - any part ending with "/" and shared between two or more entries will effectively be a non-empty folder. Hope this helps!
     
    RS_Pereira_Ryu likes this.
  12. RS_Pereira_Ryu

    RS_Pereira_Ryu

    Joined:
    Aug 16, 2023
    Posts:
    2
    hello! thanks for the fast reply! I didn't expect this to keep giving support to people, I made it work with the example you gave me :) thanks so much!!
    hope someday become as good developer as you and create great stuff ^.^
     
    gwiazdorrr likes this.
  13. gwiazdorrr

    gwiazdorrr

    Joined:
    Sep 29, 2014
    Posts:
    102
    Awww thanks man, I am merely repaying for all the free help I've received myself over the years. Good luck and happy coding!