ARFoundation road - environment configuration (iOS) bis

(一)AppController

  In the Project window Scripts folder, right-click the blank space in the pop cascading menu, select Create -> C # Script, create a script file named AppController, as shown below.
Here Insert Picture Description
  Double click AppController script, edit the script in Visual Studio, add the following code.

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;

[RequireComponent(typeof(ARRaycastManager))]
public class AppControler : MonoBehaviour
{
    public  GameObject spawnPrefab;
    static List<ARRaycastHit> Hits;
    private ARRaycastManager mRaycastManager;
    private GameObject spawnedObject = null;
    private void Start()
    {
        Hits = new List<ARRaycastHit>();
        mRaycastManager = GetComponent<ARRaycastManager>();
    }

    void Update()
    {
        if (Input.touchCount == 0)
            return;
        var touch = Input.GetTouch(0);
        if (mRaycastManager.Raycast(touch.position, Hits, TrackableType.PlaneWithinPolygon | TrackableType.PlaneWithinBounds))
        {
            var hitPose = Hits[0].pose;
            if (spawnedObject == null)
            {
                spawnedObject = Instantiate(spawnPrefab, hitPose.position, hitPose.rotation);
            }
            else
            {
                spawnedObject.transform.position = hitPose.position;
            }
        }
    }
}

  In the upper section of the code, we first use the [RequireComponent (typeof (ARRaycastManager))] attribute to ensure that the assembly must be ARRaycastManager add the script object because ray tests need to use ARRaycastManager components. In the Update () method, we gesture-ray detector, placed on the plane of a virtual object is detected, and if the virtual object already exists, then the virtual moving object to detect radiation plane collision point.

  After the above steps, the overall AR application framework has been completely built up, finally, we have created a Sphere in the Hierarchy window, assign it the green material, which is scaled to Scale (0.1,0.1,0.1), and finally made into Prefab Hierarchy scene and remove Sphere, as shown in FIG.
Here Insert Picture Description
  Finally, check the AR Session Origin in the Hierarchy window to add AppController scripted front (you can use the Add Component to add AppController in the search box, or directly onto the AppController script AR Session Origin objects), and on Sphere made AppController step onto the script Spawn Prefab property box.

Here Insert Picture Description
  So far, Helloworld AR application is complete and functional development environment to build.

(B) generate and configure XCode project

  将iPhone手机通过USB线或者WiFi连接上电脑,直接按Command+Shift+B组合键(或者选择File-> Build Settings)打开Build Settings对话框,如下图所示。在打开的对话框中保证选中当前场景,点击Build And Run将生成XCode工程,建议将工程保存到另一个工程文件夹下,设置发布后的程序名,最后点击“保存”按钮开始编译生成XCode工程,生成完成后会自动打开XCode IDE(如果没有自动打开XCode,可以先启动XCode选择右下角的Open another Project,选择我们用Unity发布出来的Xcode工程并打开)。
Here Insert Picture Description

Here Insert Picture Description

  如若编译没有错误,在XCode打开生成的工程后,依次选择XCode工程图标 -->工程名,然后选择发布的设备iPhone手机,因为我们是在要真机上测试应用,如下图所示。
Here Insert Picture Description  在工程属性面板中,选择General选项卡,填写好Display Name(工程名)、Bundle Identifier(包ID)、Version、Build,Bundle Identifier也即是我们在Unity中设置好的Bundle Identifier,如果要发布到AppStore上,Bundle Identifier必须与开发者网站上的设置一样,Version、Build也要符合按递增的要求,并选择开发者证书,如下图所示。
Here Insert Picture Description
  如果还没有开发者账号,可点击Team 框后的下拦菜单,选择Add an Account 新建一个开发者账号,具体操作请参见官方说明文档,如下图所示。

Here Insert Picture Description
Here Insert Picture Description

(三)运行Helloworld

  在XCode配置完后,点击XCode IDE左上角的编译运行图标开始编译、部署、运行。

Here Insert Picture Description
  If the iPhone is the first run XCode applications, but also need to set up, the first step to open the phone settings -> general, find the "Device Manager", as shown below.
Here Insert Picture Description
  After entering the Device Manager, click on the developer account, as shown below.
Here Insert Picture Description
  In the developer of the application management interface, click "Verify apps", iPhone mobile phone will be the developer network authentication, authentication is passed, the application will be "verified" the words, now you can deploy applications to the phone and run the application directly from XCode a.
Here Insert Picture Description
  If the whole process of problem does not occur (in question is inevitable, consult the appropriate information to solve the problems after), after Helloworld AR application is open, to find a relatively flat and the texture rich plane and move around phone plane detection, detection to the plane, the plane finger tap on the phone screen has been detected, a ball will be loaded on the plane, as shown below. At this point, we use iOS ARFoundation developed Helloworld AR application has been successful.
Here Insert Picture Description

Guess you like

Origin blog.csdn.net/yolon3000/article/details/93655054