Exemplo n.º 1
0
        void ICmpInitializable.OnInit(Component.InitContext context)
        {
            if (context == InitContext.Activate && DualityApp.ExecContext != DualityApp.ExecutionContext.Editor)
            {
                AnimSpriteRenderer r = this.GameObj.Renderer as AnimSpriteRenderer;
                SoundEmitter s = this.GameObj.GetComponent<SoundEmitter>();
                Transform t = this.GameObj.Transform;

                r.AnimDuration = MathF.RoundToInt(0.4f * r.AnimDuration * MathF.Rnd.NextFloat(0.8f, 1.25f) * MathF.Sqrt(intensity));
                t.RelativeScale *= MathF.Sqrt(intensity);
                t.RelativeAngle = MathF.Rnd.NextFloat(MathF.RadAngle360);
                t.RelativeVel = new Vector3(MathF.Rnd.NextVector2(1.0f));

                ContentRef<Sound> soundRes = ContentRef<Sound>.Null;
                switch (MathF.Rnd.Next(5))
                {
                    case 0:	soundRes = GameRes.Data.Sound.Explo1_Sound; break;
                    case 1:	soundRes = GameRes.Data.Sound.Explo2_Sound; break;
                    case 2:	soundRes = GameRes.Data.Sound.Explo3_Sound; break;
                    case 3:	soundRes = GameRes.Data.Sound.Explo4_Sound; break;
                    case 4:	soundRes = GameRes.Data.Sound.Explo5_Sound; break;
                }
                SoundEmitter.Source source = new SoundEmitter.Source(soundRes, false);
                source.Volume = MathF.Rnd.NextFloat(0.9f, 1.15f) * MathF.Sqrt(intensity);
                source.Pitch = MathF.Rnd.NextFloat(0.8f, 1.25f) / MathF.Sqrt(intensity);
                source.Paused = false;
                s.Sources.Add(source);
            }
        }
Exemplo n.º 2
0
		public override bool Convert(ConvertOperation convert)
		{
			List<Sound> availData = convert.Perform<Sound>().ToList();

			// Generate objects
			foreach (Sound snd in availData)
			{
				if (convert.IsObjectHandled(snd)) continue;

				GameObject gameobj = convert.Result.OfType<GameObject>().FirstOrDefault();
				SoundEmitter emitter = convert.Result.OfType<SoundEmitter>().FirstOrDefault();
				if (emitter == null && gameobj != null) emitter = gameobj.GetComponent<SoundEmitter>();
				if (emitter == null) emitter = new SoundEmitter();
				convert.SuggestResultName(emitter, snd.Name);
					
				SoundEmitter.Source source = new SoundEmitter.Source(snd);
				emitter.Sources.Add(source);

				convert.AddResult(emitter);
				convert.MarkObjectHandled(snd);
			}
			return false;
		}