private void StartLife(string nucleationMethod)
    {
        for (int y = 0; y < heightTotal; y++)
        {
            for (int x = 0; x < widthTotal; x++)
            {
                actualColor[y, x] = colorBlack;
            }
        }

        switch (nucleationMethod)
        {
        case "Plain":
        {
            int biasX = (int)widthTotal / PlayerPrefs.GetInt("widthUnits");
            int biasY = (int)heightTotal / PlayerPrefs.GetInt("heightUnits");
            for (int y = 0; y < PlayerPrefs.GetInt("heightUnits"); y++)
            {
                for (int x = 0; x < PlayerPrefs.GetInt("widthUnits"); x++)
                {
                    objects[y * biasY, x *biasY].GetComponent <Image>().color = ColorHandler.GenerateColor();         //podstawienie
                }
            }
            break;
        }

        case "Random":
        {
            for (int i = 0; i < PlayerPrefs.GetInt("randomUnits"); i++)
            {
                for (; ;)
                {
                    int x = (int)Random.Range(0, widthTotal);
                    int y = (int)Random.Range(0, heightTotal);
                    if (actualColor[y, x].Equals(colorBlack))
                    {
                        objects[y, x].GetComponent <Image>().color = ColorHandler.GenerateColor();         //podstawienie
                        break;
                    }
                }
            }
            break;
        }

        case "Radius":
        {
            for (int i = 0; i < PlayerPrefs.GetInt("amountNucleation"); i++)
            {
                for (int j = 0; j < 500; j++)
                {
                    int x = (int)Random.Range(0, widthTotal);
                    int y = (int)Random.Range(0, heightTotal);
                    if (!CheckIfAnyInRadius(objects[y, x]))
                    {
                        objects[y, x].GetComponent <Image>().color = ColorHandler.GenerateColor();         //Podstawienie
                        list.Add(objects[y, x]);
                        break;
                    }

                    if (j == 499)         // Too many tries. Give up
                    {
                        Debug.LogError("Box is full! Cannot add any grain with that radius!");
                        return;
                    }
                }
            }
            break;
        }
        }
        UpdateColorBase();
    }
Пример #2
0
 public void OnButtonClick()
 {
     gameObject.GetComponent <Image>().color = ColorHandler.GenerateColor();
 }