public override void OnInspectorGUI()
    {
        DrawDefaultInspector();

        EncircleMenu menuScript = (EncircleMenu)target;

        EditorGUILayout.TextArea("This button will update UI on all the submenus, everything will be rearanged based on Hierarchy. Only the objects with EncircleSubMenu components will be affected. It will add EncircleMenu component to EncircleSubmenus that have EncircleSubMenu in their children."
                                 , GUI.skin.GetStyle("HelpBox"));
        if (GUILayout.Button("Update UI Recursively"))
        {
            menuScript.UpdateUI();
        }

        EditorGUILayout.TextArea("This will add UI Dummy Objects to All SubMenus That their UI value is not set. It does not position them to the right place. Press Update UI Recursively to rearrange everything automatically."
                                 , GUI.skin.GetStyle("HelpBox"));
        if (GUILayout.Button("Generate UI Containers Recursively"))
        {
            menuScript.GenerateUIContainers();
        }
    }
Beispiel #2
0
 // Use this for initialization
 void Start()
 {
     lastpos = transform.position;
     menu    = transform.parent.GetComponent <EncircleMenu>();
 }
    void AddUI(Transform t, int index, int total)
    {
        Mesh m = new Mesh();
        //if for each 10 deg 1 vert
        // 360/4 = 90 // 90/10 = 9// 9 +2 = 11
        int verlength;

        verlength = ((360 / total) / inverseMeshQuality) + 3;

        Vector3[] verts = new Vector3[verlength];
        Vector2[] uvs   = new Vector2[verts.Length];
        // 9 triangles in 90 = 9 * 3 ints

        int[] tris = new int[(verlength - 2) * 3];
        verts[0] = Vector3.zero;
        uvs[0]   = Vector2.zero;

        for (int i = 1; i < verts.Length - 1; i++)
        {
            verts[i] = new Vector3(Mathf.Cos(((360f / total * index) + (i - 1) * inverseMeshQuality) * Mathf.Deg2Rad), Mathf.Sin(((360f / total * index) + (i - 1) * inverseMeshQuality) * Mathf.Deg2Rad), 0);
            uvs[i]   = new Vector2(Mathf.Sin(Mathf.Deg2Rad * (90 - (i - 1) * (90f / (verts.Length - 2f)))), Mathf.Cos(Mathf.Deg2Rad * (90 - (i - 1) * (90f / (verts.Length - 2f)))));
        }
        verts[verts.Length - 1] = new Vector3(Mathf.Cos(((360f / total * (index + 1))) * Mathf.Deg2Rad), Mathf.Sin(((360f / total * (index + 1))) * Mathf.Deg2Rad), 0);
        uvs[verts.Length - 1]   = Vector2.right;
        for (int i = 0; i < verlength - 2; i++)
        {
            tris[3 * i] = 0; tris[3 * i + 1] = i + 1; tris[3 * i + 2] = i + 2;
        }

        m.vertices  = verts;
        m.triangles = tris;
        m.uv        = uvs;
        m.RecalculateBounds();
        m.RecalculateNormals();
        MeshFilter filter;
        Renderer   renderer;

        if (t.gameObject.GetComponent <MeshFilter>() != null)
        {
            filter   = t.gameObject.GetComponent <MeshFilter>();
            renderer = t.gameObject.GetComponent <MeshRenderer>();
        }
        else
        {
            filter   = t.gameObject.AddComponent <MeshFilter>();
            renderer = t.gameObject.AddComponent <MeshRenderer>();
        }

        //UI Placement
        if (t.GetComponent <EncircleSubMenu>().UI)
        {
            t.GetComponent <EncircleSubMenu>().UI.transform.localPosition = verts[Mathf.RoundToInt((verts.Length - 1) / 2)] * uiDistFromCenter
                                                                            + Vector3.forward * 0.01f;
        }

        foreach (Transform ch in t)
        {
            if (ch.GetComponent <EncircleSubMenu>())
            {
                if (!t.gameObject.GetComponent <EncircleMenu>())
                {
                    EncircleMenu menu =
                        t.gameObject.AddComponent <EncircleMenu>();
                    menu.menuMat            = menuMat;
                    menu.trackedObj         = trackedObj;
                    menu.hideChildren       = true;
                    menu.inverseMeshQuality = inverseMeshQuality;
                    menu.UpdateUI();
                    menu.SetDisabled();
                    break;
                }
                else
                {
                    t.gameObject.GetComponent <EncircleMenu>().UpdateUI();
                }
            }
        }

        isenabled = true;

        filter.mesh             = m;
        renderer.sharedMaterial = menuMat;
    }