示例#1
0
        public async void PlaySearchRandom()
        {
            if (config == null)
            {
                Debug.LogError("Config is null. Please create a GiphyConfig asset using the Create->Gameframe->Giphy->Config menu and assign it to the config variable", this);
                return;
            }

            if (string.IsNullOrEmpty(config.ApiKey))
            {
                Debug.LogError("Giphy ApiKey is not configured. You must create a developer app and get an API key from the giphy developer website and add it to your GiphyConfig file.", this);
                return;
            }

            Alpha = 0;
            var result = await GiphyQuery.Search(config, searchQuery);

            var validResults = result.Data.Where(x => !string.IsNullOrEmpty(x.Images.OriginalMp4.Mp4)).ToList();
            var randomResult = validResults[UnityEngine.Random.Range(0, validResults.Count)];

            if (string.IsNullOrEmpty(randomResult.Images.OriginalMp4.Mp4))
            {
                Debug.Log("No MP4 result");
                return;
            }

            int width  = 0;
            int height = 0;

            videoPlayer.source = VideoSource.Url;

            if (videoPlayer.isLooping)
            {
                videoPlayer.url = randomResult.Images.Looping.Mp4;
                width           = randomResult.Images.Original.Width;
                height          = randomResult.Images.Original.Height;
            }
            else
            {
                videoPlayer.url = randomResult.Images.OriginalMp4.Mp4;
                width           = randomResult.Images.OriginalMp4.Width;
                height          = randomResult.Images.OriginalMp4.Height;
            }

            SetImageSize(width, height);

            videoPlayer.Play();
        }
示例#2
0
        public async void PlayRandom()
        {
            if (config == null)
            {
                Debug.LogError("Config is null. Please create a GiphyConfig asset using the Create->Gameframe->Giphy->Config menu and assign it to the config variable", this);
                return;
            }

            if (string.IsNullOrEmpty(config.apiKey))
            {
                Debug.LogError("Giphy ApiKey is not configured. You must create a developer app and get an API key from the giphy developer website and add it to your GiphyConfig file.", this);
                return;
            }

            Alpha = 0;
            var result = await GiphyQuery.Random(config, searchQuery);

            if (string.IsNullOrEmpty(result.data.image_mp4_url))
            {
                Debug.Log("No MP4 result");
                return;
            }

            int width  = 0;
            int height = 0;

            videoPlayer.source = VideoSource.Url;

            if (videoPlayer.isLooping)
            {
                videoPlayer.url = result.data.images.looping.mp4;
                width           = result.data.image_width;
                height          = result.data.image_height;
            }
            else
            {
                videoPlayer.url = result.data.images.original_mp4.mp4;
                width           = result.data.image_width;
                height          = result.data.image_height;
            }

            SetImageSize(width, height);

            videoPlayer.Play();
        }