private AudioSource PrepareAudioSource(TankFallEvent evt, TankFallingSoundEffectComponent tankFallingSoundEffect, MapDustComponent mapDust, Transform root) { AudioSource collisionSourceAsset; switch (evt.FallingType) { case TankFallingType.TANK: case TankFallingType.VERTICAL_STATIC: collisionSourceAsset = tankFallingSoundEffect.CollisionSourceAsset; break; case TankFallingType.FLAT_STATIC: case TankFallingType.SLOPED_STATIC_WITH_TRACKS: collisionSourceAsset = tankFallingSoundEffect.FallingSourceAsset; break; case TankFallingType.SLOPED_STATIC_WITH_COLLISION: { DustEffectBehaviour effectByTag = mapDust.GetEffectByTag(evt.FallingTransform, Vector2.zero); if (effectByTag == null) { collisionSourceAsset = tankFallingSoundEffect.FallingSourceAsset; } else { DustEffectBehaviour.SurfaceType surface = effectByTag.surface; collisionSourceAsset = ((surface == DustEffectBehaviour.SurfaceType.Metal) || (surface == DustEffectBehaviour.SurfaceType.Concrete)) ? tankFallingSoundEffect.CollisionSourceAsset : tankFallingSoundEffect.FallingSourceAsset; } break; } default: throw new ArgumentException("Illegal type of falling"); } GetInstanceFromPoolEvent eventInstance = new GetInstanceFromPoolEvent { Prefab = collisionSourceAsset.gameObject, AutoRecycleTime = ((collisionSourceAsset != tankFallingSoundEffect.FallingSourceAsset) ? collisionSourceAsset.clip : this.GetFallingAudioClip(tankFallingSoundEffect)).length + 0.2f }; base.ScheduleEvent(eventInstance, new EntityStub()); Transform instance = eventInstance.Instance; AudioSource component = instance.GetComponent <AudioSource>(); instance.parent = root; instance.localPosition = Vector3.zero; instance.localRotation = Quaternion.identity; instance.gameObject.SetActive(true); component.Play(); return(component); }
public void PlayTankFrictionSound(UpdateEvent evt, ReadyActiveTankFrictionSoundNode tank) { TankFrictionSoundBehaviour tankFrictionSoundBehaviour = tank.tankFrictionSoundEffectReady.TankFrictionSoundBehaviour; if (tankFrictionSoundBehaviour.TriggerStay) { TankFrictionSoundEffectComponent tankFrictionSoundEffect = tank.tankFrictionSoundEffect; Collider frictionCollider = tankFrictionSoundBehaviour.FrictionCollider; if (frictionCollider == null) { this.StopSounds(tankFrictionSoundEffect); } else { Vector3 velocity = tank.rigidbody.Rigidbody.velocity; if (frictionCollider.gameObject.layer == Layers.FRICTION) { this.SetMetallFriction(tankFrictionSoundEffect, velocity); } else { DustEffectBehaviour effect = tank.collisionDust.CollisionDustBehaviour.Effect; if (effect == null) { this.StopSounds(tankFrictionSoundEffect); } else { DustEffectBehaviour.SurfaceType surface = effect.surface; if (surface == DustEffectBehaviour.SurfaceType.Metal) { this.SetMetallFriction(tankFrictionSoundEffect, velocity); } else if (surface != DustEffectBehaviour.SurfaceType.Concrete) { this.StopSounds(tankFrictionSoundEffect); } else { this.SetStoneFriction(tankFrictionSoundEffect, velocity); } } } } } }