Search Unity

UnifiedIO - Cross-platform IO for Unity

Discussion in 'Assets and Asset Store' started by CanisLupus, Dec 20, 2014.

  1. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    UnifiedIO is available on the Asset Store!

    Keeping it brief: UnifiedIO is a library of methods that handle file and directory reading/writing in Application.persistentDataPath. It is "unified" because it does so consistently for all main platforms, including Windows Store Apps (Windows/Mac/Linux, Android, iOS, Windows Phone, Windows Store Apps, Blackberry).

    It was developed coming from this old but updated question/answer about IO on Windows Store Apps. Check that link or the library's documentation for details on the problem that UnifiedIO tries to solve.

    The asset includes:

    UnifiedIO.Directory class:


    bool Exists(string path)
    void Create(string path)
    void Rename(string path, string newName)
    void Move(string path, string destinationPath)
    void Copy(string path, string destinationPath)
    void MoveInside(string path, string destinationPath)
    void CopyInside(string path, string destinationPath)
    void Delete(string path)
    void DeleteContents(string path)
    string[] GetFiles(string path, string searchPattern, SearchOption searchOption)
    string[] GetDirectories(string path, string searchPattern, SearchOption searchOption)

    UnifiedIO.File class:


    bool Exists(string path)
    void CreateEmpty(string path)
    void Rename(string path, string newName)
    void Move(string path, string destinationPath)
    void Copy(string path, string destinationPath)
    void MoveInside(string path, string destinationPath)
    void CopyInside(string path, string destinationPath)
    void Delete(string path)
    Stream GetReadStream(string path)
    Stream GetWriteStream(string path)
    Stream GetAppendStream(string path)
    byte[] ReadBytes(string path, int position = 0, int nBytes = 0)
    void WriteBytes(string path, byte[] content)
    void WriteBytes(string path, byte[] content, int position)
    void AppendBytes(string path, byte[] content)
    string ReadText(string path)
    void WriteText(string path, string content)
    void AppendText(string path, string content)
    IList<string> ReadLines(string path)
    void WriteLines(string path, IEnumerable<string> content)
    void AppendLines(string path, IEnumerable<string> content)

    Most of these methods are similar in signature to what you find in the System.IO namespace, but internally include different code for the various main platforms, so that, no matter which one you're building for, you can read/write/copy/move/rename/delete/enumerate/etc your app's files and folders in Application.persistentDataPath.

    If you want code that just provides IO in Windows Store Apps, while keeping your existing code for other platforms, you can also use UnifiedIO. Simply use platform dependent compilation and call UnifiedIO methods inside #if NETFX_CORE sections. Both the documentation and the question/answer linked before contain more details on this.

    Please check the above list of methods before buying, so you don't feel cheated in any way. If you require a method that is not currently present, I will consider suggestions!

    If you buy, leave a rating or review if you can (good or bad; developers need feedback!). :)

    Finally, all UnifiedIO methods were unit-tested, but bugs can slip in any software, so I also welcome any bug reports.

    Thanks for checking it out! :)

    - Daniel
     
    Last edited: Feb 23, 2021
  2. sevensails

    sevensails

    Joined:
    Aug 22, 2013
    Posts:
    483
    Do you intend to add support to File.ReadAllBytes?

    I need to make this code works:

    Code (csharp):
    1.  
    2.   if (Splash2File.Contains("://"))
    3.         {
    4.             var www = new WWW(Splash2File);
    5.             yield return www;
    6.             if (www.texture)
    7.             {
    8.                 Splash2 = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height),
    9.                     new Vector2(0.5f, 0.5f), 1);
    10.             }
    11.         }
    12.         else
    13.         {
    14.             var _tex = new Texture2D(2, 2);
    15.             if (File.Exists(Splash2File))
    16.             {
    17.                 _tex.LoadImage(File.ReadAllBytes(Splash2File));
    18.                 Splash2 = Sprite.Create(_tex, new Rect(0, 0, _tex.width, _tex.height),
    19.                     new Vector2(0.5f, 0.5f), 1);
    20.             }
    21.         }
    22.  
     
  3. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    @Wagenheimer

    UnifiedIO already has that function, but it's called "ReadBytes" instead. :) The signature is:

    Code (CSharp):
    1. byte[] ReadBytes(string path)
    You should be able to use it with:

    Code (CSharp):
    1. UnifiedIO.File.ReadBytes(Splash2File)
    If any problem arises, post here. I might only be able to answer tomorrow, though!

    - Daniel
     
  4. Mark-Sweeney

    Mark-Sweeney

    Joined:
    Feb 21, 2010
    Posts:
    172
    Hey Daniel,
    I'm porting iOS apps to Windows Phone 8.

    Currently my iOS apps read a text file, then parse it using TinyXmlReader.js
    The apps use Unity Javascript. Will I be able to call the various UnifiedIO functions from my Unity js scripts?

    Thanks!
     
  5. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    I'll be honest with you and say that I've never used Unity's JavaScript (UnityScript). However, I also have no reason to believe that it won't work (due to the way Unity compiles both C# and JS code to assemblies). :)

    You just have to place "UnifiedIO" (the whole folder) inside the "Plugins" or "Standard Assets" folder in your project. This is because calling C# code from UnityScript code requires the C# code to be compiled first, and the two folders I mentioned are compiled before the remaining ones (see this link for more details). I just tested this and it worked as expected in the the Editor, calling the library successfully from js code. It also compiled nicely in a WP8 build.

    In your case, you seem to want to read the whole file and then parse it with another script. You should be able to do this by calling UnifiedIO.File.ReadText("path/to/file/inside/persistentDataPath"), which returns a string with the entire file contents.

    I hope this helps. :) I'll probably add a short section about calling UnifiedIO from UnityScript next time I update the documentation. Thanks!

    - Daniel
     
  6. Mark-Sweeney

    Mark-Sweeney

    Joined:
    Feb 21, 2010
    Posts:
    172
    Thanks for the info Daniel. Just bought UnifiedIO as it sounds like it's going to solve my problems.

    Future apps I develop will be done with C# to avoid headaches, but Unity js was what I first learned on. Redoing everything to C# for older apps would be a colossal pain.

    If I run into any problems, I'll let you know.
     
  7. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    You're quite welcome, Mark. Yeah, life is too short to port whole projects to another language. :) Based what I know of features and compile times, I don't think you'll regret the switch to C# in new projects.

    Any problem and I'm here. Oh, and if you have the time after you try UnifiedIO, leave a rating or even a review on the Asset Store. Whatever you think it deserves! It helps a lot, and might also help other people decide if they want the package. :)
     
  8. skullthug

    skullthug

    Joined:
    Oct 16, 2011
    Posts:
    202
    Hi there. I just recently bought UnifiedIO to help me tackle porting my iOS/Android project to Windows Phone 8 and Windows Store.
    Using UnifiedIO I got Unity to finally stop exploding with errors during the build process, however I'm getting errors instead now from Visual Studio pertaining to UnifiedIO.
    https://www.dropbox.com/s/q0z41y5wrk29wj3/ScreenClip.png?dl=0

    Any ideas why this might be happening? I've tested UnifiedIO on my iOS/Android projects to make sure it's setup correctly and everything seems to be in order there.
     
  9. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    Hi! Nothing comes to my mind currently, except that it should be something particular to the WSA API. I would like to know more, namely what platform where you were running your project. Was it Windows Store Apps, version 8 or 8.1? On a simulator or real device?

    Could you tell me what is contained in that AggregateException? Visual Studio's debugger might help here, but you can also use something like the following:

    Code (CSharp):
    1. try {
    2.     // your code that calls UnifiedIO.Directory.Create(...)
    3. } catch (AggregateException exception) {
    4.     foreach (Exception e in exception.InnerExceptions) {
    5.         MonoBehaviour.print(e.Message);    // or any other way you use to print information
    6.     }
    7. }
    Furthermore, do you know if it happens only in Directory.Create? Do other methods have problems? Sorry for all the questions! :)

    If you can, contact me via e-mail for further discussion. I'm always afraid that the forums won't notify me of new messages, or that they will notify me at weird times.

    Due to my timezone, I'm about to go sleep now, so I apologize in advance if I can only get back to you tomorrow!

    - Daniel
     
    skullthug likes this.
  10. skullthug

    skullthug

    Joined:
    Oct 16, 2011
    Posts:
    202
    Thanks for the quick reply! I'll send you an email shortly.
     
  11. fantastisch_

    fantastisch_

    Joined:
    Mar 4, 2015
    Posts:
    26
    Code (CSharp):
    1. Debug.Log("Application.persistentDataPath exists: " + UnifiedIO.Directory.Exists(Application.persistentDataPath));
    2. Application.persistentDataPath exists: False
    Should this not be True?
     
  12. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    I think there is a misunderstanding in your code. :) You should never try to pass Application.persistentDataPath as an argument to UnifiedIO, because the library already operates in that folder and only there. All paths should be relative to persistentDataPath, like using UnifiedIO.Directory.Exists("Users") and not UnifiedIO.Directory.Exists(Application.persistentDataPath + "/Users"). If you use the second, it will try to concatenate persistentDataPath twice internally, and come out wrong. Please check the documentation pdf that comes with the package.

    That said, persistentDataPath should exist at all times, as it is created and handled by Unity (unless something catastrophic occurs!). It even uses the folder for Cloud services caches and similar. Did you have problems where it did not exist? That would break a lot of stuff, and not only UnifiedIO.

    I must say that I didn't predict that users could try calling UnifiedIO.Directory.Exists("/") or UnifiedIO.Directory.Exists(""), which would be the correct ways to do what you are trying in UnifiedIO style, so these calls probably won't work correctly in WSA (i.e. they should return true but in WSA they probably return false). But again, you shouldn't use them. Unity handles the existence of that folder. :)

    I hope I have helped!

    - Daniel
     
  13. fantastisch_

    fantastisch_

    Joined:
    Mar 4, 2015
    Posts:
    26
    Yes, that helped - thank you for clarifying!
     
  14. arendhil

    arendhil

    Joined:
    Sep 22, 2014
    Posts:
    3
    I'm using Unity 5.2.2f1 and I have been having this issue when I compile. Unified IO is not even linked with my code yet.
    I think there was a change in System.IO to UnityEngine.Windows from Unity 5.2.1f1 to 5.2.2f1 that might be the source of the issue.

    Reference Rewriter found some errors while running with command --target="Temp\StagingArea\Assembly-CSharp.dll" --additionalreferences="Temp\StagingArea\ARM","Temp\StagingArea\x86" --platform="C:\Program Files (x86)\Windows Phone Kits\8.0\Windows MetaData\Windows.winmd" --support="Temp\StagingArea\WinRTLegacy.dll" --supportpartialns=Unity.Partial --system=System --dbg=pdb --framework="C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\WindowsPhone\v8.0","C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v8.0\Libraries","C:\Program Files\Unity\Editor\Data\PlaybackEngines\wp8support\Players\ARM\release" --alt=System.Net;System.Net.Sockets,System.Net;System.Xml.Serialization;System.ComponentModel,System.Windows;System.Threading,mscorlib.
    Error: method `System.Void System.IO.Directory::Move(System.String,System.String)` doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Void UnifiedIO.SystemIO.Directory::Rename(System.String,System.String).
    Error: method `System.IO.DirectoryInfo System.IO.DirectoryInfo::get_Parent()` doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Boolean UnifiedIO.SystemIO.Directory::areSameDirectory(System.String,System.String).
    Error: method `System.IO.DirectoryInfo System.IO.DirectoryInfo::get_Parent()` doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Boolean UnifiedIO.SystemIO.Directory::isSubdirectory(System.String,System.String).
    Error: method `System.IO.DirectoryInfo System.IO.DirectoryInfo::get_Parent()` doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Boolean UnifiedIO.SystemIO.Directory::isSubdirectory(System.String,System.String).
    Error: method `System.IO.DirectoryInfo System.IO.DirectoryInfo::get_Parent()` doesn't exist in target framework. It is referenced from Assembly-CSharp.dll at System.Boolean UnifiedIO.SystemIO.Directory::isSubdirectory(System.String,System.String).

    UnityEngine.Debug:LogError(Object)
    PostProcessWinRT:RunReferenceRewriter() (at C:/buildslave/unity/build/PlatformDependent/WinRT/SharedSources/CSharp/PostProcessWinRT.cs:556)
    PostProcessWinRT:process() (at C:/buildslave/unity/build/PlatformDependent/WinRT/SharedSources/CSharp/PostProcessWinRT.cs:118)
    UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
     
  15. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    Hi there, @arendhil.

    I'm sorry to hear that you are having problems. :( I appreciate the report, as I was not aware of this issue. First of all, you are building for Windows Phone 8.0, correct?

    I have three versions of Unity 5 installed and I just tested this in WP8. It is indeed a change in Unity. I can confirm that the problem you report happens in 5.2.2f1, but also happens in 5.2.1f1. It does not happen in 5.0.0f4.

    Somewhere between those releases, Unity started adding this message when building for WP8, which might be related:

    "Support for Windows Phone 8.0 will be removed in Unity 5.3, please switch to Windows Phone 8.1"

    Every build should now be done for the Windows Apps platform, which does not include WP8 (it does have Phone 8.1). However, I don't know why the removal of support from future 5.3 would affect older versions, which still have the WP8 platform menu. Maybe some breaking changes were already introduced due to Windows 10, but they shouldn't! I will update to Windows 10 soon, so I expect to see some of these changes... :rolleyes:

    Could you explain what you mean by "I think there was a change in System.IO to UnityEngine.Windows"? 5.2.1f1 still has the problem, so this might not be the issue, but I still want to know, in case it helps. :)

    Finally, have you by any chance contacted Unity support about this? I assume you came here first, so I will contact them to try to get some answers. If this is a breaking change that they introduced, you would have to either revert to a previous Unity version that supports WP8 or get a refund from me. If UnifiedIO does not do what it's supposed to, I think it's fair, even though it is likely a Unity change.

    - Daniel
     
  16. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    @arendhil

    I was able to ask in the forums about this issue and it is a confirmed Unity bug in version 5.2. I have tested the newest patch release, 5.2.3p1, and the release notes mention this:

    "(745932) - Windows Phone 8.0: Fixed regression with System.IO classes."

    Indeed, I have downloaded and tested this version and the errors related to WP8 seem to be gone. Unfortunately, these patch versions might be the only versions in the 5.2 releases which don't have this bug, since Unity 5.3 will remove support for WP8.

    I have tried to go around the issue by creating a custom dll for WP8, as was suggested to me, but was still unsuccessful. I would appreciate it if you could tell me if this is an urgent matter to you, or if you are at all able to update to 5.2.3p1, which solves the issue.

    - Daniel
     
  17. wouter_vugt

    wouter_vugt

    Joined:
    Feb 25, 2015
    Posts:
    129
    Hi,

    I want to get this asset.
    I need to save a screenshot to a local folder (on all platforms).
    Other assets that do this work, but only for android or ios, never for windows store or OSx.

    Is it possible to write a texture 2D from the application to local storage (for ALL platforms) with this asset?
     
  18. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    Hi there!

    In general, anything you can convert to a byte array, string or write directly into a stream can be written in a cross platform way using UnifiedIO. Fortunately, Unity provides the EncodeToPNG method for textures, which returns the texture as a byte array, which you can then pass to UnifiedIO.File.WriteBytes to create a PNG image file.

    So you can do something like this test class I created:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ScreenshotTest : MonoBehaviour
    5. {
    6.     void Update ()
    7.     {
    8.         if (Input.GetKeyDown(KeyCode.Space))
    9.         {
    10.             StartCoroutine(takeScreenshot());
    11.         }
    12.     }
    13.  
    14.     IEnumerator takeScreenshot()
    15.     {
    16.         yield return new WaitForEndOfFrame();
    17.  
    18.         var texture = new Texture2D (Screen.width, Screen.height, TextureFormat.RGB24, true);
    19.         texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
    20.         texture.Apply();
    21.  
    22.         byte[] bytes = texture.EncodeToPNG();
    23.         UnifiedIO.File.WriteBytes("screenshot.png", bytes); // normally, System.IO.File.WriteAllBytes
    24.     }
    25. }
    26.  
    Use the spacebar to take a screenshot of the game. It should save it in your game's persistentDataPath folder.

    I hope this helps! :)

    - Daniel
     
  19. wouter_vugt

    wouter_vugt

    Joined:
    Feb 25, 2015
    Posts:
    129
    Thanks, I am going to buy your plugin and try!
    I will let you know if it works :)
     
  20. wouter_vugt

    wouter_vugt

    Joined:
    Feb 25, 2015
    Posts:
    129
    Ok it seems to work(at least for WSA, going to check other platforms soon) :)

    I know this is not part of the plugin, but maybe you know this.
    I want to open the written png (even better its folder) afterwards and I can't get it to work (windows store application).
    Application.OpenUrl doesnt work (even when setting "File://" in front of it).
    Do you have any idea how to do this?
     
  21. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    @wouter_vugt To be honest, no, I don't know how to do it. :p I did create an example just now to see what you were talking about, and sure, using Application.OpenURL(Application.persistentDataPath) opens the folder when playing in the editor, but not in a WSA build.

    I suspect it has to do with the WSA API not allowing methods that take absolute paths, so maybe the code inside OpenURL isn't able to open folders in WSA. See for example this similar problem (not Unity related) in StackOverflow:

    http://stackoverflow.com/questions/13320326/launch-windows-explorer-from-metro-style-app

    Maybe there is an API method to open the LocalState folder of the WSA application, but I have never required that functionality, so I'm not aware of it!

    I know I probably wasn't of much help to you... :( If you find a solution, I would be interested to know, actually.

    - Daniel
     
  22. wouter_vugt

    wouter_vugt

    Joined:
    Feb 25, 2015
    Posts:
    129
    Hi Daniel,

    Thanks, I will look into it some more, I will let you know once I find a solution.
    Great support btw, appreciate it!
     
  23. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    OK, thanks. No problem, you're welcome! :)
     
  24. wouter_vugt

    wouter_vugt

    Joined:
    Feb 25, 2015
    Posts:
    129
    I got a different problem.
    When using unifiedIO with javascript everything works fine in the editor.
    However when I try to build (wsa 10) I get errors saying:
    "Unknown identifier: 'UnifiedIO'""

    How come I only get these when trying to do a build and not in the editor?
    and how can I fix this?
    (I moved the entire folder into the plugins folder..)
     
  25. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    Hi again, @wouter_vugt!

    I tried and sure enough, I also got the same error. It's unexpected. In my brief encounter with using UnityScript/Javascript last year I must not have tried building for WSA (only for WP8) when calling UnifiedIO. Unless this was caused by some change in Unity, that would have caught this.

    I searched around, as I hadn't encountered that issue before (I only use C#), and found this page about WSA from the Unity manual, where it says that, for WSA specifically, "You can’t access C# classes from JS scripts unless you check .NET Core Partially in Compilation Overrides in PlayerSettings". I apologize because this means my UnityScript instructions in the manual are incomplete for WSA! :oops:

    Changing that option successfully compiled my project in WSA. I'm now facing errors with Unity's AssemblyConverter when building in Visual Studio, however. Could you tell me if this is the case for you too? I still haven't found a solution for this. I will have to keep looking tomorrow, or maybe ask the Unity team.

    - Daniel
     
  26. wouter_vugt

    wouter_vugt

    Joined:
    Feb 25, 2015
    Posts:
    129
    Hi,

    Well that seemed to have fixed it, however I am unable to make a proper build due to some unrelated issues I have to fix first.
    When I get to make a proper build I will try it in visual studio.
    I should have never started using javascript, lol.
     
  27. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    [POST EDIT: Users of UnityScript reading this post now can ignore it, as DLLs can solve the issue with using UnityScript in WSA builds. The original post follows:]

    Good to know, but I think I've found a "game-breaking" issue when using JS. :( Not directly related to JS itself, but instead to .NET Core Partially. It seems that activating this option, which is the only way to use JS scripts on WSA builds, forces Unity to compile code using Mono instead of the supposed .NET compiler. What this means is that any code that references the WinRT API - which doesn't exist when using Mono - cannot be used! And UnifiedIO must use it for file access. This thread mentions this.

    In summary, it seems that UnityScript/JavaScript cannot be used for WSA builds if you require anything from the WinRT API, which UnifiedIO uses.

    Which is very bad, because I was under the impression that UnifiedIO worked fine using JS on all platforms, and that isn't the case for WSA after all.

    I will see if there's any way of doing this using pre-compiled DLLs, so I haven't given up hope completely for JS, but if you (@wouter_vugt) or anyone that uses JS bought UnifiedIO under the assumption that this worked, this is my fault entirely, so I will be accepting refunds. If you want, contact me with your invoice number and mention this. Hopefully not too many people have faced this issue. I'll also update the manual.

    - Daniel

    PS: I'm very tempted to say that you are correct about never using JS. ;) But I have my issues with the language, so I'm already biased. :) Use C# in Unity and be happy!
     
    Last edited: May 5, 2016
  28. wouter_vugt

    wouter_vugt

    Joined:
    Feb 25, 2015
    Posts:
    129
    Ah that is bad news.
    I don't require a refund, however I really hope you will try to fix this issue with a DLL like you said.
    I really like your plugin, would suck if couldn't use it.

    thanks for your quick responses anyway.
     
  29. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    @wouter_vugt I have good news. :) I got things to work using JS by following Tautvydas suggestions on the thread I linked above, meaning that I was able to use JS and UnifiedIO as normal in a WSA build.

    The downsides of what I did are:
    1. It requires a C# script to initialize 2 static vars before any JS calls to UnifiedIO may happen.
    2. To still allow calling UnifiedIO from C# as normal, all calls to UnifiedIO coming from JS use the namespace UnifiedIO.UnityScript instead of just UnifiedIO.

    The upside is that it doesn't require DLLs at all, but the downsides are bad enough, so I will want to try other approaches.

    Either way, you can use JS with UnifiedIO and WSA. Phew... ;) I'm glad for that.

    If you are in a hurry, I can send you what I have right now, but it requires the setup script and changing calls to use the additional namespace. If a better solution works, maybe using DLLs, this might become simpler or require no changes at all. I will look into this.
     
  30. wouter_vugt

    wouter_vugt

    Joined:
    Feb 25, 2015
    Posts:
    129
    Ah cool!
    I was already trying to implement my own logic without using UnifiedIO.
    Really glad I dont have to do this. I will keep working with your plugin, in a week or so I'm hoping to finish my application and then I would need a solution.
    So you don't have to send me anything right now, maybe then you have a cleaner method.
    Otherwise I will use what you have now for the time being :)

    Thanks for the amazing support!

    Btw I just got an error when using read bytes.
    "'UnifiedIO.File.ReadBytes(String, int, int)' is not compatible with the argument list '(String)'."
    In the documentation it says you can just pass a path and it should read all bytes?
     
    Last edited: May 2, 2016
  31. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    @wouter_vugt First of all, let me thank you for all the bug reports related to UnityScript! Honestly. These issues are driving me nuts, but it's a good thing that I'm now aware of them. Thanks! :)

    I've successfully created working DLLs to use with Universal Windows 10 apps and Windows 8.1, but creating DLLs for WSA requires several different ones depending on platform, so I still have to solve the Universal 8.1 and Windows Phone DLLs. Will your builds be Universal Windows 10?

    About your error, does UnityScript not support optional arguments in functions? I've added those extra int parameters to ReadBytes recently due to a user's request. I guess I'll have to create several function overloads instead, but that's okay. If you don't require reading from arbitrary points in the file (and arbitrary lengths), and just want to read everything, a quick workaround for you could be to call ReadBytes with 0s as arguments (those are the defaults). Like so:
    Code (CSharp):
    1. UnifiedIO.File.ReadBytes(path, 0, 0);
    Could you tell me if this works for you temporarily?
     
  32. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    @wouter_vugt I had some time yesterday and finished up the DLLs. :) If you can shoot me an e-mail I'll send you a Unity package which should work nicely with UnityScript, no setup required. ;) And it should fix the issue you had with the optional parameters too.

    I still have to decide how to give these DLLs to UnityScript users, so as to not bloat the UnifiedIO packaging. I could package only the DLLs for everyone, but I wanted buyers to have the actual code. We'll see... :)

    - Daniel
     
  33. wouter_vugt

    wouter_vugt

    Joined:
    Feb 25, 2015
    Posts:
    129

    Hi Daniel,

    thanks so much, I will email you today, I've said it before but this is amazing support.
    I will probably only be using windows universal 10 in the future, but from what I understand I can publish for 8.1 as well now? (not a deal breaker if that is not possible).

    I would be fine with sending an email with a receipt to receive the dll's and I think most people would. Probably just a small percentage of your users are using javascript anyway.
     
  34. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    Hi there, Wouter

    I just sent you the e-mail with the Unity package. All details are in there, but I want to publicly thank you for finding and reporting these issues when using UnityScript. You're welcome and I should thank you instead! :)

    I also want to apologize to anyone having issues with this language because it's my fault that I didn't test its support as I should. I will rewrite the manual section regarding this and fix the optional parameters thing in the next update.

    Yes, you should be able to publish for 8.1 as well. Regarding the DLLs packaging, maybe I'll do that, yes. :)

    Thanks again!

    - Daniel
     
  35. Pedro-Alaiagames

    Pedro-Alaiagames

    Joined:
    Apr 15, 2014
    Posts:
    28
    Hello.

    Im developing an app where the user takes a photo of himself for the avatar. I store the path of the photo on a database and I can load it in runtime from the gallery. Thats is working fine. But if the user delete it the photo is lost. Obviously.
    Id like to copy the photo to app persistent data and store the new path, so the user can delete it from the gallery but is still accesible from the persistent data.
    Is this posible with this plugin in IOS and Android?

    Thanx!
     
  36. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    Hi, Pedro!

    Yes, if I understand correctly, that is perfectly possible. UnifiedIO saves everything in your app's persistentDataPath, so if you'd like to save a user photo as a backup, for example, you can use

    Code (CSharp):
    1. string path = "Photo Backups/some-photo-123.txt";
    2. UnifiedIO.File.WriteBytes(path, photoAsByteArray);
    And it will be saved under the "Photo Backups" directory of your app's persistentDataPath (please create the folder with UnifiedIO.Directory.Create("Photo Backups") first). You always give relative paths to UnifiedIO, because it - like Unity's persistentDataPath - abstracts away the exact path, so you would probably have to save relative paths in your database too.

    I hope I have helped. If something is unclear, please reply or send me an email! :)

    Cheers,
    Daniel
     
  37. Pedro-Alaiagames

    Pedro-Alaiagames

    Joined:
    Apr 15, 2014
    Posts:
    28
    Thanx! Im on it!
     
  38. Pedro-Alaiagames

    Pedro-Alaiagames

    Joined:
    Apr 15, 2014
    Posts:
    28
    Ok! It works!

    But Ive got another question.
    If I want to copy a file from other path that is not in PersistentDataPath. Is there a way to use explicits paths? For example to copy a file from gallery in android .../.../DCIM/picture.jpeg to PersistentDataPath?

    I know that is not the purpose of UnifiedIO so its a Cross-platform IO
     
  39. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    Nice! :)

    I didn't realize you could simply want to copy files directly (instead of having the photo in memory and storing bytes). :oops: Well, like you mentioned, in order to be cross platform, UnifiedIO makes use of persistentDataPath, so all paths in calls are relative to that folder. There's no way to directly copy from outside to that folder because some platforms, like WSA, don't allow the app to access files/folders outside of a few specific directories (one of them being Unity's persistentDataPath), unless there's user intervention at runtime (like when using a file picker).

    You could, however, use System.IO classes and methods, seeing that you don't seem to be doing anything for WSA/UWP, where file calls are completely different, or for Windows Phone 8, where for example some methods do not exist. This kind of defeats the purpose of UnifiedIO, but for Android and iOS it should work. :)

    - Daniel
     
  40. Pedro-Alaiagames

    Pedro-Alaiagames

    Joined:
    Apr 15, 2014
    Posts:
    28
    Thanx for answer so quick..., great support.

    Its a great plugin, Good Job!
     
  41. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    Thank you! I'm glad I could help. :)
     
    Pedro-Alaiagames likes this.
  42. ippdev

    ippdev

    Joined:
    Feb 7, 2010
    Posts:
    3,853
    I did some looking around for file IO for an archviz app that requires loading .csv and .fbx files from anywhere the Usertmay have stored them. Yours looks the best without plugins or dll's in case I have to customize it...but I am slightly confused as you speak to PlayerPrefs and persistentDataPath, and while I am going to use those to store the final project states as they tweak the model I am wondering if this will load a .csv from anywhere on the User's file system to initiate the tagging of the models meshes. I already have a file loader and parser for fbx. I am now trying to get text files in and out to the Users choice of location except for project properties and params which will be stored at persistentDataPath.
     
  43. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    Hi @ippdev,

    Indeed, UnifiedIO works mainly in the persistentDataPath folder. :) It was made to be cross platform, but cannot, unfortunately, be cross platform if I aim to support every directory in the filesystem, essentially because Windows Store simply does not allow it without the user's permission by using something like a file picker.

    What I could do, and did, is let the programmer who uses UnifiedIO change its working directory to any other folder at any time, even between calls (this feature was added in UnifiedIO 2.1.0). That's a special use case mostly for people who want their saved data to go into a specific custom folder or one that is chosen by their users (possibly through a file picker).

    I'm not sure if it would help you. It depends on if you are creating Unity builds for Windows Store / Windows Phone. If you aren't, it is likely that you simply won't need UnifiedIO. :) The classes and methods in the System.IO namespace already allow you to read and write anywhere in the filesystem in the "main" platforms (Windows, Mac, Linux, Android, iOS) but not Windows Store / Windows Phone. They are similar to the methods in UnifiedIO.

    If, however, you want to build for Windows Store and avoid most of the hassle, UnifiedIO can help. You would have to give it a new StorageFolder so that it reads and writes from there instead of the default StorageFolder that is actually persistentDataPath. The documentation talks a bit about this in section 5 and gives an example. Here.

    I hope this makes the reasons a bit clearer. :) If you have any questions, feel free to ask!

    Cheers,
    Daniel
     
  44. tech247

    tech247

    Joined:
    Jul 2, 2013
    Posts:
    60
  45. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    Hello! Unfortunately I encounter this error when accessing that link:
    You do not have permission to view this page or perform this action.

    Is it down? Can you still access it?

    I should say that Xbox (or any console platform) is not officially supported by UnifiedIO. I don't have access to those platforms, so I could never test UnifiedIO on them.

    Has anyone here perhaps tried to use UnifiedIO on Xbox and could report their findings? :)

    Best regards,
    Daniel
     
  46. wouter_vugt

    wouter_vugt

    Joined:
    Feb 25, 2015
    Posts:
    129
    Hi, I have an error on windows universal buil.
    Using the latest unity version and the latest visual studio version.
    Anything I load or save anything through unified io the app gets stuck...
    Any idea how this could be?
     
  47. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    Hi! Right now I can't say what it could be. :| A few questions:
    1. Most important: Can you use the Visual Studio debugger, set a breakpoint on one of the misbehaving calls and step in and see what it is doing to cause the hang?
    2. What version of UnifiedIO are you using? (you can see the documentation PDF, for example). Unless you are using the custom dlls for UnityScript from some time ago. :)
    3. Did UnifiedIO work correctly for you in UWP before or is this the first UWP build?
    4. Are you using Unity 2017.1.0?
    5. [EDIT] Does the problem happen on a laptop/destkop or on Windows Phone?
    Cheers,
    Daniel
     
  48. wouter_vugt

    wouter_vugt

    Joined:
    Feb 25, 2015
    Posts:
    129
    1.I have no idea how to do this.. what it sais in the out put is : ''thread has exited with code 0 (0x0)."
    2.the latest version 2.2 I believe, I just downloaded and imported agian
    3.yes it worked before (different laptop, with older unity and older VS), and it works on all other platforms.
    4.I am using the latest unity verion
    5.Havent tried it out on my phone yet, but that doesn't matter, it should be universal anyway (so it will have to work on desktops as well).
     
  49. CanisLupus

    CanisLupus

    Joined:
    Jul 29, 2013
    Posts:
    427
    OK, thank you for answering everything. :) Replying to both your post and email:

    If you export the project from Unity and check "Unity C# Projects" you will get a Visual Studio project that includes the source for all your scripts. This lets you set a breakpoint on any script by pressing the area to the left of the code line where you want execution to stop. A red circle should appear. Then when you run the build from VS in Debug mode (it's the default mode) it should stop there and you can step line by line and see where the hang happens.

    I just did that and was a bit surprised. I'm using Unity 2017.1 and VS 2017.2 (version 15.2 in the about window) and indeed, I could reproduce the hang. However, the hang does not happen if I step through code; only when I let it run normally. This looks like a problem with async calls (i.e. when I step through code the processor has a lot of time to complete the instructions before reaching the Wait()/Result call), but it really shouldn't happen.

    In fact the problem isn't related to UnifiedIO in particular. This code with a simple async Task that returns 5 also hangs:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Threading.Tasks;
    3.  
    4. public class TestScript : MonoBehaviour
    5. {
    6.     void Start()
    7.     {
    8.         Debug.LogError(TestAsync().Result);
    9.     }
    10.    
    11.     public static async Task<int> TestAsync()
    12.     {
    13.         return await Task.Run<int>(() => 5);
    14.     }
    15. }
    This is bizarre. It may be related to the VS incompatibility you reported (https://forum.unity3d.com/threads/n...-visual-studio-2017-3-incompatibility.487833/) but it may also be something else. From that thread, it seems that Unity 2017.1.0p5 was already released with a fix. Could you try that Unity version?

    Daniel
     
  50. wouter_vugt

    wouter_vugt

    Joined:
    Feb 25, 2015
    Posts:
    129
    Hi Daniel,

    Thanks for you reply.
    I just tried the latest unity patch, although the build problem is fixed, unifiedIO still hangs...

    Do you think this can be fixed? or is it a unity bug or something?