Ejemplo n.º 1
0
    private void RecycleBot(tnUIBot i_Bot)
    {
        if (i_Bot == null)
        {
            return;
        }

        i_Bot.gameObject.SetActive(false);
        m_BotsPool.Add(i_Bot);
    }
Ejemplo n.º 2
0
    private void CreateBotsPool()
    {
        m_BotsPool = new List <tnUIBot>();

        if (m_UIBotPrefab == null)
        {
            return;
        }

        for (int index = 0; index < m_EntriesCount; ++index)
        {
            tnUIBot bot = GameObject.Instantiate <tnUIBot>(m_UIBotPrefab);
            bot.transform.SetParent(transform, false);
            bot.gameObject.SetActive(false);
            m_BotsPool.Add(bot);
        }
    }
Ejemplo n.º 3
0
    public bool RemoveBot()
    {
        GridEntry gridEntry = GetFirstBotEntry();

        if (gridEntry == null)
        {
            return(false);
        }

        gridEntry.isBot = false;

        tnUIBot lastBot = m_Bots[m_Bots.Count - 1];

        m_Bots.RemoveAt(m_Bots.Count - 1);

        RecycleBot(lastBot);

        return(true);
    }
Ejemplo n.º 4
0
    private tnUIBot SpawnBot()
    {
        if (m_BotsPool != null && m_BotsPool.Count > 0)
        {
            tnUIBot bot = m_BotsPool[m_BotsPool.Count - 1];
            m_BotsPool.RemoveAt(m_BotsPool.Count - 1);
            bot.gameObject.SetActive(true);
            return(bot);
        }
        else
        {
            if (m_UIBotPrefab == null)
            {
                return(null);
            }

            tnUIBot bot = GameObject.Instantiate <tnUIBot>(m_UIBotPrefab);
            return(bot);
        }
    }
Ejemplo n.º 5
0
    public bool AddBot()
    {
        if (!CanAddBot())
        {
            return(false);
        }

        if (m_UIBotPrefab == null)
        {
            return(false);
        }

        GridEntry gridEntry = GetLastAvailableEntry();

        if (gridEntry == null)
        {
            return(false);
        }

        tnUIBot bot = SpawnBot();

        if (bot == null)
        {
            return(false);
        }

        gridEntry.isBot = true;

        RectTransform botTransform = (RectTransform)bot.transform;

        botTransform.position  = gridEntry.controllerAnchor.rectTransform.position;
        botTransform.sizeDelta = new Vector2(gridEntry.controllerAnchor.width, gridEntry.controllerAnchor.height);

        m_Bots.Add(bot);

        return(true);
    }