udPickToDepth.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using udSDK;
  5. [RequireComponent(typeof(Camera))]
  6. [RequireComponent(typeof(UDCameraOptions))]
  7. [RequireComponent(typeof(DepthOfFieldEffector))]
  8. public class udPickToDepth : MonoBehaviour
  9. {
  10. Camera cam ;
  11. UDCameraOptions camOptions ;
  12. DepthOfFieldEffector depthEffect ;
  13. bool setNext ;
  14. void Start()
  15. {
  16. cam = GetComponent<Camera>();
  17. depthEffect = GetComponent<DepthOfFieldEffector>();
  18. camOptions = GetComponent<UDCameraOptions>();
  19. }
  20. void Update()
  21. {
  22. if (setNext)
  23. {
  24. udPick pick = camOptions.lastPick;
  25. depthEffect.SetFocusDistance(Vector3.Distance(pick.pointCenter, cam.transform.position));
  26. setNext = false;
  27. }
  28. if(Input.GetMouseButtonDown(0))
  29. {
  30. setNext = true;
  31. Vector3 mp = Input.mousePosition;
  32. camOptions.optionsStruct.setPick((uint)(mp.x), (uint)((cam.pixelHeight - mp.y)));
  33. }
  34. }
  35. }