Exemplo n.º 1
0
    internal void SetValue(string newValue)
    {
        //set value
        value = newValue;

        //grey out
        foreach (Transform child in transform)
        {
            //icon
            if (child.GetSiblingIndex() == 0)
            {
                continue;
            }

            PTUI_RadialMenu_Button currButton = child.GetComponent <PTUI_RadialMenu_Button>();
            if (value == default(string) || value == "")
            {
                currButton.SetHighlight(HighlightStatus.Default);
            }
            else
            {
                if (child.GetComponentInChildren <Text>().text == value)
                {
                    currButton.SetHighlight(HighlightStatus.Highlight);
                }
                else
                {
                    currButton.SetHighlight(HighlightStatus.UnHighlight);
                }
            }
        }

        //UpdateButtonOK
        if (GetComponentInParent <PTUI_RadialMenu>().OnSetValue != null)
        {
            GetComponentInParent <PTUI_RadialMenu>().OnSetValue();
        }
    }
Exemplo n.º 2
0
    public IEnumerator UpdateContent(string iconStr, string[] content, RadialSection section, PTLogoColor color, Font fontText, Font fontIcon)
    {
        if (!updatingContent && //Make sure only one coroutine is running at the same time
            (startFrom != section || transform.childCount != content.Length + 1)    //Content inconsist
            )
        {
            updatingContent = true;

            //Reset
            Reset();

            if (section != RadialSection.inside && section != RadialSection.outside && section != RadialSection.unknown)
            {
                //Calculate new parameters of radail button group
                float targetArc = buttonDistance * (content.Length + 1);
                arc       = 0;
                offset    = -targetArc / 2.0f;
                startFrom = section;

                //Instantiate empty buttons for animation
                if (content.Length > 0)
                {
                    Instantiate(buttonPref.gameObject, transform).GetComponent <PTUI_RadialMenu_Button>().Set(color, fontIcon, iconStr);
                }
                foreach (string str in content)
                {
                    PTUI_RadialMenu_Button newButton = Instantiate(buttonPref.gameObject, transform).GetComponent <PTUI_RadialMenu_Button>();
                    newButton.Set(color, fontText, "");
                    newButton.name = "Button " + str;
                }

                //Animation
                float initArc      = arc;
                float coveredTimer = 0;
                while (arc < targetArc)
                {
                    yield return(new WaitForEndOfFrame());

                    coveredTimer += Time.deltaTime;
                    float frac = coveredTimer / animationTimer;
                    arc = initArc + (targetArc - initArc) * frac;
                    arc = arc < targetArc ? arc : targetArc;
                    UpdateChildrenPosition();
                }

                //Set the buttons to actually value
                if (transform.childCount > 0)
                {
                    transform.GetChild(0).GetComponent <PTUI_RadialMenu_Button>().Set(color, fontIcon, iconStr);
                }
                try
                {
                    for (int i = 0; i < content.Length; i++)
                    {
                        if (transform.childCount > i + 1 && transform.GetChild(i + 1) != null)
                        {
                            //Get currButton
                            Transform currButton = transform.GetChild(i + 1);
                            currButton.GetComponent <PTUI_RadialMenu_Button>().Set(color, fontText, content[i]);
                            Text childText = currButton.GetComponentInChildren <Text>();

                            Collider colliderCurrButton = currButton.GetComponent <Collider>();
                            PTGlobalInput.OnTouchEnter += (PTTouch touch, Collider collider) =>
                            {
                                if (collider == colliderCurrButton)
                                {
                                    if (value == default(string) || value == "")
                                    {
                                        SetValue(childText.text);
                                    }
                                }
                            };
                            PTGlobalInput.OnShortHoldBegin += (PTTouch touch) =>
                            {
                                if (colliderCurrButton && touch.hits.ContainsKey(colliderCurrButton))
                                {
                                    SetValue(childText.text);
                                }
                            };
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                catch { }
            }

            //Turn off updatingContent
            updatingContent = false;
        }
    }