Unity3D的項(xiàng)目,這周吃虧在宏上了。大背景是項(xiàng)目需要在Unity中用Hudson自動(dòng)生成不同平臺(tái)的版本。
成都創(chuàng)新互聯(lián)公司長(zhǎng)期為上千多家客戶(hù)提供的網(wǎng)站建設(shè)服務(wù),團(tuán)隊(duì)從業(yè)經(jīng)驗(yàn)10年,關(guān)注不同地域、不同群體,并針對(duì)不同對(duì)象提供差異化的產(chǎn)品和服務(wù);打造開(kāi)放共贏平臺(tái),與合作伙伴共同營(yíng)造健康的互聯(lián)網(wǎng)生態(tài)環(huán)境。為科爾沁左翼企業(yè)提供專(zhuān)業(yè)的網(wǎng)站設(shè)計(jì)、成都網(wǎng)站建設(shè),科爾沁左翼網(wǎng)站改版等技術(shù)服務(wù)。擁有10年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制開(kāi)發(fā)。程序設(shè)計(jì)語(yǔ)言的預(yù)處理的概念:在編譯之前進(jìn)行的處理。
#if UNITY_WEBPLAYER
BuildTarget target = BuildTarget.WebPlayer;
#elif UNITY_STANDALONE_WIN && UNITY_EDITOR
BuildTarget target = BuildTarget.StandaloneWindows;
#elif UNITY_ANDROID
BuildTarget target = BuildTarget.Android;
#else
BuildTarget target = BuildTarget.iPhone;
#endif
#if UNITY_WEBPLAYER
public const string AssetRootPath = AutomaticBuild.WebPlatFormDataPath + "/";
#elif UNITY_STANDALONE_WIN && UNITY_EDITOR
public const string AssetRootPath = AutomaticBuild.WinPlatFormDataPath + "/";
#elif UNITY_ANDROID
public const string AssetRootPath = AutomaticBuild.AndRoidPlatFormDataPath + "/";
#else
public const string AssetRootPath = AutomaticBuild.IOSPlatFormDataPath + "/";
#endif
如上面兩段代碼,打開(kāi)Unity項(xiàng)目(例如PC & Mac Standalone保存的)之后,再打開(kāi)項(xiàng)目的Script(這里用VS2008+VA),會(huì)發(fā)現(xiàn)上述加粗行高亮。即Target和AssetRootPath在編譯前已然確定,且之后不能對(duì)其做出變更。
當(dāng)采用Unity支持的命令編譯時(shí)C:\program files\Unity\Editor>Unity.exe -quit -batchmode -executeMethod MyEditorScript.MyMethod
此時(shí)MyMethod可能用了如下代碼,
BuildPipeline.BuildPlayer( levels, "WebPlayerBuild", BuildTarget.WebPlayer, BuildOptions.None);但Target和AssetRootPath并沒(méi)有賦予應(yīng)有的Web相應(yīng)值,會(huì)造成生成的Unity3D文件能生成但不對(duì),執(zhí)行BuildPlayer時(shí)會(huì)報(bào)Runtime Error錯(cuò)。
不禁讓我想起Effective C++里的第2個(gè)條款:盡量以const, enum, inline替換 #define。果然金科玉律……
我的解決方式如下:
1.在MyMethod中先調(diào)用
private static string AssetRootPath = null;
public static string GetAssetRootPath()
{
if (AssetRootPath != null)
return AssetRootPath;
if (EditorUserBuildSettings.activeBuildTarget==BuildTarget.WebPlayer)
{
AssetRootPath = "WebData/LatestData/";
}
else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.Android)
{
AssetRootPath = "AndroidData/LatestData/";
}
else if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.StandaloneWindows)
{
AssetRootPath = "WinData/LatestData/";
}
else
{
AssetRootPath = "IOSData/LatestData/";
}
return AssetRootPath;
}
public static BuildTarget GetBuildTarget()
{
return EditorUserBuildSettings.activeBuildTarget;
}
由于需求的小變更,小小地重構(gòu)了上次的代碼:
ClearISingleFileSeries();}
轉(zhuǎn)載自:http://blog.csdn.net/pandawuwyj/article/details/7959335
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線(xiàn),公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)站欄目:Unity不同平臺(tái)生成中預(yù)處理的注意點(diǎn)-創(chuàng)新互聯(lián)
網(wǎng)址分享:http://vcdvsql.cn/article26/cecccg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供標(biāo)簽優(yōu)化、Google、ChatGPT、虛擬主機(jī)、移動(dòng)網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容