示例#1
0
    public GameObjectResource get()
    {
        if (idle.Count <= 0)
        {
            GameObject g = gameObjectFactory.CreateGameObject();
            add(g);
        }
        GameObjectResource r = idle.First().Value;

        r.getGameObject().SetActive(true);
        used.Add(r.getId(), r);
        idle.Remove(r.getId());
        return(r);
    }
示例#2
0
    public void release(GameObjectResource r)
    {
        if (r.getPool() != this)
        {
            Debug.LogError("gameObjectPool must release gameObjectResource belong to it");
            return;
        }
        if (!used.ContainsKey(r.getId()))
        {
            return;
        }

        r.getGameObject().SetActive(false);

        used.Remove(r.getId());
        idle.Add(r.getId(), r);
    }
示例#3
0
    public IEnumerator getAsync(LoaderResult result)
    {
        result.isDone = false;
        result.asset  = null;
        if (idle.Count <= 0)
        {
            LoaderResult r = new LoaderResult();
            yield return(gameObjectFactory.CreateGameObjectAsync(r));

            add(r.asset as GameObject);
        }
        GameObjectResource res = idle.First().Value;

        res.getGameObject().SetActive(true);
        used.Add(res.getId(), res);
        idle.Remove(res.getId());
        result.asset  = res;
        result.isDone = true;
    }
示例#4
0
    /**
    **  Create a new unit.
    **
    **  @param type      Pointer to unit-type.
    **  @param player    Pointer to owning player.
    **
    **  @return          Pointer to created unit.
    */
    public Unit createUnit(UnitType type, Player player)
    {
        Unit unit;

        unit = AllocUnit();
        if (unit == null)
        {
            return(null);
        }
        GameObjectResource g = unitDrawer.get();

        unit.init(type, g.getGameObject().GetComponent <SpriteDrawer>());

        // Only Assign if a Player was specified
        if (player != null)
        {
            unit.assignToPlayer(player);
        }

        return(unit);
    }