public void PlayDropSound(NodeAddedEvent evt, [Combine] MineDropSoundNode mine, SingleNode <MapDustComponent> map) { MinePlacingTransformComponent minePlacingTransform = mine.minePlacingTransform; if (minePlacingTransform.HasPlacingTransform) { Transform target = minePlacingTransform.PlacingData.transform; DustEffectBehaviour effectByTag = map.component.GetEffectByTag(target, minePlacingTransform.PlacingData.textureCoord); if (effectByTag != null) { AudioSource dropGroundSound; switch (effectByTag.surface) { case DustEffectBehaviour.SurfaceType.Soil: case DustEffectBehaviour.SurfaceType.Sand: case DustEffectBehaviour.SurfaceType.Grass: dropGroundSound = mine.mineSounds.DropGroundSound; break; case DustEffectBehaviour.SurfaceType.Metal: case DustEffectBehaviour.SurfaceType.Concrete: dropGroundSound = mine.mineSounds.DropNonGroundSound; break; default: return; } dropGroundSound.Play(); } } }
private void OnCollisionStay(Collision collision) { this.effect = this.mapDust.GetEffectByTag(collision.transform, Vector2.zero); if ((this.effect != null) && (this.delay <= 0f)) { this.delay = 1f / this.effect.collisionEmissionRate.RandomValue; foreach (ContactPoint point in collision.contacts) { this.effect.TryEmitParticle(point.point, collision.relativeVelocity); } } }
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); } } } } } }
private void Start() { if (this.DefaultDust == null) { foreach (DustEffectBehaviour behaviour in FindObjectsOfType <DustEffectBehaviour>()) { if (behaviour.surface == DustEffectBehaviour.SurfaceType.Concrete) { this.DefaultDust = behaviour; break; } this.DefaultDust = behaviour; } } if (this.LowGraphicDust == null) { this.LowGraphicDust = this.DefaultDust; } this._effects.Clear(); foreach (MapDustEffect effect in this.Targets) { Transform target = effect.Target; if (target) { TargetEffects effects = new TargetEffects(); MaskToDustEffect[] dustEffects = effect.DustEffects; int index = 0; while (true) { if (index >= dustEffects.Length) { this._effects.Add(target, effects); break; } MaskToDustEffect effect2 = dustEffects[index]; effects.GrayscaleRanges.Add(effect2.GrayScaleRange); effects.Textures.Add(effect2.Mask); effects.DustEffects.Add(effect2.EffectBehaviour); index++; } } } }
private void TryEmitFromSuspensionRay(float maxCompression, Track track, MapDustComponent mapDust, float[] delays, int i) { SuspensionRay ray = track.rays[i]; float num = delays[i] - UnityTime.deltaTime; if (!ray.hasCollision) { delays[i] = num; } else { RaycastHit rayHit = ray.rayHit; Transform target = rayHit.transform; DustEffectBehaviour effectByTag = mapDust.GetEffectByTag(target, rayHit.textureCoord); if (effectByTag == null) { delays[i] = num; } else { Vector3 point = rayHit.point; if (num <= 0f) { num = 1f / effectByTag.movementEmissionRate.RandomValue; effectByTag.TryEmitParticle(point, ray.velocity); delays[i] = num; } else { if (!ray.hadPreviousCollision) { float num2 = Mathf.Clamp01(ray.compression / maxCompression); if (num2 > effectByTag.landingCompressionThreshold) { effectByTag.TryEmitParticle(point, Vector3.up * (effectByTag.movementSpeedThreshold.max * num2)); } } delays[i] = num; } } } }