Supposedly there is a trick to make a global #define (preprocessor tag) by creating a special file in the root of your project. Would someone share the specifics? I am sick of having to put my #defines in every .cs file that uses it.
There is no trick, you can't make global defines on a per project base. the only thing you could do are unity wide defines that apply everywhere and that requires a little "hack"
Dreamora, I believe you are mistaken. I have it on good authority (mikeD from prime31) there is a way to make a global #define and not have to put it at the top of every .cs file that uses it. I'll see if he can share the details, but he's on the road and wasn't able to tell me right away.
There is one way and thats modifying the compiler control script. But thats not per project but per unity install
That sucks Add votes here http://feedback.unity3d.com/forums/...or-interface-for-listing-preprocessor-macros-
Correction! There is an apparently mostly unknown and undocumented feature. See this thread. Just tried and it works with C# too: http://forum.unity3d.com/threads/71445-How-To-Set-Project-Wide-pragma-Directives-with-JavaScript
That's really neat we were looking for a feature like that for ages. I noticed there is a us.rsp listed at the link too, I'm curious what other options are available and how we can go about figuring them out.
Unfortunately, it seems that Monodevelop does not always notice these defines Compilation seems to work as expected, but the source code isn't highlighted correctly and document outline is suspect. Reverting to putting the #define in .cs files, in some case.
MonoDevelop has it's own Define list, that you can add to. Unity handles it's own compilation (hence why the MonoDevelop output is called irrelvant.dll). Just go to Project Options -> Build -> Compiler -> Define Symbols and add it in. You'll notice the Unity defines are already manually included there.
I put togeather a simple example project to illustrate how to pass the compiler arguments for another thread, and thought I'd repost it here. You can download it here: http://www.slipstreamgame.com/shares/DefineExample.rar
We got tired of manually managing the smcs/gmcs files so we threw together a quick little editor script to handle it for us. Nothing fancy here, just a simple UI to add/remove defines and force a recompile. Its up on Github for those interested: https://github.com/prime31/P31UnityAddOns/blob/master/Editor/GlobalDefinesWizard.cs
If anyone is still looking at this, seems like Unity4 has a fix. http://docs.unity3d.com/Documentati...ttings.SetScriptingDefineSymbolsForGroup.html Also changes can be done via the PlayerSettings inspector *EDIT* the format is DEFINE1;DEFINE2. Make sure you don't repeat DEFINE1 multiple times because the Unity build process will get a duplicate key exception.
chsu, indeed it does - all I use now is the defines in playerSettings! thanks for following up this thread. One note to anyone trying it: the player settings are *per platform* which is confusing the first time you set a define, then switch platforms.
We are improving the documentation on Custom Defines, and it's important to update these threads with the correct way of using them in the current versions of Unity. If you want to modify only global defines, you should use Scripting Define Symbols in Player Settings, because this will cover all the compilers. If you choose the .rsp files instead, you'll have to provide one file for every compiler Unity uses, and you won't know when one or another compiler is used. To do this you must add a text file with the extra directives to the "Assets/" folder: [table="width: 500"] [tr] [td]C#[/td] [td]<Project Path>/Assets/smcs.rsp[/td] [/tr] [tr] [td]C# - Editor Scripts[/td] [td]<Project Path>/Assets/gmcs.rsp[/td] [/tr] [tr] [td]UnityScript[/td] [td]<Project Path>/Assets/us.rsp[/td] [/tr] [tr] [td]Boo[/td] [td]<Project Path>/Assets/boo.rsp[/td] [/tr] [/table] As an example, if you include the single line "-define:UNITY_DEBUG" in your smcs.rsp file the define UNITY_DEBUG will exist as a global define for C# scripts, except for Editor scripts. Every time you make changes to .rsp files you will need to recompile for them to be effective. You can do this by updating or reimporting a single script (.js, .cs or .boo) file. All this information is being added to our documentation.
Hey gang - is there any way to include a DISABLE directive, eg #pragma warning disable 414 project-wide? THANK YOU, REALLY.
In case anyone else comes looking for this - here is an editor tool I whipped up to make working with global defines super easy. https://github.com/karl-/UnityDefineManager/blob/master/DefineManager.cs
I do it this way. FYI Unity 5.6.2 > Code (CSharp): #define DEBUG //Must be very first line or you get error. ONLY define it once in your main script using System.Reflection; using UnityEngine; //Please use name spaces in your Apps and API's => ;) namespace apicompany.apiname { public class MyGameObject : MonoBehaviour { [SerializeField] [Tooltip("Enable this for logging details informations about this class.")] protected bool VerboseLogging = true; private void Awake() { //***[You can use it this way]***/ if (mycompany.myapp.APIConfig.DEBUG_ENABLED && VerboseLogging) print(string.Format("{0}:{1} - Debug Mode {2} enabled.", GetType(), MethodBase.GetCurrentMethod(), ((mycompany.myapp.APIConfig.DEBUG_ENABLED) ? "is" : "is not"))); /// This prints to console => /// apicompany.apiname.MyGameObject:Void Start() - Debug Mode is enabled. /// or /// apicompany.apiname.MyGameObject:Void Start() - Debug Mode is not enabled. } // Or This Way - without any need of the static global void Start() { #if DEBUG if (VerboseLogging) print(string.Format("{0}:{1} - Debug Mode {2} enabled.", GetType(), MethodBase.GetCurrentMethod(), ((mycompany.myapp.APIConfig.DEBUG_ENABLED) ? "is" : "is not"))); #endif } } } namespace mycompany.myapp { #if DEBUG class APIConfig { public static bool DEBUG_ENABLED = true; } #endif #if !DEBUG //use this api - let's say SecurePlayerPrefs for example class APIConfig { public static bool DEBUG_ENABLED = false; } #endif /// /// This does not work - Wish it did. But the above is a work around. /// /* #if apiname //Is Defined #elif //<= Error on else? Bug? //Not Defined #endif */ }
Edit -> Project Settings -> Player Inspector -> (Settings for PC,Mac and Linux standalone) -> Other Settings -> Scripting define symbols Always press Enter after editing. You'll see the difference in open VS immediately.