Example #1
0
    MapTileInfo CreateMapItem(UIMapItem.ItemType type)
    {
        MapTileInfo info = new MapTileInfo();
        GameObject  obj  = new GameObject("item_" + type.ToString());
        UIMapItem   item = null;

        item = obj.AddComponent <UIMapItem>();

        AddObjToMap(obj);
        info.obj  = obj;
        info.type = type;


        item.type      = type;
        item.iDelegate = this;
        item.info      = info;

        obj.transform.localPosition = new Vector3(0, 0, rootPosZ - 1);
        float w, h;

        w = meshRoad.roadWidth;
        h = meshRoad.roadWidth;
        item.UpdateItem(w, h);
        return(info);
    }
Example #2
0
    public void SetTile(MapTileInfo info)
    {
        if (_spriteRenderer == null)
        {
            _spriteRenderer = this.GetComponent <SpriteRenderer>();
        }

        _tileInfo = info;

        switch (info.TileType)
        {
        case MapTileInfo.Type.Ground:
            if (info.Humidity > 0)
            {
                _spriteRenderer.color = new Color(1 - info.Humidity * 0.5f, 1 - info.Humidity, 1);
            }
            else
            {
                _spriteRenderer.color = Color.white;
            }
            break;

        case MapTileInfo.Type.Water:
            _spriteRenderer.color = Color.blue;
            break;
        }

        humidity = info.Humidity;
    }
Example #3
0
        public byte[] GetTile(Uri tileUri, ImageryProvider provider, MapTileInfo tileInfo)
        {
            var contentBytes = cache.GetOrCreate(tileUri, entry =>
            {
                entry.SetSlidingExpiration(TimeSpan.FromMinutes(options.ImageryCacheExpirationMinutes));

                // Check if present on disk
                if (options.UseImageryDiskCache)
                {
                    var tileFile = GetTileDiskPath(provider, tileInfo);
                    if (File.Exists(tileFile) && (DateTime.Now - File.GetLastWriteTime(tileFile)) <= diskExpirationHours)
                    {
                        return(File.ReadAllBytes(tileFile));
                    }


                    HttpClient httpClient = httpClientFactory.CreateClient();
                    var bytes             = httpClient.GetByteArrayAsync(tileUri).GetAwaiter().GetResult();
                    File.WriteAllBytes(tileFile, bytes);

                    return(bytes);
                }
                else
                {
                    HttpClient httpClient = httpClientFactory.CreateClient();
                    return(httpClient.GetByteArrayAsync(tileUri).GetAwaiter().GetResult());
                }
            });

            return(contentBytes);
        }
Example #4
0
 /// <summary>
 /// Sets the humidity.
 /// if value is more bigger than info's humadity, update humadity in info
 /// </summary>
 /// <param name="value">Value.</param>
 public void SetHumidity(MapTileInfo info, float value)
 {
     if (value > info.Humidity)
     {
         info.Humidity = value;
     }
 }
Example #5
0
    //统计可走的“方向”总数
    int GetAllMoveDirection(CarMotion.Move[] listMove)
    {
        MapTileInfo infoLeft   = GetRoadTileLeft();
        MapTileInfo infoRight  = GetRoadTileRight();
        MapTileInfo infoTop    = GetRoadTileTop();
        MapTileInfo infoBottom = GetRoadTileBottom();
        //统计可走的“方向”总数
        int total = 0;

        if ((infoLeft != null) && (GePretRoadTileDirection() != CarMotion.Move.LEFT))
        {
            listMove[total] = CarMotion.Move.LEFT;
            total++;
        }
        if ((infoRight != null) && (GePretRoadTileDirection() != CarMotion.Move.RIGHT))
        {
            listMove[total] = CarMotion.Move.RIGHT;
            total++;
        }

        if ((infoTop != null) && (GePretRoadTileDirection() != CarMotion.Move.UP))
        {
            listMove[total] = CarMotion.Move.UP;
            total++;
        }

        if ((infoBottom != null) && (GePretRoadTileDirection() != CarMotion.Move.DOWN))
        {
            listMove[total] = CarMotion.Move.DOWN;
            total++;
        }
        return(total);
    }
Example #6
0
    //xi yi -> plant group list's center.
    public void AddPlantToGroup(MapTileInfo[,] mapTiles, int xi, int yi, PlantGroupInfo info, PlantGroupTableInfo tableInfo)
    {
        int range = tableInfo.GroupRange;

        PlantTableInfo plantInfo = null;
        Plant          plant     = null;

        for (int x_i = xi - range; x_i < xi + range; x_i++)
        {
            if (x_i < 0)
            {
                continue;
            }
            if (x_i >= MapTileInfo.ColumnCount)
            {
                break;
            }

            for (int y_i = yi - range; y_i < yi + range; y_i++)
            {
                if (y_i < 0)
                {
                    continue;
                }
                if (y_i >= MapTileInfo.RowCount)
                {
                    break;
                }
                if (JUtil.NextFloat() > tableInfo.Chance)
                {
                    continue;
                }

                int         index   = JUtil.NextInt(0, tableInfo.Plants.Count);
                int         plantId = tableInfo.Plants [index];
                MapTileInfo curTile = mapTiles [x_i, y_i];

                if (curTile.GetBuildableObject <BuildableObject>() == null &&
                    TableManager.Instance.PlantList.TryGetValue(plantId, out plantInfo))
                {
                    if (!TableManager.Instance.IsAdaptableEnvironment(plantInfo.ProperTemperature, plantInfo.ProperHumidity, curTile.Temperature, curTile.Humidity))
                    {
                        continue;
                    }

                    GameObject obj = ResourcesManager.Instance.GetObject("Plant");

                    plant = obj.GetComponent <Plant> ();
                    plant.SetPlantInfo(plantInfo, x_i, y_i);
                    plant.transform.position = MapTile.IndexToPosition(x_i, y_i);

                    mapTiles [x_i, y_i].SetBuildableObject(plant);
                    info.AddPlant(plant);
                }
            }
        }
    }
Example #7
0
    //相邻
    MapTileInfo GetItemSide(MapTileInfo info, int type)
    {
        MapTileInfo ret   = null;
        int         stepx = 0;
        int         stepy = 0;

        foreach (MapTileInfo infotmp in listTile)
        {
            stepx = infotmp.tileX - info.tileX;
            stepy = infotmp.tileY - info.tileY;
            switch (type)
            {
            case SIDE_TYPE_LEFT:
            {
                if ((stepx == -1) && (stepy == 0))
                {
                    ret = infotmp;
                    return(ret);
                }
            }
            break;

            case SIDE_TYPE_RIGHT:
            {
                if ((stepx == 1) && (stepy == 0))
                {
                    ret = infotmp;
                    return(ret);
                }
            }
            break;

            case SIDE_TYPE_TOP:
            {
                if ((stepx == 0) && (stepy == 1))
                {
                    ret = infotmp;
                    return(ret);
                }
            }
            break;

            case SIDE_TYPE_BOTTOM:
            {
                if ((stepx == 0) && (stepy == -1))
                {
                    ret = infotmp;
                    return(ret);
                }
            }
            break;
            }
        }
        return(ret);
    }
    public void ParseMapInfo(CodeCarItemInfo info)
    {
        itmeInfoGuanka = info;
        string fileName = Common.GAME_RES_DIR + "/guanka/place" + GameManager.placeLevel + "/guanka_" + GameManager.gameLevel + ".json";
        //FILE_PATH
        string json = FileUtil.ReadStringAsset(fileName);//((TextAsset)Resources.Load(fileName, typeof(TextAsset))).text;
        // Debug.Log("json::"+json);
        JsonData root     = JsonMapper.ToObject(json);
        string   strPlace = (string)root["place"];

        mapSizeX = Common.String2Int((string)root["mapSizeX"]);
        mapSizeY = Common.String2Int((string)root["mapSizeY"]);
        ResizeMainRect();
        JsonData items = root["item"];

        info.listTile = new List <MapTileInfo>();
        bool iscreate_car = false;

        for (int i = 0; i < items.Count; i++)
        {
            JsonData    item     = items[i];
            MapTileInfo infotile = new MapTileInfo();
            string      type     = (string)item["itemtype"]; //ROAD_TILE
                                                             // string strpos =//(573.0, 200.0)
            infotile.type     = UIMapItem.String2Type(type);
            infotile.id       = GetIdJson(item, "id");
            infotile.idLeft   = GetIdJson(item, "idLeft");
            infotile.idRight  = GetIdJson(item, "idRight");
            infotile.idTop    = GetIdJson(item, "idTop");
            infotile.idBottom = GetIdJson(item, "idBottom");

            infotile.tileX = (int)item["tileX"];
            infotile.tileY = (int)item["tileY"];

            info.listTile.Add(infotile);
            CreateMapItem(infotile);

            if ((!iscreate_car) && (infotile.type == UIMapItem.ItemType.ROAD_TILE))
            {
                //   Vector2 posworld = mainCam.ScreenToWorldPoint(infotile.pos);
                //car
                MapTileInfo infocar = new MapTileInfo();
                infocar.type  = UIMapItem.ItemType.CAR;
                infocar.tileX = infotile.tileX;
                infocar.tileY = infotile.tileY;
                // infocar.pos = infotile.pos;
                CreateMapItem(infocar);
                iscreate_car = true;
            }
        }


        meshRoad.Draw();
    }
Example #9
0
    MapTileInfo GetItemById(string id)
    {
        MapTileInfo ret = null;

        foreach (MapTileInfo infotmp in listTile)
        {
            if (infotmp.id == id)
            {
                ret = infotmp;
                break;
            }
        }
        return(ret);
    }
Example #10
0
        private string GetTileDiskPath(ImageryProvider provider, MapTileInfo tileInfo)
        {
            var providerDir = Path.Combine(_localDirectory, provider.Name);

            CreateDirectoryIfNotExists(providerDir);

            var zoomDir = Path.Combine(providerDir, tileInfo.Zoom.ToString());

            CreateDirectoryIfNotExists(zoomDir);

            var xDir = Path.Combine(zoomDir, tileInfo.X.ToString());

            CreateDirectoryIfNotExists(xDir);

            return(Path.Combine(xDir, string.Concat(tileInfo.Y, ".png")));
        }
    void CreateMapItem(MapTileInfo info)
    {
        Vector3 posworld = MapUtils.GetPositionCenter(info.tileX, info.tileY, mapSizeX, mapSizeY, sizeRect);

        posworld.z = rootPosZ - 1;
        float w, h;

        w = meshRoad.roadWidth;
        h = w;
        // Vector2 posworld = mainCam.ScreenToWorldPoint(pos);

        if (info.type == UIMapItem.ItemType.ROAD_TILE)
        {
            meshRoad.AddPoint(posworld);
        }

        if ((info.type == UIMapItem.ItemType.FLAG) || (info.type == UIMapItem.ItemType.TREE) || (info.type == UIMapItem.ItemType.CAR))
        {
            GameObject obj = new GameObject("item_" + info.type.ToString());
            //AppSceneBase.main.AddObjToMainWorld(obj);
            obj.transform.parent        = this.gameObject.transform;
            obj.transform.localScale    = new Vector3(1f, 1f, 1f);
            obj.transform.localPosition = new Vector3(posworld.x, posworld.y, rootPosZ - 1);
            if (info.type == UIMapItem.ItemType.CAR)
            {
                uiCar                   = obj.AddComponent <UICar>();
                uiCar.type              = info.type;
                uiCar.iDelegate         = this;
                uiCar.sizeRect          = sizeRect;
                uiCar.uiCmdBarRun       = uiCmdBarRun;
                uiCar.localPositionInit = obj.transform.localPosition;
                uiCar.SetMapSize(mapSizeX, mapSizeY);
                uiCar.UpdateGuankaItem(itmeInfoGuanka);
                uiCar.UpdateItem(w, h);
            }
            else
            {
                UIMapItem item = obj.AddComponent <UIMapItem>();
                item.type       = info.type;
                item.enableMove = false;
                item.UpdateItem(w, h);
            }

            //
        }
    }
Example #12
0
    MapTileInfo GetRoadTileInfo(int x, int y)
    {
        MapTileInfo inforet = null;

        if ((x < 0) || (x >= mapSizeX) || (y < 0) || (y >= mapSizeY))
        {
            return(null);
        }
        foreach (MapTileInfo info in itmeInfoGuanka.listTile)
        {
            if (info.type == UIMapItem.ItemType.ROAD_TILE)
            {
                if ((x == info.tileX) && (y == info.tileY))
                {
                    inforet = info;
                    break;
                }
            }
        }
        return(inforet);
    }
Example #13
0
    //计算地图拐点等
    void FormatMapData()
    {
        foreach (MapTileInfo info in listTile)
        {
            //left
            {
                MapTileInfo infoside = GetItemSide(info, SIDE_TYPE_LEFT);
                if (infoside != null)
                {
                    info.idLeft = infoside.id;
                }
            }

            //right
            {
                MapTileInfo infoside = GetItemSide(info, SIDE_TYPE_RIGHT);
                if (infoside != null)
                {
                    info.idRight = infoside.id;
                }
            }

            //top
            {
                MapTileInfo infoside = GetItemSide(info, SIDE_TYPE_TOP);
                if (infoside != null)
                {
                    info.idTop = infoside.id;
                }
            }
            //bottom
            {
                MapTileInfo infoside = GetItemSide(info, SIDE_TYPE_BOTTOM);
                if (infoside != null)
                {
                    info.idBottom = infoside.id;
                }
            }
        }
    }
Example #14
0
        public override void Initialize()
        {
            _mapTiles = new MapTileInfo[MapWidth][];

            for (int i = 0; i < _mapTiles.Length; i++)
            {
                _mapTiles[i] = new MapTileInfo[MapHeight];
            }

            for (int i = 0; i < _mapTiles.Length; i++)
            {
                for (int j = 0; j < _mapTiles[0].Length; j++)
                {
                    _mapTiles[i][j].TileSprite = MapSpriteTile.None;
                }
            }

            CreateSampleMap();

            CreateBodies(Game as BazingaGame);

            base.Initialize();
        }
    string GetImageOfItem(MapTileInfo info)
    {
        string pic = "";

        switch (info.type)
        {
        case UIMapItem.ItemType.FLAG:
            pic = ResMap.IMAGE_FLAG;
            break;

        case UIMapItem.ItemType.TREE:
            pic = ResMap.IMAGE_TREE;
            break;

        case UIMapItem.ItemType.CAR:
            pic = ResMap.IMAGE_CAR;
            break;

        case UIMapItem.ItemType.ROAD_TILE:
            pic = ResMap.IMAGE_TILE;
            break;
        }
        return(pic);
    }
Example #16
0
 public void OnClickBtnTile()
 {
     tileInfoNow = CreateMapItem(UIMapItem.ItemType.ROAD_TILE);
     listTile.Add(tileInfoNow);
 }
Example #17
0
    public void CreateMapInfo(MapTileInfo[,] tileInfoList)
    {
        int columnCount = MapTileInfo.ColumnCount;
        int rowCount    = MapTileInfo.RowCount;

        //tileInfoList = new MapTileInfo[columnCount, rowCount];

        //Create Map First
        for (int x = 0; x < columnCount; x++)
        {
            for (int y = 0; y < rowCount; y++)
            {
                MapTileInfo info = new MapTileInfo();

                //this is for temp -> almost ground
                MapTileInfo.Type type = JUtil.NextInt(0, 75) != 0 ? MapTileInfo.Type.Ground : MapTileInfo.Type.Water;
                info.Init(x, y, type);
                tileInfoList [x, y] = info;
            }
        }

        int humididyRange = 5;

        //Set temperature and humidity
        for (int x = 0; x < columnCount; x++)
        {
            for (int y = 0; y < rowCount; y++)
            {
                if (tileInfoList[x, y].TileType == MapTileInfo.Type.Water)
                {
                    for (int tx = x - humididyRange; tx <= x + humididyRange; tx++)
                    {
                        if (tx < 0)
                        {
                            continue;
                        }
                        if (tx >= columnCount)
                        {
                            break;
                        }

                        for (int ty = y - humididyRange; ty <= y + humididyRange; ty++)
                        {
                            if (ty < 0)
                            {
                                continue;
                            }
                            if (ty >= rowCount)
                            {
                                break;
                            }
                            if (tileInfoList [tx, ty].TileType == MapTileInfo.Type.Water)
                            {
                                continue;
                            }

                            float temperature = 25;
                            float humidity    = 0;

                            if (Mathf.Abs(tx - x) == 5 || Mathf.Abs(ty - y) == 5)
                            {
                                humidity = 0.1f;
                            }
                            else if (Mathf.Abs(tx - x) == 4 || Mathf.Abs(ty - y) == 4)
                            {
                                humidity = 0.2f;
                            }
                            else if (Mathf.Abs(tx - x) == 3 || Mathf.Abs(ty - y) == 3)
                            {
                                humidity = 0.3f;
                            }
                            else if (Mathf.Abs(tx - x) == 2 || Mathf.Abs(ty - y) == 2)
                            {
                                humidity = 0.4f;
                            }
                            else if (Mathf.Abs(tx - x) == 1 || Mathf.Abs(ty - y) == 1)
                            {
                                humidity = 0.5f;
                            }

                            SetHumidity(tileInfoList[tx, ty], humidity);
                            tileInfoList [tx, ty].Temperature = temperature;
                        }
                    }
                }
            }
        }
    }
Example #18
0
 public WorldData()
 {
     MapTiles   = new MapTileInfo[MapTileInfo.ColumnCount, MapTileInfo.RowCount];
     PlantGroup = new List <PlantGroupInfo> ();
 }
Example #19
0
    public void OnClickBtnEndFlag()
    {
        MapTileInfo info = CreateMapItem(UIMapItem.ItemType.FLAG);

        listTile.Add(info);
    }
Example #20
0
    MapTileInfo GetRoadTileRight()
    {
        MapTileInfo info = GetRoadTileInfo(tileX + 1, tileY);

        return(info);
    }
Example #21
0
    MapTileInfo GetRoadTileBottom()
    {
        MapTileInfo info = GetRoadTileInfo(tileX, tileY - 1);

        return(info);
    }
Example #22
0
    MapTileInfo GetRoadTileTop()
    {
        MapTileInfo info = GetRoadTileInfo(tileX, tileY + 1);

        return(info);
    }
Example #23
0
    public void OnClickBtnTree()
    {
        MapTileInfo info = CreateMapItem(UIMapItem.ItemType.TREE);

        listTile.Add(info);
    }
Example #24
0
    //获取当前位置左右上下的道路tile,如果不存在返回null
    MapTileInfo GetRoadTileLeft()
    {
        MapTileInfo info = GetRoadTileInfo(tileX - 1, tileY);

        return(info);
    }