sega 8a6d23b77d Реорг Scripts
Разделено на 4 модуля
- Menu
- Gameplay
- Settings
- Common
2026-07-15 10:49:55 +03:00

86 lines
2.4 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Video;
public class VideoUtility : MonoBehaviour
{
[SerializeField] private VideoPlayer player;
[SerializeField] private AudioSource audioSource;
[SerializeField] private VideoClip fon, ads, ending;
[SerializeField] private Canvas canvas;
public static float adsLength => (float)instance.ads.length;
public static float victoryLength => (float)instance.ending.length;
private static VideoUtility instance;
public void Initialize()
{
if (instance == null) instance = this;
PlayFon();
}
public static void PlayFon()
{
instance.player.renderMode = VideoRenderMode.CameraFarPlane;
instance.player.isLooping = true;
instance.player.clip = instance.fon;
}
public static void PlayAds()
{
var v = instance;
v.player.renderMode = VideoRenderMode.CameraNearPlane;
v.player.Stop();
v.player.isLooping = false;
v.player.clip = v.ads;
// ВАЖНО: убедимся, что аудио трек включён и привязан к источнику
v.player.audioOutputMode = VideoAudioOutputMode.AudioSource;
v.player.EnableAudioTrack(0, true);
v.player.SetTargetAudioSource(0, v.audioSource);
v.audioSource.Stop();
v.StartCoroutine(v.PrepareAndPlay());
}
private IEnumerator PrepareAndPlay()
{
player.Prepare();
while (!player.isPrepared) yield return null;
// Для AudioSource-режима часто помогает запускать оба
audioSource.Play();
player.Play();
}
public static void PlayEnding()
{
var v = instance;
v.player.renderMode = VideoRenderMode.CameraNearPlane;
v.player.Stop();
v.player.isLooping = false;
v.player.clip = v.ending;
// Те же аудио-настройки, что и в PlayAds
v.player.audioOutputMode = VideoAudioOutputMode.AudioSource;
v.player.EnableAudioTrack(0, true);
v.player.SetTargetAudioSource(0, v.audioSource);
v.audioSource.Stop();
v.StartCoroutine(v.PrepareAndPlay());
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha5)) PlayFon();
if (Input.GetKeyDown(KeyCode.Alpha6)) PlayAds();
if (Input.GetKeyDown(KeyCode.Alpha7)) PlayEnding();
}
}