Exemplo n.º 1
0
        public static void SetVehicleTex(VehicleDef selectedDef)
        {
            if (selectedDef is null)
            {
                selectedVehicleTex = null;
                return;
            }
            var bodyGraphicData = selectedDef.graphicData;
            var graphicData     = new GraphicDataRGB();

            graphicData.CopyFrom(bodyGraphicData);
            graphicInt         = graphicData.Graphic as Graphic_Vehicle;
            selectedVehicleTex = graphicInt.TexAt(Rot8.North);
        }
Exemplo n.º 2
0
        static VehicleTex()
        {
            StringBuilder tasks = new StringBuilder();

            foreach (VehicleDef vehicleDef in DefDatabase <VehicleDef> .AllDefs)
            {
                tasks.Clear();
                tasks.AppendLine($"Generating TextureCache for {vehicleDef.defName}");
                try
                {
                    tasks.Append("Creating icon...");
                    string iconFilePath = vehicleDef.properties.iconTexPath;
                    if (iconFilePath.NullOrEmpty())
                    {
                        switch (vehicleDef.vehicleType)
                        {
                        case VehicleType.Land:
                            iconFilePath = DefaultVehicleIconTexPath;
                            break;

                        case VehicleType.Sea:
                            iconFilePath = DefaultBoatIconTexPath;
                            break;

                        case VehicleType.Air:
                            iconFilePath = DefaultShuttleIconTexPath;
                            break;
                        }
                    }
                    tasks.AppendLine("Icon created");
                    tasks.AppendLine("Creating BodyGraphicData and cached graphics...");
                    if (vehicleDef.graphicData is GraphicDataRGB graphicDataRGB)
                    {
                        Texture2D tex;
                        var       graphicData = new GraphicDataRGB();
                        graphicData.CopyFrom(graphicDataRGB);
                        Graphic_Vehicle graphic = graphicData.Graphic as Graphic_Vehicle;
                        tasks.AppendLine("Setting TextureCache...");
                        SetTextureCache(vehicleDef, graphicData);
                        tasks.AppendLine("Finalized TextureCache");
                        if (cachedTextureFilepaths.ContainsKey(iconFilePath))
                        {
                            tex = cachedTextureFilepaths[iconFilePath];
                        }
                        else
                        {
                            tex = ContentFinder <Texture2D> .Get(iconFilePath);

                            cachedTextureFilepaths.Add(iconFilePath, tex);
                        }
                        tasks.AppendLine("Finalizing caching");
                        CachedGraphics.Add(vehicleDef, graphic);
                        CachedTextureIcons.Add(vehicleDef, tex);
                    }
                    else
                    {
                        SmashLog.Error($"Unable to create GraphicData of type <type>{vehicleDef.graphicData?.GetType().ToStringSafe() ?? "Null"} for {vehicleDef.defName}.\n{tasks}");
                    }
                }
                catch (Exception ex)
                {
                    Log.Error($"Exception thrown while trying to generate cached textures. Exception=\"{ex.Message}\"\n-----------------Tasks-----------------\n{tasks}");
                }
            }
        }