Include platform defines in dll

I’ve been trying move some of my c# code into a dll reduce compile time and so I can create a custom Debug output tool (since putting the code in the dll will allow to click on the log and take you to the line of code that generated the log) . I’ve placed unity defines inside the code but I have noticed that any code placed inside the defines are ignored, even if I am on the correct platform. I’ve attached code which I’ve compiled into a dll which displays this issue. Does anyone have a solution to this problem or is this a limitation of using .dlls?

using System;
using UnityEngine;

namespace UnityDefineTest
{
	public class DefineTest:MonoBehaviour 
	{
		private string outputText = string.Empty;


		private void Start()
		{
			#if UNITY_EDITOR
			outputText += "Unity editor ";
			#endif

			#if UNITY_WEBPLAYER
			outputText += "Unity webplayer ";
			#endif

			#if UNITY_STANDALONE
			outputText += "Unity standalone ";
			#endif

			outputText += "default text";
		}

		private void OnGUI()
		{
			GUILayout.Label(outputText);
		}
	}
}

When you’re compiling the dll yourself, you decide which defines to define. In your, you would need to create three targets in the dll solution, for ex, “Editor”, “WebPlayer”, “Standalone”, in each of these targets, in project properties you would need to define a define accordingly.

After compiling each target, you would have 3 dlls… You would need to place them in your project… but Unity will probably complain that there a multiple dlls with same name, if you’re using 4.6.

In 5.0, it will be possible to mark individual plugins on when they should be used, so you would mark one dll to be usable only in editor, the other one - usable only in Standalone, and the last one - Webplayer.

The other option would be - don’t use defines :slight_smile: and simply use Unity - Scripting API: Application.platform for determining which platform is being used.