Exemple #1
0
    private void Start()
    {
        // Get all Tools and instantiate them with the content as a parent
        ToolCost[] toolCosts = ToolCostDict.Instance.Tools;
        for (int i = 0; i < toolCosts.Length; i++)
        {
            ToolElement inst = Instantiate(toolPrefab, content);
            inst.Tool = toolCosts[i];
        }

        gameObject.SetActive(false);
    }
Exemple #2
0
 /// <summary>
 /// 生成道具
 /// </summary>
 /// <param name="availableIndex">尚未初始化的地图元素的索引值列表</param>
 private void GenerateTool(List <int> availableIndex)
 {
     for (int i = 0; i < 5; i++)
     {
         int tempIndex = availableIndex[Random.Range(0, availableIndex.Count)]; //随机生成道具位置
         availableIndex.Remove(tempIndex);                                      //剩余可以生成的位置
         ToolElement t = (ToolElement)SetElement(tempIndex, ElementContent.Tool);
         t.toolType = (ToolType)Random.Range(0, 9);
         if (t.isHide == false)
         {
             t.ConfirmSprite();
         }
     }
 }
Exemple #3
0
    private void CreateTool(int _area, List <int> _avaliableIndex, ElementContent _elementContent)
    {
        int sx, ex;

        _area -= 1;
        if (_area < 0)
        {
            sx = 0;
            ex = standAreaW - 1;
        }
        else
        {
            sx = standAreaW + _area * obstacleAreaW;
            ex = sx + obstacleAreaW - 1;
        }

        int index = -1;

        for (int i = 0; i < 10; i++)
        {
            int ranX      = Random.Range(sx, ex + 1);
            int ranY      = Random.Range(0, h);
            int tempIndex = GetIndexByPos(ranX, ranY);
            if (_avaliableIndex.Contains(tempIndex))
            {
                index = tempIndex;
                break;
            }
        }

        if (index < 0)
        {
            List <int> randomList = new List <int>();
            for (int y = 0; y < h; y++)
            {
                for (int x = sx; x < ex; x++)
                {
                    int tempIndex = GetIndexByPos(x, y);
                    if (_avaliableIndex.Contains(tempIndex))
                    {
                        randomList.Add(tempIndex);
                    }
                }
            }
            if (randomList.Count <= 0)
            {
                CreateTool(_area, _avaliableIndex, _elementContent);
                return;
            }
            else
            {
                index = randomList[Random.Range(0, randomList.Count)];
            }
        }

        if (index >= 0)
        {
            _avaliableIndex.Remove(index);
            ToolType    tt   = (ToolType)_elementContent;
            ToolElement tool = SetElement <ToolElement>(index);
            tool.ReOnInit(tt);
        }
    }