浏览代码

Merge branch 'tdmowrer-2018.3'

/1.5-preview
Tim Mowrer 6 年前
当前提交
5e6609a9
共有 12 个文件被更改,包括 268 次插入112 次删除
  1. 30
      Assets/Scripts/ARFeatheredPlaneMeshVisualizer.cs
  2. 106
      Assets/Scripts/ARWorldMapController.cs
  3. 13
      Assets/Scripts/DisableVerticalPlanes.cs
  4. 13
      Assets/Scripts/LightEstimation.cs
  5. 71
      Assets/Scripts/LightEstimationUI.cs
  6. 43
      Assets/Scripts/PlaceOnPlane.cs
  7. 18
      Assets/Scripts/PlaneDetectionController.cs
  8. 20
      Assets/Scripts/TestCameraImage.cs
  9. 48
      Packages/manifest.json
  10. 2
      ProjectSettings/ProjectVersion.txt
  11. 13
      README.md
  12. 3
      ProjectSettings/VFXManager.asset

30
Assets/Scripts/ARFeatheredPlaneMeshVisualizer.cs


using System.Collections;
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine.Experimental.XR;
/// <summary>
/// This plane visualizer demonstrates the use of a feathering effect
/// at the edge of the detected plane, which reduces the visual impression
/// of a hard edge.
/// </summary>
float featheringWidth
[Tooltip("The width of the texture feathering (in world units).")]
[SerializeField]
float m_FeatheringWidth = 0.2f;
/// <summary>
/// The width of the texture feathering (in world units).
/// </summary>
public float featheringWidth
[Tooltip("The width of the texture feathering (in world units).")]
[SerializeField]
float m_FeatheringWidth = 0.2f;
ARPlaneMeshVisualizer m_PlaneMeshVisualizer;
Material m_FeatheredPlaneMaterial;
void Awake()
{

}
static List<Vector3> s_FeatheringUVs = new List<Vector3>();
ARPlaneMeshVisualizer m_PlaneMeshVisualizer;
Material m_FeatheredPlaneMaterial;
}

106
Assets/Scripts/ARWorldMapController.cs


/// </remarks>
public class ARWorldMapController : MonoBehaviour
{
[Tooltip("The ARSession component controlling the session from which to generate ARWorldMaps.")]
/// <summary>
/// The ARSession component controlling the session from which to generate ARWorldMaps.
/// </summary>
public ARSession arSession
{
get { return m_ARSession; }
set { m_ARSession = value; }
}
[Tooltip("UI Text component to display error messages")]
/// <summary>
/// The UI Text component used to display error messages
/// </summary>
public Text errorText
{
get { return m_ErrorText; }
set { m_ErrorText = value; }
}
[Tooltip("The UI Text element used to display log messages.")]
Button m_SaveButton;
Text m_LogText;
/// <summary>
/// The UI Text element used to display log messages.
/// </summary>
public Text logText
{
get { return m_LogText; }
set { m_LogText = value; }
}
[Tooltip("The UI Text element used to display the current AR world mapping status.")]
Button m_LoadButton;
Text m_MappingStatusText;
/// <summary>
/// The UI Text element used to display the current AR world mapping status.
/// </summary>
public Text mappingStatusText
{
get { return m_MappingStatusText; }
set { m_MappingStatusText = value; }
}
[Tooltip("A UI button component which will generate an ARWorldMap and save it to disk.")]
Text m_LogText;
Button m_SaveButton;
/// <summary>
/// A UI button component which will generate an ARWorldMap and save it to disk.
/// </summary>
public Button saveButton
{
get { return m_SaveButton; }
set { m_SaveButton = value; }
}
[Tooltip("A UI button component which will load a previously saved ARWorldMap from disk and apply it to the current session.")]
Text m_MappingStatus;
Button m_LoadButton;
/// <summary>
/// A UI button component which will load a previously saved ARWorldMap from disk and apply it to the current session.
/// </summary>
public Button loadButton
{
get { return m_LoadButton; }
set { m_LoadButton = value; }
}
/// <summary>
/// Create an <c>ARWorldMap</c> and save it to disk.

m_LogMessages.Add(logMessage);
}
static void SetActive(Button button, bool active)
{
if (button != null)
button.gameObject.SetActive(active);
}
static void SetActive(Text text, bool active)
{
if (text != null)
text.gameObject.SetActive(active);
}
static void SetText(Text text, string value)
{
if (text != null)
text.text = value;
}
m_ErrorText.gameObject.SetActive(false);
m_SaveButton.gameObject.SetActive(true);
m_LoadButton.gameObject.SetActive(true);
m_MappingStatus.gameObject.SetActive(true);
SetActive(errorText, false);
SetActive(saveButton, true);
SetActive(loadButton, true);
SetActive(mappingStatusText, true);
m_ErrorText.gameObject.SetActive(true);
m_SaveButton.gameObject.SetActive(false);
m_LoadButton.gameObject.SetActive(false);
m_MappingStatus.gameObject.SetActive(false);
SetActive(errorText, true);
SetActive(saveButton, false);
SetActive(loadButton, false);
SetActive(mappingStatusText, false);
}
var sessionSubsystem = ARSubsystemManager.sessionSubsystem;

msg += m_LogMessages[i];
msg += "\n";
}
m_LogText.text = msg;
SetText(logText, msg);
m_MappingStatus.text = string.Format("Mapping Status: {0}", sessionSubsystem.GetWorldMappingStatus());
SetText(mappingStatusText, string.Format("Mapping Status: {0}", sessionSubsystem.GetWorldMappingStatus()));
#endif
}

13
Assets/Scripts/DisableVerticalPlanes.cs


[RequireComponent(typeof(ARPlaneManager))]
public class DisableVerticalPlanes : MonoBehaviour
{
[Tooltip("The UI Text element used to display log messages.")]
/// <summary>
/// The UI Text element used to display log messages.
/// </summary>
public Text logText
{
get { return m_LogText; }
set { m_LogText = value; }
}
void OnEnable()
{

plane.gameObject.SetActive(false);
// Add to our log so the user knows something happened.
m_LogText.text += string.Format("\n{0}", plane.boundedPlane.Id);
if (logText != null)
logText.text = string.Format("\n{0}", plane.boundedPlane.Id);
}
}
}

13
Assets/Scripts/LightEstimation.cs


[RequireComponent(typeof(Light))]
public class LightEstimation : MonoBehaviour
{
Light m_Light;
/// <summary>
/// The estimated brightness of the physical environment, if available.
/// </summary>

m_Light.color = colorCorrection.Value;
}
}
}
Light m_Light;
}

71
Assets/Scripts/LightEstimationUI.cs


using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// A simple UI controller to display light estimation information.
/// </summary>
[Tooltip("The UI Text element used to display the estimated brightness in the physical environment.")]
Text m_BrightnessVal;
Text m_BrightnessText;
/// <summary>
/// The UI Text element used to display the estimated brightness value.
/// </summary>
public Text brightnessText
{
get { return m_BrightnessText; }
set { m_BrightnessText = brightnessText; }
}
[Tooltip("The UI Text element used to display the estimated color temperature in the physical environment.")]
Text m_ColorTempVal;
Text m_ColorTemperatureText;
/// <summary>
/// The UI Text element used to display the estimated color temperature in the scene.
/// </summary>
public Text colorTemperatureText
{
get { return m_ColorTemperatureText; }
set { m_ColorTemperatureText = value; }
}
[Tooltip("The UI Text element used to display the estimated color correction value for the physical environment.")]
Text m_ColorCorrectVal;
Text m_ColorCorrectionText;
LightEstimation m_LightEstimation;
const string k_UnavailableText = "Unavailable";
/// <summary>
/// The UI Text element used to display the estimated color correction value for the scene.
/// </summary>
public Text colorCorrectionText
{
get { return m_ColorCorrectionText; }
set { m_ColorCorrectionText = value; }
}
void Awake()
{

void Update()
{
SetUIValue(m_LightEstimation.brightness, m_BrightnessVal);
SetUIValue(m_LightEstimation.colorTemperature, m_ColorTempVal);
SetUIValue(m_LightEstimation.colorCorrection, m_ColorCorrectVal);
SetUIValue(m_LightEstimation.brightness, brightnessText);
SetUIValue(m_LightEstimation.colorTemperature, colorTemperatureText);
SetUIValue(m_LightEstimation.colorCorrection, colorCorrectionText);
void SetUIValue<T>(T? displayVar, Text uiText) where T : struct
void SetUIValue<T>(T? displayValue, Text text) where T : struct
if (uiText)
{
if (displayVar.HasValue)
{
uiText.text = displayVar.Value.ToString();
}
else
{
uiText.text = k_UnavailableText;
}
}
if (text != null)
text.text = displayValue.HasValue ? displayValue.Value.ToString(): k_UnavailableText;
const string k_UnavailableText = "Unavailable";
LightEstimation m_LightEstimation;
}

43
Assets/Scripts/PlaceOnPlane.cs


using UnityEngine.Experimental.XR;
using UnityEngine.XR.ARFoundation;
/// <summary>
/// Listens for touch events and performs an AR raycast from the screen touch point.
/// AR raycasts will only hit detected trackables like feature points and planes.
///
/// If a raycast hits a trackable, the <see cref="placedPrefab"/> is instantiated
/// and moved to the hit position.
/// </summary>
[RequireComponent(typeof(ARSessionOrigin))]
public class PlaceOnPlane : MonoBehaviour
{

/// </summary>
public GameObject spawnedObject { get; private set; }
ARSessionOrigin m_SessionOrigin;
static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>();
void Awake()
{
m_SessionOrigin = GetComponent<ARSessionOrigin>();

{
if (Input.touchCount > 0)
if (Input.touchCount == 0)
return;
var touch = Input.GetTouch(0);
if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
Touch touch = Input.GetTouch(0);
// Raycast hits are sorted by distance, so the first one
// will be the closest hit.
var hitPose = s_Hits[0].pose;
if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
if (spawnedObject == null)
{
spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation);
}
else
Pose hitPose = s_Hits[0].pose;
if (spawnedObject == null)
{
spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation);
}
else
{
spawnedObject.transform.position = hitPose.position;
}
spawnedObject.transform.position = hitPose.position;
static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>();
ARSessionOrigin m_SessionOrigin;
}

18
Assets/Scripts/PlaneDetectionController.cs


[RequireComponent(typeof(ARPlaneManager))]
public class PlaneDetectionController : MonoBehaviour
{
[Tooltip("The UI Text element used to display plane detection messages.")]
/// The UI Text element used to display plane detection messages.
/// </summary>
public Text togglePlaneDetectionText
{
get { return m_TogglePlaneDetectionText; }
set { m_TogglePlaneDetectionText = value; }
}
/// <summary>
/// Toggles plane detection and the visualization of the planes.
/// </summary>
public void TogglePlaneDetection()

string planeDetectionMessage = "";
m_TogglePlaneDetectionText.text = "Disable Plane Detection and Hide Existing";
planeDetectionMessage = "Disable Plane Detection and Hide Existing";
m_TogglePlaneDetectionText.text = "Enable Plane Detection and Show Existing";
planeDetectionMessage = "Enable Plane Detection and Show Existing";
if (togglePlaneDetectionText != null)
togglePlaneDetectionText.text = planeDetectionMessage;
}
/// <summary>

20
Assets/Scripts/TestCameraImage.cs


using UnityEngine.UI;
using UnityEngine.XR.ARExtensions;
using UnityEngine.XR.ARFoundation;
#if !UNITY_2018_2_OR_NEWER
using Unity.Collections;
#endif
/// <summary>
/// This component tests getting the latest camera image

get { return m_ImageInfo; }
set { m_ImageInfo = value; }
}
Texture2D m_Texture;
void OnEnable()
{

// We can also get a sub rectangle, but we'll get the full image here.
var conversionParams = new CameraImageConversionParams(image, format, CameraImageTransformation.MirrorY);
#if UNITY_2018_2_OR_NEWER
// In 2018.2+, Texture2D allows us write directly to the raw texture data
// Texture2D allows us write directly to the raw texture data
#else
// In 2018.1, Texture2D didn't have this feature, so we'll create
// a temporary buffer and perform the conversion using that data.
int size = image.GetConvertedDataSize(conversionParams);
var rawTextureData = new NativeArray<byte>(size, Allocator.Temp);
var ptr = new IntPtr(rawTextureData.GetUnsafePtr());
image.Convert(conversionParams, ptr, rawTextureData.Length);
m_Texture.LoadRawTextureData(ptr, rawTextureData.Length);
rawTextureData.Dispose();
#endif
// We must dispose of the CameraImage after we're finished
// with it to avoid leaking native resources.

// Set the RawImage's texture so we can visualize it.
m_RawImage.texture = m_Texture;
}
Texture2D m_Texture;
}

48
Packages/manifest.json


{
"dependencies": {
"com.unity.xr.arcore": "1.0.0-preview.23",
"com.unity.xr.arfoundation": "1.0.0-preview.20",
"com.unity.xr.arkit": "1.0.0-preview.17"
}
}
"dependencies": {
"com.unity.ads": "2.3.1",
"com.unity.analytics": "3.2.2",
"com.unity.collab-proxy": "1.2.15",
"com.unity.package-manager-ui": "2.0.3",
"com.unity.purchasing": "2.0.3",
"com.unity.textmeshpro": "1.3.0",
"com.unity.xr.arcore": "1.0.0-preview.23",
"com.unity.xr.arfoundation": "1.0.0-preview.20",
"com.unity.xr.arkit": "1.0.0-preview.17",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.animation": "1.0.0",
"com.unity.modules.assetbundle": "1.0.0",
"com.unity.modules.audio": "1.0.0",
"com.unity.modules.cloth": "1.0.0",
"com.unity.modules.director": "1.0.0",
"com.unity.modules.imageconversion": "1.0.0",
"com.unity.modules.imgui": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.particlesystem": "1.0.0",
"com.unity.modules.physics": "1.0.0",
"com.unity.modules.physics2d": "1.0.0",
"com.unity.modules.screencapture": "1.0.0",
"com.unity.modules.terrain": "1.0.0",
"com.unity.modules.terrainphysics": "1.0.0",
"com.unity.modules.tilemap": "1.0.0",
"com.unity.modules.ui": "1.0.0",
"com.unity.modules.uielements": "1.0.0",
"com.unity.modules.umbra": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.unitywebrequestassetbundle": "1.0.0",
"com.unity.modules.unitywebrequestaudio": "1.0.0",
"com.unity.modules.unitywebrequesttexture": "1.0.0",
"com.unity.modules.unitywebrequestwww": "1.0.0",
"com.unity.modules.vehicles": "1.0.0",
"com.unity.modules.video": "1.0.0",
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.wind": "1.0.0",
"com.unity.modules.xr": "1.0.0"
}
}

2
ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2018.1.1f1
m_EditorVersion: 2018.3.0f1

13
README.md


# AR Foundation Samples
Example projects that utilize *AR Foundation* and demonstrates its functionality with sample assets and components.
Example projects that use *AR Foundation* and demonstrate its functionality with sample assets and components.
Requires Unity version 2018.1+
Requires the AR Foundation package
Compatible with Unity 2018.3.
1. Download the latest version of Unity 2018.1 or 2018.2
1. Download the latest version of Unity 2018.3
3. Open your choice of sample scenes.
3. Open your choice of sample scene.
4. See the documentation for the AR Foundation for usage instructions and more information
See the [AR Foundation Documentation](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@1.0/manual/index.html) to learn how to get started with the core components.
4. See the [AR Foundation Documentation](https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@1.0) for usage instructions and more information.

3
ProjectSettings/VFXManager.asset


�42018.3.0b12����
�7��T���>��VsR�#��7����������  ��0�.�9� B ��0�.�9� U ��0 �.�9
�H�b���� �1�1����� @��� Q�j���{���VFXManagerPPtr<ComputeShader>m_IndirectShaderm_FileIDm_PathIDm_CopyBufferShaderm_SortShaderm_RenderPipeSettingsPathm_FixedTimeStepm_MaxDeltaTime4���<��L=
正在加载...
取消
保存