Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by betafreakgames · Oct 29, 2017 at 04:05 AM · preprocessor

Is there a simple #if UNITY?

The Unity Manual has a page on platform dependent compilation, which explains a set of #if directives we can use to differentiate between the editor, Windows, Android, and so on. However, is there a similar directive for when Unity is used at all?

For instance:

     string text;
 #if UNITY
     text = Resource.Load<string>("/path/to/textfile");
 #else
     text = System.IO.File.ReadAllText("/path/to/textfile");
 #end
     // read the text...

Essentially, the idea is that if the script is being run inside any Unity context whatsoever, the code uses Unity types to load the file. Otherwise, it uses System.IO to load the file.

Does this facility exist in Unity? If it's not defined as UNITY, is it something else?

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 Hellium · Oct 29, 2017 at 08:30 AM 0
Share

What are you trying to do in the end? Are you making a plugin (dll) you could use outside Unity?

avatar image betafreakgames Hellium · Oct 29, 2017 at 06:24 PM 0
Share

It would be a source file that I could use outside Unity, but the idea is similar.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by hoy_smallfry · Jan 14, 2018 at 05:37 AM

I do not think that there is a pre-processor definition that Unity defines that does what you want. However, it's possible to define your own in Player Settings, so you could define UNITY that exists for your project, and simply avoid defining UNITY for your non-Unity code projects: alt text

The only downside to this is that you would need to define this for every new project.

Although, your usage raises a question about why you would want to do it this way. If your code relies on reading a text file, it's possible to keep this functionality intact in Unity. Not only can you read files with System.IO.File in a Unity standalone, its also possible to have Unity to keep the text file as it's own separate file when you build a standalone if you use the Streaming Assets folder.

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

120 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 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 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 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 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

Preprocessor symbol for Linux headless mode 0 Answers

Disabling tessellation in a shader using material properties 0 Answers

PostProcessing a Json file at importation 0 Answers

ModelImporter throws TargetParameterCountException despite correctly using the functions. How do i proceed? 0 Answers

When using preprocessors, Unity throws errors 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