Beispiel #1
0
    public void AddNewColorREgion()
    {
        bool   error    = false;
        string alertMsg = "Incomplete selection : ";

        if (nexTerrainType.name.Length == 0)
        {
            error     = true;
            alertMsg += "\n\t name invalid";
        }

        if (nexTerrainType.colour == null || colorPreview == null)
        {
            error     = true;
            alertMsg += "\n\t color invalid";
        }

        if (nexTerrainType.height < 0 || nexTerrainType.height > 1)
        {
            error     = true;
            alertMsg += "\n\t value invalid";
        }

        if (error)
        {
            alertPanel.SetActive(true);
            alertPanel.GetComponentInChildren <Text>().text = alertMsg;
            Button b = alertPanel.GetComponentInChildren <Button>();
            b.onClick.RemoveAllListeners();
            b.onClick.AddListener(() => ActiveOnePanel(panels[3]));
        }
        else
        {
            Color32          tmpColor = colorPreview.GetComponent <Image>().color;
            GameObject       tmp      = Instantiate(terrainTypeUIPrefab) as GameObject;
            SetColorRegionUI tmpUI    = tmp.GetComponent <SetColorRegionUI>();
            tmpUI.setName(nexTerrainType.name);
            tmpUI.setValue(nexTerrainType.height);
            tmpUI.setColor(tmpColor);
            tmp.transform.SetParent(customColorHolder.transform);
            nexTerrainType.colour = new Color32(tmpColor.r, tmpColor.g, tmpColor.b, (byte)255);
            selectedMap.regions.Add(nexTerrainType);
        }

        Debug.Log(
            "Name : " + nexTerrainType.name +
            "\nColor : " + nexTerrainType.colour.r + " " + nexTerrainType.colour.g + " " + nexTerrainType.colour.b +
            "\nValue : " + nexTerrainType.height
            );
    }
Beispiel #2
0
    public void GoToCustomColor(GameObject customColorH)
    {
        customColorHolder = customColorH;
        for (int i = customColorH.transform.childCount - 1; i >= 0; i--)
        {
            Destroy(customColorH.transform.GetChild(i).gameObject);
        }

        foreach (TerrainType item in selectedMap.regions)
        {
            GameObject       tmp   = Instantiate(terrainTypeUIPrefab) as GameObject;
            SetColorRegionUI tmpUI = tmp.GetComponent <SetColorRegionUI>();
            tmpUI.setName(item.name);
            tmpUI.setValue(item.height);
            tmpUI.setColor(item.colour);
            tmp.transform.SetParent(customColorH.transform);
        }

        nexTerrainType        = new TerrainType();
        nexTerrainType.name   = "";
        nexTerrainType.height = -1;
    }