Пример #1
0
        private void PlaySound(SoundResource sound)
        {
            // Adjust the sound back to normal settings if it is a looping sound that is already playing
            if ((currentPlayHandle != null) && currentPlayHandle.IsPlaying() && Looping)
            {
                AdjustSound(Loudness, PitchOffset);
                return;
            }

            StopSound(false);

            PlaySettings playSettings = (Looping ? PlaySettings.Looped : PlaySettings.PlayOnce);

            playSettings.DontSync   = false;
            playSettings.Loudness   = LoudnessPercentToDb(Loudness + LoudnessVariance * RandomNegOneToOne());
            playSettings.PitchShift = PitchOffset + PitchVariance * RandomNegOneToOne();

            if (Spatialized)
            {
                if (audio != null)
                {
                    currentPlayHandle = audio.PlaySoundOnComponent(sound, playSettings);
                }
                else
                {
                    currentPlayHandle = ScenePrivate.PlaySoundAtPosition(sound, ObjectPrivate.Position, playSettings);
                }
            }
            else
            {
                currentPlayHandle = ScenePrivate.PlaySound(sound, playSettings);
            }
        }
    public override void Init()
    {
        PlaySettings playSettings = Play_Once ? PlaySettings.PlayOnce : PlaySettings.Looped;

        playSettings.Loudness = RelativePercentToRelativeLoudnessDB(Volume_Diff_Percent);
        playSettings.DontSync = Dont_Sync;
        ScenePrivate.PlaySound(Sound, playSettings);
    }
    private void PlayNote(SoundResource PlaySample, float PitchShiftIn)
    {
        bool NoLoop = true;

        playSettings = NoLoop ? PlaySettings.PlayOnce : PlaySettings.Looped;

        playSettings.Loudness   = loudnessIn; // set in Configuration
        playSettings.DontSync   = true;       // TrackDont_Sync[LoopIn2];
        playSettings.PitchShift = PitchShiftIn;
        //playHandle[LoopIn2] = ScenePrivate.PlaySound(TrackSamples[LoopIn2][PlayIndexIn], playSettings);
        playHandleSimple = ScenePrivate.PlaySound(PlaySample, playSettings);
    }
Пример #4
0
 private void Collide(CollisionData obj)
 {
     if (!Opening)
     {
         Opening = true;
         if (OpenSound != null)
         {
             ScenePrivate.PlaySound(OpenSound, PlaySettings.PlayOnce);
         }
     }
     LatestOpenSignal = DateTime.Now;
 }
Пример #5
0
    private void PlayNextSound()
    {
        SoundResource nextSound = AvailableSounds[NextSoundIndex];

        if (LocalAudioComponent != null)
        {
            LocalAudioComponent.PlaySoundOnComponent(nextSound, PlaySettings.PlayOnce).OnFinished(OnSoundFinished);
        }
        else
        {
            ScenePrivate.PlaySound(nextSound, PlaySettings.PlayOnce).OnFinished(OnSoundFinished);
        }
    }
Пример #6
0
 private void StartSound(AnimationData obj)
 {
     StopSound(obj);
     if (playHandle == null)
     {
         if (audioComp == null)
         {
             playHandle = ScenePrivate.PlaySound(Sound, playSettings);
         }
         else
         {
             playHandle = audioComp.PlaySoundOnComponent(Sound, playSettings);
         }
     }
 }
Пример #7
0
    private void RevealLetter(string inLetter)
    {
        int  rowCntr = 0;
        bool hit     = false;

        do
        {
            //Log.Write("Current Text: " + CurrentText[rowCntr]);
            //Log.Write("Hidden Text: " + HiddenText[rowCntr]);
            int    columnCntr      = 0;
            string MessageEventOut = BoardName + (rowCntr + 1).ToString();
            string LineText        = HiddenText[rowCntr];
            if (CenterMyText)
            {
                LineText = CenterText(LineText);
            }

            do
            {
                string boardLetter = LineText.Substring(columnCntr, 1).ToUpper();
                //Log.Write("row: " + rowCntr + " column: " + columnCntr + " boardLetter: " + boardLetter + " inLetter: " + inLetter);
                if (boardLetter == inLetter)
                {
                    //Log.Write("LetterMatch");
                    SendChar sendChar = new SendChar();
                    sendChar.CharIndex  = columnCntr;
                    sendChar.CharToSend = inLetter;
                    //Log.Write("MessageEvent: " + MessageEvent + " Sending Letter: " + CharToSendOut + " To Letter #: " + sendChar.CharIndex);
                    PostScriptEvent(ScriptId.AllScripts, MessageEventOut, sendChar);
                    currentPlayHandle = ScenePrivate.PlaySound(MatchSound, playSettings);
                    hit = true;
                    Wait(TimeSpan.FromSeconds(0.5));
                }
                columnCntr++;
            } while (columnCntr < LineText.Length);

            rowCntr++;
        } while (rowCntr < HiddenText.Count());
        if (!hit)
        {
            currentPlayHandle = ScenePrivate.PlaySound(MissSound, playSettings);
        }
        //DisplayBoard(CurrentText);
    }
Пример #8
0
    public override void Init()
    {
        // Check to make sure a sound has been configured in the editor
        if (Sound == null)
        {
            Log.Write("SoundScript has no configured sound to play!");
            return;
        }

        ObjectPrivate.AddInteractionData addData = (ObjectPrivate.AddInteractionData)WaitFor(ObjectPrivate.AddInteraction, "Play sound", true);

        addData.Interaction.Subscribe((InteractionData data) =>
        {
            PlaySettings playSettings = PlaySettings.PlayOnce;
            playSettings.Loudness     = (60.0f * (Loudness / 100.0f)) - 48.0f; // Convert percentage to decibels (dB)

            ScenePrivate.PlaySound(Sound, playSettings);
        });
    }
Пример #9
0
    private void ChatMessage(ChatData obj)
    //private void ChatMessage(int Channel, string Source, SessionId SourceId, ScriptId SourceScriptId, string Message)
    {
        // Parse the message
        string[] Parts = obj.Message.Split('|');
        if (Parts.Length < 3)
        {
            return;
        }

        // Wrong kind of message
        if (Parts[0] != "Sensor")
        {
            return;
        }

        // Is the message from one of the sensors we're listening to?
        if (!SensorNameList.Contains(Parts[1]))
        {
            return;
        }

        if (Parts[2] != "Collision")
        {
            return;
        }

        if (!Opening)
        {
            Opening = true;
            if (OpenSound != null)
            {
                ScenePrivate.PlaySound(OpenSound, PlaySettings.PlayOnce);
            }
        }
        LatestOpenSignal = DateTime.Now;
    }
Пример #10
0
    private void UpdateLoop()
    {
        float Tick      = 0.01f;
        float AngleStep = 5 * OpenAngle * Tick / SecondsToOpen;

        TimeSpan Moment = TimeSpan.FromSeconds(Tick);

        float Angle = 0.0f;

        while (true)
        {
            Wait(Moment);

            // If we're in the process of opening or closing, we'll adjust the angle a little toward the target
            if (Opening)
            {
                if (OpenOut)
                {
                    Angle -= AngleStep;
                    if (Angle < -OpenAngle)
                    {
                        Angle = -OpenAngle;
                    }
                }
                else
                {
                    Angle += AngleStep;
                    if (Angle > OpenAngle)
                    {
                        Angle = OpenAngle;
                    }
                }

                // If it's been a while since we've heard an open signal, let's start closing the door
                if (DateTime.Now.Subtract(LatestOpenSignal).TotalSeconds >= SecondsBeforeClose)
                {
                    Opening = false;
                    if (CloseSound != null)
                    {
                        ScenePrivate.PlaySound(CloseSound, PlaySettings.PlayOnce);
                    }
                }
            }
            else
            {
                if (OpenOut)
                {
                    Angle += AngleStep;
                    if (Angle > 0f)
                    {
                        Angle = 0f;
                    }
                }
                else
                {
                    Angle -= AngleStep;
                    if (Angle < 0f)
                    {
                        Angle = 0f;
                    }
                }
            }

            // Compute the new position and rotation of the door
            Quaternion Rotation = Quaternion.FromEulerAngles(new Vector(0, 0, Angle, 0));
            Quaternion NewOri   = ClosedOrientation * Rotation;
            Vector     NewPos   = ClosedPosition - HingeOffset.Rotate(ref Rotation);

            // Update the door's position and orientation
            DoorBody.SetAngularVelocity(Vector.Zero);
            DoorBody.SetLinearVelocity(Vector.Zero);
            DoorBody.SetPosition(NewPos);
            DoorBody.SetOrientation(QuaternionToVector(NewOri));
        }
    }