//This method trigger the creation of the objects on which films are rendered void spawnFilms(RectTransform canvasRect, VideoClip[] clips) { GameObject films = new GameObject(); films.name = "Films"; films.transform.SetParent(canvasRect.transform); float available_size = (1 - (clips.Length + 1) * 0.01f) * Mathf.Min(canvasRect.rect.width, canvasRect.rect.height); float min_width = canvasRect.rect.width / 8f * Mathf.Max(15f / (5 + 1f), 1f); float max_width = canvasRect.rect.width / 7.5f * Mathf.Max(15f / (5 + 1f), 1f); SquaresTree sqt = new SquaresTree(canvasRect.rect.width * widthRatio, canvasRect.rect.height, max_width, min_width, canvasRect.position - new Vector3(canvasRect.rect.width * (1 - widthRatio) * 0.5f, 0, 0)); int choice = Random.Range(0, clips.Length); SquareCell sqc = sqt.getSquare(); float size = sqc.side; GameObject vid = Instantiate(image, sqc.center, Quaternion.identity); vid.name = string.Format("film{0}", 1); vid.transform.SetParent(films.transform); var videoPlayer = vid.AddComponent <UnityEngine.Video.VideoPlayer>(); videoPlayer.clip = clips[choice]; videoPlayer.playOnAwake = false; (vid.GetComponent <VideoController>()).StartCoroutine((vid.GetComponent <VideoController>()).SetUpFilm()); (vid.GetComponent <VideoController>()).SetSize(size, size); (vid.GetComponent <VideoController>()).SetPos(sqc.center); }
// Use this for initialization void Start() { if (decade == null) { throw new System.Exception("Need a decade"); } RectTransform canvasRect = GetComponent <RectTransform>(); createBorders(canvasRect); images = new GameObject(); images.name = "Images"; images.transform.SetParent(canvasRect.transform); //DIR TO LOAD PICTURES FROM string basedir = photos_dir + decade; if (category != null) { basedir += "/" + category; } float available_size = (1 - (maxImages + 1) * 0.01f) * Mathf.Min(canvasRect.rect.width, canvasRect.rect.height); float min_width = canvasRect.rect.width / 8f * Mathf.Max(15f / (maxImages + 1f), 1f); float max_width = canvasRect.rect.width / 7.5f * Mathf.Max(15f / (maxImages + 1f), 1f); sqt = new SquaresTree(canvasRect.rect.width * widthRatio, canvasRect.rect.height, max_width, min_width, canvasRect.position - new Vector3(canvasRect.rect.width * (1 - widthRatio) * 0.5f, 0, 0)); textures = new List <Texture2D>(Resources.LoadAll <Texture2D>(basedir)); List <Texture2D> textures_init = new List <Texture2D>(textures); //----Create a new list to select a subset of pictures from the available assets //Number of images to display = minimum between pictures available and set parameter int numImages = Mathf.Min(maxImages, textures.Count); Texture2D[] texturesSelection = new Texture2D[numImages]; for (int i = 0; i < texturesSelection.Length; i++) { if (textures.Count == 0) { textures = new List <Texture2D>(textures_init); } //Algorithm to randomize the choice : simple random int int choice = Random.Range(0, textures.Count); texturesSelection[i] = textures[choice]; textures.RemoveAt(choice); } //Call the method to display pictures on the screens spawnImages(texturesSelection); }
void spawnImages(RectTransform canvasRect, Texture2D[] textures) { GameObject images = new GameObject(); images.name = "Images"; images.transform.SetParent(canvasRect.transform); float available_size = (1 - (textures.Length + 1) * 0.01f) * Mathf.Min(canvasRect.rect.width, canvasRect.rect.height); float min_width = canvasRect.rect.width / 8f * Mathf.Max(15f / (textures.Length + 1f), 1f); float max_width = canvasRect.rect.width / 7.5f * Mathf.Max(15f / (textures.Length + 1f), 1f); SquaresTree sqt = new SquaresTree(canvasRect.rect.width * widthRatio, canvasRect.rect.height, max_width, min_width, canvasRect.position - new Vector3(canvasRect.rect.width * (1 - widthRatio) * 0.5f, 0, 0)); for (int i = 0; i < textures.Length; i++) { SquareCell sqc = sqt.getSquare(); float size = sqc.side; GameObject img = Instantiate(image, sqc.center, Quaternion.identity); img.name = string.Format("image{0}", i); img.transform.SetParent(images.transform); (img.GetComponent <ImageController>()).SetUpImage(textures[i]); (img.GetComponent <ImageController>()).SetSize(size, size); (img.GetComponent <ImageController>()).SetPos(sqc.center); } }