Example #1
0
    override public void InitGrid()
    {
        var imageRect = new Rect(0, 0, heightMap.width, heightMap.height);
        var map       = new RectMap(new Vector2(40, 40));
        var map2D     = new ImageMap <RectPoint>(imageRect, Grid, map);

        foreach (var point in Grid)
        {
            int   x      = Mathf.FloorToInt(map2D[point].x);
            int   y      = Mathf.FloorToInt(map2D[point].y);
            float height = heightMap.GetPixel(x, y).r * 4;

            if (height <= 0)
            {
                height = 0.01f;
            }

            var block = Grid[point];

            if (block == null)
            {
                Debug.LogWarning("block is null " + point);
            }
            else
            {
                block.Color = ExampleUtils.Blend(height, ExampleUtils.Colors[0], ExampleUtils.Colors[1]);
                block.transform.localScale = new Vector3(1, height, 1);
            }
        }
    }
Example #2
0
        public override void InitGrid()
        {
            var imageRect = new Rect(0, 0, heightMap.width, heightMap.height);
            var map       = new RectMap(new Vector2(40, 40));
            var map2D     = new ImageMap <RectPoint>(imageRect, Grid, map);

            foreach (var point in Grid)
            {
                int   x      = Mathf.FloorToInt(map2D[point].x);
                int   y      = Mathf.FloorToInt(map2D[point].y);
                float height = heightMap.GetPixel(x, y).r;

                if (height <= 0)
                {
                    height = 0.01f;
                }

                var block = Grid[point];

                if (block == null)
                {
                    Debug.LogWarning("block is null " + point);
                }
                else
                {
                    block.Color = heightGradient.Evaluate(height);
                    block.transform.localScale = new Vector3(1, height * heightMultiplier, 1);
                }
            }
        }
Example #3
0
    private void SetupGrid()
    {
        gridCopy = (RectGrid <TileCell>)Grid.Clone();

        var map = new RectMap(Vector2.one)
                  .WithWindow(new Rect(0, 0, 1, 1))
                  .Stretch(Grid);

        var textureScaleVector = new Vector2(1f / GridBuilder.Dimensions.X, 1f / GridBuilder.Dimensions.Y);

        foreach (var point in Grid)
        {
            var cellObject = (TextureCell)Grid[point];

            var material = new Material(Shader.Find("Unlit/Texture"))
            {
                mainTexture       = puzzleImage,
                mainTextureScale  = textureScaleVector,
                mainTextureOffset = map[point]
            };

            cellObject.Renderer.material = material;
            materialBag.Add(material);
        }

        emptyCell = RectPoint.Zero;
        ((TextureCell)Grid[emptyCell]).Renderer.enabled = false;
    }
Example #4
0
 public override void Initialize()
 {
     objname    = "";
     _corner    = new CornerMap();
     _lateral   = new LateralMap();
     _longitude = new LongitudeMap();
     _rect      = new RectMap();
     _hexagon   = new HexagonMap();
 }
Example #5
0
 public ConditionMap()
 {
     RectMap = new RectMap()
     {
         X = 0, Y = 0, Width = 1024, Height = 768, Hash = 0
     };
     Name     = "Default RectMap";
     Match    = 100;
     Required = true;
 }
Example #6
0
        public static Rectangle RectmapToRectangle(RectMap rectMap)
        {
            Rectangle r = new Rectangle()
            {
                X      = rectMap.X,
                Y      = rectMap.Y,
                Height = rectMap.Height,
                Width  = rectMap.Width
            };

            return(r);
        }
Example #7
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var     cellMap = SceneDataGrid[e.ColumnIndex, e.RowIndex].Value;
            RectMap map     = (RectMap)cellMap;

            selectedRectMap = map;

            RectMapXBox.Text      = map.X.ToString();
            RectMapYBox.Text      = map.Y.ToString();
            RectMapWidthBox.Text  = map.Width.ToString();
            RectMapHeightBox.Text = map.Height.ToString();
            RectMapHashBox.Text   = map.Hash.ToString();
        }
        public override WindowedMap <TPoint> CreateWindowedMap <TPoint>()
        {
            if (typeof(TPoint) == typeof(RectPoint))
            {
                var map = new RectMap(new Vector2(200, 200))
                          .Animate((x, t) => x.Rotate(30 * t), (x, t) => x.Rotate(-30 * t))
                          .Animate((x, t) => x + new Vector2(75 * Mathf.Sin(t / 5.0f), 0),
                                   (x, t) => x - new Vector2(75 * Mathf.Sin(t / 5.0f), 0))
                          .Animate((x, t) => x * (1.5f + 0.5f * Mathf.Sin(t * 7)),
                                   (x, t) => x / (1.5f + 0.5f * Mathf.Sin(t * 7)))
                          .WithWindow(ExampleUtils.ScreenRect);

                return((WindowedMap <TPoint>)(object) map);
            }

            return(null);
        }
Example #9
0
        public ContentLoader()
        {
            var tex = Application.Content.Load <Texture2D>("BattleCityAtlas");

            TextureMap.Add(tex.Name, tex);

            string filePath = @"BattleCityAtlas.atlas";

            string[] lines;

            if (System.IO.File.Exists(filePath))
            {
                lines       = System.IO.File.ReadAllLines(filePath);
                RegionCount = (lines.Length - 6.0f) / 7.0f;

                if (RegionCount > 0) // Có ít nhất 1 rectangle trong texture.
                {
                    for (int i = 6; i < lines.Length; i += 7)
                    {
                        int    rectX, rectY, sizeX, sizeY;
                        string name = lines[i];

                        var xy   = Regex.Matches(lines[i + 2], @"\d+");
                        var size = Regex.Matches(lines[i + 3], @"\d+");

                        rectX = int.Parse(xy[0].ToString());
                        rectY = int.Parse(xy[1].ToString());

                        sizeX = int.Parse(size[0].ToString());
                        sizeY = int.Parse(size[1].ToString());

                        RectMap.Add(name, new Rectangle(rectX, rectY, sizeX, sizeY));
                    }
                }
            }
            else
            {
                Console.WriteLine("File does not exist");
            }


            Map = Application.Content.Load <TiledMap>("Battle_City");
        }
Example #10
0
    private void SetupGrid()
    {
        gridCopy = (RectGrid <TileCell>)Grid.Clone();

        var map = new RectMap(Vector2.one)
                  .WithWindow(new Rect(0, 0, 1, 1))
                  .Stretch(Grid);

        var textureScaleVector = new Vector2(1f / GridBuilder.Dimensions.X, 1f / GridBuilder.Dimensions.Y);

        foreach (var point in Grid)
        {
            var cellObject = (UVCell)Grid[point];

            cellObject.SetTexture(puzzleImage);
            cellObject.SetUVs(map[point], textureScaleVector);

            materialBag.Add(cellObject.Material);
        }

        emptyCell = RectPoint.Zero;
        Grid[emptyCell].GetComponent <MeshRenderer>().enabled = false;
    }