コード例 #1
0
    public void _SliderValueChange()
    {
        if (ringMenu_Manager != null)
        {
            ringMenu_Manager._OnSelected -= RingMenu_Manager__OnSelected;
            ringMenu_Manager._OnEnter    -= RingMenu_Manager__OnEnter;
            ringMenu_Manager._OnExit     -= RingMenu_Manager__OnExit;
        }

        DestroyImmediate(ringMenu);

        int R0_B = (int)_sld_anneau0_btn.value;
        int R1_B = (int)_sld_anneau1_btn.value;
        int R2_B = (int)_sld_anneau2_btn.value;
        int R3_B = (int)_sld_anneau3_btn.value;
        int R4_B = (int)_sld_anneau4_btn.value;

        int nbrButtons = R0_B + R1_B + R2_B + R3_B + R4_B;

        _txt_btns.text = nbrButtons + " boutons";

        colors = SetColors(nbrButtons, false, false, 0.8f);

        float R0_R  = _sld_anneau0_taille.value;
        float R1_R  = _sld_anneau1_taille.value;
        float R2_R  = _sld_anneau2_taille.value;
        float R3_R  = _sld_anneau3_taille.value;
        float R4_R  = _sld_anneau4_taille.value;
        float marge = _sld_marge.value;

        Font arial = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;

        try
        {
            List <int> btns = new List <int> {
                R0_B, R1_B, R2_B, R3_B, R4_B
            };
            List <float> epaisseurs = new List <float> {
                R0_R, R1_R, R2_R, R3_R, R4_R
            };
            List <Color[]> couleurs = new List <Color[]> {
                colors, colors, colors, colors, colors
            };

            //Dictionary<int, Dictionary<int, Bouton>> boutons = new Dictionary<int, Dictionary<int, Bouton>>();
            List <Dictionary <int, Bouton> > boutons = new List <Dictionary <int, Bouton> >();

            //int k = 0;
            foreach (int ring_count in btns)
            {
                boutons.Add(new Dictionary <int, Bouton>());
                //boutons.Add(k, new Dictionary<int, Bouton>());
                for (int i = 0; i < ring_count; i++)
                {
                    Bouton bouton = new Bouton();
                    bouton.index                      = i;
                    bouton.name                       = i.ToString();
                    bouton.label                      = "";// RandomString(15);// + "\n" + RandomString(15);
                    bouton.label_color                = RingButton_Manager.ColorIntensity(colors[i], 0.2f);
                    bouton.label_font                 = arial;
                    bouton.label_fontStyle            = FontStyle.Bold;
                    bouton.label_fontSize             = 30;
                    bouton.label_resizeTextForBestFit = true;

                    bouton.icone = (Texture2D)textures[i];

                    boutons[boutons.Count - 1].Add(i, bouton);
                    //boutons[k].Add(i, bouton);
                }
                //k++;
            }

            //ringMenu = RingMenu._DrawRingMenu(btns, epaisseurs, marge, couleurs, null);
            ringMenu         = RingMenu._DrawRingMenu(boutons, epaisseurs, marge, couleurs);
            ringMenu_Manager = ringMenu.GetComponent <RingMenu_Manager>();

            ringMenu_Manager._OnSelected += RingMenu_Manager__OnSelected;
            ringMenu_Manager._OnEnter    += RingMenu_Manager__OnEnter;
            ringMenu_Manager._OnExit     += RingMenu_Manager__OnExit;

            _txt_debug.text = "";
        }
        catch (Exception ex)
        {
#if UNITY_EDITOR
            Debug.LogError(ex);
#else
            _txt_debug.text = ex.Message + "\n\n" + ex.StackTrace;
#endif
        }

        ringMenu.transform.SetPositionAndRotation(Spawn.transform.position, Spawn.transform.rotation);
        ringMenu.transform.localScale = Spawn.transform.localScale;
    }
コード例 #2
0
    void Draw()
    {
        if (Boutons.Length == 0)
        {
            //reset
            DestroyImmediate(ringMenu);
            return;
        }

        int    nbrbuttons = 0;
        Anneau a          = new Anneau(anneau_index, r_interne, r_externe, marge);

        foreach (RingButton_EditorMode item in Boutons)
        {
            if (item == null || !item.visible)
            {
                continue;
            }
            item.button_index_on_ring_int = nbrbuttons;
            item.name = nbrbuttons.ToString();
            a.butons_on_ring.Add(nbrbuttons, item);
            nbrbuttons++;
        }

        if (nbrbuttons == 0)
        {
            return;
        }

        Color[] colors = null;
        if (setDefaultColors)
        {
            colors = SetColors(nbrbuttons, randomColors, distributeColors, 0.8f);
        }

        Font arial = Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") as Font;

        foreach (RingButton_EditorMode item in a.butons_on_ring.Values)
        {
            if (setDefaultColors)
            {
                item.button_color = colors[item.button_index_on_ring_int];
            }

            item.label.label_font = arial;
        }

        if (setDefaultColors)
        {
            setDefaultColors = false;
        }

        if (ringMenu_Manager != null)
        {
            DestroyImmediate(ringMenu);
        }

        Dictionary <int, Anneau> anneaux = new Dictionary <int, Anneau>();

        anneaux.Add(a.index, a);

        //C'est parti :
        ringMenu                         = RingMenu._DrawRingMenu(anneaux, angle_initial, sens_horaire);
        ringMenu.name                    = "menu";
        ringMenu.transform.parent        = gameObject.transform;
        ringMenu.transform.localPosition = Vector3.zero;
        ringMenu_Manager                 = ringMenu.GetComponent <RingMenu_Manager>();

        foreach (var item in a.butons_on_ring.Values)
        {
            item.ringButtonManager._SetNormalColor(item.ringButtonManager.gameObject);
        }
    }