/// <summary>
        /// Load data from given object.
        /// </summary>
        /// <param name="data"></param>
        public static void LoadData(Serialization.Vehiclesv1 data)
        {
            Logger.Log($"VehicleManagerMod::LoadData: version {data.Id}");
            Clear();

            var buildings = Utils.GetSupportedServiceBuildings();

            foreach (var building in buildings)
            {
                SetBuildingUseDefaultVehicles(building, data.BuildingUseDefaultVehicles[building]);

                if (data.BuildingToVehicles[building] != null)
                {
                    foreach (var prefab in data.BuildingToVehicles[building])
                    {
                        if (PrefabMapping.TryGetValue(prefab, out int prefabIndex))
                        {
                            AddCustomVehicle(building, prefabIndex);
                        }
                        else
                        {
                            Logger.LogWarning($"VehicleManagerMod::LoadData: Could not load vehicle prefab {prefab}!!!");
                        }
                    }
                }
            }
        }
        public override void OnLoadData()
        {
            base.OnLoadData();

            if (managers.loading.currentMode == AppMode.Game)
            {
                try
                {
                    // Always try to load the latest version if possible.
                    if (Vehiclesv1.TryLoadData(this, out Vehiclesv1 data))
                    {
                        VehicleManagerMod.LoadData(data);
                    }
                    else
                    {
                        VehicleManagerMod.Clear();
                    }
                }
                catch (Exception ex)
                {
                    Logger.LogException(ex);
                }
            }
        }
Esempio n. 3
0
 public static bool TryLoadData(EnhancedDistrictVehiclesSerializableData loader, out Vehiclesv1 data)
 {
     if (loader.TryLoadData(m_id, new Vehiclesv1Binder(), out Vehiclesv1 target))
     {
         if (target != null)
         {
             data = target;
             return(true);
         }
         else
         {
             data = null;
             return(false);
         }
     }
     else
     {
         data = null;
         return(false);
     }
 }