private IEnumerator <object> ScanReferenceDirectory() { m_ScanningDirectory = true; HashSet <string> changedSet = null; // We do a switcheroo on the changed list here so that there isn't a conflict with it // if a filewatch callback happens. lock (m_ChangedFiles) { changedSet = m_ChangedFiles; m_ChangedFiles = new HashSet <string>(); } var existing = new HashSet <string>(m_Videos.Select(x => x.AbsolutePath)); var detected = new HashSet <string>( Directory.GetFiles(App.VideoLibraryPath(), "*.*", SearchOption.AllDirectories). Where(x => m_supportedVideoExtensions.Contains(Path.GetExtension(x)))); var toDelete = existing.Except(detected).Concat(changedSet).ToArray(); var toScan = detected.Except(existing).Concat(changedSet).ToArray(); // Remove deleted videos from the list. Currently playing videos may continue to play, but will // not appear in the reference panel. m_Videos.RemoveAll(x => toDelete.Contains(x.AbsolutePath)); var newVideos = new List <ReferenceVideo>(); foreach (var filePath in toScan) { ReferenceVideo videoRef = new ReferenceVideo(filePath); newVideos.Add(videoRef); m_Videos.Add(videoRef); } // If we have a lot of videos, they may take a while to create thumbnails. Make sure we refresh // every few seconds so the user sees progress if they go straight to the reference panel. TimeSpan interval = TimeSpan.FromSeconds(4); DateTime nextRefresh = DateTime.Now + interval; foreach (var videoRef in newVideos) { if (DateTime.Now > nextRefresh) { CatalogChanged?.Invoke(); nextRefresh = DateTime.Now + interval; } yield return(videoRef.Initialize()); } m_ScanningDirectory = false; CatalogChanged?.Invoke(); if (m_DebugOutput) { DebugListVideos(); } }
public static void FromTiltVideo(TiltVideo tiltVideo) { VideoWidget videoWidget = Instantiate(WidgetManager.m_Instance.VideoWidgetPrefab); videoWidget.m_LoadingFromSketch = true; videoWidget.transform.parent = App.Instance.m_CanvasTransform; videoWidget.transform.localScale = Vector3.one; var video = VideoCatalog.Instance.GetVideoByPersistentPath(tiltVideo.FilePath); if (video == null) { video = ReferenceVideo.CreateDummyVideo(); ControllerConsoleScript.m_Instance.AddNewLine( $"Could not find video {App.VideoLibraryPath()}\\{tiltVideo.FilePath}."); } videoWidget.SetVideo(video); videoWidget.m_InitialState = new VideoState { Volume = tiltVideo.Volume, Paused = tiltVideo.Paused, }; if (tiltVideo.Paused) { videoWidget.m_InitialState.Time = tiltVideo.Time; } videoWidget.SetSignedWidgetSize(tiltVideo.Transform.scale); videoWidget.Show(bShow: true, bPlayAudio: false); videoWidget.transform.localPosition = tiltVideo.Transform.translation; videoWidget.transform.localRotation = tiltVideo.Transform.rotation; if (tiltVideo.Pinned) { videoWidget.PinFromSave(); } videoWidget.Group = App.GroupManager.GetGroupFromId(tiltVideo.GroupId); TiltMeterScript.m_Instance.AdjustMeterWithWidget(videoWidget.GetTiltMeterCost(), up: true); videoWidget.UpdateScale(); }
public void SetVideo(ReferenceVideo video) { m_Video = video; ImageTexture = m_NoImageTexture; var size = GetWidgetSizeRange(); if (m_Video.Aspect > 1) { m_Size = Mathf.Clamp(2 / m_Video.Aspect / Coords.CanvasPose.scale, size.x, size.y); } else { m_Size = Mathf.Clamp(2 * m_Video.Aspect / Coords.CanvasPose.scale, size.x, size.y); } // Create in the main canvas. HierarchyUtils.RecursivelySetLayer(transform, App.Scene.MainCanvas.gameObject.layer); HierarchyUtils.RecursivelySetMaterialBatchID(transform, m_BatchId); InitSnapGhost(m_ImageQuad.transform, transform); Play(); }