Ejemplo n.º 1
0
        /// <summary>
        /// Генерация визуальной части острова.
        /// </summary>
        /// <param name="islandLength">Длина мира</param>
        /// <param name="islandWidth">Высота мира</param>
        public Grid <RendererObject> ShowIsland(Island island)
        {
            ClearGrid();

            if (tileGridVisual != null)
            {
                throw new Exception("Tile grid visual не очищен перед инициализацией");
            }

            tileGridVisual = new Grid <RendererObject>(island.Length, island.Width,
                                                       tileSizeHorizontal, tileSizeVertical);


            if (tileGridVisual != null || tileGridVisual.Count != 0)
            {
                // Генерируем меш
                tileGridVisual.ForEachSet((x, y) =>
                {
                    var cell = MeshUtils.CreateDiamondMesh(tileSizeHorizontal, tileSizeVertical)
                               .TransformToRenderer(tileMaterial, "tileMesh");

                    cell.transform.parent   = tileParent.transform;
                    cell.transform.position = IsoBasis.GetIsoVector(x, y);

                    return(cell);
                });
            }

            return(tileGridVisual);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Генерация меша.
        /// </summary>
        /// <param name="worldLength">Длина мира</param>
        /// <param name="worldWidth">Высота мира</param>
        public Grid <RendererObject> GenerateMesh(int worldLength, int worldWidth)
        {
            // Поиск и очистка родительского объекта
            var tileParentTransform = transform.Find("tileParent");

            if (tileParentTransform == null)
            {
                tileParent = new GameObject("tileParent");
                tileParent.transform.parent = transform;
            }
            else
            {
                tileParent = tileParentTransform.gameObject;
            }

            // Очищение потерянных объектов
            if (tileParent.transform.childCount > 0)
            {
                GameObjectUtils.DestroyAllChildrens(tileParent.transform);
            }

            ClearGrid();

            if (TileGridVisual != null)
            {
                throw new Exception("Tile grid visual не очищен перед инициализацией");
            }

            TileGridVisual = new Grid <RendererObject>(worldLength, worldWidth,
                                                       tileSizeHorizontal, tileSizeVertical);


            if (TileGridVisual != null || TileGridVisual.Count != 0)
            {
                // Определяем базис
                SetIsoBasis();

                // Генерируем меш
                TileGridVisual.ForEachSet((x, y) =>
                {
                    var cell = MeshUtils.CreateDiamondMesh(tileSizeHorizontal, tileSizeVertical)
                               .TransformToRenderer(tileMaterial, "tileMesh");

                    cell.transform.parent   = tileParent.transform;
                    cell.transform.position = IsoBasis.GetIsoVector(x, y);

                    return(cell);
                });
            }

            return(TileGridVisual);
        }
Ejemplo n.º 3
0
        public void Enable()
        {
            IsoBasis.SetCellSize(tileSizeHorizontal, tileSizeVertical);

            // Поиск и очистка родительского объекта
            var tileParentTransform = transform.Find("tileParent");

            if (tileParentTransform == null)
            {
                tileParent = new GameObject("tileParent");
                tileParent.transform.parent = transform;
            }
            else
            {
                tileParent = tileParentTransform.gameObject;
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Устанавливает систему координат. В зависимости от размера тайлов.
 /// </summary>
 public void SetIsoBasis()
 {
     IsoBasis.SetCellSize(tileSizeHorizontal, tileSizeVertical);
 }