Пример #1
0
        public FBNetData CreateFBData(FlatBufferBuilder fbbParent = null, IFBObject child = null)
        {
            if (fbbParent == null)
            {
                fbbParent = new FlatBufferBuilder(1);
            }

            VectorOffset soundsOffset = new VectorOffset();

            if (Sounds.Any())
            {
                List <int> soundOffsets = new List <int>();
                foreach (var sound in Sounds)
                {
                    var localSoundFileOffset = XFBType.LocalFile.CreateLocalFile(fbbParent, sound.FileLocation,
                                                                                 fbbParent.CreateString(sound.FileName),
                                                                                 fbbParent.CreateString(sound.FilePath),
                                                                                 fbbParent.CreateString(sound.ResourceGroup ?? ""));

                    soundOffsets.Add(XFBType.Sound.CreateSound(fbbParent, localSoundFileOffset).Value);
                }

                XFBType.SoundComponent.StartSoundsVector(fbbParent, Sounds.Count);
                foreach (var sound in soundOffsets)
                {
                    fbbParent.AddOffset(sound);
                }
                soundsOffset = fbbParent.EndVector();
            }

            XFBType.SoundComponent.StartSoundComponent(fbbParent);

            if (Sounds.Any())
            {
                XFBType.SoundComponent.AddSounds(fbbParent, soundsOffset);
            }

            var finishOffset = XFBType.SoundComponent.EndSoundComponent(fbbParent);

            fbbParent.Finish(finishOffset.Value); //!!!!! important ..
            return(new FBNetData()
            {
                _fbData = fbbParent.SizedByteArray(), _offset = finishOffset.Value, Fbb = fbbParent
            });                                                                                                             //bytebuffer
        }
Пример #2
0
        public static async void PlaySound(SoundManagerSounds sound, bool oneatatime = false, bool excludefrommute = false)
        {
            if (MuteAllSounds && !excludefrommute)
            {
                return;
            }

            if (oneatatime)
            {
                if (Sounds.Any(a => a.SoundName == sound && a.IsPlaying))
                {
                    return;
                }
            }

            var options = new HowlOptions
            {
                Sources = new[] { "/Assets/sounds/" + Enum.GetName(typeof(SoundManagerSounds), sound) + ".mp3" },
                Formats = new[] { "mp3" }
            };

            var soundid = await Howl.Play(options);

            if (!Sounds.Any(a => a.SoundName == sound))
            {
                Sounds.Add(new Sound()
                {
                    SoundId   = soundid,
                    SoundName = sound,
                    IsPlaying = true
                });
            }
            else
            {
                Sounds.FirstOrDefault(a => a.SoundName == sound).SoundId   = soundid;
                Sounds.FirstOrDefault(a => a.SoundName == sound).IsPlaying = true;
            }
        }
Пример #3
0
        // accept a single input and show consequences
        public void AcceptInput(string input)
        {
            try {
                var split   = input.SplitTrim(" ");
                var inevent = split[0].SafeEnumParse <InputEvent>() ?? InputEvent.None;
                if (inevent == InputEvent.None)
                {
                    throw Error.Argument("Bad input: '{0}'".Fmt(input));
                }
                var inparam = (split.Count > 1) ? split[1].SafeIntParse() : null;
                AcceptEvent(inevent, inparam);

                if (Sounds.Any())
                {
                    Logger.WriteLine(1, "# Sounds: {0}", Sounds.Join());
                }
                if (_messages.Any())
                {
                    Logger.WriteLine(1, "# Messages: {0}", _messages.Join());
                }
                if (Logger.Level >= 2)
                {
                    ShowLevel("input");
                }
            } catch (Exception ex) {
                _messages.Insert(0, "Error: {0}".Fmt(ex.Message));
                VerboseLog("{0}", _messages.First());
                if (ex is DOLEException)
                {
                    Logger.WriteLine("*** '{0}': runtime error: {1}", _sourcename, ex.Message);
                }
                else
                {
                    Logger.WriteLine("*** '{0}': runtime exception: {1}", _sourcename, ex.ToString());
                }
                _modelstate = ModelState.Failed;
            }
        }