コード例 #1
0
 public EffectSoundEmitter(uint id, Vector3 position, MySoundPair sound)
 {
     ParticleSoundId = id;
     Updated = true;
     Emitter = new MyEntity3DSoundEmitter(null);
     Emitter.SetPosition(position);
     Emitter.PlaySound(sound);
     if (Emitter.Sound != null)
         OriginalVolume = Emitter.Sound.Volume;
     else
         OriginalVolume = 1f;
     Emitter.Update();
 }
コード例 #2
0
        private void PlaySound(string soundName)
        {
            MyPhysicalMaterialDefinition def;
            if(MyDefinitionManager.Static.TryGetDefinition<MyPhysicalMaterialDefinition>(new MyDefinitionId(typeof(MyObjectBuilder_PhysicalMaterialDefinition),m_physItemDef.PhysicalMaterial), out def))
            {
                MySoundPair sound;
                if (def.GeneralSounds.TryGetValue(MyStringId.GetOrCompute(soundName), out sound) && !sound.SoundId.IsNull)
                {
                    m_soundEmitter.PlaySound(sound);
                }
                else
                {
                    MySoundPair soundPair;
                    if (!m_toolSounds.TryGetValue(soundName, out soundPair))
                    {
                        soundPair = new MySoundPair(soundName);
                        m_toolSounds.Add(soundName, soundPair);
                    }

                    m_soundEmitter.PlaySound(soundPair);
                }
            }
        }
コード例 #3
0
        public override void UpdateBeforeSimulation()
        {
            base.UpdateBeforeSimulation();

            //Sound control
            if (MySandboxGame.IsDedicated == false)
            {
                if (m_fallSoundShouldPlay.Value == true)
                {
                    if (m_soundEmitter == null)
                    {
                        m_soundEmitter = new MyEntity3DSoundEmitter(this);
                        NeedsUpdate   |= MyEntityUpdateEnum.EACH_100TH_FRAME;
                    }
                    if (m_soundEmitter.IsPlaying == false && m_fallSound != null && m_fallSound != MySoundPair.Empty)
                    {
                        m_soundEmitter.PlaySound(m_fallSound, true, true);
                    }
                }
                else
                {
                    if (m_soundEmitter != null && m_soundEmitter.IsPlaying)
                    {
                        m_soundEmitter.StopSound(false);
                    }
                }
            }

            //contact was made
            if (m_obstacleContact && m_groundContact == false)
            {
                if (Physics.LinearVelocity.Y > 0f || Physics.LinearVelocity.LengthSquared() < 9f)
                {
                    m_groundContact             = true;
                    m_fallSoundShouldPlay.Value = false;//start crash sound
                    m_soundStart = DateTime.UtcNow;
                }
                else
                {
                    m_obstacleContact = false;//scratching
                }
            }
        }
コード例 #4
0
 public EffectSoundEmitter(uint id, Vector3 position, MySoundPair sound)
 {
     ParticleSoundId = id;
     Updated = true;
     MyEntity entity = null;
     if (MyFakes.ENABLE_NEW_SOUNDS && MySession.Static.Settings.RealisticSound)//snap emitter to closest block - used for realistic sounds
     {
         List<MyEntity> m_detectedObjects = new List<MyEntity>();
         BoundingSphereD effectSphere = new BoundingSphereD(MySession.Static.LocalCharacter != null ? MySession.Static.LocalCharacter.PositionComp.GetPosition() : MySector.MainCamera.Position, 2f);
         MyGamePruningStructure.GetAllEntitiesInSphere(ref effectSphere, m_detectedObjects);
         float distBest = float.MaxValue;
         float dist;
         for (int i = 0; i < m_detectedObjects.Count; i++)
         {
             MyCubeBlock block = m_detectedObjects[i] as MyCubeBlock;
             if (block != null)
             {
                 dist = Vector3.DistanceSquared(MySession.Static.LocalCharacter.PositionComp.GetPosition(), block.PositionComp.GetPosition());
                 if (dist < distBest)
                 {
                     dist = distBest;
                     entity = block;
                 }
             }
         }
         m_detectedObjects.Clear();
     }
     Emitter = new MyEntity3DSoundEmitter(entity);
     Emitter.SetPosition(position);
     if (sound == null)
         sound = MySoundPair.Empty;
     Emitter.PlaySound(sound);
     if (Emitter.Sound != null)
         OriginalVolume = Emitter.Sound.Volume;
     else
         OriginalVolume = 1f;
     Emitter.Update();
     SoundPair = sound;
 }
コード例 #5
0
ファイル: MyGunBase.cs プロジェクト: fluxit/SpaceEngineers
 internal void StartShootSound(MyEntity3DSoundEmitter soundEmitter)
 {
     if (ShootSound != null)
     {
         if (soundEmitter.IsPlaying && !soundEmitter.Loop)
             soundEmitter.StopSound(true);
         soundEmitter.PlaySound(ShootSound, true);
     }
 }
コード例 #6
0
        private void IKFeetStepSounds(MyEntity3DSoundEmitter walkEmitter, MySoundPair cueEnum)
        {
            var movementState = m_character.GetCurrentMovementState();

			if (movementState.GetMode() == MyCharacterMovement.Flying)
				return;

            if (movementState.GetSpeed() != m_lastUpdateMovementState.GetSpeed())
            {
                walkEmitter.StopSound(true);
                m_lastStepTime = 0;
            }

			int usedMinimumDelay = int.MaxValue;
			if (movementState.GetDirection() != MyCharacterMovement.NoDirection)
			{
			    switch (movementState.GetSpeed())
			    {
			        case MyCharacterMovement.NormalSpeed:
			            usedMinimumDelay = m_stepMinimumDelayWalk;
			            break;
			        case MyCharacterMovement.Fast:
			            usedMinimumDelay = m_stepMinimumDelayRun;
			            break;
			        case MyCharacterMovement.VeryFast:
			            usedMinimumDelay = m_stepMinimumDelaySprint;
			            break;
			    }
			}

            bool minimumDelayExceeded = false;
			minimumDelayExceeded = (MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastStepTime) >= usedMinimumDelay;
            //MyRenderProxy.DebugDrawAABB(m_character.PositionComp.WorldAABB, Color.White);

			if (minimumDelayExceeded)
            {
                int leftAnkleBoneIndex, rightAnkleBoneIndex;
                MyCharacterBone leftAnkleBone = m_character.AnimationController != null 
                    ? m_character.AnimationController.FindBone(m_character.Definition.LeftAnkleBoneName, out leftAnkleBoneIndex) 
                    : null;
                MyCharacterBone rightAnkleBone = m_character.AnimationController != null 
                    ? m_character.AnimationController.FindBone(m_character.Definition.RightAnkleBoneName, out rightAnkleBoneIndex)
                    : null;
                Vector3 posLeftFoot = leftAnkleBone != null
                    ? leftAnkleBone.AbsoluteTransform.Translation
                    : m_character.PositionComp.LocalAABB.Center;
                Vector3 posRightFoot = rightAnkleBone != null 
                    ? rightAnkleBone.AbsoluteTransform.Translation 
                    : m_character.PositionComp.LocalAABB.Center;
                float ankleHeight;
                MyFeetIKSettings settingsIK;
                if (m_character.Definition.FeetIKSettings != null
                    && m_character.Definition.FeetIKSettings.TryGetValue(MyCharacterMovementEnum.Standing, out settingsIK))
                {
                    ankleHeight = settingsIK.FootSize.Y;
                }
                else
                {
                    ankleHeight = DEFAULT_ANKLE_HEIGHT;
                }
                float charSpeed = 0f;
                if (m_character.AnimationController != null)
                    m_character.AnimationController.Variables.GetValue(MyAnimationVariableStorageHints.StrIdSpeed, out charSpeed);
                if (posLeftFoot.Y - ankleHeight < m_character.PositionComp.LocalAABB.Min.Y
                    || posRightFoot.Y - ankleHeight < m_character.PositionComp.LocalAABB.Min.Y)
                {
                    if(charSpeed > 0.05f)
                        walkEmitter.PlaySound(cueEnum);
                    m_lastStepTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
                }
            }

			m_lastUpdateMovementState = movementState;
        }
コード例 #7
0
ファイル: Ladder.cs プロジェクト: THDigi/Ladder
        public void ReceivedStepPacket(byte[] bytes)
        {
            try
            {
                long entId = BitConverter.ToInt64(bytes, 0);

                if(MyAPIGateway.Entities.EntityExists(entId))
                {
                    var ent = MyAPIGateway.Entities.GetEntityById(entId);
                    var emitter = new MyEntity3DSoundEmitter(ent as MyEntity);
                    emitter.PlaySound(soundStep, false, false, false);
                }
            }
            catch(Exception e)
            {
                Log.Error(e);
            }
        }
コード例 #8
0
 internal void StartShootSound(MyEntity3DSoundEmitter soundEmitter)
 {
     if (ShootSound != null && soundEmitter != null)
     {
         if (soundEmitter.IsPlaying)
         {
             if (!soundEmitter.Loop)
                 soundEmitter.PlaySound(ShootSound, true);
         }
         else
             soundEmitter.PlaySound(ShootSound,true);
     }
 }