Advertisement
Guest User

Untitled

a guest
Jun 25th, 2021
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using ZXing;
  6. using ZXing.QrCode;
  7.  
  8. public class NewBehaviourScript : MonoBehaviour
  9. {
  10. [Header("raw_image_video")]
  11. public RawImage raw_image_video;
  12.  
  13. [Header("audio source")]
  14. public AudioSource audio_source;
  15.  
  16. //camera texture
  17. private WebCamTexture cam_texture;
  18.  
  19. void OnEnable()
  20. {
  21. StartCoroutine(this.start_webcam());
  22. }
  23.  
  24. private IEnumerator start_webcam()
  25. {
  26. yield return new WaitForSeconds(0.11f);
  27.  
  28. //init camera texture
  29. this.cam_texture = new WebCamTexture();
  30.  
  31. //this.cam_texture.requestedWidth = 720;
  32. //this.cam_texture.requestedHeight = 1280;
  33.  
  34. this.cam_texture.requestedWidth = 540;
  35. this.cam_texture.requestedHeight = 720;
  36.  
  37.  
  38. this.cam_texture.Play();
  39.  
  40. if (Application.platform == RuntimePlatform.Android)
  41. {
  42. this.raw_image_video.rectTransform.sizeDelta = new Vector2(Screen.width * cam_texture.width / (float)this.cam_texture.height, Screen.width);
  43. this.raw_image_video.rectTransform.rotation = Quaternion.Euler(0, 0, -90);
  44. }
  45. else if (Application.platform == RuntimePlatform.IPhonePlayer)
  46. {
  47. this.raw_image_video.rectTransform.sizeDelta = new Vector2(1080, 1080 * this.cam_texture.width / (float)this.cam_texture.height);
  48. this.raw_image_video.rectTransform.localScale = new Vector3(-1, 1, 1);
  49. this.raw_image_video.rectTransform.rotation = Quaternion.Euler(0, 0, 90);
  50. }
  51. else
  52. {
  53. this.raw_image_video.rectTransform.sizeDelta = new Vector2(Camera.main.pixelWidth, Camera.main.pixelWidth * this.cam_texture.height / (float)this.cam_texture.width);
  54. this.raw_image_video.rectTransform.localScale = new Vector3(-1, 1, 1);
  55. }
  56.  
  57. this.raw_image_video.texture = cam_texture;
  58.  
  59. yield return null;
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement