private void _RebuildTileIcons() { CUtility.DestroyChildren(_tileIcons); for (int iX = 0; iX < _asset.mWidth * 2; ++iX) { for (int iY = 0; iY < _asset.mLength * 2; ++iY) { if (_asset.mTiles[iX, iY].mSolid) { GameObject gob = GameObject.CreatePrimitive(PrimitiveType.Quad); //GameObject gob = new GameObject(); gob.transform.SetParent(_tileIcons.transform); gob.transform.localPosition = new Vector3(iX * 0.5f + 0.25f, 0.0f, iY * 0.5f + 0.25f); gob.transform.rotation = Quaternion.Euler(90, 0, 0); gob.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); gob.GetComponent <MeshRenderer>().material = CGame.WorldResources.TileIconSolid; } } } for (int i = 0; i < _asset.mUsageSlots.Count; ++i) { CItemAsset.CUsageSlot s = _asset.mUsageSlots[i]; // Entry point tile hits Vector3 size = s.mEntrySize; Vector3 halfExtents = size * 0.5f; Vector3 min = s.mEntryPosition - halfExtents; Vector3 max = s.mEntryPosition + halfExtents; // Search for tiles within bounds int sX = (int)(min.x * 2.0f) - 1; int sY = (int)(min.z * 2.0f) - 1; int eX = (int)(max.x * 2.0f); int eY = (int)(max.z * 2.0f); for (int iX = sX; iX <= eX; ++iX) { for (int iY = sY; iY <= eY; ++iY) { Vector3 origin = new Vector3(iX * 0.5f + 0.25f, -0.01f, iY * 0.5f + 0.25f); if (origin.x >= min.x && origin.x <= max.x && origin.z >= min.z && origin.z <= max.z) { CDebug.DrawYSquare(origin, 0.45f, Color.blue, true); GameObject gob = GameObject.CreatePrimitive(PrimitiveType.Quad); //GameObject gob = new GameObject(); gob.transform.SetParent(_tileIcons.transform); gob.transform.localPosition = origin; gob.transform.rotation = Quaternion.Euler(90, 0, 0); gob.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f); gob.GetComponent <MeshRenderer>().material = CGame.WorldResources.TileIconTrigger; } } } } }
public override void Update(CInputState InputState) { if (_showGrid) { _DrawGrid(20); Vector3 c1 = new Vector3(0.0f, 0.01f, 0.0f); Vector3 c2 = new Vector3(0.0f, 0.01f, _asset.mLength); Vector3 c3 = new Vector3(_asset.mWidth, 0.01f, _asset.mLength); Vector3 c4 = new Vector3(_asset.mWidth, 0.01f, 0.0f); CDebug.DrawLine(c1, c2, Color.white); CDebug.DrawLine(c2, c3, Color.white); CDebug.DrawLine(c3, c4, Color.white); CDebug.DrawLine(c4, c1, Color.white); for (int i = 0; i < _asset.mUsageSlots.Count; ++i) { CItemAsset.CUsageSlot s = _asset.mUsageSlots[i]; CDebug.DrawYSquare(s.mEntryPosition, 0.2f, Color.blue, false); // Entry point tile hits Vector3 size = s.mEntrySize; CDebug.DrawYRect(s.mEntryPosition, size.x, size.z, Color.cyan, true); /* * Vector3 halfExtents = size * 0.5f; * Vector3 min = s.mEntryPosition - halfExtents; * Vector3 max = s.mEntryPosition + halfExtents; * * // Search for tiles within bounds * int sX = (int)(min.x * 2.0f) - 1; * int sY = (int)(min.z * 2.0f) - 1; * int eX = (int)(max.x * 2.0f); * int eY = (int)(max.z * 2.0f); * * for (int iX = sX; iX <= eX; ++iX) * for (int iY = sY; iY <= eY; ++iY) * { * Vector3 origin = new Vector3(iX * 0.5f + 0.25f, 0.0f, iY * 0.5f + 0.25f); * * if (origin.x >= min.x && origin.x <= max.x && origin.z >= min.z && origin.z <= max.z) * CDebug.DrawYSquare(origin, 0.45f, Color.blue, true); * } */ CDebug.DrawLine(s.mEntryPosition, s.mUsePosition, Color.cyan, false); CDebug.DrawYSquare(s.mUsePosition, 0.2f, Color.green, false); } } _helpers.SetActive(_showGrid); if (_selectedTileX != -1 && _selectedTileY != -1) { CDebug.DrawYSquare(new Vector3(_selectedTileX * 0.5f + 0.25f, 0.0f, _selectedTileY * 0.5f + 0.25f), 0.5f, Color.green, false); } Ray mouseRay = _GetViewportMouseRay(); Vector3 floorHitPoint; if (_IntersectFloor(mouseRay, out floorHitPoint)) { //CDebug.DrawLine(floorHitPoint, floorHitPoint + Vector3.up, Color.white); _hoverTileX = -1; _hoverTileY = -1; if (floorHitPoint.x >= 0.0f && floorHitPoint.z >= 0.0f) { int tileX = (int)(floorHitPoint.x * 2.0f); int tileY = (int)(floorHitPoint.z * 2.0f); if ((tileX >= 0 && tileX < _asset.mWidth * 2) && (tileY >= 0 && tileY < _asset.mLength * 2)) { _hoverTileX = tileX; _hoverTileY = tileY; CDebug.DrawYSquare(new Vector3(tileX * 0.5f + 0.25f, 0.0f, tileY * 0.5f + 0.25f), 0.5f, Color.yellow, false); } } } if (_viewportMouseDown && !_prevMouseDown) { _prevMouseDown = _viewportMouseDown; _SelectTile(_hoverTileX, _hoverTileY); if (_hoverTileX == -1 || _hoverTileY == -1) { _RebuildItemPropertiesView(); } } else if (!_viewportMouseDown && _prevMouseDown) { _prevMouseDown = _viewportMouseDown; } }