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 LightStriker · Aug 03, 2013 at 09:51 PM · c#directoryio

DirectoryInfo and FileInfo not working in standalone build

I've read in another question that to parse a collection of files from a folder to use DirectoryInfo and FileInfo from System.IO which both work fine within the confine of the editor.

However, once I build a stand-alone version (even PC), those classes and methods fail to work properly.

Is there anyway to retrieve a list of assets contained in a folder once the assets are properly built in a unity resources files?

Example of what I'm doing:

 DirectoryInfo root = new DirectoryInfo("Assets/Resources/Sound/Music");
 FileInfo[] infos = root.GetFiles();

 musics = new Music[infos.Length];
 for (int i = 0; i < infos.Length; i++)
     musics[i] = new Music(infos[i].Name.Split('.')[0]);

 return musics;

While being there, is there other .NET assembly that won't work properly in other environment such as iOS/Android? If I use System.Reflection, will I get some nasty surprises down the line?

Comment
Add comment
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

2 Replies

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

Answer by Graham-Dunnett · Aug 04, 2013 at 08:48 AM

When you make a standalone the contents of Assets\Resources are compressed into a data file. You access the contents of this file at runtime using Resources.Load().

On iOS all your script code and .Net bytecode is converted into Arm assembler. There is no reflection or runtime code generation possible on this platform.

Comment
Add comment · Show 6 · 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 LightStriker · Aug 04, 2013 at 04:10 PM 1
Share

Good grief, this is terrible. Nobody should tell people to use System.IO or System.Reflection, it's just seeking troubles! And nobody is going to run a game in the editor. Do you mean Activator is also out of question? Would typeof() or GetType() even works since they access the class definition, which is reflection?

avatar image RalphTrickey · Aug 04, 2013 at 04:19 PM 0
Share

A lot of system.reflection should work, I'd think, things like finding members and attributes, I'm not sure how JScript or Boo would work without those pieces.

Things like dynamically loading assemblies and emitting bytecode cannot work on iOS.

avatar image LightStriker · Aug 04, 2013 at 05:33 PM 0
Share

@RalphTrickey Do you think Activator works?

avatar image RalphTrickey · Aug 04, 2013 at 06:17 PM 0
Share

It is, but there are some caveats. The big issue is that iOS compiles at link time ins$$anonymous$$d of at run-time so things like Emit aren't supported and never will be.

http://forums.xamarin.com/discussion/204/is-there-a-simple-workaround-for-system-activator-createinstance-being-not-supported

http://docs.xamarin.com/guides/ios/advanced_topics/limitations

avatar image LightStriker · Aug 04, 2013 at 06:34 PM 0
Share

The first links talk about Xamarin, and I guess the attributes specified in it is Xamarin's specific? Is a workaround to prevent class from being flush to explicitly reference them somewhere in your code paths or does Unity provide attributes to prevent code removal?

Show more comments
avatar image
0

Answer by chin13577 · Jan 15, 2017 at 05:31 PM

This is my code when I try to read all of .txt file in folder "Resource".

     path = "FolderInResource/SubFolder/";
     UnityEngine.Object[] fileInfo = Resources.LoadAll(path, typeof(TextAsset));
     foreach (var file in fileInfo)
        {
               TextAsset mytext = (TextAsset)file;
                string str = mytext.text;
        }

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 tsef · Mar 31, 2020 at 08:38 PM 0
Share

but this is a very bad solution if you have a lot of files

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

18 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Namespaces that correspond to file location 1 Answer

Debug.Log(files in a directory) problem 0 Answers

Mac/PC differences in directory symbols '\' and '/' 2 Answers


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