custom version define

Hi,

I want to make a sub-versions with different language in my project. The current solution is to use #define & #if to decide witch resource version to load. But it seems like #define does not work global in Unity, I have to define every script.

In c++ I can put the define into a h file, and every script includes it. When changing I only have to edit the h file, but now I have to edit every script in Unity.

Is there any way to make Unity include a common header, or use a global define?

Thanks

Hey Linphency.

What you described can be achieved by adding a file called smcs.rsp to the /Assets/ folder. Anything within this file will be added to the compiler as arguments.

So for instance, adding ‘-define:VER_1’ to smcs.rsp, will add VER_1 as a global define for all C# scripts, and will save you having to add it to each file.

I’ve found this to be a pretty handy, and hardly documented little feature, hopefully you find it as useful as I have.

Hi, yoyo. I mean defines like this..


#define VER_1

using UnityEngine; using System.Collections;

public class NewBehaviourScript : MonoBehaviour {

void Start () {
    #if VER_1
        //load resource ver. 1
    #else 
        //load default resource ver.
    #endif
}

}


In general C# define is global wide, but in Unity it only affect the defined script.

So I have to write "#define VER_1" in every script...

I am wondering is there a way to make the define global or other way to quickly change versions?

Hey Guys, I’ve put togeather a little example project to better illustrate this, if my post didn’t clarify things, it will. You can grab it here: [1615-defineexample.zip|1615]