Can I use the mouse instead of the emulation pen to interact with UGUI?

I want to use the mouse to click on the UI, but there will be a problem with the offset, causing the mouse to not interact properly.

Hi there,

The problem you’re encountering is the result of lacking a proper Event Camera for your UI’s Canvas component. zCore’s cameras aren’t publicly exposed in the scene hierarchy, so the best solution currently is to replicate the internal cameras with a public one. It’s a little tricky to do, so see the script below for a demonstration. You’ll have to modify the script slightly. Instead of replicating ZCore.Eye.Left and Right, you should change it to Center. When the script generates the camera on start-up, assign it to your canvas’ public property, Event Camera . This should solve your problem, but let me know if you have any troubles with it.

Alex S.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using zSpace.Core;

public class MimicCams : MonoBehaviour {

	private ZCore core;
	private Camera l_cam;
	private Camera r_cam;
	private GameObject main_cam_obj;

    private static readonly Matrix4x4 s_flipHandednessMap = Matrix4x4.Scale(new Vector4(1.0f, 1.0f, -1.0f));

	void Start () {
		core = GameObject.FindObjectOfType<ZCore>();
		main_cam_obj = core.CurrentCameraObject;

		GameObject l_cam_obj = new GameObject();
		GameObject r_cam_obj = new GameObject();
		l_cam_obj.transform.parent = transform;
		r_cam_obj.transform.parent = transform;
		l_cam_obj.name = "Left Mimc Cam";
		r_cam_obj.name = "Right Mimc Cam";
		l_cam = l_cam_obj.AddComponent<Camera>();
		r_cam = r_cam_obj.AddComponent<Camera>();
		l_cam.enabled = false;
		r_cam.enabled = false;
		l_cam.farClipPlane = 7.5f;
		r_cam.farClipPlane = 7.5f;
	}
	
	void Update () {
		MimicStereoCamera(l_cam, ZCore.Eye.Left);
		MimicStereoCamera(r_cam, ZCore.Eye.Right);
	}

	private void MimicStereoCamera(Camera cam, ZCore.Eye eye){
		cam.projectionMatrix  = core.GetFrustumProjectionMatrix(eye);

		cam.transform.position = core.GetFrustumEyePosition(eye, ZCore.CoordinateSpace.World);

		Matrix4x4 v_mtx = FlipHandedness(core.GetFrustumViewMatrix(eye));
		Matrix4x4 cam_mtx = main_cam_obj.transform.localToWorldMatrix * v_mtx.inverse;
		cam.transform.position = cam_mtx.GetColumn(3);
		cam.transform.rotation =
                    Quaternion.LookRotation(
                        cam_mtx.GetColumn(2),
                        cam_mtx.GetColumn(1));
	}

	private Matrix4x4 FlipHandedness(Matrix4x4 matrix) {
		return s_flipHandednessMap * matrix * s_flipHandednessMap;
	}
}