Texture controller for applying palettes (UWPalette) to textures for object sprites.
Наследование: UWEBase
Пример #1
0
 void Awake()
 {
     TextureController.Init();
     OptController.Init();
     VoronoiNoise.Init();
     tex = new TTexture(Vector3.zero, resolution, (int)size, type);
 }
Пример #2
0
    private void Awake()
    {
        TextureController.Initialise("", texture);
        chunkPosMap = new Dictionary <Vector3Int, Chunk>();

        instance = this;
    }
Пример #3
0
        public Destroyer(Vector2 position, DirectionType direction, CoordinateDirection coordinate)
        {
            Position    = position;
            _direction  = direction;
            _coordinate = coordinate;

            Texture = direction == DirectionType.Horizontal ? TextureController.GetTexture(GemType.HorizontalLine.SelectedSpritePath())
                                                            : TextureController.GetTexture(GemType.VerticalLine.SelectedSpritePath());
        }
Пример #4
0
        public MaterialPage GetPage([Url] string map, [Url] int index)
        {
            var bsp   = Program.GetMap(map);
            var first = index * MaterialPage.MaterialsPerPage;
            var count = Math.Min(first + MaterialPage.MaterialsPerPage, MaterialDictionary.GetResourceCount(bsp)) - first;

            if (count < 0)
            {
                first = MaterialDictionary.GetResourceCount(bsp);
                count = 0;
            }

            var texDict = new Dictionary <string, int>();

            var page = new MaterialPage();

            for (var i = 0; i < count; ++i)
            {
                var path = MaterialDictionary.GetResourcePath(bsp, first + i);
                var mat  = Material.Get(bsp, path);
                page.Materials.Add(mat);

                if (mat == null)
                {
                    continue;
                }

                foreach (var prop in mat.Properties)
                {
                    if (prop.Type != MaterialPropertyType.TextureUrl)
                    {
                        continue;
                    }

                    prop.Type = MaterialPropertyType.TextureIndex;

                    var texUrl = (Url)prop.Value;
                    int texIndex;
                    if (texDict.TryGetValue(texUrl, out texIndex))
                    {
                        prop.Value = texIndex;
                        continue;
                    }

                    prop.Value = texIndex = page.Textures.Count;

                    var texPath = TextureController.GetTexturePath(texUrl);
                    var tex     = Texture.Get(bsp, texPath);

                    texDict.Add(texUrl, texIndex);
                    page.Textures.Add(tex);
                }
            }

            return(page);
        }
Пример #5
0
 void Start()
 {
     rowCount = 0;
     TextureController.Initialise();
     m_camera = gameObject.GetComponent <Camera>();
     Map.Initialise();
     m_camera.orthographicSize   = Map.size.y / 2;
     m_camera.transform.position = new Vector3(Map.size.x / 2, Map.size.y / 2, -10);
     PlateMode menu = new PlateMode();
 }
Пример #6
0
        public ButtonBuilder AddTextureByType()
        {
            if (!_isTypeSet)
            {
                throw new NullReferenceException();
            }

            _button.Texture = TextureController.GetTexture(_button.Type.SpritePath());

            return(this);
        }
Пример #7
0
        public GameState(Match3Game game, GraphicsDevice graphicsDevice, ContentManager content)
            : base(game, graphicsDevice, content)
        {
            GameField = GetPlayingField();

            _elements = new List <Element>();
            _elements.Add(new Background(TextureController.GetTexture(BackgroundType.Full.SpritePath()), Vector2.Zero));

            gameFont        = TextureController.GetFont("Fonts/galleryFont");
            _gameOverWindow = new EndWindow(_game, EndButton_Click);
        }
Пример #8
0
        public ButtonBuilder AddFontByType()
        {
            if (!_isTypeSet)
            {
                throw new NullReferenceException();
            }

            _button.Font = TextureController.GetFont(_button.Type.FontPath());

            return(this);
        }
Пример #9
0
        private void InitModules()
        {
            // init everything here so they don't need to be instantiated later
            VoronoiNoise.Init();
            MaterialController.Init();
            TextureController.Init();
            OptController.Init();
            Seeder.Init(islandDensity);

            method = Constants.NoiseFuncs [(int)noiseType];
        }
Пример #10
0
    public void Initialise()
    {
        // Database serverDB = new Database();
        Debug.Log("test");
        m_camera = new Camera[] { gameObject.GetComponent <Camera>() };
        GameObject canvasObj = new GameObject();

        m_canvas = canvasObj.AddComponent <Canvas>();
        m_canvas.transform.position = new Vector3(m_camera[0].transform.position.x, m_camera[0].transform.position.y, -3);
        TextureController.Initialise();
        CreateGameState();
    }
Пример #11
0
    public void AddSpriteMap(string givenAnimation, Color givenColor)
    {
        SpriteMap tempSpriteMap = TextureController.GetSpriteMap(givenAnimation, givenColor);

        if (m_animationList.ContainsKey(tempSpriteMap.GetName()))
        {
            m_animationList[tempSpriteMap.GetName()].AddAnimation(tempSpriteMap.GetAnimations());
        }
        else
        {
            m_animationList.Add(tempSpriteMap.GetName(), tempSpriteMap);
        }
    }
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            //loop through each cell and draw them
            var unvisitedCells = new List <Cell>();

            foreach (var cell in _maze.GetCellArray())
            {
                //Draw rectangle at cell's position
                var rect = new Rectangle(cell.X * CellSize, cell.Y * CellSize, CellSize, CellSize);
                if (cell.Visited)
                {
                    spriteBatch.Draw(TextureController.GetTexture("Cell"), rect, Color.White);
                }
                else
                {
                    unvisitedCells.Add(cell);
                }
            }

            //Loop through each cell and draw walls
            foreach (var cell in _maze.GetCellArray())
            {
                Rectangle rect;
                //Draw rectangle at wall positions
                //Since walls are shared between cells, we only need to draw a maximum of two per cell, they must be connected
                //  i.e North/East, North/West, South/East, South/West
                //  This will not draw the walls on the edge of the screen, but they do exist.
                if (cell.WallStatus(Cell.Direction.East))
                {
                    rect = new Rectangle(cell.X * CellSize + (CellSize - WallSize / 2), cell.Y * CellSize, WallSize,
                                         CellSize);
                    spriteBatch.Draw(TextureController.GetTexture("Maze Wall"), rect, Color.Black);
                }

                if (cell.WallStatus(Cell.Direction.South))
                {
                    rect = new Rectangle(cell.X * CellSize, cell.Y * CellSize + (CellSize - WallSize / 2), CellSize,
                                         WallSize);
                    spriteBatch.Draw(TextureController.GetTexture("Maze Wall"), rect, Color.Black);
                }
            }

            //Draw unvisited cells AFTER walls so they get hidden
            foreach (var cell in unvisitedCells)
            {
                var rect = new Rectangle(cell.X * CellSize, cell.Y * CellSize, CellSize, CellSize);
                spriteBatch.Draw(TextureController.GetTexture("Cell"), rect, Color.Gray);
            }
        }
Пример #13
0
    public void CreateMapDataBase()
    {
        SpriteMap oceanMap = TextureController.GetAnimations("Mediterranean_map", Color.black);

        Color[] mapPixel = oceanMap.GetAnimation(0).GetSprite(0).texture.GetPixels();
        MAPWIDTH  = (int)oceanMap.GetAnimation(0).GetSprite(0).texture.width;
        MAPHEIGHT = (int)oceanMap.GetAnimation(0).GetSprite(0).texture.height;
        using (Database.DatabaseManager db = new Database.DatabaseManager())
        {
            for (int i = 0; i < mapPixel.Length; i++)
            {
                Color        currentColour = mapPixel[i];
                int          currX         = (i % MAPWIDTH) - 1;
                int          currY         = (Mathf.FloorToInt(i / MAPWIDTH)) - 1;
                Tile.Terrain currTerrain;
                if (currX > 0 && currY > 0 && currX < MAPWIDTH - 2 && currY < MAPHEIGHT - 2)
                {
                    if (mapPixel[i] == Color.black)
                    {
                        currTerrain = Tile.Terrain.ocean;
                    }
                    else
                    {
                        int probability = UnityEngine.Random.Range(0, 10);
                        if (probability < 4)
                        {
                            currTerrain = Tile.Terrain.smooth;
                        }
                        else if (probability < 7)
                        {
                            currTerrain = Tile.Terrain.forest;
                        }
                        else if (probability < 9)
                        {
                            currTerrain = Tile.Terrain.rough;
                        }
                        else
                        {
                            currTerrain = Tile.Terrain.mountain;
                        }
                    }
                    db.Tile.Add(new Tile(currX, currY, currTerrain, TestMain.environmentDomain));
                }
            }
            db.SaveChanges();
        }
    }
Пример #14
0
        public EndWindow(Game game, EventHandler handler)
        {
            Texture  = TextureController.GetTexture(PopUpWindow.TexturePath);
            Position = GetPosition(game);

            _gameFont  = TextureController.GetFont(DefaultSettings.FontPath);
            _titleText = "Game Over!";

            var btnType = ButtonType.Yellow;

            _submitBtn = new ButtonBuilder().AddType(btnType)
                         .AddFontByType()
                         .AddTextureByType()
                         .AddPenColor(Color.Black)
                         .AddText("Ok")
                         .OnClick(handler)
                         .AddPosition(GetCenterPositionToButton(btnType))
                         .Build();
        }
    public void DisplayInEditor()
    {
        textureDetails.AttachToMaterial(areaMaterial);
        textureDetails.RefreshHeights(areaMaterial, areaNoiseDetails.minHeight, areaNoiseDetails.maxHeight);

        AreaNoise noiseArea = NoiseController.BuildNoiseArea(areaDetails.verticesPerLine, areaNoiseDetails, Vector2.zero);

        if (displayMode == DisplayMode.Noise)
        {
            DisplayMap(TextureController.GenerateFromNoise(noiseArea));
        }
        else if (displayMode == DisplayMode.Mesh)
        {
            DisplayMesh(MeshController.BuildMesh(noiseArea.area, previevLOD, areaDetails));
        }
        else if (displayMode == DisplayMode.Falloff)
        {
            DisplayMap(TextureController.GenerateFromNoise(new AreaNoise(FalloffController.GenerateFalloffArea(areaDetails.verticesPerLine), 0, 1)));
        }
    }
Пример #16
0
        private void Awake()
        {
            _meshFilter = GetComponent <MeshFilter>();

            _radialController = new TextureController(_meshFilter, _texture, false);
            return;

            _mesh             = _meshFilter.mesh;
            _originalMeshData = new MeshData(_mesh);
            _newMeshData      = new MeshData();
            _trianglesPool    = new TrianglesPool(_newMeshData);

            _meshFilter.mesh.Clear();

            GenerateTriangles();

            ProcessDirection();

            _directionValue = _unfoldDirection.Min;
        }
Пример #17
0
        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            for (var x = 0; x < _map.Width; x++)
            {
                for (var y = 0; y < _map.Height; y++)
                {
                    spriteBatch.Draw(TextureController.GetTexture(_map.GetTile(x, y).Id),
                                     new Vector2(x, y) * ScreenComponentMaze.CellSize + Position, Color.White);

                    if (_map.GetTile(x, y).EntityInTile?.GetType() == typeof(Enemy))
                    {
                        spriteBatch.Draw(TextureController.GetTexture("Enemy"),
                                         new Vector2(x, y) * ScreenComponentMaze.CellSize + Position, Color.White);
                    }
                }
            }

            if (_map.Player != null)
            {
                spriteBatch.Draw(TextureController.GetTexture("Player"),
                                 _map.Player.Position.ToVector2() * ScreenComponentMaze.CellSize, null, Color.White);
            }
        }
Пример #18
0
        public MenuState(Match3Game game, GraphicsDevice graphicsDevice, ContentManager content)
            : base(game, graphicsDevice, content)
        {
            var background = new Background(TextureController.GetTexture(BackgroundType.Sky.SpritePath()), Vector2.Zero);

            var btnType  = ButtonType.Yellow;
            var startBtn = new ButtonBuilder()
                           .AddType(btnType)
                           .AddTextureByType()
                           .AddFontByType()
                           .AddText("Play")
                           .AddPenColor(Color.Black)
                           .OnClick(StartButton_Click)
                           .AddPosition(new Vector2(
                                            game.Window.ClientBounds.Width / 2f - btnType.ButtonWidth() / 2f,
                                            game.Window.ClientBounds.Height / 2f - btnType.ButtonHeight() / 2f))
                           .Build();

            _elements = new List <Element>()
            {
                background,
                startBtn
            };
        }
Пример #19
0
        public SceneMainMenu(ProjectMazelike game)
        {
            _game   = game;
            _screen = ScreenController.GetScreen("Main Menu");

            //Main Components
            _background = new ScreenComponentSprite(
                new Sprite(TextureController.GetTexture("Player"), game.GraphicsDevice.Viewport.Width,
                           game.GraphicsDevice.Viewport.Height, Vector2.Zero),
                ScreenController.MainMenuScreen,
                DrawLayer.Background,
                DrawSpace.Screen);
            _screen.AddComponent(_background);

            _newGameButton = new ScreenComponentButton(
                new Vector2(game.GraphicsDevice.Viewport.Width / 2 - 120,
                            game.GraphicsDevice.Viewport.Height / 2 - 140),
                240,
                120,
                ScreenController.MainMenuScreen,
                DrawLayer.Ui,
                DrawSpace.Screen);
            _newGameButton.Text       = "New Game";
            _newGameButton.OnClicked += OnClicked_NewGame;
            _screen.AddComponent(_newGameButton);

            _quitGameButton = new ScreenComponentButton(
                new Vector2(game.GraphicsDevice.Viewport.Width / 2 - 120,
                            game.GraphicsDevice.Viewport.Height / 2 + 20),
                240,
                120,
                ScreenController.MainMenuScreen,
                DrawLayer.Ui,
                DrawSpace.Screen);
            _quitGameButton.Text       = "Quit Game";
            _quitGameButton.OnClicked += game.Exit;
            _screen.AddComponent(_quitGameButton);

            //New Game submenu
            _startGameButton = new ScreenComponentButton(
                new Vector2(game.GraphicsDevice.Viewport.Width / 2 - 120,
                            game.GraphicsDevice.Viewport.Height / 2 - 60),
                240,
                120,
                ScreenController.MainMenuScreen,
                DrawLayer.Ui,
                DrawSpace.Screen);
            _startGameButton.Text       = "Start";
            _startGameButton.OnClicked += game.StartGame;
            _startGameButton.Enabled    = false;
            _screen.AddComponent(_startGameButton);

            _backButton = new ScreenComponentButton(
                _startGameButton.Position + new Vector2(0, 150),
                160,
                80,
                ScreenController.MainMenuScreen,
                DrawLayer.Ui,
                DrawSpace.Screen);
            _backButton.Text       = "Back";
            _backButton.OnClicked += OnClicked_Back;
            _backButton.Enabled    = false;
            _screen.AddComponent(_backButton);
        }
Пример #20
0
    public void AddSpriteMap(string givenAnimation)
    {
        SpriteMap tempSpriteMap = TextureController.GetAnimations(givenAnimation, m_colour);

        m_animationList.Add(tempSpriteMap.GetName(), tempSpriteMap);
    }
Пример #21
0
    public override void ThreadFunction()
    {
        // Generate faces
        int index = 0;

        Chunk[] neighbours = new Chunk[6];
        bool[]  exists     = new bool[6];

        exists[0] = World.instance.GetChunkAt(position.x, position.y, position.z + Chunk.size.z, out neighbours[0]);
        exists[1] = World.instance.GetChunkAt(position.x + Chunk.size.x, position.y, position.z, out neighbours[1]);
        exists[2] = World.instance.GetChunkAt(position.x, position.y, position.z - Chunk.size.z, out neighbours[2]);
        exists[3] = World.instance.GetChunkAt(position.x - Chunk.size.x, position.y, position.z, out neighbours[3]);
        exists[4] = World.instance.GetChunkAt(position.x, position.y + Chunk.size.y, position.z, out neighbours[4]);
        exists[5] = World.instance.GetChunkAt(position.x, position.y - Chunk.size.y, position.z, out neighbours[5]);


        for (int x = 0; x < Chunk.size.x; x++)
        {
            for (int y = 0; y < Chunk.size.y; y++)
            {
                for (int z = 0; z < Chunk.size.z; z++)
                {
                    if (blocks[index].IsTransparent())
                    {
                        faces[index] = 0;
                        index++;
                        continue;
                    }

                    if (z == 0 && (exists [2] == false || neighbours[2].GetBlockAt(position.x + x, position.y + y, position.z + z - 1) == Block.Air))
                    {
                        faces[index] |= (byte)Directions.South;
                        sizeEstimate += 4;
                    }
                    else if (z > 0 && blocks[index - 1] == Block.Air)
                    {
                        faces[index] |= (byte)Directions.South;
                        sizeEstimate += 4;
                    }

                    if (z == Chunk.size.z - 1 && (exists[0] == false || neighbours[0].GetBlockAt(position.x + x, position.y + y, position.z + z + 1) == Block.Air))
                    {
                        faces[index] |= (byte)Directions.North;
                        sizeEstimate += 4;
                    }
                    else if (z < Chunk.size.z - 1 && blocks[index + 1] == Block.Air)
                    {
                        faces[index] |= (byte)Directions.North;
                        sizeEstimate += 4;
                    }

                    if (y == 0 && (exists[5] == false || neighbours[5].GetBlockAt(position.x + x, position.y + y - 1, position.z + z) == Block.Air))
                    {
                        faces[index] |= (byte)Directions.Down;
                        sizeEstimate += 4;
                    }
                    else if (y > 0 && blocks[index - Chunk.size.z] == Block.Air)
                    {
                        faces[index] |= (byte)Directions.Down;
                        sizeEstimate += 4;
                    }

                    if (y == Chunk.size.y - 1 && (exists[4] == false || neighbours[4].GetBlockAt(position.x + x, position.y + y + 1, position.z + z) == Block.Air))
                    {
                        faces[index] |= (byte)Directions.Up;
                        sizeEstimate += 4;
                    }
                    else if (y < Chunk.size.y - 1 && blocks[index + Chunk.size.z] == Block.Air)
                    {
                        faces[index] |= (byte)Directions.Up;
                        sizeEstimate += 4;
                    }

                    if (x == 0 && (exists[3] == false || neighbours[3].GetBlockAt(position.x + x - 1, position.y + y, position.z + z) == Block.Air))
                    {
                        faces[index] |= (byte)Directions.West;
                        sizeEstimate += 4;
                    }
                    else if (x > 0 && blocks[index - Chunk.size.z * Chunk.size.y] == Block.Air)
                    {
                        faces[index] |= (byte)Directions.West;
                        sizeEstimate += 4;
                    }

                    if (x == Chunk.size.x - 1 && (exists[1] == false || neighbours[1].GetBlockAt(position.x + x + 1, position.y + y, position.z + z) == Block.Air))
                    {
                        faces[index] |= (byte)Directions.East;
                        sizeEstimate += 4;
                    }
                    else if (x < Chunk.size.x - 1 && blocks[index + Chunk.size.z * Chunk.size.y] == Block.Air)
                    {
                        faces[index] |= (byte)Directions.East;
                        sizeEstimate += 4;
                    }

                    isVisible = true;

                    index++;
                }
            }
        }

        if (isVisible == false)
        {
            return;
        }

        // Generate mesh

        vertices  = new Vector3[sizeEstimate];
        uvs       = new Vector2[sizeEstimate];
        triangles = new int[(int)(sizeEstimate * 1.5f)];

        index = 0;;

        for (int x = 0; x < Chunk.size.x; x++)
        {
            for (int y = 0; y < Chunk.size.y; y++)
            {
                for (int z = 0; z < Chunk.size.z; z++)
                {
                    if (faces [index] == 0)
                    {
                        index++;
                        continue;
                    }

                    if ((faces[index] & (byte)Directions.North) != 0)
                    {
                        vertices[vertexIndex]     = new Vector3(x + position.x, y + position.y, z + position.z + 1);
                        vertices[vertexIndex + 1] = new Vector3(x + position.x + 1, y + position.y, z + position.z + 1);
                        vertices[vertexIndex + 2] = new Vector3(x + position.x, y + position.y + 1, z + position.z + 1);
                        vertices[vertexIndex + 3] = new Vector3(x + position.x + 1, y + position.y + 1, z + position.z + 1);

                        triangles[trianglesIndex]     = vertexIndex + 1;
                        triangles[trianglesIndex + 1] = vertexIndex + 2;
                        triangles[trianglesIndex + 2] = vertexIndex;

                        triangles[trianglesIndex + 3] = vertexIndex + 1;
                        triangles[trianglesIndex + 4] = vertexIndex + 3;
                        triangles[trianglesIndex + 5] = vertexIndex + 2;

                        TextureController.AddTextures(blocks[index], Directions.North, vertexIndex, uvs);

                        vertexIndex    += 4;
                        trianglesIndex += 6;
                    }

                    if ((faces[index] & (byte)Directions.East) != 0)
                    {
                        vertices[vertexIndex]     = new Vector3(x + position.x + 1, y + position.y, z + position.z);
                        vertices[vertexIndex + 1] = new Vector3(x + position.x + 1, y + position.y, z + position.z + 1);
                        vertices[vertexIndex + 2] = new Vector3(x + position.x + 1, y + position.y + 1, z + position.z);
                        vertices[vertexIndex + 3] = new Vector3(x + position.x + 1, y + position.y + 1, z + position.z + 1);

                        triangles[trianglesIndex]     = vertexIndex;
                        triangles[trianglesIndex + 1] = vertexIndex + 2;
                        triangles[trianglesIndex + 2] = vertexIndex + 1;

                        triangles[trianglesIndex + 3] = vertexIndex + 2;
                        triangles[trianglesIndex + 4] = vertexIndex + 3;
                        triangles[trianglesIndex + 5] = vertexIndex + 1;

                        TextureController.AddTextures(blocks[index], Directions.East, vertexIndex, uvs);

                        vertexIndex    += 4;
                        trianglesIndex += 6;
                    }

                    if ((faces[index] & (byte)Directions.South) != 0)
                    {
                        vertices[vertexIndex]     = new Vector3(x + position.x, y + position.y, z + position.z);
                        vertices[vertexIndex + 1] = new Vector3(x + position.x + 1, y + position.y, z + position.z);
                        vertices[vertexIndex + 2] = new Vector3(x + position.x, y + position.y + 1, z + position.z);
                        vertices[vertexIndex + 3] = new Vector3(x + position.x + 1, y + position.y + 1, z + position.z);

                        triangles[trianglesIndex]     = vertexIndex;
                        triangles[trianglesIndex + 1] = vertexIndex + 2;
                        triangles[trianglesIndex + 2] = vertexIndex + 1;

                        triangles[trianglesIndex + 3] = vertexIndex + 2;
                        triangles[trianglesIndex + 4] = vertexIndex + 3;
                        triangles[trianglesIndex + 5] = vertexIndex + 1;

                        TextureController.AddTextures(blocks[index], Directions.South, vertexIndex, uvs);

                        vertexIndex    += 4;
                        trianglesIndex += 6;
                    }

                    if ((faces[index] & (byte)Directions.West) != 0)
                    {
                        vertices[vertexIndex]     = new Vector3(x + position.x, y + position.y, z + position.z);
                        vertices[vertexIndex + 1] = new Vector3(x + position.x, y + position.y, z + position.z + 1);
                        vertices[vertexIndex + 2] = new Vector3(x + position.x, y + position.y + 1, z + position.z);
                        vertices[vertexIndex + 3] = new Vector3(x + position.x, y + position.y + 1, z + position.z + 1);

                        triangles[trianglesIndex]     = vertexIndex + 1;
                        triangles[trianglesIndex + 1] = vertexIndex + 2;
                        triangles[trianglesIndex + 2] = vertexIndex;

                        triangles[trianglesIndex + 3] = vertexIndex + 1;
                        triangles[trianglesIndex + 4] = vertexIndex + 3;
                        triangles[trianglesIndex + 5] = vertexIndex + 2;

                        TextureController.AddTextures(blocks[index], Directions.West, vertexIndex, uvs);

                        vertexIndex    += 4;
                        trianglesIndex += 6;
                    }

                    if ((faces[index] & (byte)Directions.Up) != 0)
                    {
                        vertices[vertexIndex]     = new Vector3(x + position.x, y + position.y + 1, z + position.z);
                        vertices[vertexIndex + 1] = new Vector3(x + position.x + 1, y + position.y + 1, z + position.z);
                        vertices[vertexIndex + 2] = new Vector3(x + position.x, y + position.y + 1, z + position.z + 1);
                        vertices[vertexIndex + 3] = new Vector3(x + position.x + 1, y + position.y + 1, z + position.z + 1);

                        triangles[trianglesIndex]     = vertexIndex;
                        triangles[trianglesIndex + 1] = vertexIndex + 2;
                        triangles[trianglesIndex + 2] = vertexIndex + 1;

                        triangles[trianglesIndex + 3] = vertexIndex + 2;
                        triangles[trianglesIndex + 4] = vertexIndex + 3;
                        triangles[trianglesIndex + 5] = vertexIndex + 1;

                        TextureController.AddTextures(blocks[index], Directions.Up, vertexIndex, uvs);

                        vertexIndex    += 4;
                        trianglesIndex += 6;
                    }

                    if ((faces[index] & (byte)Directions.Down) != 0)
                    {
                        vertices[vertexIndex]     = new Vector3(x + position.x, y + position.y, z + position.z);
                        vertices[vertexIndex + 1] = new Vector3(x + position.x, y + position.y, z + position.z + 1);
                        vertices[vertexIndex + 2] = new Vector3(x + position.x + 1, y + position.y, z + position.z + 1);
                        vertices[vertexIndex + 3] = new Vector3(x + position.x + 1, y + position.y, z + position.z + 1);

                        triangles[trianglesIndex]     = vertexIndex;
                        triangles[trianglesIndex + 1] = vertexIndex + 2;
                        triangles[trianglesIndex + 2] = vertexIndex + 1;

                        triangles[trianglesIndex + 3] = vertexIndex + 2;
                        triangles[trianglesIndex + 4] = vertexIndex + 3;
                        triangles[trianglesIndex + 5] = vertexIndex + 1;

                        TextureController.AddTextures(blocks[index], Directions.Down, vertexIndex, uvs);

                        vertexIndex    += 4;
                        trianglesIndex += 6;
                    }

                    index++;
                }
            }
        }
    }
Пример #22
0
    // главная функция генерирующая мешь в многопоточности
    public override void ThreadFunction()
    {
        int index = 0;

        // Поиск соседних чанков
        Chunk[] neighbors = new Chunk[6];
        bool[]  exists    = new bool[6];

        exists[0] = World.Instance.GetChunkAt(position.x, position.y, position.z + Chunk.size.z, out neighbors[0]);
        exists[1] = World.Instance.GetChunkAt(position.x + Chunk.size.x, position.y, position.z, out neighbors[1]);
        exists[2] = World.Instance.GetChunkAt(position.x, position.y, position.z - Chunk.size.z, out neighbors[2]);
        exists[3] = World.Instance.GetChunkAt(position.x - Chunk.size.x, position.y, position.z, out neighbors[3]);

        exists[4] = World.Instance.GetChunkAt(position.x, position.y + Chunk.size.y, position.z, out neighbors[4]);
        exists[5] = World.Instance.GetChunkAt(position.x, position.y - Chunk.size.y, position.z, out neighbors[5]);

        // Generate faces
        for (int x = 0; x < Chunk.size.x; x++)
        {
            for (int y = 0; y < Chunk.size.y; y++)
            {
                for (int z = 0; z < Chunk.size.z; z++)
                {
                    // Блок - это воздух, не обыгываем. Переход к новому элементу
                    if (blocks[index] == Block.Air)
                    {
                        faces[index] = 0;
                        index++;
                        continue;
                    }

                    //Куда смотрят стороны блока:

                    // На ЮГ
                    if (z == 0 && (exists[2] == false || neighbors[2].GetBlockAt(position.x + x, position.y + y, position.z + z - 1) == Block.Air))
                    {
                        faces[index] |= (byte)Direction.South;
                        sizeEstimate += 4;
                    }
                    else if (z > 0 && blocks[index - 1] == Block.Air)
                    {
                        faces[index] |= (byte)Direction.South;
                        sizeEstimate += 4;
                    }

                    // На СЕВЕР
                    if (z == Chunk.size.z - 1 && (exists[0] == false || neighbors[0].GetBlockAt(position.x + x, position.y + y, position.z + z + 1) == Block.Air))
                    {
                        faces[index] |= (byte)Direction.North;
                        sizeEstimate += 4;
                    }
                    else if (z < Chunk.size.z - 1 && blocks[index + 1] == Block.Air)
                    {
                        faces[index] |= (byte)Direction.North;
                        sizeEstimate += 4;
                    }

                    // ВНИЗ
                    if (y == 0 && (exists[5] == false || neighbors[5].GetBlockAt(position.x + x, position.y + y - 1, position.z + z) == Block.Air))
                    {
                        faces[index] |= (byte)Direction.Down;
                        sizeEstimate += 4;
                    }
                    else if (y > 0 && blocks[index - Chunk.size.z] == Block.Air)
                    {
                        faces[index] |= (byte)Direction.Down;
                        sizeEstimate += 4;
                    }

                    // ВВЕРХ
                    if (y == Chunk.size.y - 1 && (exists[4] == false || neighbors[4].GetBlockAt(position.x + x, position.y + y + 1, position.z + z) == Block.Air))
                    {
                        faces[index] |= (byte)Direction.Up;
                        sizeEstimate += 4;
                    }
                    else if (y < Chunk.size.y - 1 && blocks[index + Chunk.size.z] == Block.Air)
                    {
                        faces[index] |= (byte)Direction.Up;
                        sizeEstimate += 4;
                    }

                    // На ВОСТОК
                    if (x == 0 && (exists[3] == false || neighbors[3].GetBlockAt(position.x + x - 1, position.y + y, position.z + z) == Block.Air))
                    {
                        faces[index] |= (byte)Direction.West;
                        sizeEstimate += 4;
                    }
                    else if (x > 0 && blocks[index - Chunk.size.z * Chunk.size.y] == Block.Air)
                    {
                        faces[index] |= (byte)Direction.West;
                        sizeEstimate += 4;
                    }


                    // На ЗАПАД
                    if (x == Chunk.size.x - 1 && (exists[1] == false || neighbors[1].GetBlockAt(position.x + x + 1, position.y + y, position.z + z) == Block.Air))
                    {
                        faces[index] |= (byte)Direction.East;
                        sizeEstimate += 4;
                    }
                    else if (x < Chunk.size.z - 1 && blocks[index + Chunk.size.z * Chunk.size.y] == Block.Air)
                    {
                        faces[index] |= (byte)Direction.East;
                        sizeEstimate += 4;
                    }

                    isVisible = true;

                    index++;
                }
            }
        }
        if (isVisible == false)
        {
            return;
        }


        index = 0;

        // Generate mesh

        vertices  = new Vector3[sizeEstimate];
        uvs       = new Vector2[sizeEstimate];
        triangles = new int[(int)(sizeEstimate * 1.5)];

        for (int x = 0; x < Chunk.size.x; x++)
        {
            for (int y = 0; y < Chunk.size.y; y++)
            {
                for (int z = 0; z < Chunk.size.z; z++)
                {
                    if (faces[index] == 0)
                    {
                        index++;
                        continue;
                    }

                    if ((faces[index] & (byte)Direction.North) != 0)
                    {
                        vertices[vertexIndex]     = new Vector3(x + position.x, y + position.y, z + position.z + 1);
                        vertices[vertexIndex + 1] = new Vector3(x + position.x + 1, y + position.y, z + position.z + 1);
                        vertices[vertexIndex + 2] = new Vector3(x + position.x, y + position.y + 1, z + position.z + 1);
                        vertices[vertexIndex + 3] = new Vector3(x + position.x + 1, y + position.y + 1, z + position.z + 1);

                        triangles[triangleIndex]     = vertexIndex + 1;
                        triangles[triangleIndex + 1] = vertexIndex + 2;
                        triangles[triangleIndex + 2] = vertexIndex;

                        triangles[triangleIndex + 3] = vertexIndex + 1;
                        triangles[triangleIndex + 4] = vertexIndex + 3;
                        triangles[triangleIndex + 5] = vertexIndex + 2;

                        TextureController.AddTextures(blocks[index], Direction.North, vertexIndex, uvs);

                        vertexIndex   += 4;
                        triangleIndex += 6;
                    }
                    if ((faces[index] & (byte)Direction.East) != 0)
                    {
                        vertices[vertexIndex]     = new Vector3(x + position.x + 1, y + position.y, z + position.z);
                        vertices[vertexIndex + 1] = new Vector3(x + position.x + 1, y + position.y, z + position.z + 1);
                        vertices[vertexIndex + 2] = new Vector3(x + position.x + 1, y + position.y + 1, z + position.z);
                        vertices[vertexIndex + 3] = new Vector3(x + position.x + 1, y + position.y + 1, z + position.z + 1);

                        triangles[triangleIndex]     = vertexIndex;
                        triangles[triangleIndex + 1] = vertexIndex + 2;
                        triangles[triangleIndex + 2] = vertexIndex + 1;

                        triangles[triangleIndex + 3] = vertexIndex + 2;
                        triangles[triangleIndex + 4] = vertexIndex + 3;
                        triangles[triangleIndex + 5] = vertexIndex + 1;

                        TextureController.AddTextures(blocks[index], Direction.East, vertexIndex, uvs);

                        vertexIndex   += 4;
                        triangleIndex += 6;
                    }
                    if ((faces[index] & (byte)Direction.South) != 0)
                    {
                        vertices[vertexIndex]     = new Vector3(x + position.x, y + position.y, z + position.z);
                        vertices[vertexIndex + 1] = new Vector3(x + position.x + 1, y + position.y, z + position.z);
                        vertices[vertexIndex + 2] = new Vector3(x + position.x, y + position.y + 1, z + position.z);
                        vertices[vertexIndex + 3] = new Vector3(x + position.x + 1, y + position.y + 1, z + position.z);

                        triangles[triangleIndex]     = vertexIndex;
                        triangles[triangleIndex + 1] = vertexIndex + 2;
                        triangles[triangleIndex + 2] = vertexIndex + 1;

                        triangles[triangleIndex + 3] = vertexIndex + 2;
                        triangles[triangleIndex + 4] = vertexIndex + 3;
                        triangles[triangleIndex + 5] = vertexIndex + 1;

                        TextureController.AddTextures(blocks[index], Direction.South, vertexIndex, uvs);

                        vertexIndex   += 4;
                        triangleIndex += 6;
                    }
                    if ((faces[index] & (byte)Direction.West) != 0)
                    {
                        vertices[vertexIndex]     = new Vector3(x + position.x, y + position.y, z + position.z);
                        vertices[vertexIndex + 1] = new Vector3(x + position.x, y + position.y, z + position.z + 1);
                        vertices[vertexIndex + 2] = new Vector3(x + position.x, y + position.y + 1, z + position.z);
                        vertices[vertexIndex + 3] = new Vector3(x + position.x, y + position.y + 1, z + position.z + 1);

                        triangles[triangleIndex]     = vertexIndex + 1;
                        triangles[triangleIndex + 1] = vertexIndex + 2;
                        triangles[triangleIndex + 2] = vertexIndex;

                        triangles[triangleIndex + 3] = vertexIndex + 1;
                        triangles[triangleIndex + 4] = vertexIndex + 3;
                        triangles[triangleIndex + 5] = vertexIndex + 2;

                        TextureController.AddTextures(blocks[index], Direction.West, vertexIndex, uvs);

                        vertexIndex   += 4;
                        triangleIndex += 6;
                    }
                    if ((faces[index] & (byte)Direction.Up) != 0)
                    {
                        vertices[vertexIndex]     = new Vector3(x + position.x, y + position.y + 1, z + position.z);
                        vertices[vertexIndex + 1] = new Vector3(x + position.x + 1, y + position.y + 1, z + position.z);
                        vertices[vertexIndex + 2] = new Vector3(x + position.x, y + position.y + 1, z + position.z + 1);
                        vertices[vertexIndex + 3] = new Vector3(x + position.x + 1, y + position.y + 1, z + position.z + 1);

                        triangles[triangleIndex]     = vertexIndex;
                        triangles[triangleIndex + 1] = vertexIndex + 2;
                        triangles[triangleIndex + 2] = vertexIndex + 1;

                        triangles[triangleIndex + 3] = vertexIndex + 2;
                        triangles[triangleIndex + 4] = vertexIndex + 3;
                        triangles[triangleIndex + 5] = vertexIndex + 1;

                        TextureController.AddTextures(blocks[index], Direction.Up, vertexIndex, uvs);

                        vertexIndex   += 4;
                        triangleIndex += 6;
                    }
                    if ((faces[index] & (byte)Direction.Down) != 0)
                    {
                        vertices[vertexIndex]     = new Vector3(x + position.x, y + position.y, z + position.z);
                        vertices[vertexIndex + 1] = new Vector3(x + position.x, y + position.y, z + position.z + 1);
                        vertices[vertexIndex + 2] = new Vector3(x + position.x + 1, y + position.y, z + position.z);
                        vertices[vertexIndex + 3] = new Vector3(x + position.x + 1, y + position.y, z + position.z + 1);

                        triangles[triangleIndex]     = vertexIndex;
                        triangles[triangleIndex + 1] = vertexIndex + 2;
                        triangles[triangleIndex + 2] = vertexIndex + 1;

                        triangles[triangleIndex + 3] = vertexIndex + 2;
                        triangles[triangleIndex + 4] = vertexIndex + 3;
                        triangles[triangleIndex + 5] = vertexIndex + 1;

                        TextureController.AddTextures(blocks[index], Direction.Down, vertexIndex, uvs);

                        vertexIndex   += 4;
                        triangleIndex += 6;
                    }

                    index++;
                }
            }
        }
    }
Пример #23
0
        public void LoadContent(ContentManager contentManager)
        {
            textures = new TextureController(contentManager);

            #region Cells
            textures.RegisterTexture(@"Textures\Cell1");
            #endregion
        }
Пример #24
0
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(GraphicsDevice);
     TextureController.SetContent(Content);
     _currentState = new MenuState(this, graphics.GraphicsDevice, Content);
 }
Пример #25
0
 public void AssignTargetCube(TextureController targetCube)
 {
     this.targetCube = targetCube;
 }
Пример #26
0
 void Awake()
 {
     TextureController.Initialize("", chunkPrefab.GetComponent <Renderer>().sharedMaterial.mainTexture);
 }