Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- using ZXing;
- using ZXing.QrCode;
- public class NewBehaviourScript : MonoBehaviour
- {
- [Header("raw_image_video")]
- public RawImage raw_image_video;
- [Header("audio source")]
- public AudioSource audio_source;
- //camera texture
- private WebCamTexture cam_texture;
- void OnEnable()
- {
- StartCoroutine(this.start_webcam());
- }
- private IEnumerator start_webcam()
- {
- yield return new WaitForSeconds(0.11f);
- //init camera texture
- this.cam_texture = new WebCamTexture();
- //this.cam_texture.requestedWidth = 720;
- //this.cam_texture.requestedHeight = 1280;
- this.cam_texture.requestedWidth = 540;
- this.cam_texture.requestedHeight = 720;
- this.cam_texture.Play();
- if (Application.platform == RuntimePlatform.Android)
- {
- this.raw_image_video.rectTransform.sizeDelta = new Vector2(Screen.width * cam_texture.width / (float)this.cam_texture.height, Screen.width);
- this.raw_image_video.rectTransform.rotation = Quaternion.Euler(0, 0, -90);
- }
- else if (Application.platform == RuntimePlatform.IPhonePlayer)
- {
- this.raw_image_video.rectTransform.sizeDelta = new Vector2(1080, 1080 * this.cam_texture.width / (float)this.cam_texture.height);
- this.raw_image_video.rectTransform.localScale = new Vector3(-1, 1, 1);
- this.raw_image_video.rectTransform.rotation = Quaternion.Euler(0, 0, 90);
- }
- else
- {
- this.raw_image_video.rectTransform.sizeDelta = new Vector2(Camera.main.pixelWidth, Camera.main.pixelWidth * this.cam_texture.height / (float)this.cam_texture.width);
- this.raw_image_video.rectTransform.localScale = new Vector3(-1, 1, 1);
- }
- this.raw_image_video.texture = cam_texture;
- yield return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement