Пример #1
0
        public WallMeshComponents(Wall wall, Texture texture)
        {
            this.wall          = wall;
            this.texture       = texture;
            this.gameObject    = new GameObject($"Wall {wall.Index} ({wall.Section}: Line {wall.Side.Line.Index}, Side {wall.Side.Index})");
            this.Mesh          = CreateMesh();
            this.Filter        = CreateFilter();
            this.Renderer      = CreateRenderer();
            this.Collider      = CreateBoxCollider();
            this.collisionInfo = CollisionInfo.CreateOn(gameObject, wall);

            Update(0);
        }
Пример #2
0
        public void Update(float tickFraction)
        {
            SpriteRotations rotations = entity.Frame.SpriteRotations;

            if (rotations.DoNotRender)
            {
                EnsureDisabled();
                return;
            }

            EnsureEnabled();

            // TODO: If the index or the texture does not change, don't do some of the following.

            int     index   = CameraManager.CalculateRotationIndex(entity, tickFraction);
            Texture texture = entity.Frame.SpriteRotations[index];

            Renderer.sharedMaterial = texture.Material;

            // Since the 0-7 range has us looking for 5, 6, or 7, we can check
            // anything >= 5 to see if we should be mirroring.
            bool shouldFlip = rotations.Mirrored && index >= 5;

            Mesh.uv = shouldFlip ? flippedUV : nonFlippedUV;

            float y = texture.Height.MapUnit() / 2;

            gameObject.transform.localPosition    = new Vector3(0, y, 0);
            gameObject.transform.localScale       = new Vector3(texture.Width, texture.Height, 1);
            gameObject.transform.localEulerAngles = CameraManager.SpriteEulerAngles;

            // TODO: Only do this if the brightness level changes.
            float lightLevel = entity.Sector.LightLevelNormalized;
            Color color      = new Color(lightLevel, lightLevel, lightLevel, 1.0f);

            Color[] colors = meshDataManager.ColorBufferSwap(color);
            Mesh.colors = colors;
        }