我将材料路径存储在Unity中的.plist中,并在运行时将它们渲染到我的对象中。代码如下所示:
public static Dictionary<string, object> uiElements = (Dictionary<string, object>)Plist.readPlist("Assets/EditUI.plist");
foreach (string key in User.purchasedItems.Keys)
{
GameObject tmpObj = (GameObject)Instantiate(Resources.Load(key) ,position ,Quaternion.identity);
tmpObj.transform.localScale = Vector3.one;
tmpObj.SetActive(true);
}
它在Unity编辑器中运行良好,但是当我进行iOS构建(Xcode项目)时,没有任何内容被加载。一切都是空的。我无法弄清楚问题是plist路径还是运行时加载。与自定义plist相关的东西也在这里发布,没有解决方案:
http://answers.unity3d.com/questions/468667/custom-plist-file-not-added-to-ios-project.html
答案 0 :(得分:0)
您需要使用Unity's iOS Scripting API将文件添加到Xcode项目中。创建一个PostProcessBuild
脚本,执行以下操作:
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
{
// Go get pbxproj file
string projPath = path + "/Unity-iPhone.xcodeproj/project.pbxproj";
// PBXProject class represents a project build settings file,
// here is how to read that in.
PBXProject proj = new PBXProject ();
proj.ReadFromFile (projPath);
// This is the Xcode target in the generated project
string target = proj.TargetGuidByName ("Unity-iPhone");
// Copy plist from the project folder to the build folder
FileUtil.CopyFileOrDirectory ("Assets/EditUI.plist", path + "/EditUI.plist");
proj.AddFileToBuild (target, proj.AddFile("EditUI.plist", "EditUI.plist"));
// Write PBXProject object back to the file
proj.WriteToFile (projPath);
}