123456789101112131415161718192021222324252627282930313233343536373839404142 |
- using System;
- using UnityEngine;
- namespace ICODES.STUDIO.WWebView
- {
- public class SimpleGazeCursor : MonoBehaviour
- {
- protected void Start()
- {
- this.cursorInstance = UnityEngine.Object.Instantiate<GameObject>(this.cursorPrefab);
- }
- protected void Update()
- {
- this.UpdateCursor();
- }
- protected void UpdateCursor()
- {
- Ray ray = new Ray(this.viewCamera.transform.position, this.viewCamera.transform.rotation * Vector3.forward);
- RaycastHit raycastHit;
- if (Physics.Raycast(ray, out raycastHit, float.PositiveInfinity))
- {
- this.cursorInstance.transform.position = raycastHit.point;
- this.cursorInstance.transform.rotation = Quaternion.FromToRotation(Vector3.up, raycastHit.normal);
- }
- else
- {
- this.cursorInstance.transform.position = ray.origin + ray.direction.normalized * this.maxCursorDistance;
- this.cursorInstance.transform.rotation = Quaternion.FromToRotation(Vector3.up, -ray.direction);
- }
- }
- public Camera viewCamera;
- public GameObject cursorPrefab;
- public float maxCursorDistance = 30f;
- private GameObject cursorInstance;
- }
- }
|