Exemplo n.º 1
0
        private static void SetTextureCache(VehicleDef vehicleDef, GraphicDataRGB graphicData)
        {
            var textureArray = new Texture2D[Graphic_RGB.MatCount];

            textureArray[0] = ContentFinder <Texture2D> .Get(graphicData.texPath + "_north", false);

            textureArray[0] ??= ContentFinder <Texture2D> .Get(graphicData.texPath, false);

            textureArray[1] = ContentFinder <Texture2D> .Get(graphicData.texPath + "_east", false);

            textureArray[2] = ContentFinder <Texture2D> .Get(graphicData.texPath + "_south", false);

            textureArray[3] = ContentFinder <Texture2D> .Get(graphicData.texPath + "_west", false);

            textureArray[4] = ContentFinder <Texture2D> .Get(graphicData.texPath + "_northEast", false);

            textureArray[5] = ContentFinder <Texture2D> .Get(graphicData.texPath + "_southEast", false);

            textureArray[6] = ContentFinder <Texture2D> .Get(graphicData.texPath + "_southWest", false);

            textureArray[7] = ContentFinder <Texture2D> .Get(graphicData.texPath + "_northWest", false);

            if (textureArray[0] is null)
            {
                if (textureArray[2] != null)
                {
                    textureArray[0] = textureArray[2];
                }
                else if (textureArray[1] != null)
                {
                    textureArray[0] = textureArray[1];
                }
                else if (textureArray[3] != null)
                {
                    textureArray[0] = textureArray[3];
                }
            }
            if (textureArray[0] is null)
            {
                Log.Error($"Failed to find any textures at {graphicData.texPath} while constructing texture cache.");
                return;
            }
            if (textureArray[2] is null)
            {
                textureArray[2] = textureArray[0];
            }
            if (textureArray[1] is null)
            {
                if (textureArray[3] != null)
                {
                    textureArray[1] = textureArray[3];
                }
                else
                {
                    textureArray[1] = textureArray[0];
                }
            }
            if (textureArray[3] is null)
            {
                if (textureArray[1] != null)
                {
                    textureArray[3] = textureArray[1];
                }
                else
                {
                    textureArray[3] = textureArray[0];
                }
            }

            if (textureArray[4] is null)
            {
                textureArray[4] = textureArray[0];
            }
            if (textureArray[5] is null)
            {
                textureArray[5] = textureArray[2];
            }
            if (textureArray[6] is null)
            {
                textureArray[6] = textureArray[2];
            }
            if (textureArray[7] is null)
            {
                textureArray[7] = textureArray[0];
            }

            for (int i = 0; i < 8; i++)
            {
                CachedVehicleTextures.Add(new Pair <VehicleDef, Rot8>(vehicleDef, new Rot8(i)), textureArray[i]);
            }
        }
Exemplo n.º 2
0
 public virtual void CopyFrom(GraphicDataRGB graphicData)
 {
     base.CopyFrom(graphicData);
     colorThree = graphicData.colorThree;
     pattern    = graphicData.pattern ?? PatternDefOf.Default;
 }
Exemplo n.º 3
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}");
                }
            }
        }
Exemplo n.º 4
0
 public GraphicRequestRGB(Type graphicClass, string path, Shader shader, Vector2 drawSize, Color color, Color colorTwo, Color colorThree, float tiles, Vector2 displacement, GraphicDataRGB graphicData, int renderQueue, List <ShaderParameter> shaderParameters)
 {
     this.graphicClass     = graphicClass;
     this.path             = path;
     this.shader           = shader;
     this.drawSize         = drawSize;
     this.color            = color;
     this.colorTwo         = colorTwo;
     this.colorThree       = colorThree;
     this.tiles            = tiles;
     this.displacement     = displacement;
     this.graphicData      = graphicData;
     this.renderQueue      = renderQueue;
     this.shaderParameters = (shaderParameters.NullOrEmpty() ? null : shaderParameters);
 }