您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

89 行
2.1 KiB

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.ARFoundation;
public class UIManager : MonoBehaviour
{
const string k_FadeOffAnim = "FadeOff";
const string k_FadeOnAnim = "FadeOn";
[SerializeField]
ARPlaneManager m_PlaneManager;
public ARPlaneManager planeManager
{
get { return m_PlaneManager; }
set { m_PlaneManager = value; }
}
[SerializeField]
Animator m_MoveDeviceAnimation;
public Animator moveDeviceAnimation
{
get { return m_MoveDeviceAnimation; }
set { m_MoveDeviceAnimation = value; }
}
[SerializeField]
Animator m_TapToPlaceAnimation;
public Animator tapToPlaceAnimation
{
get { return m_TapToPlaceAnimation; }
set { m_TapToPlaceAnimation = value; }
}
static List<ARPlane> s_Planes = new List<ARPlane>();
bool m_ShowingTapToPlace = false;
bool m_ShowingMoveDevice = true;
void OnEnable()
{
ARSubsystemManager.cameraFrameReceived += FrameChanged;
PlaceMultipleObjectsOnPlane.onPlacedObject += PlacedObject;
}
void OnDisable()
{
ARSubsystemManager.cameraFrameReceived -= FrameChanged;
PlaceMultipleObjectsOnPlane.onPlacedObject -= PlacedObject;
}
void FrameChanged(ARCameraFrameEventArgs args)
{
if (PlanesFound() && m_ShowingMoveDevice)
{
if (moveDeviceAnimation)
moveDeviceAnimation.SetTrigger(k_FadeOffAnim);
if (tapToPlaceAnimation)
tapToPlaceAnimation.SetTrigger(k_FadeOnAnim);
m_ShowingTapToPlace = true;
m_ShowingMoveDevice = false;
}
}
bool PlanesFound()
{
if (planeManager == null)
return false;
planeManager.GetAllPlanes(s_Planes);
return s_Planes.Count > 0;
}
void PlacedObject()
{
if (m_ShowingTapToPlace)
{
if (tapToPlaceAnimation)
tapToPlaceAnimation.SetTrigger(k_FadeOffAnim);
m_ShowingTapToPlace = false;
}
}
}