コード例 #1
0
 void Stop()
 {
     channel?.Stop();
     channel = null;
     sound   = null;
     replayIntervalRemainingTime = 0;
     lastChannelTime             = 0;
 }
コード例 #2
0
 internal void OnVirtualChannelUpdatePause(SoundVirtualChannel virtualChannel)
 {
     if (!virtualChannel.IsTotalPaused())
     {
         if (lastUpdateTime != 0)
         {
             UpdateChannels(lastUpdateTime);
         }
     }
     else
     {
         if (virtualChannel.currentRealChannel != null)
         {
             virtualChannel.currentRealChannel.PreDetachVirtualChannel();
             virtualChannel.currentRealChannel.currentVirtualChannel = null;
             virtualChannel.currentRealChannel = null;
         }
     }
 }
コード例 #3
0
 static int VirtualChannelsTempPriorityComparer(SoundVirtualChannel c1, SoundVirtualChannel c2)
 {
     return(c2.tempPriority.CompareTo(c1.tempPriority));
 }
コード例 #4
0
        public static SoundVirtualChannel SoundPlay(Component_Scene attachedToScene, Sound sound, SoundChannelGroup group, double priority, bool paused = false)
        {
            if (sound == null)
            {
                return(null);
            }

            ////!!!!так?
            //if( ( sound.Mode & SoundModes.Loop ) == 0 && ( sound.Mode & SoundModes.Stream ) == 0 )
            //{
            //	if( attachedToScene != null && listenerCurrentScene != attachedToScene )
            //		return null;
            //}

            //!!!!было
            ////!!!!так?
            //if( ( sound.Mode & SoundModes.Loop ) == 0 && ( sound.Mode & SoundModes.Stream ) == 0 )
            //{
            //	List<RealChannel> realChannels = ( sound.Mode & SoundModes.Mode3D ) != 0 ? real3DChannels : real2DChannels;

            //	bool allowPlay = false;
            //	for( int n = 0; n < realChannels.Count; n++ )
            //	{
            //		VirtualChannel c = realChannels[ n ].CurrentVirtualChannel;
            //		if( c == null || c.Priority < priority )
            //		{
            //			allowPlay = true;
            //			break;
            //		}
            //	}
            //	if( !allowPlay )
            //		return null;
            //}

            //priority = MathEx.Saturate( priority );

            //!!!!было
            //if( ( sound.Mode & SoundModes.Stream ) != 0 )
            //{
            //	if( sound.playingCount == 1 )
            //	{
            //		Log.Warning( "SoundSystem: It is impossible to play simultaneously more one channel stream sound." );
            //		return null;
            //	}
            //}

            if (group == null)
            {
                group = MasterChannelGroup;
            }

            SoundVirtualChannel virtualChannel = new SoundVirtualChannel();

            if ((sound.Mode & SoundModes.Mode3D) != 0)
            {
                activeVirtual3DChannels.Add(virtualChannel);
                if (activeVirtual3DChannels.Count > 2048)
                {
                    Log.Info("SoundSystem: Quantity of active 3D channels > 2048.");
                }
            }
            else
            {
                activeVirtual2DChannels.Add(virtualChannel);
                if (activeVirtual2DChannels.Count > 2048)
                {
                    Log.Info("SoundSystem: Quantity of active 2D channels > 2048.");
                }
            }

            virtualChannel.SoundPlayInit(attachedToScene, sound, group);
            virtualChannel.Priority = priority;

            if (!paused)
            {
                virtualChannel.Pause = false;
            }

            return(virtualChannel);
        }
コード例 #5
0
        void Play()
        {
            if (playCalling)
            {
                return;
            }
            playCalling = true;

            Stop();

            if (EnabledInHierarchyAndIsNotResource && ParentScene != null)
            {
                var res = ParentRoot?.HierarchyController?.CreatedByResource;
                if (res != null && res.InstanceType == Resource.InstanceType.SeparateInstance)
                {
                    var soundComponent = Sound.Value;
                    if (soundComponent != null && soundComponent.Result != null)
                    {
                        bool streaming = false;

                        switch (Streaming.Value)
                        {
                        case StreamingEnum.Auto:
                        {
                            string fileName = soundComponent.LoadFile.Value.ResourceName;
                            if (!string.IsNullOrEmpty(fileName) && Path.GetExtension(fileName).ToLower() == ".ogg")
                            {
                                long length = 0;
                                try
                                {
                                    length = VirtualFile.GetLength(fileName);
                                }
                                catch { }
                                if (length > 400000)
                                {
                                    streaming = true;
                                }
                            }
                        }
                        break;

                        case StreamingEnum.Enable:
                            streaming = true;
                            break;
                        }

                        SoundModes mode = SoundModes.Mode3D;
                        if (ReplayDelay == 0 || streaming)                         //if( replayDelay == 0 )
                        {
                            mode |= SoundModes.Loop;
                        }
                        if (streaming)
                        {
                            mode |= SoundModes.Stream;
                        }

                        sound = soundComponent.Result.LoadSoundByMode(mode);
                        if (sound != null)
                        {
                            channel = SoundWorld.SoundPlay(ParentScene, sound, EngineApp.DefaultSoundChannelGroup, Priority, true);
                            if (channel != null)
                            {
                                channel.Position = Transform.Value.Position;
                                channel.Volume   = Volume;
                                UpdateChannelRolloffGraph();
                                channel.Pitch = Pitch;

                                OnBeforePlay();
                                BeforePlayEvent?.Invoke(this);

                                channel.Pause = false;

                                lastUpdateEngineTime = EngineApp.EngineTime;
                            }
                        }
                    }
                }
            }

            playCalling = false;
        }