Exemple #1
0
        /// <summary>
        /// Creates a array of colors based on given perameters
        /// </summary>
        /// <param name="count"></param>
        /// <param name="minRange"></param>
        /// <param name="maxRange"></param>
        /// <param name="channel"></param>
        /// <param name="alphaBlack"></param>
        /// <returns></returns>
        public static Color[] ToColorArray(byte count, byte minRange, byte maxRange, ColorAssistChannel channel, bool alphaBlack = false)
        {
            if (maxRange <= minRange)
            {
                Debug.LogErrorFormat("maxRange of {0} is smaller or equal to minRange of {1}", maxRange, minRange);
                return(null);
            }
            Color[] colors = new Color[count];

            float value = (maxRange - minRange) / count;

            for (int i = 0; i < count; i++)
            {
                value    *= i;
                value    /= 256;
                colors[i] = value.ToColor(channel, alphaBlack);
            }
            return(colors);
        }
Exemple #2
0
 /// <summary>
 /// Converts a float to colour, basec on channel
 /// </summary>
 /// <param name="value"></param>
 /// <param name="channel"></param>
 /// <returns></returns>
 public static Color ToColor(this float value, ColorAssistChannel channel, bool alphaBlack = false)
 {
     if (channel == ColorAssistChannel.Red)
     {
         return(new Color(value, 0, 0, 1));
     }
     else if (channel == ColorAssistChannel.Blue)
     {
         return(new Color(0, value, 0, 1));
     }
     else if (channel == ColorAssistChannel.Green)
     {
         return(new Color(0, 0, value, 1));
     }
     else if (channel == ColorAssistChannel.Alpha && alphaBlack)
     {
         return(new Color(0, 0, 0, value));
     }
     else if (channel == ColorAssistChannel.Alpha)
     {
         return(new Color(1, 1, 1, value));
     }
     return(Color.black);
 }