public int List( Rect rect, GUIContent buttonContent, GUIContent[] listContent, GUIStyle buttonStyle, GUIStyle boxStyle, GUIStyle listStyle) { if (current != null) { if (current != this) return selectedItemIndex; } if( forceToUnShow ) { forceToUnShow = false; isClickedComboButton = false; } bool done = false; int controlID = GUIUtility.GetControlID( FocusType.Passive ); switch( Event.current.GetTypeForControl(controlID) ) { case EventType.mouseUp: { if( isClickedComboButton ) { done = true; } } break; } if (GUI.Button (rect, buttonContent, buttonStyle)) { if (current != null) { if (current != this) return selectedItemIndex; } else current = this; if (useControlID == -1) { useControlID = controlID; //isClickedComboButton = false; } if (useControlID != controlID) { forceToUnShow = true; useControlID = controlID; } isClickedComboButton = true; } if( isClickedComboButton ) { float items_height = listStyle.CalcHeight(listContent[0], 1.0f) * (listContent.Length + 5); Rect listRect = new Rect( rect.x, rect.y + listStyle.CalcHeight(listContent[0], 1.0f), rect.width, items_height); //GUILayout.BeginArea (listRect, listStyle); scrollViewVector = GUI.BeginScrollView (new Rect (rect.x, rect.y + rect.height, rect.width * 1.4f, 200), scrollViewVector, new Rect (rect.x, rect.y, rect.width, items_height + rect.height), false, false); //GUI.color = new Color (1.0f, 1.0f, 1.0f, 0.5f); //0.5 is half opacity // Texture2D myListBackGround = UtilModule.Instance.GetTexture(UtilModule.E_TEXTURE.black); // GUI.DrawTexture(listRect, myListBackGround); //var listColors = new Color32[2 * 2]; //for (int ii =0; ii<4;ii++) listColors[ii] = Color.black; //boxStyle.normal.background.SetPixels32 (listColors); //boxStyle.normal.background.Apply(); GUI.Box( new Rect(rect.x, rect.y, rect.width, items_height + rect.height) , "", boxStyle ); //GUI.color = Color.white; //GUILayout.EndArea(); int newSelectedItemIndex = GUI.SelectionGrid( listRect, selectedItemIndex, listContent, 1, listStyle ); if( newSelectedItemIndex != selectedItemIndex ) { selectedItemIndex = newSelectedItemIndex; done = true; } GUI.EndScrollView(); } if (done) { isClickedComboButton = false; forceToUnShow = false; useControlID = -1; current = null; } return GetSelectedItemIndex(); }
public int List( Rect rect, GUIContent buttonContent, GUIContent[] listContent, GUIStyle buttonStyle, GUIStyle boxStyle, GUIStyle listStyle) { if (current != null) { if (current != this) return selectedItemIndex; } if( forceToUnShow ) { forceToUnShow = false; isClickedComboButton = false; } bool done = false; int controlID = GUIUtility.GetControlID( FocusType.Passive ); switch( Event.current.GetTypeForControl(controlID) ) { case EventType.mouseUp: { if( isClickedComboButton ) { done = true; } } break; } if (GUI.Button (rect, buttonContent, buttonStyle)) { if (current != null) { if (current != this) return selectedItemIndex; } else current = this; if (useControlID == -1) { useControlID = controlID; //isClickedComboButton = false; } if (useControlID != controlID) { forceToUnShow = true; useControlID = controlID; } isClickedComboButton = true; } if( isClickedComboButton ) { float items_height = listStyle.CalcHeight(listContent[0], 1.0f) * (listContent.Length + 5); Rect listRect = new Rect( rect.x, rect.y + listStyle.CalcHeight(listContent[0], 1.0f), rect.width, items_height); scrollViewVector = GUI.BeginScrollView (new Rect (rect.x, rect.y + rect.height, rect.width /* * 1.4f */, 200), scrollViewVector, new Rect (rect.x, rect.y, rect.width, items_height + rect.height), false, false); GUI.Box( new Rect(rect.x, rect.y, rect.width, items_height + rect.height) , "", boxStyle ); int newSelectedItemIndex = GUI.SelectionGrid( listRect, selectedItemIndex, listContent, 1, listStyle ); if( newSelectedItemIndex != selectedItemIndex ) { selectedItemIndex = newSelectedItemIndex; done = true; } GUI.EndScrollView(); } if (done) { isClickedComboButton = false; forceToUnShow = false; useControlID = -1; current = null; } return GetSelectedItemIndex(); }