daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest Jan 19th, 2018 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5.  
  6. public class CamSurface : MonoBehaviour {
  7.  
  8.     public UrlFeeder Feeder;
  9.     public string URL;
  10.     public CamSurfaceController controller;
  11.     private float GetRate;
  12.     private float nextGet = 0f;
  13.     private int succesFullTrick, maxSuccesFullTricks;
  14.     public WWW CamWww;
  15.  
  16.     private void Start()
  17.     {
  18.         GetRate = controller.SearchingRate;
  19.         GetRate = GetRate + Random.RandomRange(0,2);
  20.         URL = Feeder.GetRandomUrl();
  21.         maxSuccesFullTricks = 30;
  22.     }
  23.  
  24.     IEnumerator GetTexture()
  25.     {
  26.         if (gameObject.GetComponent<MeshRenderer>().material.mainTexture == null)
  27.         {
  28.             URL = Feeder.GetRandomUrl();
  29.         }
  30.  
  31.         if (succesFullTrick >= maxSuccesFullTricks)
  32.         {
  33.             URL = Feeder.GetRandomUrl();
  34.         }
  35.  
  36.         Texture2D tex;
  37.  
  38.         tex = new Texture2D(4, 4, TextureFormat.DXT1, false);
  39.  
  40.         CamWww = new WWW(URL);
  41.  
  42.         yield return CamWww;
  43.  
  44.         if (CamWww.error != null)
  45.         {
  46.             URL = Feeder.GetRandomUrl();
  47.             yield return null;
  48.         } else {
  49.             GetRate = controller.RefreshRate;
  50.  
  51.             CamWww.LoadImageIntoTexture(tex);
  52.             CamWww.Dispose();
  53.             if (tex.width <= 20)
  54.             {
  55.                 yield return null;
  56.             }
  57.             else
  58.             {
  59.                 succesFullTrick++;
  60.                 gameObject.GetComponent<MeshRenderer>().material.mainTexture = tex;
  61.             }
  62.         }
  63.     }
  64.  
  65.     public void StopCoroutine()
  66.     {
  67.         StopCoroutine("GetTexture");
  68.     }
  69.  
  70.     public void OnApplicationQuit()
  71.     {
  72.         print("quit");
  73.     }
  74.  
  75.  
  76.     louisvoid Update()
  77.     {
  78.         if (Time.time > nextGet)
  79.         {
  80.             StartCoroutine("GetTexture");
  81.             print("starting");
  82.             nextGet = Time.time + GetRate;
  83.         }
  84.     }
  85.  
  86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top