Hi!
I need move the canvas depending of the dimension of the VolumeCamera in bound mode, but, when I move it, I cannot interact correctly with the buttons inside to that canvas.
Steps:
- Create a scene.
- Add a VolumeCamera in bound mode with both dimension in (x:1.28; y:0.72; z:0.25).
- Add the component VolumeCameraResizeListener to the GameObject that has the component VolumeCamera.
- Copy the EventSystem of the scene UGUI of the sample of PolySpatial and paste it in your scene.
- Copy the SceneCamera of the scene UGUI of the sample of PolySpatial and paste it in your scene.
- Create a Canvas equals to the scene UGUI of the sample of PolySpatial but without childs.
- Add the script VolumeCameraFollower attached in this post with the fields:
Offset: (0; 0; 0.01)
Is Bounded: true
Horizontal Alignment: Center
Vertical Alignment: Middle
Depth Alignment: Back
Volume Camera: (set the reference) - Add a button as a child of the Canvas
- Test in the simulator or with a physical device, you will see that is difficult click the button pointing to it with the eyes.
I know that we can use the Guest Mode to improve the tracking of our eyes but I also tested it without my component and work fine.
Move the Canvas at runtime is not supported?
I should call a magic function of PolySpatial after move the Canvas to make it work correctly?
Thanks!
using Unity.PolySpatial;
using UnityEngine;
namespace Enviz.AppleVisionProDemo.Runtime
{
public class VolumeCameraFollower : MonoBehaviour
{
[Header("Settings")]
[SerializeField] private Vector3 m_Offset = default;
[SerializeField] private bool m_IsBounded = default;
[SerializeField] private HorizontalAlignmentTypes m_HorizontalAlignment = HorizontalAlignmentTypes.Center;
[SerializeField] private VerticalAlignmentTypes m_VerticalAlignment = VerticalAlignmentTypes.Middle;
[SerializeField] private DepthAlignmentTypes m_DepthAlignment = DepthAlignmentTypes.Middle;
[Header("References")]
[SerializeField] private VolumeCamera m_VolumeCamera = default;
private void Update()
{
if (m_VolumeCamera == null)
{
return;
}
if (!m_IsBounded)
{
transform.position = m_VolumeCamera.transform.position + m_Offset;
return;
}
var x = m_HorizontalAlignment switch
{
HorizontalAlignmentTypes.Left => m_VolumeCamera.Dimensions.x / -2f,
HorizontalAlignmentTypes.Center => 0f,
HorizontalAlignmentTypes.Right => m_VolumeCamera.Dimensions.x / 2f,
_ => throw new System.Exception($"Not supported: {m_HorizontalAlignment}"),
};
var y = m_VerticalAlignment switch
{
VerticalAlignmentTypes.Top => m_VolumeCamera.Dimensions.y / 2f,
VerticalAlignmentTypes.Middle => 0f,
VerticalAlignmentTypes.Bottom => m_VolumeCamera.Dimensions.y / -2f,
_ => throw new System.Exception($"Not supported: {m_VerticalAlignment}"),
};
var z = m_DepthAlignment switch
{
DepthAlignmentTypes.Front => m_VolumeCamera.Dimensions.z / 2f,
DepthAlignmentTypes.Middle => 0f,
DepthAlignmentTypes.Back => m_VolumeCamera.Dimensions.z / -2f,
_ => throw new System.Exception($"Not supported: {m_DepthAlignment}"),
};
transform.position = m_VolumeCamera.transform.position + m_Offset + new Vector3(x, y, z);
}
public enum HorizontalAlignmentTypes
{
Left,
Center,
Right
}
public enum VerticalAlignmentTypes
{
Top,
Middle,
Bottom
}
public enum DepthAlignmentTypes
{
Front,
Middle,
Back
}
}
}