Beispiel #1
0
    private void GiveTile(strange.extensions.dispatcher.eventdispatcher.api.IEvent data)
    {
        if (tilePool != null)
        {
            TileModel tile = data.data as TileModel;

            if (tile != null)
            {
                if (tilePool.ContainsKey(tile.TileType))
                {
                    if (tilePool[tile.TileType] != null && tilePool[tile.TileType].Count > 0)
                    {
                        GameObject tileGameObject = tilePool[tile.TileType][0];

                        if (tileGameObject != null)
                        {
                            TileView tileView = tileGameObject.GetComponent <TileView>();

                            if (tileView != null)
                            {
                                tileView.Init(tile);
                            }

                            dispatcher.Dispatch(RootEvents.E_TileSetToWorld, tileGameObject);

                            tilePool[tile.TileType].Remove(tileGameObject);
                        }

                        else
                        {
                            Debug.LogError("tileGameObject == NULL");
                        }
                    }

                    else
                    {
                        Debug.LogError(string.Format("tilePool[{0}] == NULL", tile.TileType.ToString()));
                    }
                }

                else
                {
                    Debug.LogError(string.Format("tilePool not Contains {0} key", tile.TileType.ToString()));
                }
            }

            else
            {
                Debug.LogError("tile == NULL");
            }
        }

        else
        {
            Debug.LogError("tilePool == NULL");
        }
    }
    public Entity CreateTile(ResTile cfg, Vector3 position)
    {
        var entity        = World.CreateEntity();
        var tileComponent = World.AddComponentOnce <TileComponent>(entity);

        tileComponent.tileId = cfg.id;

        var prefabComponent = World.AddComponentOnce <PrefabComponent>(entity);

        prefabComponent.go             = prefabComponent.gameObject;
        prefabComponent.trans          = prefabComponent.transform;
        prefabComponent.trans.position = position;
        var tileView = new TileView();

        tileView.Init(cfg.path, prefabComponent.trans);
        prefabComponent.view = tileView;

        var tileMoveComponent    = World.AddComponentOnce <TileMoveComponent>(entity);
        var tileDestroyComponent = World.AddComponentOnce <TileDestroyComponent>(entity);

        return(entity);
    }
Beispiel #3
0
 private void CreateGrig()
 {
     gridstartx = gameObject.GetComponent <Transform>().position.x - 3.5f;
     gridstarty = gameObject.GetComponent <Transform>().position.y + 3f;
     for (int y = 0; y < Constant.YGrid; y++)
     {
         Line line = new Line();
         for (int x = 0; x < Constant.XGrid; x++)
         {
             GameObject newslot  = LeanPool.Spawn(ElementPrefab);
             TileView   tileView = newslot.GetComponent <TileView>();
             tileView.Init(new Point(x, y));
             newslot.transform.position = new Vector3(gridstartx + x * 1.7f, gridstarty - y * 2, 1);
             newslot.name             = "slot_" + x.ToString() + "_" + y.ToString();
             newslot.transform.parent = gameObject.transform;
             AllElement.Add(tileView);
             line.AddElement(tileView);
         }
         AllLine.Add(line);
         line.Init();
     }
 }