Пример #1
0
    /// <summary>Adds hazard to the given tile.</summary>
    /// <param name="tile">Tile that the hazard will be spawned at.</param>
    public void AddLevelHazard(EditorTile tile)
    {
        if (tile.IsOccuppied() && !tile.GridObject.IsUnit())
        {
            ObjectType type = ((EditorLevelObject)tile.GridObject).Type;
            if (type == editorParams.obj)
            {
                return;
            }
        }

        if (tile.Type != TileType.UnbreakableWall)
        {
            //Grid has change and file is no longer consistant with grid
            if (currentGridFile != null)
            {
                currentGridFile = null;
            }

            int variant = 0;
            if (editorParams.objVariants.ContainsKey(editorParams.obj))
            {
                variant = editorParams.objVariants[editorParams.obj].variant;
            }

            EditorLevelObject hazard = new EditorLevelObject(editorParams.obj, tile, variant);
            tile.AddGridObject(hazard);

            if (levelObjects == null)
            {
                levelObjects = new List <EditorLevelObject>();
            }
            levelObjects.Add(hazard);
        }
    }
Пример #2
0
    private void Start()
    {
        for (int x = 0; x < TileController.x_max_value; x++)
        {
            for (int y = 0; y < TileController.y_max_value; y++)
            {
                EditorTile tileobj = Instantiate(Resources.Load <EditorTile>("EditorObj/EditorTile"), transform);
                tileobj.pos = new Vector2(x, y);
                //tileobj.transform.localPosition = new Vector2(40f * x, 33.3f * y);
                tileobj.transform.localPosition = new Vector2(55f * x, 40f * y);
                tileobj.TileChange(Tile_Type.White);
                tileobj.Tile_mng = this;
                if (y < 4 && (x <= 2 || x >= 12))
                {
                    tileobj.TileChange(Tile_Type.None, true);
                }
                //클릭시 호출 이벤트 등록
                tileobj.clickEvent += ChangeTileType;

                tiles.Add(tileobj);
            }
        }

        transform.parent.GetComponent <Editor_Mnr>().ChangeTileOn();
    }
Пример #3
0
    public void ResetPos(EditorTile tile)
    {
        Vector3 tilepos = tile.transform.position;

        tilepos.z         += 100;
        transform.position = tilepos;
    }
Пример #4
0
    public void SetTeleportDesination(EditorTile tile, int color)
    {
        if (tile != null)
        {
            int x = tile.Position.x;
            if (gridCreator.grid.Count > x && x > -1 && gridCreator.grid[x].Contains(tile))
            {
                if (tile.Type == TileType.Teleport && tileType == TileType.Teleport)
                {
                    if (!CheckTeleportPosition(tile.Position))
                    {
                        teleportPartner = tile;
                    }
                    SetVariant(color);

                    if (!tile.CheckTeleportPosition(Position))
                    {
                        tile.SetTeleportDesination(this, color);
                    }
                    return;
                }
            }
        }
        //Teleport Desination Removed
        teleportPartner = null;
    }
    // Start is called before the first frame update
    void Start()
    {
        // Load all tiles as editor tile objects
        Sprite[]   tileSprites = Resources.LoadAll <Sprite>(ENV.TILES_ART_RESOURCE_PATH);
        TileData[] tileData    = Resources.LoadAll <TileData>(ENV.TILE_DATA_RESOURCE_PATH);
        for (int i = 0; i < tileSprites.Length; i++)
        {
            EditorTile newEditorTile = Instantiate(editorTilePrefab, transform);
            Tile       newTile       = (Tile)ScriptableObject.CreateInstance("Tile");
            newTile.sprite = tileSprites[i];
            newTile.name   = tileSprites[i].name;
            newEditorTile.SetTile(newTile);

            // Get tile data
            for (int j = 0; j < tileData.Length; j++)
            {
                if (tileData[j].tileName == newTile.name)
                {
                    newEditorTile.SetTileData(tileData[j]);
                    break;
                }
            }
        }
        Resources.UnloadUnusedAssets();
    }
Пример #6
0
    // Use this for initialization
    void Awake()
    {
        S = this; // Initialize the private Singleton
#if (UsePlayerPrefsForFileName)
        // Read the most recent fileName from PlayerPrefs
        if (PlayerPrefs.HasKey("fileName"))
        {
            mapNameInput.text = PlayerPrefs.GetString("fileName");
        }
#endif

        ROOM_HAS_CONTENT = new bool[mapSize, mapSize];

        // Set up EditorTiles for each position on the map
        float x0 = size / 8f;
        float y0 = size / 8f;
        for (int j = 0; j < roomH; j++)
        {
            for (int i = 0; i < roomW; i++)
            {
                GameObject go = Instantiate(uiTilePrefab);
                go.name = i.ToString("D3") + "x" + j.ToString("D3");
                EditorTile et = go.GetComponent <EditorTile>();
                et.x = i;
                et.y = j;
                RectTransform rt = go.GetComponent <RectTransform>();
                rt.SetParent(mapAnchor);
                rt.anchoredPosition = new Vector2(x0 + (i * size), y0 + (j * size));
                roomTiles[i, j]     = et;
            }
        }

//        LoadMap();
    }
Пример #7
0
    /// <summary>Adds character spawns to the grid (only used for loading grids).</summary>
    /// <param name="spawns">List of spawn info to be added to the grid.</param>
    private void AddSpawners(List <UnitInfo> spawns)
    {
        if (spawns != null && spawns.Count > 0)
        {
            enemySpawns = new List <EditorUnit>();
            foreach (UnitInfo info in spawns)
            {
                if (!CheckTilePosition(info.GetPosition()))
                {
                    continue;
                }

                Vector2Int position = info.GetPosition();
                EditorTile tile     = grid[position.x].Get(position.y);
                UnitType   type     = info.GetInfoType();

                EditorUnit character = new EditorUnit(type, tile);
                tile.AddGridObject(character);

                if (type == UnitType.Player)
                {
                    player = character;
                }
                else if (type == UnitType.DecoyBot)
                {
                    decoyBotSpawns.Add(character);
                }
                else
                {
                    enemySpawns.Add(character);
                }
            }
        }
    }
Пример #8
0
        public static int maxView, minView;// pour le scroll
        #endregion

        #region construct
        public TileSelection()
        {
            LoadContent(Game1.Content);
            ActiveTile     = new EditorTile(507);
            maxView        = 60;
            minView        = 0;
            previousScroll = Mouse.GetState().ScrollWheelValue;
        }
    public void CalculateHeight(EditorTile tile, EditorGridPosition info, float y)
    {
        int numLayers = y >= .75 ? 2 : y >= .5 ? 1 : y <= -.75 ? -2 : y <= .5 ? -1 : 0;
        int height    = Mathf.FloorToInt(numLayers * tileHeightPerLayer);

        info.worldUnitHeight = info.savedWorldUnitHeight + height;
        tileDictionary[tile.gridPosition].worldHeight = info.worldUnitHeight;
    }
Пример #10
0
    private void CreateTiles(CubeModel model)
    {
        int widthFace;
        int heightFace;

        for (int faceNumber = 0; faceNumber < 6; faceNumber++)
        {
            GameObject face = new GameObject(faceNumber + "");
            face.transform.SetParent(transform);
            face.transform.localRotation = GetFaceRotation((CubeFace)faceNumber);
            face.transform.localPosition = GetFacePosition((CubeFace)faceNumber);
            switch (faceNumber)
            {
            case (int)CubeFace.X:
            case (int)CubeFace.MX:
                widthFace  = model.Z_SIZE;
                heightFace = model.Y_SIZE;
                break;

            case (int)CubeFace.Y:
            case (int)CubeFace.MY:
                widthFace  = model.X_SIZE;
                heightFace = model.Z_SIZE;
                break;

            case (int)CubeFace.Z:
            case (int)CubeFace.MZ:
                widthFace  = model.X_SIZE;
                heightFace = model.Y_SIZE;
                break;

            default:
                throw new UnhandledSwitchCaseException(faceNumber);
            }
            exterior[faceNumber] = new TileController[widthFace, heightFace];
            for (int x = 0; x < widthFace; x++)
            {
                for (int y = 0; y < heightFace; y++)
                {
                    TileData       tileData = model.faces[faceNumber][x, y];
                    TileController tile     = TileCreator.CreateTile(tileData, GetTilePosition((CubeFace)faceNumber, x, y), SizeRatio);
                    tile.transform.SetParent(face.transform, false);
                    //
                    if (GameObjects.GetGameState().LevelEditor)
                    {
                        EditorTile editorTile = tile.Mesh.AddComponent <EditorTile>();
                        editorTile.Init((CubeFace)faceNumber, x, y);
                        editorTile.GridTileClickEvent += GameObjects.GetLevelCreatorController().OnTileClick;
                    }
                    model.objectivesFilled.TryFillTile(tile);
                    //
                    exterior[faceNumber][x, y] = tile;
                }
            }
        }
    }
Пример #11
0
    static public void CopyTile(EditorTile et)
    {
        if (!mapLoaded)
        {
            return;
        }
        int ndx = et.tileNum;

        EditorTileSelection.SELECTED_TILE = ndx;
    }
    // Update new selected tile
    public void UpdateSelectedTile(EditorTile newTile)
    {
        Tile newPaintTile = newTile.GetTile();

        currentTile             = newPaintTile;
        selectedTileName.text   = currentTile.name;
        currentTileImage.sprite = currentTile.sprite;
        editorMapObject.SetSelectedEditorTile(currentTile);
        moveCostLabel.text = newTile.GetTileMoveCost().ToString();
    }
Пример #13
0
        private void CreateTile(TileCreator.TileTypes type)
        {
            GameObject tile = _tileEditor.CreateTile(type, _floorEditor.SelectedFloor);
            EditorTile et   = tile.GetComponent <EditorTile>();

            _boardEditor.AddTile(et);

            InvalidateExporter();
            _validatorEnabled = true;
        }
 public EditorGridPosition(GridPosition gridPosition, Vector3 worldPosition, int height, EditorTile tile = null)
 {
     this.gridPosition       = gridPosition;
     this.worldPosition      = worldPosition;
     this.savedWorldPosition = worldPosition;
     this.tile                 = tile;
     this.worldUnitHeight      = height;
     this.savedWorldUnitHeight = height;
     this.baseWorldUnitHeight  = height;
     this.offsetY              = new Vector3();
 }
Пример #15
0
 public void init()
 {
     for (int i = 0; i < numberOfTiles; i++)
     {
         for (int j = 0; j < numberOfTiles; j++)
         {
             Rectangle rect = new Rectangle(32 * i, 32 * j, 32, 32);
             tilesBounds[j, i] = rect;
             tiles[i, j]       = new EditorTile(-1);
         }
     }
 }
Пример #16
0
        public new void Draw(SpriteBatch sp)
        {
            Update();
            sp.Draw(bgTex, sourceRectangle, new Color(Color.Gray, 0.2f));

            int x = 10;
            int y = 80;

            if (ColorPicker.ActiveColor != System.Drawing.Color.Empty)
            {
                int min = 0;
                int max = 0;
                numberOfTilesFound = tiles_by_closest_color_list[ColorPicker.ActiveColor].Count;
                //scrollBar = new Rectangle(200, scrollBarX, 20, (numberOfTilesFound*32*100/7)/(16*(32)) );
                sp.Draw(bgTex, scrollBar, Color.Red);
                foreach (int tileIndex in tiles_by_closest_color_list[ColorPicker.ActiveColor])
                {
                    if (min >= minView && max <= maxView)
                    {
                        int column = (int)(tileIndex / EditorLayer.numberOfTiles);
                        int row    = tileIndex % EditorLayer.numberOfTiles;

                        Rectangle rect = new Rectangle(row * 32, column * 32, 32, 32);
                        Rectangle destinationRectangle = new Rectangle(x, y, 32, 32);

                        sp.Draw(texture, destinationRectangle, rect, Color.White);

                        x += 40;

                        if (x > sourceRectangle.Width + sourceRectangle.X - 40 - 40)
                        {
                            x  = 10;
                            y += 40;
                        }

                        if (destinationRectangle.Contains(MapEditorPage.ms.Position) && MapEditorPage.ms.LeftButton == ButtonState.Pressed)
                        {
                            if (ActiveTile.Index != tileIndex)
                            {
                                ActiveTile = new EditorTile(tileIndex);
                            }
                        }
                    }
                    min++;
                    max++;
                }
            }
            else
            {
                DisplayAllTiles(sp, x, y);
            }
        }
Пример #17
0
    private void RemoveTeleportPartner(TeleporterColor color)
    {
        if (teleportPartner != null)
        {
            teleportPartner.SetTeleportDesination(null, this.variant);
        }

        if (gridCreator.teleportTiles[color].Contains(this))
        {
            gridCreator.teleportTiles[color].Remove(this);
        }
        teleportPartner = null;
    }
Пример #18
0
    static public void ChangeTile(EditorTile et)
    {
        if (!mapLoaded)
        {
            return;
        }
        Vector2 mLoc = InRoomToMap(ROOM, new Vector2(et.x, et.y));
        int     i    = (int)mLoc.x;
        int     j    = (int)mLoc.y;

        MAP[i, j] = EditorTileSelection.SELECTED_TILE;
        S.ShowRoom();
    }
Пример #19
0
 void PreInteractTile(EditorTile tile)
 {
     if (color == CitizenColor.Red)
     {
         if (tile.tile_Type == Tile_Type.White)
         {
             tile.TileChange(Tile_Type.Red);
         }
         else if (tile.tile_Type == Tile_Type.Blue)
         {
             tile.TileChange(Tile_Type.White);
         }
     }
 }
Пример #20
0
 /// <summary>Removes tile from the grid.</summary>
 /// <param name="list">The editor list the tile is contained in.</param>
 /// <param name="tile">The tile to be removed.</param>
 private void RemoveTile(EditorList list, EditorTile tile)
 {
     list.list.Remove(tile);
     tile.RemoveGridObject();
     SimpleObjectPool.Despawn(tile.gameObject);
     foreach (List <EditorTile> teleporters in teleportTiles.Values)
     {
         if (teleporters.Contains(tile))
         {
             teleporters.Remove(tile);
             break;
         }
     }
 }
Пример #21
0
        private void TilesByFloorMenu()
        {
            TileSubmenusVisualCalculation();

            SeparateSubMenu();

            List <EditorTile> tiles = _boardEditor.Tiles();

            GUILayout.Label($"Tiles Count: {tiles.Count.ToString()}");
            EditorGUILayout.Separator();

            GUIStyle labelStyle   = CreateStyleWithMargin(GUI.skin.label, 30, 0);
            GUIStyle buttonStyle  = CreateStyleWithMargin(GUI.skin.button, 0, 15);
            GUIStyle foldoutStyle = CreateStyleWithMargin(EditorStyles.foldout, 5, 0);

            for (int i = 0; i < _floorEditor.FloorsQuantity; i++)
            {
                _tilesSubmenus[i] = EditorGUILayout.Foldout(_tilesSubmenus[i], $"Floor {i.ToString()}", foldoutStyle);
                if (_tilesSubmenus[i])
                {
                    while (tiles.Count > 0)
                    {
                        EditorTile et = tiles[0];
                        if (et.floor != i)
                        {
                            tiles.RemoveAt(0);
                            continue;
                        }

                        EditorGUILayout.BeginHorizontal();
                        GUILayout.Label(et.Name(), labelStyle);

                        if (GUILayout.Button("Select", buttonStyle, GUILayout.Width(100)))
                        {
                            Selection.activeGameObject = et.gameObject;
                        }

                        if (GUILayout.Button("Remove", buttonStyle, GUILayout.Width(150)))
                        {
                            _boardEditor.RemoveTile(et);
                            InvalidateExporter();
                        }

                        EditorGUILayout.EndHorizontal();
                        tiles.RemoveAt(0);
                    }
                }
            }
        }
Пример #22
0
    IEnumerator MoveTo()
    {
        yield return(null);

        isMoveTo = true;
        Vector2 target = Path.Pop().Position;

        EditorTile tile = tileController.tiles[(int)target.x, (int)target.y];

        ChangeAnimatorDir(target);
        pos = tile.pos;
        PreInteractTile(tile);

        while (Approximately(transform.position, tile.transform.position) == false)
        {
            float step = MoveSpeed * Time.deltaTime;

            Vector3 tilepos = tile.transform.position;
            tilepos.z         += 100;
            transform.position = Vector3.MoveTowards(transform.position, tilepos, step);

            yield return(null);
        }

        PostInteractTile(tile);

        // 도착 체크 및 처리
        if (Path.Count <= 0)
        {
            // 건물
            if (targetBuilding != null && NodeType.Home <= nodeType && nodeType <= NodeType.Company)
            {
                if (isMoveTo) // 터치로 패턴 변경 시 타이밍 에러 방지
                {
                    targetBuilding.Come_In(gameObject);
                    ForceMove   = false;
                    destination = null;
                }
            }
            else // 타일
            {
                destination = null;
                ChangePattern();
            }
        }

        isMoveTo = false;
    }
Пример #23
0
    // Use this for initialization
    void Start()
    {
        Tilemap tilemap = GetComponentInParent <Tilemap>();

        if (tilemap != null)
        {
            EditorTile tile = tilemap.GetTile <EditorTile>(Vector3Int.RoundToInt(transform.position));
            if (tile != null)
            {
                transform.rotation  = Quaternion.Euler(0, 0, tile.m_Rot);
                transform.position += getShift(tile.m_Rot);
                //print("rot = " + tile.m_Rot.ToString());
            }
        }
        //print("Start");
    }
Пример #24
0
    /// <summary>Creates a tile at the given position.</summary>
    /// <param name="parent">The editor list the tile will be in.</param>
    /// <param name="position">The desired position of the tile.</param>
    private EditorTile CreateTile(EditorList parent, Vector3 position)
    {
        Quaternion rotation    = Quaternion.Euler(new Vector3(0, 90, 0));
        GameObject EditorSpace = SimpleObjectPool.Spawn(tilePrefab, position, rotation, transform.GetChild(0));
        EditorTile tile        = EditorSpace.GetComponent <EditorTile>();

        rotation = Quaternion.Euler(new Vector3(90, 0, 0));
        GameObject gridButton = SimpleObjectPool.Spawn(buttonPrefab, position, rotation, transform.GetChild(1));

        UnityEngine.UI.Button button = gridButton.GetComponent <UnityEngine.UI.Button>();
        button.onClick.RemoveAllListeners();
        button.onClick.AddListener(tile.AddTile);

        tile.Initalize(parent, this, gridButton);
        return(tile);
    }
Пример #25
0
    public void ChangeActiveTile(int ind, GameObject obj, int tileIndex)
    {
        if (ind != -1 && obj != null)
        {
            activeTileIndex        = ind;
            activeObject           = obj;
            activeObjectIndex      = tileIndex;
            activeObjectProperties = obj.GetComponent <TileInitiator>().tile;
            SpriteRenderer newSprite = obj.GetComponent <SpriteRenderer>();
            Debug.Log("selected tile with index: " + ind + " obj: " + obj.name + " sprite renderer: " + newSprite.sprite + " tile index: " + activeObjectIndex);
            editorTexture.transform.localScale = new Vector3(1, 1, 1);
            editorTextureRenderer.sprite       = newSprite.sprite;
            editorTextureRenderer.color        = newSprite.color;

            tileRotation = 0;
        }
    }
Пример #26
0
 public void Draw(SpriteBatch spriteBatch)
 {
     Update();
     for (int i = 0; i < numberOfTiles; i++)
     {
         for (int j = 0; j < numberOfTiles; j++)
         {
             EditorTile currentTile = tiles[j, i];
             if (currentTile.Index != -1)
             {
                 int row    = (int)(currentTile.Index / numberOfTiles);
                 int column = currentTile.Index % numberOfTiles;
                 spriteBatch.Draw(TileSet, tilesBounds[j, i], new Rectangle(column * 32, row * 32, 32, 32), Color.White);
             }
         }
     }
 }
    public void OnPointerUp(PointerEventData eventData)
    {
        image.gameObject.SetActive(true);
        idText.gameObject.SetActive(true);
        moveImage.gameObject.SetActive(false);

        Vector2 world_pos = Camera.main.ScreenToWorldPoint(eventData.position);

        GameObject recycleBinOBJ      = GameObject.Find("Delete");
        Vector2    recycleBinOBJPos   = recycleBinOBJ.transform.position;
        float      recycleBinDistance = Vector2.Distance(recycleBinOBJPos, world_pos);

        if (recycleBinDistance < 100)
        {
            DeleteOn();
            return;
        }

        EditorTile tile     = null;
        float      distance = 100;

        for (int x = 0; x < TileController.x_max_value; x++)
        {
            for (int y = 0; y < TileController.y_max_value; y++)
            {
                EditorTile tempTile = editorStage.tiles.Find(tileData => tileData.pos == new Vector2(x, y));

                float tempDistance = Vector2.Distance(world_pos, tempTile.transform.position);

                if (distance > tempDistance)
                {
                    distance = tempDistance;
                    tile     = tempTile;
                }
            }
        }

        if (tile != null)
        {
            tile = editorStage.GetResultPos((int)tile.pos.x, (int)tile.pos.y, buildSize, id);
            if (tile != null)
            {
                ResetPos(tile);
            }
        }
    }
Пример #28
0
        /// <summary>
        /// Initialise les tiles du tileset avec leur index et la couleur la plus présente
        /// (hormis la couleur vide (0,0,0,0))
        /// </summary>
        public void InitializeTiles()
        {
            // Variables
            int currentRow    = 0;
            int currentColumn = 0;

            // Boucle d'itération à travers tile_list
            for (int i = 0; i < 1024; i++)
            {
                currentColumn = i % LargeurEnTiles;
                if (i > 0 && currentColumn == 0)
                {
                    currentRow++;
                }


                tile_list[i] = new EditorTile(i);
                Dictionary <System.Drawing.Color, int> colors = new Dictionary <System.Drawing.Color, int>();

                for (int j = currentRow * TailleTile; j < (currentRow * TailleTile) + TailleTile; j++)
                {
                    for (int k = currentColumn * TailleTile; k < (currentColumn * TailleTile) + TailleTile; k++)
                    {
                        System.Drawing.Color pixel = tileset.GetPixel(k, j);
                        if (colors.ContainsKey(pixel))
                        {
                            colors[pixel]++;
                        }

                        else if (pixel.A != 0)
                        {
                            colors.Add(pixel, 1);
                        }
                    }
                }
                if (colors.Count == 0)
                {
                    tile_list[i].DominantColor = System.Drawing.Color.FromArgb(0, 0, 0, 0);
                }
                else
                {
                    tile_list[i].DominantColor = colors.Aggregate((x, y) => x.Value > y.Value ? x : y).Key; // Récupère la couleur la plus trouvée
                }
            }
        }
Пример #29
0
 void PostInteractTile(EditorTile tile)
 {
     if (tile.tile_Type == Tile_Type.Red)
     {
         if (color == CitizenColor.White)
         {
             ChangeColor(CitizenColor.Red);
         }
         else if (color == CitizenColor.Blue)
         {
             ChangeColor(CitizenColor.White);
         }
     }
     else if (tile.tile_Type == Tile_Type.Blue)
     {
         if (color == CitizenColor.White)
         {
             ChangeColor(CitizenColor.Blue);
         }
     }
 }
Пример #30
0
    /// <summary>Adds level objects to the level (only used for loading grids).</summary>
    /// <param name="levelObjectInfo">List of hazard info to be added to the grid.</param>
    public void AddLevelObjects(List <LevelObjectInfo> levelObjectInfo)
    {
        if (levelObjectInfo != null && levelObjectInfo.Count > 0)
        {
            levelObjects = new List <EditorLevelObject>();
            foreach (LevelObjectInfo info in levelObjectInfo)
            {
                if (!CheckTilePosition(info.GetPosition()))
                {
                    continue;
                }

                Vector2Int        position = info.GetPosition();
                EditorTile        tile     = grid[position.x].Get(position.y);
                ObjectType        type     = info.GetInfoType();
                EditorLevelObject hazard   = new EditorLevelObject(type, tile, info.GetVariant());

                tile.AddGridObject(hazard);
                levelObjects.Add(hazard);
            }
        }
    }