【问题标题】:Custom .plist file not added to ios project自定义 .plist 文件未添加到 ios 项目
【发布时间】:2015-10-29 07:53:42
【问题描述】:

我将材质路径存储在 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

【问题讨论】:

    标签: c# ios xcode unity3d plist


    【解决方案1】:

    您需要使用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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-27
      • 1970-01-01
      • 2015-12-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多