AR Foundation演示项目,使用 AR Foundation 4.1.7 并围绕某些功能演示更高级功能。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

76 行
2.2 KiB

using UnityEngine;
public class DistanceManager : MonoBehaviour
{
[SerializeField]
[Tooltip("Image Tracking manager that detects tracked images")]
ImageTrackingObjectManager m_ImageTrackingObjectManager;
/// <summary>
/// Get the <c>ImageTrackingObjectManger</c>
/// </summary>
public ImageTrackingObjectManager imageTrackingObjectManager
{
get => m_ImageTrackingObjectManager;
set => m_ImageTrackingObjectManager = value;
}
[SerializeField]
[Tooltip("Prefab to be spawned and showed between numbers based on distance")]
GameObject m_SumPrefab;
/// <summary>
/// Get the sum prefab
/// </summary>
public GameObject sumPrefab
{
get => m_SumPrefab;
set => m_SumPrefab = value;
}
GameObject m_SpawnedSumPrefab;
GameObject m_OneObject;
GameObject m_TwoObject;
float m_Distance;
bool m_SumActive;
const float k_SumDistance = 0.3f;
void Start()
{
m_SpawnedSumPrefab = Instantiate(m_SumPrefab, Vector3.zero, Quaternion.identity);
m_SpawnedSumPrefab.SetActive(false);
}
void Update()
{
m_OneObject = m_ImageTrackingObjectManager.spawnedOnePrefab;
m_TwoObject = m_ImageTrackingObjectManager.spawnedTwoPrefab;
if (m_ImageTrackingObjectManager.NumberOfTrackedImages() > 1)
{
m_Distance = Vector3.Distance(m_OneObject.transform.position, m_TwoObject.transform.position);
if (m_Distance <= k_SumDistance)
{
if (!m_SumActive)
{
m_SpawnedSumPrefab.SetActive(true);
m_SumActive = true;
}
m_SpawnedSumPrefab.transform.position = (m_OneObject.transform.position + m_TwoObject.transform.position) / 2;
}
else
{
m_SpawnedSumPrefab.SetActive(false);
m_SumActive = false;
}
}
else
{
m_SpawnedSumPrefab.SetActive(false);
m_SumActive = false;
}
}
}