您好,登錄后才能下訂單哦!
Unity3D的項(xiàng)目,這周吃虧在宏上了。大背景是項(xiàng)目需要在Unity中用Hudson自動(dòng)生成不同平臺的版本。
程序設(shè)計(jì)語言的預(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
如上面兩段代碼,打開Unity項(xiàng)目(例如PC & Mac Standalone保存的)之后,再打開項(xiàng)目的Script(這里用VS2008+VA),會發(fā)現(xiàn)上述加粗行高亮。即Target和AssetRootPath在編譯前已然確定,且之后不能對其做出變更。
當(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并沒有賦予應(yīng)有的Web相應(yīng)值,會造成生成的Unity3D文件能生成但不對,執(zhí)行BuildPlayer時(shí)會報(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
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。