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

56 行
1.5 KiB

using UnityEngine;
using UnityEngine.XR.ARFoundation;
namespace UnityEngine.XR.ARFoundation.Samples
{
[RequireComponent(typeof(ARPlane))]
[RequireComponent(typeof(Animator))]
public class FadePlaneOnBoundaryChange : MonoBehaviour
{
const string k_FadeOffAnim = "FadeOff";
const string k_FadeOnAnim = "FadeOn";
const float k_TimeOut = 2.0f;
Animator m_Animator;
ARPlane m_Plane;
float m_ShowTime = 0;
bool m_UpdatingPlane = false;
void OnEnable()
{
m_Plane = GetComponent<ARPlane>();
m_Animator = GetComponent<Animator>();
m_Plane.boundaryChanged += PlaneOnBoundaryChanged;
}
void OnDisable()
{
m_Plane.boundaryChanged -= PlaneOnBoundaryChanged;
}
void Update()
{
if (m_UpdatingPlane)
{
m_ShowTime -= Time.deltaTime;
if (m_ShowTime <= 0)
{
m_UpdatingPlane = false;
m_Animator.SetBool(k_FadeOffAnim, true);
m_Animator.SetBool(k_FadeOnAnim, false);
}
}
}
void PlaneOnBoundaryChanged(ARPlaneBoundaryChangedEventArgs obj)
{
m_Animator.SetBool(k_FadeOffAnim, false);
m_Animator.SetBool(k_FadeOnAnim, true);
m_UpdatingPlane = true;
m_ShowTime = k_TimeOut;
}
}
}