x


#ifdef UNITY_IPHONE equivalent for JavaScript

Using C# you can simply employ #ifdef UNITY_IPHONE to hide iPhone functions when loading an iPhone project in regular Unity. But it doesn't work in JavaScript. Is there some alternative method?

more ▼

asked Oct 20 '09 at 06:18 PM

Alec Holowka gravatar image

Alec Holowka
41 1 1 3

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

While the answer "No" is strictly correct, you may find the following workaround helpful until Unity3.0 unifies the iPhone and non-iPhone versions.

In your .js file, instead of writing "#if(UNITY_IPHONE)" and "#endif" you can hide it in a multi-line comment like by writing this: "/*#if(UNITY_IPHONE)" and "#endif*/" your code will be hidden while working in your non-iphone version of the project.

After you do a fresh checkout of your project and are ready to try it in the iphone version of unity, run this python script:

import os
for root, dirs, files in os.walk(os.getcwd()):
        for file in files:
                if (file[-3::] == '.js'):
                        filePath = os.path.join(root,file)
                        fileStr = open(filePath).read()
                        fileStr = fileStr.replace ('/*#if(UNITY_IPHONE)', '')
                        fileStr = fileStr.replace ('#endif*/', '')
                        open(filePath,'w').write(fileStr)
        if ('.svn' in dirs):
                dirs.remove('.svn')

Definitely not a permanent solution! It doesn't support "#else". It won't touch anything in your svn directories. Since I don't actually use a lot of javascript and just need some existing scripts to compile on both, It will hold me over until summer.

It seems like like python or bash is the right tool here; a C# editor script wouldn't be able to run until after all your unity stuff could compile, which is what this script is supposed to make happen!

more ▼

answered Apr 23 '10 at 06:22 PM

DtBeloBrown gravatar image

DtBeloBrown
433 6 7 19

(comments are locked)
10|3000 characters needed characters left

No. Sorry. We'll note this down as a feature request

more ▼

answered Oct 20 '09 at 10:27 PM

Lucas Meijer 1 gravatar image

Lucas Meijer 1 ♦♦
7.9k 19 43 85

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1999
x108

asked: Oct 20 '09 at 06:18 PM

Seen: 3440 times

Last Updated: Nov 20 '09 at 01:17 PM