浏览代码

Add a sample showing how to place content with scale

/1.5-preview
Tim Mowrer 6 年前
当前提交
762d8bf0
共有 6 个文件被更改,包括 1146 次插入0 次删除
  1. 1001
      Assets/Scenes/Scale.unity
  2. 7
      Assets/Scenes/Scale.unity.meta
  3. 57
      Assets/Scripts/MakeAppearOnPlane.cs
  4. 11
      Assets/Scripts/MakeAppearOnPlane.cs.meta
  5. 59
      Assets/Scripts/ScaleController.cs
  6. 11
      Assets/Scripts/ScaleController.cs.meta

1001
Assets/Scenes/Scale.unity
文件差异内容过多而无法显示
查看文件

7
Assets/Scenes/Scale.unity.meta


fileFormatVersion: 2
guid: 13ac91f677dc22f4ca320ef8ae727b68
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

57
Assets/Scripts/MakeAppearOnPlane.cs


using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Experimental.XR;
using UnityEngine.XR.ARFoundation;
[RequireComponent(typeof(ARSessionOrigin))]
public class MakeAppearOnPlane : MonoBehaviour
{
[SerializeField]
Transform m_Content;
public Transform content
{
get { return m_Content; }
set { m_Content = value; }
}
[SerializeField]
Quaternion m_Rotation;
public Quaternion rotation
{
get { return m_Rotation; }
set
{
m_Rotation = value;
if (m_SessionOrigin != null)
m_SessionOrigin.MakeContentAppearAt(content, content.transform.position, m_Rotation);
}
}
void Awake()
{
m_SessionOrigin = GetComponent<ARSessionOrigin>();
}
void Update()
{
if (Input.touchCount == 0 || m_Content == null)
return;
var touch = Input.GetTouch(0);
if (m_SessionOrigin.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
{
// Raycast hits are sorted by distance, so the first one
// will be the closest hit.
var hitPose = s_Hits[0].pose;
m_SessionOrigin.MakeContentAppearAt(content, hitPose.position, m_Rotation);
}
}
static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>();
ARSessionOrigin m_SessionOrigin;
}

11
Assets/Scripts/MakeAppearOnPlane.cs.meta


fileFormatVersion: 2
guid: 32a0d282cb4f2bf45b5e443d47af5ac3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

59
Assets/Scripts/ScaleController.cs


using UnityEngine;
using UnityEngine.UI;
using UnityEngine.XR.ARFoundation;
[RequireComponent(typeof(ARSessionOrigin))]
public class ScaleController : MonoBehaviour
{
[SerializeField]
Slider m_Slider;
public Slider slider
{
get { return m_Slider; }
set { m_Slider = value; }
}
[SerializeField]
public float m_Min = .1f;
public float min
{
get { return m_Min; }
set { m_Min = value; }
}
[SerializeField]
public float m_Max = 10f;
public float max
{
get { return m_Max; }
set { m_Max = value; }
}
public void SetScale()
{
if (slider == null)
return;
float scale = slider.value * (max - min) + min;
m_SessionOrigin.transform.localScale = Vector3.one * scale;
}
void Awake()
{
m_SessionOrigin = GetComponent<ARSessionOrigin>();
}
void OnEnable()
{
if (slider != null)
{
var scale = m_SessionOrigin.transform.localScale.x;
slider.value = (scale - min) / (max - min);
}
}
ARSessionOrigin m_SessionOrigin;
}

11
Assets/Scripts/ScaleController.cs.meta


fileFormatVersion: 2
guid: 73cae9c7ea34fe64891a0c865e8781f2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存