Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by uanmanarmy · Jul 21, 2014 at 02:28 PM · stringresourcespathresources.load

Store the path with Resources.Load in a string

Hi I need to store the path in a string using resources.Load.

for example ;

 string path = Resources.Load("Objects/Levels");

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image calebheale · Jul 21, 2014 at 02:51 PM 0
Share

Could you be more specific about what you are going to do with the string? Is this for a script running in the editor or in game? I don't believe what you are trying to do is possible but with more information maybe someone could help you find an alternate solution.

avatar image uanmanarmy · Jul 22, 2014 at 07:39 AM 0
Share

I'm going to parse an X$$anonymous$$L file, and this string will be as the path to that Xml File.

 TextReader reader = new StreamReader (path);

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by uanmanarmy · Jul 22, 2014 at 09:07 AM

I will put the solution that I made.

Put your XML file in the resources folder in your project (that is, Assets/Resources/).

Make a variable of type class that you made.

 LevelsDirectory XmlData;

In your code, use this to load the file as a TextAsset:

 TextAsset textAsset= Resources.Load ("xml_path") as TextAsset;

From here, you can get it into XMLDocument, if that is what you want.

     XmlSerializer deserializer = new XmlSerializer (typeof(LevelsDirectory));
     TextReader reader = new StringReader (textAsset.text);
     XmlData = (LevelsDirectory)deserializer.Deserialize (reader);
     reader.Close ();

LevelsDirectory is a public class with information from your Xml

 public class LevelsDirectory
     {
         [XmlElement("Level")]
         public List<Level> levelList = new List<Level> ();
     }
 
     public class Level
     {
         public int LevelNumber{ get; set; }
         public int ItemsNumber{ get; set; }
         public string ItemsColor { get; set; }
     }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by WillTM · Jul 21, 2014 at 03:01 PM

Is this what you want?

string path = "Objects/Levels";

Resources.Load(path + "assetname.txt") as TextAsset;

using a text asset as an example.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image uanmanarmy · Jul 21, 2014 at 03:55 PM 0
Share

not really but good one.

Why in a string, cuz I need this string for an build in Function that accept only strings ;D

avatar image
1

Answer by calebheale · Jul 22, 2014 at 08:39 AM

I don't think you want Resources for this. You probably want StreamingAssets. Place the xml file in a folder called StreamingAssets (similar to what you do with resources) and then you can access the file using Application.streamingAssetsPath like:

 StreamReader sr = new StreamReader(Application.streamingAssetsPath + "/myXml.xml");

You will want to take a look at the documentation to see the additional notes on android and web platforms if those are intended targets.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Loading a ScriptableObject at Runtime. 1 Answer

Access path of stored asset 0 Answers

A node in a childnode? 1 Answer

Writing on text file in an Android Build 1 Answer

Loading resources into a ScriptableObject instead of Resources.Load? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges