17
2017
11

Unity瀹+RSP鏂囦欢瀹氫箟瀹

       鍙傝冩枃妗o細https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

       鍦║nity寮鍙戜腑锛屽彲浠ヤ娇鐢ㄩ缂栬瘧鏉′欢锛屽畯瀹氫箟銆傛瘮濡傚湪涓涓猚s鏂囦欢涓

#define DevTest

using UnityEngine;

namespace Test
{
    public class Dev : MonoBehaviour                                      
    {
        public void Start()
        {
#if DevTest
            DoSomeThing();
#else 
            DoSomeThing2();
#endif
        }

        private void DoSomeThing()
        {
        }

        private void DoSomeThing2()
        {
        }
    }
}

       鍦ㄦ枃浠剁殑棣栬瀹氫箟涓涓眬閮ㄥ畯锛屼粎闄愬湪鏈枃浠朵腑鏈夋晥銆傜劧鍚庝娇鐢#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鐨勫睘鎬ч〉闈腑鍙互閰嶇疆瀹忋

2017111701

       浣嗘槸鍦║nity鐢熸垚鐨勫伐绋嬩腑鏄棤娉曟墦寮Project鐨勫睘鎬ч厤缃晫闈€傚洜姝ゆ棤娉曞湪C#宸ョ▼涓繘琛岄厤缃

浣跨敤PlayerSetting瀹氫箟瀹

       瑕佽繘琛岃嚜瀹氫箟鐨勫畯锛岄渶瑕佸湪Unity鐨凱layerSetting涓繘琛岃缃紝澶氫釜瀹忓畾涔夐棿鐢ㄥ垎鍙封;鈥濋殧寮銆傝缃殑鏁版嵁浼氳瀛樺偍鍦ㄩ」鐩殑ProjectSettings/ProjectSettings.asset鏂囦欢涓

2017111702

       鐢变簬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/

芦 涓婁竴绡 涓嬩竴绡 禄