DisplayPopupMenu() public static method

Displays a popup menu.

public static DisplayPopupMenu ( Rect position, string menuItemPath, MenuCommand command ) : void
position UnityEngine.Rect
menuItemPath string
command MenuCommand
return void
Esempio n. 1
0
        public static int ShowTerrainLayersSelectionHelper(Terrain terrain, int activeTerrainLayer)
        {
            GUILayout.Label(s_Styles.terrainLayers, EditorStyles.boldLabel);
            GUI.changed = false;
            int selectedTerrainLayer = activeTerrainLayer;

            if (terrain.terrainData.terrainLayers.Length > 0)
            {
                TerrainLayer[] layers           = terrain.terrainData.terrainLayers;
                var            layerGUIContents = new GUIContent[layers.Length];
                for (int i = 0; i < layers.Length; ++i)
                {
                    layerGUIContents[i] = new GUIContent
                    {
                        image   = (layers[i] == null || layers[i].diffuseTexture == null) ? EditorGUIUtility.whiteTexture : AssetPreview.GetAssetPreview(layers[i].diffuseTexture) ?? layers[i].diffuseTexture,
                        text    = layers[i] == null ? "Missing" : layers[i].name,
                        tooltip = layers[i] == null ? "Missing" : layers[i].name
                    };
                }
                selectedTerrainLayer = TerrainInspector.AspectSelectionGridImageAndText(activeTerrainLayer, layerGUIContents, 64, s_Styles.errNoLayersFound, out _);
            }
            else
            {
                selectedTerrainLayer = -1;
            }

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            // menu button
            Rect r = GUILayoutUtility.GetRect(s_Styles.btnEditTerrainLayers, new GUIStyle("Button"));

            if (GUI.Button(r, s_Styles.btnEditTerrainLayers, new GUIStyle("Button")))
            {
                MenuCommand context = new MenuCommand(terrain, selectedTerrainLayer);
                EditorUtility.DisplayPopupMenu(new Rect(r.x, r.y, 0, 0), "CONTEXT /TerrainLayers", context);
            }
            GUILayout.EndHorizontal();

            return(selectedTerrainLayer);
        }