public AudioStreamPlayer3D AddSoundInstance(Actor actor, Guid id, AudioStream audioClip, MediaStateOptions options) { float offset = options.Time.GetValueOrDefault(); if (options.Looping != null && options.Looping.Value && audioClip.GetLength() != 0.0f) { offset = offset % audioClip.GetLength(); } if (offset < audioClip.GetLength()) { var soundInstance = new AudioStreamPlayer3D(); actor.AddChild(soundInstance); soundInstance.Stream = audioClip; soundInstance.Seek(offset); soundInstance.UnitSize = 1.0f; soundInstance.EmissionAngleDegrees = 45.0f; //only affects multichannel sounds. Default to 50% spread, 50% stereo. soundInstance.MaxDistance = 1000000.0f; ApplyMediaStateOptions(actor, soundInstance, options, id, true); if (options.paused != null && options.paused.Value == true) { //start as paused soundInstance.Play(); soundInstance.StreamPaused = true; } else { //start as unpaused _unpausedSoundInstances.Add(new SoundInstance(id, actor)); soundInstance.Play(); soundInstance.StreamPaused = false; } return(soundInstance); } return(null); }
public override void _Ready() { var env = GetNode <WorldEnvironment>("sky").Environment; env.BackgroundColor = new Color(Lib.Node.BackgroundColorHtmlCode); env.BackgroundMode = Godot.Environment.BGMode.Sky; env.BackgroundSky = new PanoramaSky() { Panorama = ((Texture)GD.Load("res://assets/night_city.hdr")) }; env.BackgroundSkyRotationDegrees = new Vector3(0, 0, 0); env.BackgroundSkyCustomFov = 130; InitSound(); AddChild(Audio); rainAudio.Play(Audio); Audio.Seek((float)GD.RandRange(0, rainAudio.GetLength())); var glass = GetNode("Window").GetNode <MeshInstance>("Glass"); var noiseTexture = new NoiseTexture() { Noise = new OpenSimplexNoise() { Period = 40, Persistence = 0.2f }, AsNormalmap = true, BumpStrength = 32 }; glass.MaterialOverride = new SpatialMaterial() { AlbedoColor = new Color(1, 1, 1, 0.05f), AlbedoTexture = noiseTexture, NormalEnabled = true, NormalScale = -0.1f, NormalTexture = noiseTexture, RefractionEnabled = true, RefractionScale = 0.1f, RefractionTexture = noiseTexture }; var rainWindowParticles = new CPUParticles(); AddChild(rainWindowParticles); rainWindowParticles.RotateX(Mathf.Deg2Rad(16)); rainWindowParticles.Mesh = new SphereMesh() { Radius = 0.005f, Height = 0.01f, RadialSegments = 4, Rings = 4 }; rainWindowParticles.Amount = 500; rainWindowParticles.EmissionShape = CPUParticles.EmissionShapeEnum.Sphere; rainWindowParticles.EmissionSphereRadius = 4.5f; var rainParticles = new CPUParticles(); AddChild(rainParticles); rainParticles.RotateX(Mathf.Deg2Rad(16)); rainParticles.Translate(new Vector3(7.6f, 2.7f, 0)); rainParticles.Mesh = new SphereMesh() { Radius = 0.005f, Height = 1, RadialSegments = 4, Rings = 1 }; rainParticles.Amount = 200; rainParticles.EmissionShape = CPUParticles.EmissionShapeEnum.Sphere; rainParticles.EmissionSphereRadius = 8f; }
public override void _Ready() { var env = GetNode <WorldEnvironment>("sky").Environment; env.BackgroundColor = new Color(Lib.Node.BackgroundColorHtmlCode); env.BackgroundMode = Godot.Environment.BGMode.Sky; env.BackgroundSky = new PanoramaSky() { Panorama = ((Texture)GD.Load("res://assets/temple.hdr")) }; env.BackgroundSkyRotationDegrees = new Vector3(0, 0, 0); env.BackgroundSkyCustomFov = 100; InitSound(); AddChild(Audio); templeAudio.Play(Audio); Audio.Seek((float)GD.RandRange(0, templeAudio.GetLength())); var particles = new CPUParticles() { Mesh = new QuadMesh(), EmissionShape = CPUParticles.EmissionShapeEnum.Sphere, Amount = 800, EmissionSphereRadius = 0.2f, Spread = 3, Gravity = new Vector3(0, 0, 0), InitialVelocity = 1, InitialVelocityRandom = 1, ScaleAmountRandom = 0.5f, Lifetime = 20, AngularVelocity = 30, AngularVelocityRandom = 1, LinearAccel = -0.01f, Scale = Scale * 0.15f, ScaleAmount = 0.5f, AngleRandom = 1, ColorRamp = new Gradient() { Offsets = new[] { 0, 0.5f, 1 }, Colors = new[] { Color.FromHsv(0, 0, 0, 0), Color.FromHsv(0, 0, 0.7f), Color.FromHsv(0, 0, 0, 0) } } }; AddChild(particles); particles.Translate(new Vector3(0, 6f, 0)); particles.RotateZ(Mathf.Deg2Rad(90)); var mat = new SpatialMaterial() { FlagsUnshaded = true, VertexColorUseAsAlbedo = true, FlagsTransparent = true, ParamsBlendMode = SpatialMaterial.BlendMode.Add, ParamsBillboardMode = SpatialMaterial.BillboardMode.Particles, AlbedoColor = Color.FromHsv(0, 0, 0.1f), AlbedoTexture = new NoiseTexture() { Noise = new OpenSimplexNoise() { Period = 40, Persistence = 0, Lacunarity = 0.1f, } } }; particles.MaterialOverride = mat; }