나는로부터 public 메서드에 액세스하려고 ARCoreBackgroundRenderer
MonoBehavior이며에 위치한 클래스 GoogleARCore
도 MonoBehavior하고라는 다른 클래스, 네임 스페이스 UIController
와라는 다른 네임 스페이스에 있습니다 CompanyController
. 이것이 가능한가? 내가 어떻게 해?
두 번째 클래스에서 호출하려는 방법은 다음과 같습니다.
public void DisableARBackgroundRendering()
{
if (m_CommandBuffer == null || m_Camera == null)
{
return;
}
m_Camera.clearFlags = m_CameraClearFlags;
.......
}
두 번째 클래스에서이 메서드를 간단한 메서드로 호출하고 싶습니다.
일반적으로 해당 API 를 참조하면 도움이됩니다.
ARCoreBackgroundRenderer
( API 참조 ) 자신이 네임 스페이스 의 클래스 라고 말했듯이 GoogleARCore
..
using GoogleARCore;
또는 사용
GoogleARCore.ARCoreBackgroundRenderer
에 코드를 입력하십시오 UIController
.
using UnityEngine;
using GoogleARCore;
namespace CompanyController
{
public class UIController : MonoBehaviour
{
// Reference this via the Inspector by drag and drop
// [SerializeField] simply allows to serialize also private fields in Unity
[SerializeField] private ARCoreBackgroundRenderer arRenderer;
// Alternatively you could as said use the type like
//[SerializeField] private GoogleARCore.ARCoreBackgroundRenderer arRenderer;
private void Awake ()
{
// As a fallback find it on the scene
if(!arRenderer) arRenderer = FindObjectOfType<ARCoreBackgroundRenderer>();
}
public void DisableARBackgroundRendering()
{
// Now use any public method of the arRenderer
arRenderer.SomePublicMethod();
}
}
}
그러나이 방법 DisableARBackgroundRendering
이 private
있고 사용할 수 없다는 것도 알 수 있습니다. 또한 m_Camera
및 m_CommandBuffer
모두는 private
당신이 그들에 액세스 할 수 없습니다 그래서.
당신이 할 수 와 - 당신이 가까이의 구현에 보면 ARBackgroundRenderer
- 원하는 단지 활성화 및 따라 구성 요소를 사용하지 않도록 여기에 할 :
public void EnableARBackgroundRendering(bool enable)
{
arRenderer.enabled = enable;
}
내부적으로 나머지 자체를 처리하므로 메서드, 필드 및 속성에 대한 추가 액세스가 필요하지 않습니다.
private void OnEnable() { if (BackgroundMaterial == null) { Debug.LogError("ArCameraBackground:: No material assigned."); return; } LifecycleManager.Instance.OnSessionSetEnabled += _OnSessionSetEnabled; m_Camera = GetComponent<Camera>(); m_TransitionImageTexture = Resources.Load<Texture2D>("ViewInARIcon"); BackgroundMaterial.SetTexture("_TransitionIconTex", m_TransitionImageTexture); EnableARBackgroundRendering(); // AS YOU SEE IT ALREADY CALLS THIS ANYWAY } private void OnDisable() { LifecycleManager.Instance.OnSessionSetEnabled -= _OnSessionSetEnabled; m_TransitionState = BackgroundTransitionState.BlackScreen; m_CurrentStateElapsed = 0.0f; m_Camera.ResetProjectionMatrix(); DisableARBackgroundRendering(); // AS YOU SEE IT ALREADY CALLS THIS ANYWAY }
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다