Example #1
0
    /// <summary>
    /// Actulally switch section.
    /// </summary>
    /// <param name="newSection">The new section going to be set.</param>
    void Switch(RadialSection newSection)
    {
        //Do nothing if new section is the as same as the current one.
        if (section == newSection)
        {
            return;
        }

        //Change section value
        section = newSection;

        //Trigger OnSefctionEnter event
        if (OnSectionSwitched != null)
        {
            OnSectionSwitched(section);
        }

        //UpdateHighlight
        if (section == RadialSection.unknown || section == RadialSection.inside)
        {
            foreach (PTUI_RadialMenu_Section section in content)
            {
                section.GetComponentInChildren <Button>().interactable = true;
            }
        }
        else if (section != RadialSection.outside)
        {
            foreach (PTUI_RadialMenu_Section section in content)
            {
                section.GetComponentInChildren <Button>().interactable = false;
            }
            //print(section);
            content[(int)section].GetComponentInChildren <Button>().interactable = true;
        }
    }
Example #2
0
    private void SetSelectionEvent(float currentRotation)
    {
        int index = GetNearestIncrement(currentRotation);

        if (index == 4)
        {
            index = 0;
        }

        highlightedSection = radialSections[index];
    }
Example #3
0
 /// <summary>
 /// Get PTUI_RadialMenu_Section object by RadialSection enum
 /// </summary>
 /// <param name="section"></param>
 /// <returns></returns>
 public PTUI_RadialMenu_Section GetSection(RadialSection section)
 {
     try
     {
         return(content[(int)section]);
     }
     catch
     {
         return(null);
     }
 }
Example #4
0
    private void SetSelectedEvent(float currentRotation)
    {
        int index = GetNearestIncrement(currentRotation);

        if (index == 4)
        {
            index = 0;
        }

        if (highlightedSection == radialSections[index])
        {
            return;
        }

        highlightedSection = radialSections[index];
        _highlightChanged.Invoke();
    }
Example #5
0
    /// <summary>
    /// Raw input with the information where the touch is on.
    /// </summary>
    /// <param name="newSection">The section touch is currently on.</param>
    internal void Input(RadialSection newSection)
    {
        if (newSection != section_LastTouched.Key)
        {
            section_LastTouched = new KeyValuePair <RadialSection, DateTime>(newSection, DateTime.Now);
        }

        float coveredtime     = (float)((DateTime.Now - section_LastTouched.Value).Milliseconds) / 1000.0f;
        bool  holdEnoughTime  = coveredtime > timerHoldToSwitchInside;
        bool  validNewSection = section != newSection;
        bool  validTo         = holdEnoughTime && newSection != RadialSection.outside;
        bool  validFrom       = section == RadialSection.unknown || section == RadialSection.inside;
        bool  validSwitch     = validNewSection && (validTo || validFrom);

        if (validSwitch)
        {
            Switch(newSection);
        }
    }
Example #6
0
    public void SelecetSection(PTTouch touch)
    {
        if (sections.GetComponent <Image>().fillAmount < 1)
        {
            return;
        }

        Vector2 screenPosition = Camera.main.WorldToScreenPoint(transform.position);
        Vector2 screenPosition_BorderInside  = Camera.main.WorldToScreenPoint(radialBorderInside.position);
        Vector2 screenPosition_BorderOutside = Camera.main.WorldToScreenPoint(radialBorderOutside.position);
        Vector2 diffTouch = new Vector2(touch.position.x, touch.position.y) - screenPosition;
        Vector2 diffMin   = screenPosition_BorderInside - screenPosition;
        Vector2 diffMax   = screenPosition_BorderOutside - screenPosition;

        RadialSection section = RadialSection.unknown;

        float angle = PTUtility.Angle(screenPosition, touch.position) + 45;

        angle = angle > 360 ? angle - 360 : angle;
        int direction = (int)(angle / 90);

        if (diffTouch.sqrMagnitude < diffMin.sqrMagnitude)
        {
            section = RadialSection.inside;
        }
        else if (diffTouch.sqrMagnitude > diffMax.sqrMagnitude)
        {
            section = RadialSection.outside;
        }
        else
        {
            section = (RadialSection)direction;
        }

        sections.Input(section);
    }
    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;
        }
    }