예제 #1
0
        /// <summary>
        /// For sounds!
        /// </summary>
        /// <param name="lthing">The Thing this component is attached to</param>
        /// <param name="template">The template from the Thing</param>
        /// <param name="block">The block we're creating this component from</param>
        public SoundComponent(LThing lthing, ThingBlock template, SoundBlock block)
        {
            Name = block.GetStringProperty("name", template.ThingName);
            owner = lthing;

            var soundMain = LKernel.GetG<SoundMain>();
            ISoundSource source = soundMain.GetSource(block.GetStringProperty("File", null));

            bool looping = block.GetBoolProperty("looping", true);
            bool sfx = block.GetBoolProperty("SpecialEffects", false);
            relativePosition = block.GetVectorProperty("position", Vector3.ZERO);
            bool startPaused = block.GetBoolProperty("StartPaused", true);

            Sound = soundMain.Play3D(source, relativePosition, looping, startPaused, sfx);

            if(Sound != null) {
                Sound.PlaybackSpeed = block.GetFloatProperty("Speed", 1);
                float volume;
                if (block.FloatTokens.TryGetValue("volume", out volume))
                    Sound.Volume = volume;

                Sound.MinDistance = block.GetFloatProperty("mindistance", soundMain.Engine.Default3DSoundMinDistance);

                // TODO: effects, if we end up using any of them

                Update();
                Sound.Paused = false;
            }

            soundMain.AddSoundComponent(this);
        }
예제 #2
0
        /// <summary>
        /// Sound blocks
        /// </summary>
        void ParseSound(ThingDefinition thingDef, RuleInstance block)
        {
            SoundBlock soundBlock = new SoundBlock(thingDef);

            for (int a = 2; a < block.Children.Length - 1; a++) {
                RuleInstance rule = block.Children[a] as RuleInstance;
                if (rule.Type == NodeType.Rule_Property)
                    ParseProperty(soundBlock, rule.Children[0] as RuleInstance);
            }

            thingDef.SoundBlocks.Add(soundBlock);
        }