public static GameObject DrawRing(Anneau anneau, float angle_initial, bool sens_horaire) { float r_int = anneau.r_int; float r_ext = anneau.r_ext; float marge = anneau.marge * (r_ext - r_int); GameObject go = new GameObject(); go.name = "ring_" + anneau.index; int nbrboutons = anneau.butons_on_ring.Count; float angle_ouverture_deg = (float)360 / nbrboutons; if (sens_horaire) { angle_initial = -angle_initial; } float angle_position_deg_init = angle_initial + angle_ouverture_deg / 2; foreach (RingButton_EditorMode bouton in anneau.butons_on_ring.Values) { float angle_position_deg; if (sens_horaire) { angle_position_deg = angle_position_deg_init - (bouton.button_index_on_ring_int + 1) * angle_ouverture_deg; } else { angle_position_deg = angle_position_deg_init + (bouton.button_index_on_ring_int - 1) * angle_ouverture_deg; } //Debug.Log("Bouton \"" + bouton.name + "\" angle " + (int)angle_position_deg + " sur " + (int)angle_ouverture_deg + "°"); GameObject btn; try { btn = RingButton.DrawButton(r_ext, r_int, angle_ouverture_deg, angle_position_deg, marge); if (btn == null) { continue; } btn.name = go.name + "_btn_" + bouton.name; btn.transform.parent = go.transform; RingButton_Manager rb = btn.AddComponent <RingButton_Manager>(); bouton.ringButtonManager = rb; rb._ring_index = anneau.index; rb._index = bouton.button_index_on_ring_int; rb._SetColors(bouton.button_color); //icône if (bouton.icon != null) { try { Texture texture = bouton.icon; GameObject icn = RingButton.DrawIcon(texture, r_ext, r_int, angle_position_deg + angle_ouverture_deg / 2); icn.transform.parent = rb.gameObject.transform; rb._icone = icn; } catch (System.Exception ex) { Debug.Log(ex.Message + "\n" + ex.StackTrace); } } //texte if (bouton.label.label_show && bouton.label.label != "") { GameObject canvas_go = new GameObject(); canvas_go.transform.SetParent(rb.gameObject.transform); Canvas canvas = canvas_go.gameObject.AddComponent <Canvas>(); canvas.renderMode = RenderMode.WorldSpace; canvas.worldCamera = Camera.main; float amplitude = r_int + r_ext * 0.8f; canvas.GetComponent <RectTransform>().sizeDelta = new Vector2(amplitude, amplitude); GameObject text_go = new GameObject(); text_go.transform.SetParent(canvas_go.transform); text_go.transform.Translate(0, 0, -20); text_go.transform.Rotate(0, 0, angle_position_deg + angle_ouverture_deg / 2); UnityEngine.UI.Text text = text_go.gameObject.AddComponent <UnityEngine.UI.Text>(); text.GetComponent <RectTransform>().sizeDelta = new Vector2(r_ext + r_int, r_ext + r_int); text.alignment = TextAnchor.UpperCenter; text.text = bouton.label.label; text.font = bouton.label.label_font; text.fontStyle = bouton.label.label_fontStyle; text.resizeTextForBestFit = bouton.label.label_resizeTextForBestFit; if (!bouton.label.label_resizeTextForBestFit) { text.fontSize = bouton.label.label_fontSize; } text.color = bouton.label.label_color; } //events rb._OnClick = bouton.events._OnClick; rb._OnEnter = bouton.events._OnEnter; rb._OnExit = bouton.events._OnExit; } catch (System.Exception ex) { Debug.Log(ex.Message + "\n" + ex.StackTrace); } } return(go); }
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); } }