private void RingMenu_Manager__OnSelected(object sender, EventArgs e)
    {
        RingButton_Manager rbm = (RingButton_Manager)sender;

        _txt_btn.text      = rbm.gameObject.name;
        _txt_btn.fontStyle = FontStyle.Bold;
        _txt_btn.color     = Color.red;
    }
    private void RingMenu_Manager__OnEnter(object sender, EventArgs e)
    {
        RingButton_Manager rbm = (RingButton_Manager)sender;

        _txt_btn.text      = rbm.gameObject.name;
        _txt_btn.fontStyle = FontStyle.Normal;
        _txt_btn.color     = Color.black;
    }
Beispiel #3
0
    GameObject DrawRing(Dictionary <string, RingButton_Manager> dico, int ring_index, float r_ext, float epaisseur, int nbrboutons, float marge, string prename)
    {
        btn_index_onthisRing = 0;
        GameObject go    = new GameObject();
        float      r_int = r_ext - epaisseur;

        float angle_ouverture_deg     = (float)360 / nbrboutons;
        float angle_position_deg_init = angle_ouverture_deg / 2;

        for (int i = 0; i < nbrboutons; i++)
        {
            float angle_position_deg = angle_position_deg_init + i * angle_ouverture_deg;
            //bouton
            GameObject btn = DrawButton(r_ext,
                                        r_int,
                                        angle_ouverture_deg,
                                        angle_position_deg,
                                        marge);
            btn.name             = prename + "ring_" + ring_index + "_btn_" + i;
            btn.transform.parent = go.transform;

            int index = btn_index;
            while (index >= textures.Length)
            {
                index -= textures.Length;
            }

            //script de gestion du bouton (index, nom, couleurs, ...)
            RingButton_Manager rb = btn.AddComponent <RingButton_Manager>();
            //rb._name = btn.name;
            rb._ring_index = ring_index;
            rb._index      = i;
            rb._SetColors(colors[index]);



            ////icône
            //Texture texture = (Texture)textures[index];
            //GameObject icn = DrawIcon(btn, texture);
            //if (icn != null)
            //    icn.transform.parent = go.transform;

            //rb._icone = icn;

            dico.Add(btn.name, rb);

            btn_index_onthisRing++;
            btn_index++;
        }

        go.name = "Ring_" + ring_index;
        return(go);
    }
    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;
    }
Beispiel #5
0
    void Update()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        //Debug.DrawRay(ray.origin, ray.direction * hit.distance, Color.red);
        if (Physics.Raycast(ray, out RaycastHit hit))
        {
            //Debug.Log(hit.transform.name);
            _txt_btn.text = hit.transform.name;
            if (!dico.ContainsKey(hit.transform.name))
            {
                Debug.Log(hit.transform.name);
            }
            RingButton_Manager rb = dico[hit.transform.name];
            if (rb != rb_previsous)
            {
                if (rb_previsous != null)
                {
                    rb_previsous._SetNormalColor();
                }

                if (rb != null)
                {
                    rb._SetHighlightColor();
                }
                rb_previsous = rb;
            }

            if (Input.GetMouseButtonDown(0))
            {
                if (rb != null)
                {
                    rb._SetSelectedColor();
                    GameObject selectedRingMenu = hit.transform.parent.parent.gameObject;

                    //OBJ & MTL
                    MeshExporter.ObjExporter.OBJ_MTL_TXT om = MeshExporter.ObjExporter.MeshToString(selectedRingMenu, selectedRingMenu.name);
                    //display in 2 textboxes
                    //_if_obj.text = om.obj;
                    //_if_mtl.text = om.mtl;

                    _txt_obj.text = om.objfilename;
                    _txt_mtl.text = om.mtlfilename;
                    GC.Collect();

                    //FBX
                    string path = selectedRingMenu.name + ".fbx";
                    _if_fbx.text = "";

                    string fbxfile = UnityFBXExporter.FBXExporter.MeshToString(selectedRingMenu, path, false, false);

                    GUIUtility.systemCopyBuffer = fbxfile;
                    //TextEditor te = new TextEditor();
                    //te.text = fbxfile;
                    //te.SelectAll();
                    //te.Copy();



                    _txt_fbx.text = path;
                    GC.Collect();

#if UNITY_WEBGL && !UNITY_EDITOR
                    try
                    {
                        //save to disk // download file ??
                        MeshExporter.ObjExporter.OBJ_MTL_TXT.ToFile(om);
                        _txt_debug.text = "";
                    }
                    catch (Exception ex)
                    {
                        _txt_debug.text = ex.Message + "\n\n" + ex.StackTrace;
                    }
#else
                    //save to disk OBJ
                    MeshExporter.ObjExporter.OBJ_MTL_TXT.ToFile(om);

                    //save to disk FBX
                    UnityFBXExporter.FBXExporter.ExportGameObjToFBX(selectedRingMenu, path, false, false);
                    //UnityFBXExporter.FBXExporter.ExportGameObjToFBX(selectedRingMenu, path, true, true);

                    //MeshExporter.ObjExporter.MeshToFile(selectedRingMenu, pathToSaveOBJs + selectedRingMenu.name);
#endif
                }
            }
            else
            {
                _txt_btn.text = "";
                if (rb_previsous != null)
                {
                    rb_previsous._SetNormalColor();
                }
                rb_previsous = null;
            }
        }
    }