Ejemplo n.º 1
0
    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);
    }