예제 #1
0
        public static HSBColor FromColor(Color color)
        {
            HSBColor ret = new HSBColor(0f, 0f, 0f, color.a);

            float r = color.r;
            float g = color.g;
            float b = color.b;

            float max = Mathf.Max(r, Mathf.Max(g, b));

            if (max <= 0)
            {
                return ret;
            }

            float min = Mathf.Min(r, Mathf.Min(g, b));
            float dif = max - min;

            if (max > min)
            {
                if (g == max)
                {
                    ret.h = (b - r)/dif*60f + 120f;
                }
                else if (b == max)
                {
                    ret.h = (r - g)/dif*60f + 240f;
                }
                else if (b > g)
                {
                    ret.h = (g - b)/dif*60f + 360f;
                }
                else
                {
                    ret.h = (g - b)/dif*60f;
                }
                if (ret.h < 0)
                {
                    ret.h = ret.h + 360f;
                }
            }
            else
            {
                ret.h = 0;
            }

            ret.h *= 1f/360f;
            ret.s = (dif/max)*1f;
            ret.b = max;

            return ret;
        }
예제 #2
0
        private void RefreshContinued()
        {
            normalColor = thisImage.color;

            if (highlightWhen != HighlightActive.Never)
            {
                highlightColor = rippleColor;

                HSBColor highlightColorHSB = HSBColor.FromColor(highlightColor);
                HSBColor normalColorHSB    = HSBColor.FromColor(normalColor);

                if (highlightColorHSB.s <= 0.05f)
                {
                    if (highlightColorHSB.b > 0.5f)
                    {
                        if (normalColorHSB.b > 0.9f)
                        {
                            highlightColorHSB.h = normalColorHSB.h;
                            highlightColorHSB.s = normalColorHSB.s - 0.1f;
                            highlightColorHSB.b = normalColorHSB.b + 0.2f;
                        }
                        else
                        {
                            highlightColorHSB.h = normalColorHSB.h;
                            highlightColorHSB.s = normalColorHSB.s;
                            highlightColorHSB.b = normalColorHSB.b + 0.2f;
                        }
                    }
                    else
                    {
                        highlightColorHSB.h = normalColorHSB.h;
                        highlightColorHSB.s = normalColorHSB.s;
                        highlightColorHSB.b = normalColorHSB.b - 0.15f;
                    }

                    highlightColor   = HSBColor.ToColor(highlightColorHSB);
                    highlightColor.a = normalColor.a;
                }
                else
                {
                    highlightColor.r = Anim.Linear(normalColor.r, highlightColor.r, 0.2f, 1f);
                    highlightColor.g = Anim.Linear(normalColor.g, highlightColor.g, 0.2f, 1f);
                    highlightColor.b = Anim.Linear(normalColor.b, highlightColor.b, 0.2f, 1f);
                    highlightColor.a = Anim.Linear(normalColor.a, highlightColor.a, 0.2f, 1f);
                }
            }

            animationDuration = 4 / rippleSpeed;
        }
예제 #3
0
        public static HSBColor Lerp(HSBColor a, HSBColor b, float t)
        {
            float h, s;

            //check special case black (Color.b==0): interpolate neither hue nor saturation!
            //check special case grey (Color.s==0): don't interpolate hue!
            if (a.m_B == 0)
            {
                h = b.m_H;
                s = b.m_S;
            }
            else if (b.m_B == 0)
            {
                h = a.m_H;
                s = a.m_S;
            }
            else
            {
                if (a.m_S == 0)
                {
                    h = b.m_H;
                }
                else if (b.m_S == 0)
                {
                    h = a.m_H;
                }
                else
                {
                    // works around bug with LerpAngle
                    float angle = Mathf.LerpAngle(a.m_H * 360f, b.m_H * 360f, t);
                    while (angle < 0f)
                    {
                        angle += 360f;
                    }
                    while (angle > 360f)
                    {
                        angle -= 360f;
                    }
                    h = angle / 360f;
                }
                s = Mathf.Lerp(a.m_S, b.m_S, t);
            }
            return(new HSBColor(h, s, Mathf.Lerp(a.m_B, b.m_B, t), Mathf.Lerp(a.m_A, b.m_A, t)));
        }
        public void Setup()
        {
            contractedListColor = thisImage.color;
            normalColor         = expandedListColor;

            contractedNormalShadow = shadowConfig.shadowNormalSize;
            contractedHoverShadow  = shadowConfig.shadowActiveSize;

            if (textLine)
            {
                textLineAlpha = textLine.color.a;
            }

            listItemObjects = new GameObject[listItems.Length];

            for (int i = 0; i < listItems.Length; i++)
            {
                listItem = Instantiate(listItemPrefab) as GameObject;

                listItemObjects[i] = listItem;

                listItem.transform.SetParent(listLayer.transform);
                listItem.GetComponent <RectTransform>().localScale = new Vector3(1f, 1f, 1f);
                listItem.transform.localPosition = new Vector3(listItem.transform.localPosition.x, listItem.transform.localPosition.y, 0f);
                listItem.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
                listItem.GetComponentInChildren <Text>().text = listItems[i];

                SelectionListItemConfig tempConfig = listItem.GetComponent <SelectionListItemConfig>();
                tempConfig.listId = i;

                RippleConfig tempRippleConfig = tempConfig.GetComponent <RippleConfig>();

                if (rippleEnabled)
                {
                    tempRippleConfig.autoSize         = false;
                    tempRippleConfig.rippleSize       = rippleSize;
                    tempRippleConfig.rippleSpeed      = rippleSpeed;
                    tempRippleConfig.rippleColor      = rippleColor;
                    tempRippleConfig.rippleStartAlpha = rippleStartAlpha;
                    tempRippleConfig.rippleEndAlpha   = rippleEndAlpha;
                    tempRippleConfig.moveTowardCenter = moveTowardCenter;
                    tempRippleConfig.toggleMask       = toggleMask;
                }
                else
                {
                    tempRippleConfig.autoSize         = false;
                    tempRippleConfig.rippleSize       = 0;
                    tempRippleConfig.rippleStartAlpha = 0f;
                    tempRippleConfig.rippleEndAlpha   = 0f;
                }

                if (highlightWhen == HighlightActive.Never)
                {
                    tempRippleConfig.highlightWhen = RippleConfig.HighlightActive.Never;
                }
                else if (highlightWhen == HighlightActive.Clicked)
                {
                    tempRippleConfig.highlightWhen = RippleConfig.HighlightActive.Clicked;
                }
                else if (highlightWhen == HighlightActive.Hovered)
                {
                    tempRippleConfig.highlightWhen = RippleConfig.HighlightActive.Hovered;
                }

                tempRippleConfig.Refresh();

                listItem.GetComponent <Image>().color = normalColor;

                listItem.GetComponent <SelectionListItemConfig>().Setup();
            }

            highlightColor = rippleColor;

            HSBColor highlightColorHSB = HSBColor.FromColor(highlightColor);


            if (highlightColorHSB.s <= 0.05f)
            {
                highlightColorHSB.s = 0f;
                highlightColorHSB.b = 0.9f;
            }
            else
            {
                highlightColorHSB.s = 0.1f;
                highlightColorHSB.b = 1f;
            }

            highlightColor = HSBColor.ToColor(highlightColorHSB);

            highlightColor.a = 1f;

            HSBColor normalColorHSB = HSBColor.FromColor(normalColor);

            if (normalColorHSB.b > 0.1f)
            {
                highlightColor *= normalColor;
            }
            else
            {
                highlightColor.a = 0.2f;
            }

            originalHeight = thisRect.sizeDelta.y;

            originalPos = thisRect.anchoredPosition.y;
            listLayer.SetActive(false);
            listCanvasGroup.interactable   = false;
            listCanvasGroup.blocksRaycasts = false;

            listCanvasGroup.alpha = 0f;

            listLayer.GetComponent <Image>().color = expandedListColor;
        }
예제 #5
0
        public static Color ToColor(HSBColor hsbColor)
        {
            float r = hsbColor.b;
            float g = hsbColor.b;
            float b = hsbColor.b;
            if (hsbColor.s != 0)
            {
                float max = hsbColor.b;
                float dif = hsbColor.b*hsbColor.s;
                float min = hsbColor.b - dif;

                float h = hsbColor.h*360f;

                if (h < 60f)
                {
                    r = max;
                    g = h*dif/60f + min;
                    b = min;
                }
                else if (h < 120f)
                {
                    r = -(h - 120f)*dif/60f + min;
                    g = max;
                    b = min;
                }
                else if (h < 180f)
                {
                    r = min;
                    g = max;
                    b = (h - 120f)*dif/60f + min;
                }
                else if (h < 240f)
                {
                    r = min;
                    g = -(h - 240f)*dif/60f + min;
                    b = max;
                }
                else if (h < 300f)
                {
                    r = (h - 240f)*dif/60f + min;
                    g = min;
                    b = max;
                }
                else if (h <= 360f)
                {
                    r = max;
                    g = min;
                    b = -(h - 360f)*dif/60 + min;
                }
                else
                {
                    r = 0;
                    g = 0;
                    b = 0;
                }
            }

            return new Color(Mathf.Clamp01(r), Mathf.Clamp01(g), Mathf.Clamp01(b), hsbColor.a);
        }
예제 #6
0
        public static void Test()
        {
            HSBColor color;

            color = new HSBColor(Color.red);
            Debug.Log("red: " + color);

            color = new HSBColor(Color.green);
            Debug.Log("green: " + color);

            color = new HSBColor(Color.blue);
            Debug.Log("blue: " + color);

            color = new HSBColor(Color.grey);
            Debug.Log("grey: " + color);

            color = new HSBColor(Color.white);
            Debug.Log("white: " + color);

            color = new HSBColor(new Color(0.4f, 1f, 0.84f, 1f));
            Debug.Log("0.4, 1f, 0.84: " + color);

            Debug.Log("164,82,84   .... 0.643137f, 0.321568f, 0.329411f  :" +
                      ToColor(new HSBColor(new Color(0.643137f, 0.321568f, 0.329411f))));
        }
예제 #7
0
        public static HSBColor Lerp(HSBColor a, HSBColor b, float t)
        {
            float h, s;

            //check special case black (color.b==0): interpolate neither hue nor saturation!
            //check special case grey (color.s==0): don't interpolate hue!
            if (a.b == 0)
            {
                h = b.h;
                s = b.s;
            }
            else if (b.b == 0)
            {
                h = a.h;
                s = a.s;
            }
            else
            {
                if (a.s == 0)
                {
                    h = b.h;
                }
                else if (b.s == 0)
                {
                    h = a.h;
                }
                else
                {
                    // works around bug with LerpAngle
                    float angle = Mathf.LerpAngle(a.h*360f, b.h*360f, t);
                    while (angle < 0f)
                        angle += 360f;
                    while (angle > 360f)
                        angle -= 360f;
                    h = angle/360f;
                }
                s = Mathf.Lerp(a.s, b.s, t);
            }
            return new HSBColor(h, s, Mathf.Lerp(a.b, b.b, t), Mathf.Lerp(a.a, b.a, t));
        }
예제 #8
0
        public void Refresh()
        {
            if (autoSize)
            {
                Rect tempRect = gameObject.GetComponent <RectTransform>().rect;

                if (tempRect.width > tempRect.height)
                {
                    rippleSize = Mathf.RoundToInt(tempRect.width);
                }
                else
                {
                    rippleSize = Mathf.RoundToInt(tempRect.height);
                }

                rippleSize = Mathf.RoundToInt(rippleSize * sizePercentage / 100f);
            }

            normalColor = thisImage.color;

            if (highlightWhen != HighlightActive.Never)
            {
                highlightColor = rippleColor;

                HSBColor highlightColorHSB = HSBColor.FromColor(highlightColor);
                HSBColor normalColorHSB    = HSBColor.FromColor(normalColor);

                if (highlightColorHSB.s <= 0.05f)
                {
                    if (highlightColorHSB.b > 0.5f)
                    {
                        if (normalColorHSB.b > 0.9f)
                        {
                            highlightColorHSB.h = normalColorHSB.h;
                            highlightColorHSB.s = normalColorHSB.s - 0.1f;
                            highlightColorHSB.b = normalColorHSB.b + 0.2f;
                        }
                        else
                        {
                            highlightColorHSB.h = normalColorHSB.h;
                            highlightColorHSB.s = normalColorHSB.s;
                            highlightColorHSB.b = normalColorHSB.b + 0.2f;
                        }
                    }
                    else
                    {
                        highlightColorHSB.h = normalColorHSB.h;
                        highlightColorHSB.s = normalColorHSB.s;
                        highlightColorHSB.b = normalColorHSB.b - 0.15f;
                    }

                    highlightColor   = HSBColor.ToColor(highlightColorHSB);
                    highlightColor.a = normalColor.a;
                }
                else
                {
                    highlightColor.r = Anim.Linear(normalColor.r, highlightColor.r, 0.2f, 1f);
                    highlightColor.g = Anim.Linear(normalColor.g, highlightColor.g, 0.2f, 1f);
                    highlightColor.b = Anim.Linear(normalColor.b, highlightColor.b, 0.2f, 1f);
                    highlightColor.a = Anim.Linear(normalColor.a, highlightColor.a, 0.2f, 1f);
                }
            }

            animationDuration = 4 / rippleSpeed;
        }
예제 #9
0
        public void Setup()
        {
            assignComponents();

            if (expanded)
            {
                var tmp = thisRect.sizeDelta;
                tmp.y = originalHeight;
                thisRect.sizeDelta = tmp;

                var tmp2 = thisRect.anchoredPosition;
                tmp2.y = originalPos;
                thisRect.anchoredPosition = tmp2;
                ContractList();
            }

            listLayer.GetComponent <RectTransform> ().anchoredPosition = Vector2.zero;

            selectedText.text = defaultText;
//			Debug.LogWarning ("LIST HEIGHT: "+listheight);
//			Debug.LogWarning ("LIST LAYER HEIGHT: "+listLayerHeight);

            currentSelection = -1;

            contractedListColor = thisImage.color;
            normalColor         = expandedListColor;


            if (shadowConfig != null)
            {
                contractedNormalShadow = shadowConfig.shadowNormalSize;
                contractedHoverShadow  = shadowConfig.shadowActiveSize;
            }


            if (textLine)
            {
                textLineAlpha = textLine.color.a;
            }

            listItemObjects = new GameObject[listItems.Length];


            // clear old
            foreach (Transform r in listLayer.transform)
            {
                Destroy(r.gameObject);
            }

            for (int i = 0; i < listItems.Length; i++)
            {
                listItem = Instantiate(listItemPrefab) as GameObject;

                listItemObjects[i] = listItem;

                listItem.transform.SetParent(listLayer.transform);
                listItem.GetComponent <RectTransform>().localScale = new Vector3(1f, 1f, 1f);
                listItem.transform.localPosition = new Vector3(listItem.transform.localPosition.x, listItem.transform.localPosition.y, 0f);
                listItem.transform.localRotation = new Quaternion(0f, 0f, 0f, 0f);
                listItem.GetComponentInChildren <Text>().text = listItems[i];

                SelectionListItemConfig tempConfig = listItem.GetComponent <SelectionListItemConfig>();
                tempConfig.listId = i;

                RippleConfig tempRippleConfig = tempConfig.GetComponent <RippleConfig>();

                if (rippleEnabled)
                {
                    tempRippleConfig.autoSize         = false;
                    tempRippleConfig.rippleSize       = rippleSize;
                    tempRippleConfig.rippleSpeed      = rippleSpeed;
                    tempRippleConfig.rippleColor      = rippleColor;
                    tempRippleConfig.rippleStartAlpha = rippleStartAlpha;
                    tempRippleConfig.rippleEndAlpha   = rippleEndAlpha;
                    tempRippleConfig.moveTowardCenter = moveTowardCenter;
                    tempRippleConfig.toggleMask       = toggleMask;
                }
                else
                {
                    tempRippleConfig.autoSize         = false;
                    tempRippleConfig.rippleSize       = 0;
                    tempRippleConfig.rippleStartAlpha = 0f;
                    tempRippleConfig.rippleEndAlpha   = 0f;
                }

                if (highlightWhen == HighlightActive.Never)
                {
                    tempRippleConfig.highlightWhen = RippleConfig.HighlightActive.Never;
                }
                else if (highlightWhen == HighlightActive.Clicked)
                {
                    tempRippleConfig.highlightWhen = RippleConfig.HighlightActive.Clicked;
                }
                else if (highlightWhen == HighlightActive.Hovered)
                {
                    tempRippleConfig.highlightWhen = RippleConfig.HighlightActive.Hovered;
                }

                tempRippleConfig.Refresh();

                listItem.GetComponent <Image>().color = normalColor;

                listItem.GetComponent <SelectionListItemConfig>().Setup();
            }

            highlightColor = rippleColor;

            HSBColor highlightColorHSB = HSBColor.FromColor(highlightColor);


            if (highlightColorHSB.s <= 0.05f)
            {
                highlightColorHSB.s = 0f;
                highlightColorHSB.b = 0.9f;
            }
            else
            {
                highlightColorHSB.s = 0.1f;
                highlightColorHSB.b = 1f;
            }

            highlightColor = HSBColor.ToColor(highlightColorHSB);

            highlightColor.a = 1f;

            HSBColor normalColorHSB = HSBColor.FromColor(normalColor);

            if (normalColorHSB.b > 0.1f)
            {
                highlightColor *= normalColor;
            }
            else
            {
                highlightColor.a = 0.2f;
            }


            originalHeight = thisRect.sizeDelta.y;


            originalPos = thisRect.anchoredPosition.y;
            listLayer.SetActive(false);
            listCanvasGroup.interactable   = false;
            listCanvasGroup.blocksRaycasts = false;

            listCanvasGroup.alpha = 0f;

            listLayer.GetComponent <Image>().color = expandedListColor;
        }