public void DrawGhost(IntVec3 origin)
        {
            IntVec3 cell = origin + Position;

            if (_thingDef != null)
            {
                // normal thingdef graphic
                if (_thingDef.graphicData.linkFlags == LinkFlags.None)
                {
                    GhostDrawer.DrawGhostThing(cell, _rotation, _thingDef, null, Resources.ghostColor(CanPlace(origin)), AltitudeLayer.Blueprint);
                }

                // linked thingdef graphic
                else
                {
                    Material material;
                    Color    color = Resources.ghostColor(CanPlace(origin));
                    int      hash  = color.GetHashCode() * _rotation.GetHashCode();
                    if (!_cachedMaterials.TryGetValue(hash, out material))
                    {
                        // get a colored version (ripped from GhostDrawer.DrawGhostThing)
                        Graphic_Linked graphic = (Graphic_Linked)_thingDef.graphic.GetColoredVersion(ShaderDatabase.Transparent,
                                                                                                     color,
                                                                                                     Color.white);

                        // atlas contains all possible link graphics
                        Material atlas = graphic.MatSingle;

                        // loop over cardinal directions, and set the correct bits (e.g. 1, 2, 4, 8).
                        int linkInt = 0;
                        int dirInt  = 1;
                        for (int i = 0; i < 4; i++)
                        {
                            if (blueprint.ShouldLinkWith(Position + GenAdj.CardinalDirections[i], _thingDef))
                            {
                                linkInt += dirInt;
                            }
                            dirInt *= 2;
                        }

                        // translate int to bitmask (flags)
                        LinkDirections linkSet = (LinkDirections)linkInt;

                        // get and cache the final material
                        material = MaterialAtlasPool.SubMaterialFromAtlas(atlas, linkSet);
                        _cachedMaterials.Add(hash, material);
                    }

                    // draw the thing.
                    Vector3 position = (cell).ToVector3ShiftedWithAltitude(AltitudeLayer.MetaOverlays);
                    Graphics.DrawMesh(MeshPool.plane10, position, Quaternion.identity, material, 0);
                }
            }
            else
            {
                Vector3 position = (cell).ToVector3ShiftedWithAltitude(AltitudeLayer.MetaOverlays);
                Graphics.DrawMesh(MeshPool.plane10, position, Quaternion.identity, Resources.ghostFloorMaterial(CanPlace(origin)), 0);
            }
        }
Exemple #2
0
        protected Material LinkedDrawMatFrom(Thing parent, IntVec3 cell)
        {
            int num1 = 0;
            int num2 = 1;

            for (int index = 0; index < 4; ++index)
            {
                if (this.ShouldLinkWith(cell + GenAdj.CardinalDirections[index], parent))
                {
                    num1 += num2;
                }
                num2 *= 2;
            }
            LinkDirections LinkSet = (LinkDirections)num1;

            return(MaterialAtlasPool.SubMaterialFromAtlas(this.subGraphic.MatSingleFor(parent), LinkSet));
        }
Exemple #3
0
        public Material LinkedDrawMatFrom(Graphic_LinkedCornerFiller graphic, Thing parent, IntVec3 cell)
        {
            int num  = 0;
            int num2 = 1;

            for (int i = 0; i < 4; i++)
            {
                IntVec3 c = cell + GenAdj.CardinalDirections[i];
                if (graphic.ShouldLinkWith(c, parent))
                {
                    num += num2;
                }
                num2 *= 2;
            }
            LinkDirections linkSet = (LinkDirections)num;

            return(MaterialAtlasPool.SubMaterialFromAtlas(graphic.subGraphic.MatSingleFor(parent), linkSet));
        }