浏览代码

Update scripts to new API

/1.5-preview
Tim Mowrer 6 年前
当前提交
ed830459
共有 9 个文件被更改,包括 107 次插入40 次删除
  1. 11
      Assets/Scripts/ARFeatheredPlaneMeshVisualizer.cs
  2. 17
      Assets/Scripts/ARWorldMapController.cs
  3. 18
      Assets/Scripts/DisableVerticalPlanes.cs
  4. 31
      Assets/Scripts/LightEstimation.cs
  5. 8
      Assets/Scripts/MakeAppearOnPlane.cs
  6. 11
      Assets/Scripts/PlaceMultipleObjectsOnPlane.cs
  7. 10
      Assets/Scripts/PlaceOnPlane.cs
  8. 5
      Assets/Scripts/PlaneDetectionController.cs
  9. 36
      Assets/Scripts/UX/UIManager.cs

11
Assets/Scripts/ARFeatheredPlaneMeshVisualizer.cs


{
m_PlaneMeshVisualizer = GetComponent<ARPlaneMeshVisualizer>();
m_FeatheredPlaneMaterial = GetComponent<MeshRenderer>().material;
m_Plane = GetComponent<ARPlane>();
m_PlaneMeshVisualizer.meshUpdated += ARPlaneMeshVisualizer_meshUpdated;
m_Plane.boundaryChanged += ARPlane_boundaryUpdated;
m_PlaneMeshVisualizer.meshUpdated -= ARPlaneMeshVisualizer_meshUpdated;
m_Plane.boundaryChanged -= ARPlane_boundaryUpdated;
void ARPlaneMeshVisualizer_meshUpdated(ARPlaneMeshVisualizer planeMeshVisualizer)
void ARPlane_boundaryUpdated(ARPlaneBoundaryChangedEventArgs eventArgs)
GenerateBoundaryUVs(planeMeshVisualizer.mesh);
GenerateBoundaryUVs(m_PlaneMeshVisualizer.mesh);
}
/// <summary>

static List<Vector3> s_Vertices = new List<Vector3>();
ARPlaneMeshVisualizer m_PlaneMeshVisualizer;
ARPlane m_Plane;
Material m_FeatheredPlaneMaterial;
}

17
Assets/Scripts/ARWorldMapController.cs


using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;
using UnityEngine.XR.ARSubsystems;
#if UNITY_IOS
using UnityEngine.XR.ARKit;
#endif

#if UNITY_IOS
IEnumerator Save()
{
var sessionSubsystem = ARSubsystemManager.sessionSubsystem;
var sessionSubsystem = (ARKitSessionSubsystem)m_ARSession.subsystem;
if (sessionSubsystem == null)
{
Log("No session subsystem available. Could not save.");

IEnumerator Load()
{
var sessionSubsystem = ARSubsystemManager.sessionSubsystem;
var sessionSubsystem = (ARKitSessionSubsystem)m_ARSession.subsystem;
if (sessionSubsystem == null)
{
Log("No session subsystem available. Could not load.");

get
{
#if UNITY_IOS
var sessionSubsystem = ARSubsystemManager.sessionSubsystem;
var sessionSubsystem = (ARKitSessionSubsystem)m_ARSession.subsystem;
return sessionSubsystem.WorldMapSupported();
return sessionSubsystem.worldMapSupported;
#endif
return false;
}

SetActive(mappingStatusText, false);
}
var sessionSubsystem = ARSubsystemManager.sessionSubsystem;
#if UNITY_IOS
var sessionSubsystem = (ARKitSessionSubsystem)m_ARSession.subsystem;
#else
XRSessionSubsystem sessionSubsystem = null;
#endif
if (sessionSubsystem == null)
return;

SetText(logText, msg);
#if UNITY_IOS
SetText(mappingStatusText, string.Format("Mapping Status: {0}", sessionSubsystem.GetWorldMappingStatus()));
SetText(mappingStatusText, string.Format("Mapping Status: {0}", sessionSubsystem.worldMappingStatus));
#endif
}

18
Assets/Scripts/DisableVerticalPlanes.cs


using UnityEngine;
using UnityEngine.Experimental.XR;
using UnityEngine.XR.ARSubsystems;
/// <summary>
/// This example demonstrates disabling vertical planes as they are

void OnEnable()
{
GetComponent<ARPlaneManager>().planeAdded += OnPlaneAdded;
GetComponent<ARPlaneManager>().planesChanged += OnPlaneAdded;
GetComponent<ARPlaneManager>().planeAdded -= OnPlaneAdded;
GetComponent<ARPlaneManager>().planesChanged -= OnPlaneAdded;
void OnPlaneAdded(ARPlaneAddedEventArgs eventArgs)
void OnPlaneAdded(ARPlanesChangedEventArgs eventArgs)
var plane = eventArgs.plane;
foreach (var plane in eventArgs.added)
DisableIfVertical(plane);
}
void DisableIfVertical(ARPlane plane)
{
if (plane.boundedPlane.Alignment == PlaneAlignment.Vertical)
if (plane.alignment == PlaneAlignment.Vertical)
{
// Disable the entire GameObject.
plane.gameObject.SetActive(false);

logText.text = string.Format("\n{0}", plane.boundedPlane.Id);
logText.text = string.Format("\n{0}", plane.trackableId);
}
}
}

31
Assets/Scripts/LightEstimation.cs


[RequireComponent(typeof(Light))]
public class LightEstimation : MonoBehaviour
{
[SerializeField]
[Tooltip("The ARCameraManager which will produce frame events containing light estimation information.")]
ARCameraManager m_CameraManager;
/// <summary>
/// Get or set the <c>ARCameraManager</c>.
/// </summary>
public ARCameraManager cameraManager
{
get { return m_CameraManager; }
set
{
if (m_CameraManager == value)
return;
if (m_CameraManager != null)
m_CameraManager.frameReceived -= FrameChanged;
m_CameraManager = value;
if (m_CameraManager != null & enabled)
m_CameraManager.frameReceived += FrameChanged;
}
}
/// <summary>
/// The estimated brightness of the physical environment, if available.
/// </summary>

void OnEnable()
{
ARSubsystemManager.cameraFrameReceived += FrameChanged;
if (m_CameraManager != null)
m_CameraManager.frameReceived += FrameChanged;
ARSubsystemManager.cameraFrameReceived -= FrameChanged;
if (m_CameraManager != null)
m_CameraManager.frameReceived -= FrameChanged;
}
void FrameChanged(ARCameraFrameEventArgs args)

8
Assets/Scripts/MakeAppearOnPlane.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.XR;
using UnityEngine.XR.ARSubsystems;
/// <summary>
/// Moves the ARSessionOrigin in such a way that it makes the given content appear to be

[RequireComponent(typeof(ARRaycastManager))]
public class MakeAppearOnPlane : MonoBehaviour
{
[SerializeField]

void Awake()
{
m_SessionOrigin = GetComponent<ARSessionOrigin>();
m_RaycastManager = GetComponent<ARRaycastManager>();
}
void Update()

var touch = Input.GetTouch(0);
if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
if (m_RaycastManager.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
{
// Raycast hits are sorted by distance, so the first one
// will be the closest hit.

static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>();
ARSessionOrigin m_SessionOrigin;
ARRaycastManager m_RaycastManager;
}

11
Assets/Scripts/PlaceMultipleObjectsOnPlane.cs


using System;
using System.Collections;
using UnityEngine.Experimental.XR;
using UnityEngine.XR.ARSubsystems;
[RequireComponent(typeof(ARSessionOrigin))]
[RequireComponent(typeof(ARRaycastManager))]
public class PlaceMultipleObjectsOnPlane : MonoBehaviour
{
[SerializeField]

/// </summary>
public static event Action onPlacedObject;
ARSessionOrigin m_SessionOrigin;
ARRaycastManager m_RaycastManager;
m_SessionOrigin = GetComponent<ARSessionOrigin>();
m_RaycastManager = GetComponent<ARRaycastManager>();
}
void Update()

if (touch.phase == TouchPhase.Began)
{
if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
if (m_RaycastManager.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
{
Pose hitPose = s_Hits[0].pose;

10
Assets/Scripts/PlaceOnPlane.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.XR;
using UnityEngine.XR.ARSubsystems;
/// <summary>
/// Listens for touch events and performs an AR raycast from the screen touch point.

/// and moved to the hit position.
/// </summary>
[RequireComponent(typeof(ARSessionOrigin))]
[RequireComponent(typeof(ARRaycastManager))]
public class PlaceOnPlane : MonoBehaviour
{
[SerializeField]

void Awake()
{
m_SessionOrigin = GetComponent<ARSessionOrigin>();
m_RaycastManager = GetComponent<ARRaycastManager>();
}
void Update()

var touch = Input.GetTouch(0);
if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
if (m_RaycastManager.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
{
// Raycast hits are sorted by distance, so the first one
// will be the closest hit.

static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>();
ARSessionOrigin m_SessionOrigin;
ARRaycastManager m_RaycastManager;
}

5
Assets/Scripts/PlaneDetectionController.cs


/// <param name="value">Each planes' GameObject is SetActive with this value.</param>
void SetAllPlanesActive(bool value)
{
m_ARPlaneManager.GetAllPlanes(s_Planes);
foreach (var plane in s_Planes)
foreach (var plane in m_ARPlaneManager.trackables)
plane.gameObject.SetActive(value);
}

}
ARPlaneManager m_ARPlaneManager;
static List<ARPlane> s_Planes = new List<ARPlane>();
}

36
Assets/Scripts/UX/UIManager.cs


public class UIManager : MonoBehaviour
{
[SerializeField]
[Tooltip("The ARCameraManager which will produce frame events.")]
ARCameraManager m_CameraManager;
/// <summary>
/// Get or set the <c>ARCameraManager</c>.
/// </summary>
public ARCameraManager cameraManager
{
get { return m_CameraManager; }
set
{
if (m_CameraManager == value)
return;
if (m_CameraManager != null)
m_CameraManager.frameReceived -= FrameChanged;
m_CameraManager = value;
if (m_CameraManager != null & enabled)
m_CameraManager.frameReceived += FrameChanged;
}
}
const string k_FadeOffAnim = "FadeOff";
const string k_FadeOnAnim = "FadeOn";

void OnEnable()
{
ARSubsystemManager.cameraFrameReceived += FrameChanged;
if (m_CameraManager != null)
m_CameraManager.frameReceived += FrameChanged;
ARSubsystemManager.cameraFrameReceived -= FrameChanged;
if (m_CameraManager != null)
m_CameraManager.frameReceived -= FrameChanged;
PlaceMultipleObjectsOnPlane.onPlacedObject -= PlacedObject;
}

if (planeManager == null)
return false;
planeManager.GetAllPlanes(s_Planes);
return s_Planes.Count > 0;
return planeManager.trackables.count > 0;
}
void PlacedObject()

正在加载...
取消
保存