Guest User

Untitled

a guest
Jun 10th, 2018
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. bool screenExists = false;
  2. Texture2D tex;
  3. string url = "www.e3.com/stream.png";
  4.  
  5. private void Update()
  6. {
  7. if (Input.GetKeyDown(KeyCode.P) && !screenExists)
  8. {
  9. GameObject screen = new GameObject();
  10. screen.AddComponent<MeshFilter>();
  11. screen.AddComponent<MeshRenderer>();
  12.  
  13. Mesh mesh = BuildQuad(0.32f, 0.18f);
  14. screen.GetComponent<MeshFilter>().mesh = mesh;
  15.  
  16. tex = new Texture2D(640, 360, TextureFormat.DXT1, false);
  17.  
  18. screenExists = true;
  19. }
  20.  
  21. if (screenExists)
  22. {
  23. using (WWW www = new WWW(url))
  24. {
  25. yield return www;
  26. www.LoadImageIntoTexture(tex);
  27. GetComponent<Renderer>().material.mainTexture = tex;
  28. }
  29. }
  30. }
  31.  
  32. private Mesh BuildQuad(float width, float height)
  33. {
  34. Mesh mesh = new Mesh();
  35.  
  36. // Setup vertices
  37. Vector3[] newVertices = new Vector3[4];
  38. float halfHeight = height * 0.5f;
  39. float halfWidth = width * 0.5f;
  40. newVertices[0] = new Vector3(-halfWidth, -halfHeight, 0);
  41. newVertices[1] = new Vector3(-halfWidth, halfHeight, 0);
  42. newVertices[2] = new Vector3(halfWidth, -halfHeight, 0);
  43. newVertices[3] = new Vector3(halfWidth, halfHeight, 0);
  44.  
  45. // Setup UVs
  46. Vector2[] newUVs = new Vector2[newVertices.Length];
  47. newUVs[0] = new Vector2(0, 0);
  48. newUVs[1] = new Vector2(0, 1);
  49. newUVs[2] = new Vector2(1, 0);
  50. newUVs[3] = new Vector2(1, 1);
  51.  
  52. // Setup triangles
  53. int[] newTriangles = new int[] { 0, 1, 2, 3, 2, 1 };
  54.  
  55. // Setup normals
  56. Vector3[] newNormals = new Vector3[newVertices.Length];
  57. for (int i = 0; i < newNormals.Length; i++)
  58. {
  59. newNormals[i] = Vector3.forward;
  60. }
  61.  
  62. // Create quad
  63. mesh.vertices = newVertices;
  64. mesh.uv = newUVs;
  65. mesh.triangles = newTriangles;
  66. mesh.normals = newNormals;
  67.  
  68. return mesh;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment