// UI Canvas|UI|80010
namespace VRTK
{
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System.Collections;
using System.Reflection;
using System;
///
/// Denotes a Unity World UI Canvas can be interacted with a UIPointer script.
///
///
/// **Script Usage:**
/// * Place the `VRTK_UICanvas` script on the Unity World UI Canvas to allow UIPointer interactions with.
///
/// **Script Dependencies:**
/// * A UI Pointer attached to another GameObject (e.g. controller script alias) to interact with the UICanvas script.
///
///
/// `VRTK/Examples/034_Controls_InteractingWithUnityUI` uses the `VRTK_UICanvas` script on two of the canvases to show how the UI Pointer can interact with them.
///
[AddComponentMenu("VRTK/Scripts/UI/VRTK_UICanvas")]
public class VRTK_UICanvas : MonoBehaviour
{
[Tooltip("Determines if a UI Click action should happen when a UI Pointer game object collides with this canvas.")]
public bool clickOnPointerCollision = false;
[Tooltip("Determines if a UI Pointer will be auto activated if a UI Pointer game object comes within the given distance of this canvas. If a value of `0` is given then no auto activation will occur.")]
public float autoActivateWithinDistance = 0f;
protected BoxCollider canvasBoxCollider;
protected Rigidbody canvasRigidBody;
protected Coroutine draggablePanelCreation;
protected const string CANVAS_DRAGGABLE_PANEL = "VRTK_UICANVAS_DRAGGABLE_PANEL";
protected const string ACTIVATOR_FRONT_TRIGGER_GAMEOBJECT = "VRTK_UICANVAS_ACTIVATOR_FRONT_TRIGGER";
protected virtual void OnEnable()
{
SetupCanvas();
}
protected virtual void OnDisable()
{
RemoveCanvas();
}
protected virtual void OnDestroy()
{
RemoveCanvas();
}
protected virtual void OnTriggerEnter(Collider collider)
{
VRTK_PlayerObject colliderCheck = collider.GetComponentInParent();
VRTK_UIPointer pointerCheck = collider.GetComponentInParent();
if (pointerCheck != null && colliderCheck != null && colliderCheck.objectType == VRTK_PlayerObject.ObjectTypes.Collider)
{
pointerCheck.collisionClick = clickOnPointerCollision;
}
}
protected virtual void OnTriggerExit(Collider collider)
{
VRTK_UIPointer pointerCheck = collider.GetComponentInParent();
if (pointerCheck != null)
{
pointerCheck.collisionClick = false;
}
}
protected virtual void SetupCanvas()
{
Canvas canvas = GetComponent