Пример #1
0
        private void FlagLoadedForClip(AudioClip clip)
        {
            source = AudioSourceManager.CreateSource(clip, DJStand.Map);
            source.TargetVolume = volume;
            source.Area         = DJStand.FloorBounds;
            source.Source.pitch = Settings.GameSpeedAffectsMusic ? Find.TickManager.TickRateMultiplier : Find.TickManager.Paused ? 0f : 1f;
            source.Source.Play();
            source.IsPlaying = () => source?.Source != null && !removed;

            if (!registered)
            {
                UnityHook.OnPauseChange += UnityHook_OnPauseChange;
                registered = true;
            }
        }
Пример #2
0
        public override void Init()
        {
            string path   = Def.Get <string>("filePath");
            float  volume = Def.Get("volume", 1f);
            bool   mute   = Def.Get("mute", false);

            if (volume <= 0f)
            {
                mute = true;
            }

            // Resolve the file path.
            ModContentPack mcp = Def.modContentPack;

            if (mcp == null)
            {
                string[] split = path.Split('/');
                split[0] = split[0].ToLowerInvariant();
                Core.Warn($"Video program def '{Def.defName}' has been added by a patch operation. Attempting to resolve filepath...");
                var found = LoadedModManager.RunningModsListForReading.FirstOrFallback(mod => mod.PackageId.ToLowerInvariant() == split[0]);
                if (found == null)
                {
                    Core.Error($"Failed to resolve mod folder path from id '{split[0]}'. See below for how to solve this issue.");
                    Core.Error("If you mod's package ID is 'my.mod.name' and your video file is in 'MyModFolder/Videos/Video.bwcv' then the correct filePath would be 'my.mod.name/Videos/Video.bwcv'");
                    Remove();
                    return;
                }
                Core.Warn("Successfully resolved file path.");
                mcp = found;
            }
            path = Path.Combine(mcp.RootDir, path);

            player                 = GetParentObject().AddComponent <VideoPlayer>();
            player.renderMode      = VideoRenderMode.APIOnly;
            player.audioOutputMode = mute ? VideoAudioOutputMode.None : VideoAudioOutputMode.AudioSource;

            if (!mute)
            {
                audioContainer = AudioSourceManager.CreateSource(null, DJStand.Map);
                audioContainer.TargetVolume = volume;
                audioContainer.Area         = DJStand.FloorBounds;
                audioContainer.IsPlaying    = () => player != null && !removed;
                player.SetTargetAudioSource(0, audioContainer.Source);

                string msg = "DSC.NowPlaying".Translate(Def.Get("credits", "Unknown"));
                Messages.Message(msg, MessageTypeDefOf.PositiveEvent);
            }

            player.isLooping            = false;
            player.sendFrameReadyEvents = true;
            player.playbackSpeed        = Settings.GameSpeedAffectsMusic ? Find.TickManager.TickRateMultiplier : Find.TickManager.Paused ? 0f : 1f;
            player.loopPointReached    += OnVideoReachEnd;
            player.frameReady          += Player_frameReady;
            player.errorReceived       += Player_errorReceived;

            OnPauseChange(Find.TickManager.Paused);
            player.url = path;

            if (!isSubscribed)
            {
                UnityHook.OnPauseChange += OnPauseChange;
            }
        }