Beispiel #1
0
    public List <ARReferenceObject> LoadReferenceObjectsInSet()
    {
        List <ARReferenceObject> listRefObjects = new List <ARReferenceObject> ();

        if (UnityARSessionNativeInterface.IsARKit_2_0_Supported() == false)
        {
            return(listRefObjects);
        }

        string folderPath       = Application.streamingAssetsPath + "/ARReferenceObjects/" + resourceGroupName + ".arresourcegroup";
        string contentsJsonPath = Path.Combine(folderPath, "Contents.json");

        ARResourceGroupContents resGroupContents = JsonUtility.FromJson <ARResourceGroupContents>(File.ReadAllText(contentsJsonPath));

        foreach (ARResourceGroupResource arrgr in resGroupContents.resources)
        {
            string objectFolderPath = Path.Combine(folderPath, arrgr.filename);
            string objJsonPath      = Path.Combine(objectFolderPath, "Contents.json");
            ARReferenceObjectResourceContents resourceContents = JsonUtility.FromJson <ARReferenceObjectResourceContents> (File.ReadAllText(objJsonPath));
            string            fileToLoad = Path.Combine(objectFolderPath, resourceContents.objects [0].filename);
            ARReferenceObject arro       = ARReferenceObject.Load(fileToLoad);
            arro.name = resourceContents.referenceObjectName;
            listRefObjects.Add(arro);
        }

        return(listRefObjects);
    }
    static void AddReferenceObjectAssetToResourceGroup(ARReferenceObjectAsset arro, string parentFolderFullPath, string projectRelativePath, PBXProject project)
    {
        ARReferenceObjectResourceContents resourceContents = new ARReferenceObjectResourceContents();

        resourceContents.info         = new ARResourceInfo();
        resourceContents.info.author  = "unity";
        resourceContents.info.version = 1;

        resourceContents.objects           = new ARResourceFilename[1];
        resourceContents.objects [0]       = new ARResourceFilename();
        resourceContents.objects [0].idiom = "universal";

        //add folder for reference image
        string folderToCreate        = arro.objectName + ".arreferenceobject";
        string folderFullPath        = Path.Combine(parentFolderFullPath, folderToCreate);
        string projectRelativeFolder = Path.Combine(projectRelativePath, folderToCreate);

        Directory.CreateDirectory(folderFullPath);
        project.AddFolderReference(folderFullPath, projectRelativeFolder);

        //copy file from texture asset
        string objectPath     = AssetDatabase.GetAssetPath(arro.referenceObject);
        string objectFilename = Path.GetFileName(objectPath);
        var    dstPath        = Path.Combine(folderFullPath, objectFilename);

        File.Copy(objectPath, dstPath, true);
        project.AddFile(dstPath, Path.Combine(projectRelativeFolder, objectFilename));
        resourceContents.objects [0].filename = objectFilename;

        //add contents.json file
        string contentsJsonPath = Path.Combine(folderFullPath, "Contents.json");

        File.WriteAllText(contentsJsonPath, JsonUtility.ToJson(resourceContents, true));
        project.AddFile(contentsJsonPath, Path.Combine(projectRelativeFolder, "Contents.json"));
    }