Ejemplo n.º 1
0
        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);
            }
        }