From 77ba1a4d2249b8db09b3a1e975a01f6e50d21e33 Mon Sep 17 00:00:00 2001 From: Junrou Nishida Date: Wed, 27 Apr 2022 16:23:06 +0900 Subject: [PATCH] fix(sample): the default video/image is not selected (#543) --- .../Scripts/ImageSource/StaticImageSource.cs | 17 ++++++++--------- .../Common/Scripts/ImageSource/VideoSource.cs | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/StaticImageSource.cs b/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/StaticImageSource.cs index 431e3f044..b7ed72efc 100644 --- a/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/StaticImageSource.cs +++ b/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/StaticImageSource.cs @@ -26,7 +26,14 @@ public class StaticImageSource : ImageSource private Texture _image; private Texture image { - get => _image; + get + { + if (_image == null && _availableSources != null && _availableSources.Length > 0) + { + image = _availableSources[0]; + } + return _image; + } set { _image = value; @@ -47,14 +54,6 @@ private Texture image private bool _isPlaying = false; public override bool isPlaying => _isPlaying; - private void Start() - { - if (_availableSources != null && _availableSources.Length > 0) - { - image = _availableSources[0]; - } - } - public override void SelectSource(int sourceId) { if (sourceId < 0 || sourceId >= _availableSources.Length) diff --git a/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/VideoSource.cs b/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/VideoSource.cs index 52442e00e..e382c6cfc 100644 --- a/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/VideoSource.cs +++ b/Assets/MediaPipeUnity/Samples/Common/Scripts/ImageSource/VideoSource.cs @@ -19,7 +19,14 @@ public class VideoSource : ImageSource private VideoClip _video; private VideoClip video { - get => _video; + get + { + if (_video == null && _availableSources != null && _availableSources.Length > 0) + { + video = _availableSources[0]; + } + return _video; + } set { _video = value; @@ -38,14 +45,6 @@ private VideoClip video public override bool isPlaying => _videoPlayer != null && _videoPlayer.isPlaying; public override bool isPrepared => _videoPlayer != null && _videoPlayer.isPrepared; - private void Start() - { - if (_availableSources != null && _availableSources.Length > 0) - { - video = _availableSources[0]; - } - } - public override void SelectSource(int sourceId) { if (sourceId < 0 || sourceId >= _availableSources.Length)