Ejemplo n.º 1
0
        public static CarSettings LoadFromJson(string str)
        {
            var settings = new CarSettings();

            var json = JObject.Parse(str);

            var jCar = json.GetValue("Car");

            if (jCar != null && jCar.Type == JTokenType.Object)
            {
                var jObjCar = (JObject)jCar;

                var jFile = jObjCar.GetValue("File");
                var jName = jObjCar.GetValue("Name");

                if (jFile != null && jFile.Type == JTokenType.String)
                {
                    settings.carName = jFile.ToString();
                }

                if (jName != null && jName.Type == JTokenType.String)
                {
                    settings.carName = jFile.ToString();
                }
            }

            var jSounds = json.GetValue("Sounds");

            if (jSounds != null && jSounds.Type == JTokenType.Object)
            {
                var jObjSounds = (JObject)jSounds;

                foreach (var s in Enum.GetValues(typeof(SoundType)))
                {
                    var jSound = jObjSounds.GetValue(s.ToString());

                    var sound = settings.sounds[(int)s];

                    if (jSound != null && jSound.Type == JTokenType.Object)
                    {
                        var jObjSound = (JObject)jSound;

                        var jFile           = jObjSound.GetValue("File");
                        var jDisableDefault = jObjSound.GetValue("DisableDefault");

                        if (jFile != null && jFile.Type == JTokenType.String)
                        {
                            sound.filename = jFile.ToString();
                        }

                        if (jDisableDefault != null && jDisableDefault.Type == JTokenType.Boolean)
                        {
                            sound.disableDefault = (bool)jDisableDefault;
                        }
                    }
                }
            }

            return(settings);
        }
Ejemplo n.º 2
0
        public static CarAsset CreateFromAudioZip(string filename)
        {
            CarAsset asset = new CarAsset();

            using (FileStream zipFile = new FileStream(filename, FileMode.Open))
            {
                using (ZipArchive zip = new ZipArchive(zipFile, ZipArchiveMode.Read))
                {
                    var         settingsEntry = zip.GetEntry("settings.json");
                    CarSettings settings      = null;
                    if (settingsEntry == null)
                    {
                        settings = new CarSettings();
                    }
                    else
                    {
                        settings = CarSettings.LoadFromZipEntry(settingsEntry);
                    }

                    asset.LoadSoundAssets(zip, settings);
                }
            }

            return(asset);
        }
Ejemplo n.º 3
0
 void LoadSoundAssets(ZipArchive zip, CarSettings settings)
 {
     for (int i = 0; i < settings.sounds.Length; i++)
     {
         m_sounds[i].disableDefault = settings.sounds[i].disableDefault;
         //todo more
     }
 }
Ejemplo n.º 4
0
        void LoadCarAsset(ZipArchive zip, CarSettings settings)
        {
            ZipArchiveEntry carEntry = null;

            foreach (var e in zip.Entries)
            {
                var name = e.Name;
                if (settings.carBundlebName != "" && name == settings.carBundlebName)
                {
                    carEntry = e;
                    break;
                }
                if (settings.carBundlebName == "")
                {
                    int index = name.IndexOf('.');
                    if (index < 0)
                    {
                        carEntry = e;
                        break;
                    }
                }
            }

            if (carEntry == null)
            {
                //log error
                return;
            }

            var stream = carEntry.Open();

            byte[] bytes;
            using (var ms = new MemoryStream())
            {
                stream.CopyTo(ms);
                bytes = ms.ToArray();
            }

            m_bundle = AssetBundle.LoadFromMemory(bytes);
        }