- Home /
#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?
Answer by DtBeloBrown · Apr 23, 2010 at 06:22 PM
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!
Answer by Lucas Meijer 1 · Oct 20, 2009 at 10:27 PM
No. Sorry. We'll note this down as a feature request
Your answer
Follow this Question
Related Questions
How to use GetComponent on Unity iPhone? 2 Answers
Why am I getting "X" is not a member of "Y" on Unity iPhone, when it works regular Unity? 1 Answer
Is using MonoDevelop worth it if you are writing in JavaScript and using Unity iPhone? 1 Answer