Я работал с ZXing и ARkit, но никогда вместе.
Пытался заставить что-то работать, чтобы хотя бы дать вам подсказку о том, что может быть возможным.
Как ребенок вашегоARCameraManager, добавьте еще одну (дополнительно к вашей основной камере AR) камеру с прикрепленным к ней сценарием ARVideo (удалите такие вещи, как аудио Listener, слой Flare и guiLayer). Также добавьте следующий сценарий, который просто существует для извлечения renderTexture:
[RequireComponent(typeof(Camera))]
public class WebcamFetcher : MonoBehaviour
{
private RenderTexture _vertical;
private RenderTexture _horizontal;
private Camera _camera;
// Update is called once per frame
public RenderTexture RenderTexture
{
get
{
var orientation = Screen.orientation;
if (orientation == ScreenOrientation.Landscape || orientation == ScreenOrientation.LandscapeLeft || orientation == ScreenOrientation.LandscapeRight)
{
return _horizontal;
}
else
{
return _vertical;
}
}
}
// Use this for initialization
void Start ()
{
_camera = GetComponent<Camera>();
_horizontal = new RenderTexture(Screen.width, Screen.height, 24);
_vertical = new RenderTexture(Screen.height, Screen.width, 24);
}
// Update is called once per frame
void Update()
{
var orientation = Screen.orientation;
if (orientation == ScreenOrientation.Landscape || orientation == ScreenOrientation.LandscapeLeft || orientation == ScreenOrientation.LandscapeRight)
{
_camera.targetTexture = _horizontal;
}
else
{
_camera.targetTexture = _vertical;
}
}
}
Затем используйте такой скрипт, как:
private string DecodeQR(Color32[] pixels, int width, int height)
{
try
{
IBarcodeReader barcodeReader = new BarcodeReader();
// decode the current frame
var result = barcodeReader.Decode(pixels, width, height);
if (result != null)
{
return result.Text;
}
}
catch (Exception ex) { Debug.LogError(ex.Message); }
return null;
}
[SerializeField] Text QrDisplay; // A text field to display detected QRs to
public void OnQrDetect() // a callback for a UI button
{
var texture = new Texture2D(_webcamFetcher.RenderTexture.width, _webcamFetcher.RenderTexture.height);
RenderTexture.active = _webcamFetcher.RenderTexture;
texture.ReadPixels(new Rect(Vector2.zero, new Vector2(_webcamFetcher.RenderTexture.width, _webcamFetcher.RenderTexture.height)), 0, 0);
var qrText = DecodeQR(texture.GetPixels32(), _webcamFetcher.RenderTexture.width, _webcamFetcher.RenderTexture.height);
if (qrText != null)
{
QrDisplay.text = qrText;
}
}
Сработало для меня.Поиск текстуры может быть не самым эффективным.НО это работает -> это возможно.