Search Unity

Assets and multiplatform.

Discussion in 'Scripting' started by mibin, Nov 19, 2017.

  1. mibin

    mibin

    Joined:
    Nov 11, 2017
    Posts:
    3
    Hello!
    In android i cannot access to file in folder "Assets" but in Unity all works.

    In folder "Assets" i create folder "Config" and in "Config" create "Level":
    Assets - Config - Level

    In folder "Level" i create XML file level_1.xml

    in Script i use XmlDocuments:
    Code (CSharp):
    1. xdoc.LoadXml("Assets/Configs/Levels/level_1.xml");
    and in Unity it's work, but android it get errors.

    How i cant get access to file in android, if this file in folder "Assets"?
    Is it possible or i must use StreamingAssets or there another way?

    Thx.
     
  2. TheHighGround

    TheHighGround

    Joined:
    Nov 19, 2017
    Posts:
    68
  3. mibin

    mibin

    Joined:
    Nov 11, 2017
    Posts:
    3
    This work on Android or everywhere?
    i must set full path or "Assets/Configs/Levels/level_1.xml"?
     
    Last edited: Nov 19, 2017
  4. mibin

    mibin

    Joined:
    Nov 11, 2017
    Posts:
    3
    May i load xml file in script without resources folder or streamingassets?
     
  5. TheHighGround

    TheHighGround

    Joined:
    Nov 19, 2017
    Posts:
    68
    You could place the XML file like so

    Assets/Resources/Configs/Levels/level_1.xml

    And load it like so

    var asset = Resources.Load<TextAsset>("Configs/Levels/level_1");

    var contents = asset.text; // Returns a string containing all the contents in the TextAsset.

    If you have to deserialize from string to XML you can use XmlSerializer and StringReader.

    Hope this helps