/// <summary> /// This function takes the name of an image (usually the word itself), a RawImage Game Object, /// and some optional XY dimensions. The imageName is used to recover a byte array and load /// a png from it for display. Otherwise, it will attempt to load from assets. The optional /// dimensions are for the resizing of the image. /// </summary> /// <param name="imageName3"></param> /// <param name="obj3"></param> /// <param name="xDelta"></param> /// <param name="yDelta"></param> public void SetImage3(string imageName3, GameObject obj3 /*, int xDelta = XY_DIMENSION, int yDelta = XY_DIMENSION*/) { Debug.Log("IMG 2: IMAGE NAME IS " + imageName3); //int xVect = xDelta, yVect = yDelta; System.Random rand = new System.Random(); //TEMP CODE bool isRandom = true; //REMOVE LATER //bool success = true; byte[] bytes3 = null; // Check if load random option is checked if (isRandom) { // Choose randomly whether stock image will be used or not. Weight it towards non stock if (rand.Next(RAND_LOWER_BOUND, RAND_UPPER_BOUND) == 1) { Debug.Log("IMG: RANDO WAS 1 grabbing from assets"); // Grab a stock texture Texture2D tempTex = Resources.Load <Texture2D>("WordPictures/" + imageName3 + "/" + imageName3 + UnityEngine.Random.Range(1, 6)); // If the stock texture is not null use it else grab a random user image if (tempTex != null) { Debug.Log("IMG: ASSET RESOURCE WAS GOOD! appyling"); obj3.GetComponent <RawImage>().texture = tempTex; } else { Debug.Log("IMG: COULD NOT LOAD FROM assets! Grabbing random image"); SetRandomImage3(bytes3, obj3, imageName3); } } else { // Grab a random user image SetRandomImage3(bytes3, obj3, imageName3); } } else { if (activeTypeId == 1) { Debug.Log("IMG: ACTIVE TYPE WAS REWARD"); bytes3 = FileAccessUtil.LoadRewardPic(imageName3); } else { bytes3 = FileAccessUtil.LoadWordPic(imageName3); } if (bytes3 != null) { Debug.Log("IMG: bYTES ARE GOOD!"); if (customTexture3.LoadImage(bytes3)) { obj3.GetComponent <RawImage>().texture = customTexture3; } else { Debug.Log("Error: could not load image"); return; } } else { Debug.Log("IMG: BYTES WERE NULL"); obj3.GetComponent <RawImage>().texture = Resources.Load <Texture2D>("WordPictures/" + imageName3 + "/" + imageName3 + UnityEngine.Random.Range(1, 6)); //customTexture = Resources.Load<Texture2D>("WordPictures/" + imageName); } } //obj.GetComponent<RawImage>().texture = customTexture; RectTransform rt = obj3.GetComponent <RectTransform>(); //rt.sizeDelta = new Vector2(xVect, yVect); }