void HandleHit(LevelEditorTile tile) { if (UseTextToggle.isOn) { tile.SetText(EntityDropdown.options[EntityDropdown.value].text, EntityDropdown.value); } else { tile.SetSprite(EntityDropdown.options[EntityDropdown.value].image, EntityDropdown.value); } }
private async Task PopulateScreen() { async Task CreateTile(Panel destination, LevelDataBlock block, bool isModifiedDB) { await Dispatcher.InvokeAsync(delegate { var cell = new LevelEditorTile(LevelContext.BIKINI, block) { Width = 20, Height = 20 }; cell.MouseDown += delegate { if (!isModifiedDB) { OriginalSelected.Text = block.GUID + " " + block.Name; } else { ModifiedSelected.Text = block.GUID + " " + block.Name; } }; destination.Children.Add(cell); }); } Dispatcher.Invoke(() => { AllBlocksWrap.Children.Clear(); AllBlocksWrapModified.Children.Clear(); AddedBlocksWrap.Children.Clear(); RemovedBlocksWrap.Children.Clear(); }); foreach (var entry in diffHost.DB1_BlockData) { await CreateTile(AllBlocksWrap, entry, false); } foreach (var entry in diffHost.DB2_BlockData) { await CreateTile(AllBlocksWrapModified, entry, true); } foreach (var entry in diffHost.AddedBlocks.Values) { await CreateTile(AddedBlocksWrap, entry, true); } foreach (var entry in diffHost.RemovedBlocks.Values) { await CreateTile(AddedBlocksWrap, entry, true); } }
void GenerateGrid() { for (int i = 0; i < TileWidth; i++) { for (int j = 0; j < TileHeight; j++) { GameObject go = GameObject.Instantiate(DefaultTile, this.transform); go.name = $"{i},{j}"; go.transform.localPosition = new Vector2(i * TileScale, j * TileScale); go.transform.localScale = new Vector2(TileScale, TileScale); LevelEditorTile editorTile = go.GetComponent <LevelEditorTile>(); editorTile.SetCoords(i, j); TileGridList.Add(editorTile); } } }
// Update is called once per frame void Update() { if (Input.GetMouseButton(0)) { Vector2 screenPos = cam.ScreenToWorldPoint(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(screenPos, Vector2.zero); if (hit.collider != null) { LevelEditorTile tile = hit.collider.GetComponent <LevelEditorTile>(); if (tile) { HandleHit(tile); } } } }