public void SetData(VideoSerialize video, bool local) { titleText.text = video.title; authorText.text = video.username; sizeText.text = MathHelper.FormatBytes(video.downloadsize); lengthText.text = MathHelper.FormatSeconds(video.length); timestampText.text = MathHelper.FormatTimestampToTimeAgo(video.realTimestamp); uuid = video.id; isLocal = local; //TODO(Kristof): Prevent being able to open it without VR (will be fixed if we use raycasts from mouse instead of mouse events) if (!video.compatibleVersion) { gameObject.GetComponent <Hittable>().enabled = false; error.transform.parent.gameObject.SetActive(true); error.GetComponent <Text>().text = string.Format("This project uses a version that's higher than the player's. Please update the player. [{0}]", uuid); } else { gameObject.GetComponent <Hittable>().enabled = true; error.transform.parent.gameObject.SetActive(false); } if (isLocal) { imageDownload = new WWW("file:///" + Path.Combine(Application.persistentDataPath, Path.Combine(video.id, SaveFile.thumbFilename))); } else { imageDownload = new WWW(Web.thumbnailUrl + "/" + uuid); } Refresh(); }
private void OpenVideoFromCmdArgument() { var cmd = Environment.GetCommandLineArgs(); string rawlink = cmd[cmd.Length - 1]; bool isQuicklink = rawlink.Contains("vivista://"); string quicklink = isQuicklink ? rawlink.Substring(rawlink.IndexOf("://") + "://".Length) : null; var parts = isQuicklink ? quicklink.Split('/') : null; string type = isQuicklink ? parts[0] : null; string id = isQuicklink ? parts[1] : null; if (type == "video" && !String.IsNullOrEmpty(id)) { GuidHelpers.TryDecode(id, out var guid); var url = $"{Web.videoApiUrl}?id={guid}"; using (var request = UnityWebRequest.Get(url)) { request.SendWebRequest(); while (!request.isDone) { } detailVideo = JsonUtility.FromJson <VideoSerialize>(request.downloadHandler.text); if (detailVideo != null && detailVideo.id != null) { detailVideo.realTimestamp = DateTime.Parse(detailVideo.timestamp); ShowVideoDetails(detailVideo); return; } } } }
public void ShowVideoDetails(VideoSerialize video) { detailVideo = video; detailPanel = Instantiate(detailPanelPrefab); detailPanel.transform.SetParent(Canvass.main.transform, false); StartCoroutine(detailPanel.GetComponent <DetailPanel>().Init(detailVideo, gameObject, isLocal)); }
public void PlayVideo(VideoSerialize video) { answered = true; answerVideoId = video.id; if (detailPanel != null) { Destroy(detailPanel); detailPanel = null; } }
public IEnumerator Init(VideoSerialize videoToDownload, GameObject indexPanel, bool isLocal) { this.indexPanel = indexPanel; //NOTE(Simon): Move offscreen. We can't disable it just yet. It's still running _this_ coroutine. Disable at end of function var indexPanelPos = this.indexPanel.transform.localPosition; this.indexPanel.transform.localPosition = new Vector2(10000, 10000); video = videoToDownload; videoLength.text = MathHelper.FormatSeconds(video.length); title.text = video.title; description.text = video.description; author.text = video.username; timestamp.text = MathHelper.FormatTimestampToTimeAgo(video.realTimestamp); downloadSize.text = MathHelper.FormatBytes(video.downloadsize); if (video.title == "Corrupted file") { playButton.interactable = false; } if (isLocal) { imageDownload = UnityWebRequest.Get("file:///" + Path.Combine(Application.persistentDataPath, video.id, SaveFile.thumbFilename)); } else { imageDownload = UnityWebRequest.Get(Web.thumbnailUrl + "/" + video.id); } yield return(imageDownload.SendWebRequest()); if (imageDownload.isNetworkError) { Debug.Log("Failed to download thumbnail: " + imageDownload.error); imageDownload.Dispose(); imageDownload = null; } else if (imageDownload.isDone || imageDownload.downloadProgress >= 1f) { var texture = new Texture2D(1, 1); texture.LoadImage(imageDownload.downloadHandler.data); thumb.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); imageDownload.Dispose(); imageDownload = null; thumb.color = Color.white; } this.indexPanel.SetActive(false); this.indexPanel.transform.localPosition = indexPanelPos; Refresh(); }
public IEnumerator Init(VideoSerialize videoToDownload, GameObject indexPanel, bool isLocal) { this.indexPanel = indexPanel; indexPanel.GetComponent <IndexPanel>().modalBackground.SetActive(true); video = videoToDownload; videoLength.text = MathHelper.FormatSeconds(video.length); title.text = video.title; description.text = video.description; author.text = video.username; timestamp.text = MathHelper.FormatTimestampToTimeAgo(video.realTimestamp); downloadSize.text = MathHelper.FormatBytes(video.downloadsize); if (video.title == "Corrupted file") { playButton.interactable = false; playInVRButton.interactable = false; } if (isLocal) { imageDownload = UnityWebRequest.Get("file:///" + Path.Combine(Application.persistentDataPath, video.id, SaveFile.thumbFilename)); } else { imageDownload = UnityWebRequest.Get(Web.thumbnailUrl + "?id=" + video.id); } using (imageDownload) { yield return(imageDownload.SendWebRequest()); if (imageDownload.isNetworkError) { Debug.Log("Failed to download thumbnail: " + imageDownload.error); imageDownload.Dispose(); imageDownload = null; } else if (imageDownload.isDone || imageDownload.downloadProgress >= 1f) { var texture = new Texture2D(1, 1); texture.LoadImage(imageDownload.downloadHandler.data); thumb.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); imageDownload.Dispose(); imageDownload = null; thumb.color = Color.white; } Refresh(); } }
public void Init(VideoSerialize videoToDownload, bool isLocal) { video = videoToDownload; videoLength.text = MathHelper.FormatSeconds(video.length); title.text = video.title; description.text = video.description; author.text = video.username; timestamp.text = MathHelper.FormatTimestampToTimeAgo(video.realTimestamp); downloadSize.text = MathHelper.FormatBytes(video.downloadsize); if (isLocal) { imageDownload = new WWW("file:///" + Path.Combine(Application.persistentDataPath, Path.Combine(video.uuid, SaveFile.thumbFilename))); } else { imageDownload = new WWW(Web.thumbnailUrl + "/" + video.uuid); } Refresh(); }
public void SetData(VideoSerialize video, bool local) { titleText.text = video.title; authorText.text = video.username; sizeText.text = MathHelper.FormatBytes(video.downloadsize); lengthText.text = MathHelper.FormatSeconds(video.length); timestampText.text = MathHelper.FormatTimestampToTimeAgo(video.realTimestamp); uuid = video.uuid; isLocal = local; if (isLocal) { imageDownload = new WWW("file:///" + Path.Combine(Application.persistentDataPath, Path.Combine(video.uuid, SaveFile.thumbFilename))); } else { imageDownload = new WWW(Web.thumbnailUrl + "/" + uuid); } Refresh(); }
public void AddDownload(VideoSerialize video) { if (!queued.ContainsKey(video.uuid)) { var client = new WebClient(); var panel = Instantiate(DownloadPanelPrefab, DownloadList, false); var download = new Download { client = client, video = video, panel = panel.GetComponent <DownloadPanel>(), filesToDownload = new Queue <DownloadItem>() }; download.panel.SetTitle(video.title); queued.Add(video.uuid, download); client.DownloadStringCompleted += OnExtraListDownloaded; client.DownloadStringAsync(new Uri(Web.extrasURL + "?videoid=" + video.uuid), video.uuid); } }
public IEnumerator SetData(VideoSerialize video, bool local) { titleText.text = video.title; authorText.text = video.username; sizeText.text = MathHelper.FormatBytes(video.downloadsize); lengthText.text = MathHelper.FormatSeconds(video.length); timestampText.text = MathHelper.FormatTimestampToTimeAgo(video.realTimestamp); uuid = video.id; isLocal = local; if (video.title == "Corrupted file") { titleText.color = Color.red; } //TODO(Kristof): Prevent being able to open it without VR (will be fixed if we use raycasts from mouse instead of mouse events) if (!video.compatibleVersion) { gameObject.GetComponent <Hittable>().enabled = false; error.transform.parent.gameObject.SetActive(true); error.GetComponent <Text>().text = $"This project uses a version that's higher than the player's. Please update the player. [{uuid}]"; } else { gameObject.GetComponent <Hittable>().enabled = true; error.transform.parent.gameObject.SetActive(false); } if (isLocal) { imageDownload = UnityWebRequestTexture.GetTexture("file:///" + Path.Combine(Application.persistentDataPath, Path.Combine(video.id, SaveFile.thumbFilename))); } else { imageDownload = UnityWebRequestTexture.GetTexture(Web.thumbnailUrl + "/" + uuid); } yield return(imageDownload.SendWebRequest()); if (imageDownload == null) { Assert.IsTrue(false, "This isn't supposed to happen. Investigate! " + imageDownload.url); } if (imageDownload.isNetworkError || imageDownload.isHttpError) { Debug.Log("Failed to download thumbnail " + imageDownload.url + ": " + imageDownload.error); } else if (imageDownload.isDone) { var texture = DownloadHandlerTexture.GetContent(imageDownload); thumbnailImage.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); thumbnailImage.color = Color.white; } else { Assert.IsTrue(false, "This isn't supposed to happen. Investigate! " + imageDownload.url); } imageDownload.Dispose(); imageDownload = null; Refresh(); }
public void PlayVideoVR(VideoSerialize video) { StartCoroutine(Player.Instance.EnableVR()); PlayVideo(video); }
public void Update() { if (detailPanel != null) { var panel = detailPanel.GetComponent <DetailPanel>(); if (panel.shouldClose) { Destroy(detailPanel); detailPanel = null; } if (panel.answered) { answered = true; answerVideoId = panel.answerVideoId; //TODO(Simon): Does this work if destroy is triggered at wrong time? e.g. destroy before this.answered can be read Destroy(detailPanel); detailPanel = null; } } //Note(Simon): Spinner animation if (spinner.gameObject.activeSelf) { spinner.rectTransform.Rotate(0, 0, -1f); } //Note(Simon): Video Hovering & clicking if (videoContainer.activeSelf) { for (int i = 0; i < videos.Count; i++) { var rect = new Vector3[4]; videos[i].GetComponent <RectTransform>().GetWorldCorners(rect); bool hovering; //NOTE(Simon): Check if hovering hovering = Input.mousePosition.x > rect[0].x && Input.mousePosition.x <rect[2].x && Input.mousePosition.y> rect[0].y && Input.mousePosition.y < rect[2].y && !searchAge.isOpen(); //TODO: Get this to work with Hittable if (!XRSettings.enabled) { videos[i].GetComponent <Image>().color = hovering ? new Color(0, 0, 0, 0.1f) : new Color(0, 0, 0, 0f); } if (hovering && Input.GetMouseButtonDown(0)) { detailVideo = loadedVideos.videos[i]; detailPanel = Instantiate(detailPanelPrefab); detailPanel.transform.SetParent(Canvass.main.transform, false); StartCoroutine(detailPanel.GetComponent <DetailPanel>().Init(detailVideo, gameObject, isLocal)); } } } //Note(Simon): Pages & labels { const int maxLabels = 11; var labelsNeeded = Mathf.Min(numPages, maxLabels); while (pageLabels.Count < labelsNeeded) { var newLabel = Instantiate(pageLabelPrefab); pageLabels.Add(newLabel); newLabel.transform.SetParent(pageLabelContainer.transform, false); } while (pageLabels.Count > labelsNeeded) { var pageLabel = pageLabels[pageLabels.Count]; pageLabels.RemoveAt(pageLabels.Count - 1); Destroy(pageLabel); } //Note(Simon): This algorithm draws the page labels. We have a max of <numLabels> labels (11 currently). So if numPages > numLabels we want to draw the labels like: //Note(Simon): 1 ... 4 5 6 7 8 9 10 ... 20 { if (numPages <= maxLabels) { for (int i = 0; i < pageLabels.Count; i++) { pageLabels[i].GetComponent <Text>().text = (i + 1).ToString(); pageLabels[i].GetComponent <Text>().fontStyle = (i + 1 == page) ? FontStyle.Bold : FontStyle.Normal; } } else { var index = 0; var start = Mathf.Clamp(page - 5, 1, numPages - 10); var end = Mathf.Clamp(page + 5, maxLabels, numPages); for (int i = start; i <= end; i++) { pageLabels[index].GetComponent <Text>().fontStyle = (i == page) ? FontStyle.Bold : FontStyle.Normal; pageLabels[index++].GetComponent <Text>().text = i.ToString(); } if (page > 6) { pageLabels[0].GetComponent <Text>().text = "1"; pageLabels[1].GetComponent <Text>().text = "..."; } if (page < numPages - 5) { pageLabels[pageLabels.Count - 2].GetComponent <Text>().text = "..."; pageLabels[pageLabels.Count - 1].GetComponent <Text>().text = numPages.ToString(); } } } previousPage.gameObject.SetActive(true); nextPage.gameObject.SetActive(true); if (page == 1) { previousPage.gameObject.SetActive(false); } if (numPages == 1 || page == numPages) { nextPage.gameObject.SetActive(false); } } //NOTE(Simon): "Downloaded" message display foreach (var video in videos) { downloadedMessageTime += Time.deltaTime; if ((downloadedMessageTime > downloadedMessageRefreshTime) && isFinishedLoadingVideos) { video.GetComponent <IndexPanelVideo>().Refresh(); downloadedMessageTime = 0; } } //NOTE(Simon): Wait until to-be-imported video is copied if (importPanel != null) { if (importPanel.answered) { //NOTE(Simon): Show window by making scale 1 again transform.localScale = new Vector3(1, 1, 1); LoadPage(); Destroy(importPanel.gameObject); } } if (Time.time > lastFilterInteractionTime + filterInteractionRefreshTime) { LoadPage(); lastFilterInteractionTime = float.MaxValue; } }
public IEnumerator SetData(VideoSerialize video, bool local, IndexPanel indexPanel) { if (video.id == this.video?.id) { yield break; } titleText.text = video.title; authorText.text = video.username; sizeText.text = MathHelper.FormatBytes(video.downloadsize); lengthText.text = MathHelper.FormatSeconds(video.length); timestampText.text = MathHelper.FormatTimestampToTimeAgo(video.realTimestamp); isLocal = local; this.video = video; this.indexPanel = indexPanel; if (video.title == "Corrupted file") { titleText.color = Color.red; } if (!video.compatibleVersion) { error.transform.parent.gameObject.SetActive(true); error.GetComponent <Text>().text = $"This project uses a version that's higher than the player's. Please update the player. [{video.id}]"; } else { error.transform.parent.gameObject.SetActive(false); } if (isLocal) { imageDownload = UnityWebRequestTexture.GetTexture("file:///" + Path.Combine(Application.persistentDataPath, Path.Combine(video.id, SaveFile.thumbFilename))); } else { imageDownload = UnityWebRequestTexture.GetTexture(Web.thumbnailUrl + "?id=" + video.id); } using (imageDownload) { yield return(imageDownload.SendWebRequest()); if (imageDownload == null) { Assert.IsTrue(false, "This isn't supposed to happen. Investigate! " + imageDownload.url); } if (imageDownload.isNetworkError || imageDownload.isHttpError) { Debug.Log("Failed to download thumbnail " + imageDownload.url + ": " + imageDownload.error); } else if (imageDownload.isDone) { var texture = DownloadHandlerTexture.GetContent(imageDownload); thumbnailImage.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); thumbnailImage.color = Color.white; } else { Assert.IsTrue(false, "This isn't supposed to happen. Investigate! " + imageDownload.url); } } imageDownload = null; }