Example #1
0
    public void SetUpColorDropdownOptions(CSColorChangerDD colorDropdown, SharedColorTable colorTable, int colorTableSelected, OverlayColorData activeColor)
    {
        var thisDD = colorDropdown.gameObject.GetComponent <DropdownWithColor>();

        thisDD.ClearOptions();
        thisDD.onValueChanged.RemoveAllListeners();
        Color selectedColor      = activeColor.color;
        var   colorBlack         = new Color(0, 0, 0, 0);
        bool  selectedColorFound = false;

        for (int i = 0; i < colorTable.colors.Length; i++)
        {
            var thisddOption = new DropdownWithColor.OptionData();
            thisddOption.text  = colorTable.colors[i].name;
            thisddOption.color = colorTable.colors[i].color;
            Sprite spriteToUse = genericColorSwatch;
            if (colorTable.colors[i].channelAdditiveMask.Length >= 3)
            {
                if (colorTable.colors[i].channelAdditiveMask[2] != colorBlack)
                {
                    spriteToUse = genericColorSwatchMetallic;
                }
            }
            if (i == colorTableSelected)
            {
                selectedColorFound = true;
                selectedColor      = colorTable.colors[i].color;
            }
            thisddOption.image = spriteToUse;
            thisDD.options.Add(thisddOption);
        }
        if (selectedColorFound)
        {
            thisDD.value = colorTableSelected;
            thisDD.captionImage.color = selectedColor;
        }
        else
        {
            var thisddOption = new DropdownWithColor.OptionData();
            thisddOption.text  = colorTable.colors[0].name;
            thisddOption.color = activeColor.color;
            Sprite spriteToUse = genericColorSwatch;

            /*if (activeColor.MetallicGloss != colorBlack)
             * {
             *      spriteToUse = genericColorSwatchMetallic;
             * }*/
            if (activeColor.channelAdditiveMask.Length >= 3)
            //if (activeColor.MetallicGloss != colorBlack)
            {
                spriteToUse = genericColorSwatchMetallic;
            }
            thisddOption.image = spriteToUse;
            thisDD.options.Add(thisddOption);
            thisDD.value = colorTable.colors.Length + 1;
        }
        thisDD.RefreshShownValue();
        thisDD.onValueChanged.AddListener(colorDropdown.ChangeColor);
    }
Example #2
0
    public void SetUpColorDropdownValue(CSColorChangerDD colorDropdown, OverlayColorData colorType)
    {
        if (GenericColorList == null)
        {
            Debug.LogWarning("[TestCustomizerDD] the GenericColorList was null or missing, this must be set.");
            return;
        }
        int colorTableSelected          = -1;
        SharedColorTable thisColorTable = null;

        if (sharedColorTables.FindIndex(s => s.name == colorType.name) > -1)
        {
            thisColorTable = sharedColorTables[sharedColorTables.FindIndex(s => s.name == colorType.name)].sharedColorTable;
            if (thisColorTable == null)
            {
                Debug.LogWarning("[TestCustomizerDD] the colorList for " + colorType.name + " was null or missing, please set this or remove it from the list.");
                return;
            }
            for (int i = 0; i < thisColorTable.colors.Length; i++)
            {
                if (ColorToHex(thisColorTable.colors[i].color) == ColorToHex(colorType.color))
                {
                    colorTableSelected = i;
                    break;
                }
            }
        }
        else
        {
            thisColorTable = GenericColorList;
            for (int i = 0; i < GenericColorList.colors.Length; i++)
            {
                if (ColorToHex(GenericColorList.colors[i].color) == ColorToHex(colorType.color))
                {
                    colorTableSelected = i;
                    break;
                }
            }
        }
        SetUpColorDropdownOptions(colorDropdown, thisColorTable, colorTableSelected, colorType);
    }