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 52cwalk · Sep 10, 2021 at 09:55 AM · mobileunityeditordefine

Platform #define directives' can't work

Hello : The 'Platform #define directives' like UNTIY_IOS/UNITY_ANDROID can't work when using with c# Class Library which export with .dll file .

   public static int calc(int a,int b)
         {
 
 #if UNITY_IOS && !UNITY_EDITOR
             Debug.Log("calc IOS IOS IOS IOS IOS IOS IOS IOS IOS IOS IOS IOS IOS IOS IOS IOS IOS IOS IOS ");
             return a * b;
 #elif UNITY_ANDROID && !UNITY_EDITOR
             Debug.Log("calc Android Android Android Android Android Android Android Android Android Android Android Android Android  ");
             return a + b;
 #else
             return a - b;
             Debug.Log("calc Ohter Ohter Ohter Ohter Ohter Ohter Ohter Ohter Ohter Ohter Ohter Ohter Ohter Ohter ");
 #endif
 
         }

it always call #else no matter build on android or iOS, can you help me to solve it .

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 Captain_Pineapple · Sep 10, 2021 at 12:03 PM 0
Share

what do you mean by: when using with c# Class Library which export with .dll file


when you just do a build using a default Unity Build this code as stated should work.

avatar image logicandchaos Captain_Pineapple · Sep 10, 2021 at 03:49 PM 1
Share

I think they mean they are compiling it to a DLL and including it in the project.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Captain_Pineapple · Sep 12, 2021 at 09:44 AM

Well then, assuming that @logicandchaos 's assumption is correct and you want to compile code to a dll and then include it in your unity project: This can never work


I can only strongly recommend you read into #defines as you apparently do not completly understand what they do. They are also called "Preprocessor directives", meaning those are evaluated before the code is compiled. So at the point where you create a dll you already compile the code so Unity will not be able to handle any defines as from unitys point of view they do not exist.

And since at compilation time Visual Studio will check if UNITY_IOS, UNITY_ANDROID or UNITY_EDITOR do exist it will come to the conclusion that this is not the case and thus the #else path is always chosen.


Long story short: this code works as intended but only if you do not precompile it into a dll.

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 Bonfire-Boy · Sep 14, 2021 at 03:57 PM 0
Share

Right, so, making some more assumptions about the OP's use case... perhaps what they're after is actually platform-dependent DLL inclusion.


They'd need to compile a different version of their DLL for each platform (having set the flags themselves appropriately before building). Then they can put them all in the project but use the DLLs' import settings to only include them for the appropriate platform.

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

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

Unity donesn't work in Android 9 0 Answers

Vuforia Image Target for mobile object 0 Answers

Remove UNITY_EDITOR define even for in-Editor builds? 2 Answers

Draw a line from object to indicate power 0 Answers

issue with building unity VR google cardboard 0 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