鍙傝冩枃妗o細https://docs.unity3d.com/Manual/PlatformDependentCompilation.html
鍦║nity寮鍙戜腑锛屽彲浠ヤ娇鐢ㄩ缂栬瘧鏉′欢锛屽畯瀹氫箟銆傛瘮濡傚湪涓涓猚s鏂囦欢涓
|
鍦ㄦ枃浠剁殑棣栬瀹氫箟涓涓眬閮ㄥ畯锛屼粎闄愬湪鏈枃浠朵腑鏈夋晥銆傜劧鍚庝娇鐢#if鐨勬柟寮忓垽鏂槸鍚﹀瓨鍦ㄨ繖涓畯锛屽鏋滃瓨鍦ㄥ垯杩愯DoSomeThing1锛屽惁鍒欒繍琛孌oSomeThing2銆傛敞鎰忕紪璇戞椂锛屼細鎶婁笉闇瑕佽繍琛岀殑浠g爜绉婚櫎鎺夈傛墍浠ョ紪璇戝嚭鏉ョ殑浠g爜涓璖tart鍑芥暟涓笉浼氬嚭鐜癉oSomeThing2銆
闄や簡杩欑鎴戜滑瀹氫箟鐨勫眬閮ㄥ畯锛岃繕鏈変竴绉嶆槸鍏ㄥ眬瀹忥紝鍦ㄦ暣涓伐绋嬩腑閮界敓鏁堛傛瘮濡
#if UNITY_EDITOR DoSomething(); #elif UNITY_ANDROID DoSomething2(); #endif |
琛ㄧず鍒嗗埆鍦ㄧ紪杈戝櫒鐜涓嬪拰android鐜涓嬪仛鏌愪簺澶勭悊銆
杩欎釜瀹忔槸Unity鎻愪緵鐨勫叏灞瀹忋娉ㄦ剰锛氭湰鏂囦互涓嬬殑瀹忛兘鏄寚鍏ㄥ眬瀹銆
Unity涓殑瀹
杩欑被鐨勫畯瀹氫箟鏈変互涓嬪嚑绉嶃
骞冲彴绫诲畯
鐢变簬鍚勪釜骞冲彴鐨勫疄鐜板拰鎺ュ彛閮戒笉鍚岋紝鎵浠ュ緢澶氭椂鍊欓渶瑕佹牴鎹钩鍙版潵鍋氥俇nity鎻愪緵浜嗚鐩栦簡澶ч儴鍒嗚澶囩殑瀹忓畾涔夈
- UNITY_EDITOR #define directive for calling Unity Editor scripts from your game code.
- UNITY_EDITOR_WIN #define directive for Editor code on Windows.
- UNITY_EDITOR_OSX #define directive for Editor code on Mac OS X.
- UNITY_STANDALONE_OSX #define directive for compiling/executing code specifically for Mac OS X (including Universal, PPC and Intel architectures).
- UNITY_STANDALONE_WIN #define directive for compiling/executing code specifically for Windows standalone applications.
- UNITY_STANDALONE_LINUX #define directive for compiling/executing code specifically for Linux standalone applications.
- UNITY_STANDALONE #define directive for compiling/executing code for any standalone platform (Mac OS X, Windows or Linux).
- UNITY_WII #define directive for compiling/executing code for the Wii console.
- UNITY_IOS #define directive for compiling/executing code for the iOS platform.
- UNITY_IPHONE Deprecated. Use UNITY_IOS instead.
- UNITY_ANDROID #define directive for the Android platform.
- UNITY_PS4 #define directive for running PlayStation 4 code.
- UNITY_SAMSUNGTV #define directive for executing Samsung TV code.
- UNITY_XBOXONE #define directive for executing Xbox One code.
- UNITY_TIZEN #define directive for the Tizen platform.
- UNITY_TVOS #define directive for the Apple TV platform.
- UNITY_WSA #define directive for Universal Windows Platform. Additionally, NETFX_CORE is defined when compiling C# files against .NET Core and using .NET scripting backend.
- UNITY_WSA_10_0 #define directive for Universal Windows Platform. Additionally WINDOWS_UWP is defined when compiling C# files against .NET Core.
- UNITY_WINRT Same as UNITY_WSA.
- UNITY_WINRT_10_0 Equivalent to UNITY_WSA_10_0
- UNITY_WEBGL #define directive for WebGL.
- UNITY_FACEBOOK #define directive for the Facebook platform (WebGL or Windows standalone).
- UNITY_ADS #define directive for calling Unity Ads methods from your game code. Version 5.2 and above.
- UNITY_ANALYTICS #define directive for calling Unity Analytics methods from your game code. Version 5.2 and above.
- UNITY_ASSERTIONS #define directive for assertions control process.
Unity鐗堟湰绫诲畯
鐢变簬Unity姣忎釜鐗堟湰鐨凙PI鍙兘涓嶅悓锛岃岄」鐩垚鍛樹娇鐢ㄧ殑鏄笉鍚岀増鏈殑Unity銆傝繖鏃跺欏氨闇瑕佹牴鎹増鏈垎鍒疄鐜般
Unity鎻愪緵浜2.6.0涔嬪悗鐨勫ぇ閮ㄥ垎瀹忓畾涔夛紝褰㈠UNITY_X鎴栬匲NITY_X_Y鎴栬匲NITY_X_Y_Z锛屾瘮濡俇NITY_2017_1_0琛ㄧずUnity2017.1.0鐗堟湰銆娉ㄦ剰Unity骞舵病鏈夋彁渚沺atch鐗堟湰鐨勫畯瀹氫箟锛屽悗闈細璇存槑濡備綍瀹炵幇鑷畾涔夌殑瀹銆
浠g爜缂栬瘧绫诲畯
杩欑被瀹忔湁
- ENABLE_MONO Scripting backend #define for Mono.
- ENABLE_IL2CPP Scripting backend #define for IL2CPP.
- ENABLE_DOTNET Scripting backend #define for .NET.
- NETFX_CORE Defined when building scripts against .NET Core class libraries on .NET.
- NET_2_0 Defined when building scripts against .NET 2.0 API compatibility level on Mono and IL2CPP.
- NET_2_0_SUBSET Defined when building scripts against .NET 2.0 Subset API compatibility level on Mono and IL2CPP.
- NET_4_6 Defined when building scripts against .NET 4.6 API compatibility level on Mono and IL2CPP.
- ENABLE_WINMD_SUPPORT Defined when Windows Runtime support is enabled on IL2CPP and .NET. See Windows Runtime Support for more details.
鑷畾涔夊畯
鍦–#宸ョ▼涓紝鎴戜滑鏄彲浠ラ氳繃Project涓婄殑璁剧疆绫诲畾涔夎嚜宸辩殑瀹忋傚涓嬪浘锛岄氳繃鍦≒roject鐨勫睘鎬ч〉闈腑鍙互閰嶇疆瀹忋
浣嗘槸鍦║nity鐢熸垚鐨勫伐绋嬩腑鏄棤娉曟墦寮Project鐨勫睘鎬ч厤缃晫闈€傚洜姝ゆ棤娉曞湪C#宸ョ▼涓繘琛岄厤缃
浣跨敤PlayerSetting瀹氫箟瀹
瑕佽繘琛岃嚜瀹氫箟鐨勫畯锛岄渶瑕佸湪Unity鐨凱layerSetting涓繘琛岃缃紝澶氫釜瀹忓畾涔夐棿鐢ㄥ垎鍙封;鈥濋殧寮銆傝缃殑鏁版嵁浼氳瀛樺偍鍦ㄩ」鐩殑ProjectSettings/ProjectSettings.asset鏂囦欢涓
鐢变簬ProjectSettings/ProjectSettings.asset涓鑸細琚撼鍏ョ増鏈鐞嗭紝鎵浠ラ」鐩殑鍏ㄤ綋鎴愬憳涓鑸兘浼氬悓姝ュ畯瀹氫箟銆備絾鏄湁鏃跺欏瓨鍦ㄥ崟鐙殑鏌愪簺鎴愬憳锛岄渶瑕佽嚜宸卞崟鐙殑鑷畾涔夊畯鐨勬儏鍐点
鐗规畩妗堜緥
鍦║nity2017.2.0f3锛坒3鐗堟湰锛夊拰Unity2017.2.0p2锛坧2鐗堟湰锛夎繖2涓増鏈腑锛岀敱浜庢煇浜汚PI鎺ュ彛鐨勫彉鏇达紝p2鐗堟湰涔﹀啓鐨勪唬鐮佸氨鍦╢3鐗堟湰涓姤閿欍俧3鐗堟湰鏄」鐩ぇ澶氭暟鎴愬憳浣跨敤鐨勭増鏈紝p2鐗堟湰涓哄皯鏁颁汉浣跨敤鐨勭増鏈備絾鏄敱浜嶶nity鐗堟湰鐨勭増鏈畯瀹氫箟涓彧鏈塙NITY_2017_2_0锛屾棤娉曞尯鍒嗘槸f3鐗堟湰鍜宲2鐗堟湰锛屾墍浠ュ彧鑳戒娇鐢ㄨ嚜瀹氫箟瀹忋備絾鏄敱浜嶱layerSetting浼氳鍚屾锛屾墍浠ュ張浼氶犳垚鍏ㄩ儴寮鍚畯鐨勬儏鍐碉紝f3鐗堟湰鍜宲2鐗堟湰渚濈劧鏃犳硶鍖哄垎銆
浣跨敤RSP鏂囦欢瀹氫箟瀹
Unity鎻愪緵涓涓柟娉曪紝鍙互鐢ㄤ竴涓猺sp鏂囦欢鏉ュ畾涔夊畯銆傜劧鍚庡皢rsp鏂囦欢涓嶈绾冲叆鐗堟湰搴撱傝繖鏍峰氨鍙互瑙e喅鐗规畩妗堜緥涓棶棰樸
涓鑸潵璇村紑鍙慤nity鐢ㄧ殑鏄疌#锛岄偅涔堣繖涓猺sp鏂囦欢蹇呴』鍛藉悕涓簃sc.rsp骞朵笖鏀惧湪Assets鐩綍涓嬨備娇鐢╮sp鏂囦欢瀹氫箟瀹忥紝鍙渶瑕佹瘡涓琛岃緭鍏ヤ竴涓-define:<瀹忓悕绉>鈥濆嵆鍙紝姣斿杩欓噷闅忔剰澧炲姞2涓畯瀹氫箟锛
-define:DevTest
-define:UNITY_2017_2_0_P2
杈撳叆瀹屾垚鍚庝繚瀛橀鍑猴紝鍦║nity涓浠绘剰涓涓唬鐮乺eimort涓娆★紝浣縐nity閲嶆柊缂栬瘧銆傚叧闂苟閲嶆柊鎵撳紑浠g爜缂栬緫鍣ㄥ氨浼氱湅鍒拌繖涓狣evTest鐨勫叏灞瀹忓凡缁忕敓鏁堛
鐗规畩妗堜緥鐨勫缓璁
澶ч儴鍒嗘椂鍊欒繕鏄缓璁娇鐢≒layerSetting瀹氫箟瀹忥紝缁熶竴浣跨敤鍚屼竴涓増鏈殑Unity銆
杞浇娉ㄦ槑锛歨ttp://www.codegize.com http://www.cnblogs.com/CodeGize/