public Dictionary <int, Field> CreateField(ref MapData data) { Dictionary <int, Field> map = new Dictionary <int, Field>(); Vector3 startPosition = _parentGameObject.transform.position; Vector3 FieldPosition = startPosition; int index = 0; int mapIndex = 0; for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { FieldPosition = startPosition + Vector3.right * GameMetrics.SpriteWidth * x + Vector3.up * GameMetrics.SpriteHeight * y + Vector3.forward / 1000 * y; data.AddPosition(FieldPosition); mapIndex = GameMetrics.VectorToIndex(FieldPosition - startPosition); Field tempField = new Field(FieldPosition); Ingredient tempIngredient = CreateIngredient(); _parentGameObject.GetChild(index).transform.position = FieldPosition; if (tempIngredient != null) { _parentGameObject.GetChild(index).transform.GetChild(0).GetComponent <SpriteRenderer>().sprite = SetSprite(tempIngredient.ingredientType); } data.AddWorldRepresenation(new WorldRepresentation(_parentGameObject.GetChild(index).GetChild(0).transform, _parentGameObject.GetChild(index).GetChild(0).GetComponent <SpriteRenderer>(), index)); tempField.SetIngredient(tempIngredient); map.Add(mapIndex, tempField); index++; } } data.ChangeRect(startPosition.x - GameMetrics.SpriteWidth / 2, startPosition.y - GameMetrics.SpriteHeight / 2, 4 * GameMetrics.SpriteWidth, 4 * GameMetrics.SpriteHeight); return(map); }
// Update is called once per frame void Update() { CalculateMousePosition(); _worldPosition = Camera.main.ScreenToWorldPoint(_mousePosition); _currentIndex = GameMetrics.VectorToIndex(_worldPosition - _startPoint.position); if (_playArea.Contains(new Vector2(_worldPosition.x, _worldPosition.y))) { if (Input.GetMouseButtonDown(0) && GetCurrentField.HasContent) { PickUpIngredient(GetCurrentField.Ingredient); _currentWorldRepresentation.Lift(true); } if (Input.GetMouseButton(0) && _currentWorldRepresentation != null) { _currentWorldRepresentation.Move(_worldPosition); } else if (_currentIngredient != null) { ReleaseIngredient(); } } }