private void DrawType(Rect position, Type type, SerializedProperty property, GUIContent label, int id) { SerializedProperty typeNameProperty = property.FindPropertyRelative("assemblyQualifiedName"); if (_types == null || _types.Length == 0) { if (type.IsArray) { type = type.GetElementType(); } TypeDrawerUtillity.GetTypes(type.BaseType.GetGenericArguments()[0], out _types, out _displayTypes); _typeIndex = -1; } Type serializedType = TypeDrawerUtillity.GetTypeFromAQN(typeNameProperty.stringValue); label = EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel(position, id, label); GUIContent buttonText = serializedType == null ? new GUIContent() : new GUIContent(TypeDrawerUtillity.GetNiceTypeName(serializedType)); if (TypeDrawerUtillity.DropdownButton(id, position, buttonText)) { Action <int> onSelect = i => { _typeIndex = i; typeNameProperty.stringValue = _types[i]; property.serializedObject.ApplyModifiedProperties(); }; SearchablePopup.Show(position, _displayTypes, _typeIndex, onSelect); } EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // If this is not used on an eunum, show an error if (property.type != "Enum") { GUIStyle errorStyle = "CN EntryErrorIconSmall"; Rect r = new Rect(position); r.width = errorStyle.fixedWidth; position.xMin = r.xMax; GUI.Label(r, "", errorStyle); GUI.Label(position, TYPE_ERROR); return; } // By manually creating the control ID, we can keep the ID for the // label and button the same. This lets them be selected together // with the keyboard in the inspector, much like a normal popup. int id = GUIUtility.GetControlID(idHash, FocusType.Keyboard, position); label = EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel(position, id, label); GUIContent buttonText = new GUIContent(property.enumDisplayNames[property.enumValueIndex]); if (SearchableDropDown.DropdownButton(id, position, buttonText)) { Action <int> onSelect = i => { property.enumValueIndex = i; property.serializedObject.ApplyModifiedProperties(); }; SearchablePopup.Show(position, property.enumDisplayNames, property.enumValueIndex, onSelect); } EditorGUI.EndProperty(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (property.type != "string") { EditorGUI.PropertyField(position, property, label, true); return; } if (_hashID == 0) { _hashID = "LanguageKeyDrawer".GetHashCode(); } int ctrlId = GUIUtility.GetControlID(_hashID, FocusType.Keyboard, position); { label = EditorGUI.BeginProperty(position, label, property); position = EditorGUI.PrefixLabel(position, ctrlId, label); if (DropdownButton(ctrlId, position, new GUIContent(property.stringValue))) { int index = -1; for (int i = 0; i < _LanGroup.keys.Count; i++) { if (_LanGroup.keys[i] == property.stringValue) { index = i; break; } } SearchablePopup.Show(position, _LanGroup.keys.ToArray(), index, (i, str) => { property.stringValue = str; property.serializedObject.ApplyModifiedProperties(); }); } } EditorGUI.EndProperty(); }
protected override void OnDrawProperty(string label) { var attr = GetAttr <StringPopupAttribute>(); string[] options = attr.Options; if (!string.IsNullOrEmpty(attr.MemberName)) { options = DrawerUtility.GetMemberValue <string[]>(attr.MemberName, Property.Target); } var value = Property.GetValue <string>(); var valueIndex = Array.IndexOf(options, value); if (valueIndex < 0 && options != null && options.Length > 0) { valueIndex = 0; value = options[0]; Property.Value = value; } label = label ?? ""; if (attr.IsSearchable) { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(label); Rect btnRect = GUILayoutUtility.GetRect(new GUIContent(value), "dropdownbutton"); if (EditorGUI.DropdownButton(btnRect, new GUIContent(value), FocusType.Keyboard)) { try { SearchablePopup.Show(btnRect, new Vector2(200, 400), valueIndex, options, (selected) => { Property.Value = options[selected]; }); } catch (ExitGUIException) { lastSearchableWindow = EditorWindow.focusedWindow; throw; } } } EditorGUILayout.EndHorizontal(); if (lastSearchableWindow && lastSearchableWindow != EditorWindow.mouseOverWindow) { if (Event.current.type == EventType.ScrollWheel) { Event.current.Use(); } } } else { EditorGUI.BeginChangeCheck(); { value = EGUILayout.DrawPopup <string>(label, options, options, value); } if (EditorGUI.EndChangeCheck()) { Property.Value = value; } } }
public static void Show(Rect activatorRect, string[] options, int current, Action <int, string> onSelectionMade) { SearchablePopup win = new SearchablePopup(options, current, onSelectionMade); PopupWindow.Show(activatorRect, win); }
private void AddLanPairFunc() { if (window.lanKeys.Count == 0) { return; } Rect rect; this.EBeginHorizontal(out rect, Styles.Fold) .Foldout(ref createLanPairFlodon, "Create LanPair", true) .EEndHorizontal() .Pan(() => { if (!createLanPairFlodon) { return; } if (tmpLanPair == null) { tmpLanPair = new LanPair() { key = window.lanKeys[0] } } ; if (hashID == 0) { hashID = "CreateView".GetHashCode(); } this.DrawVertical(() => { this.BeginHorizontal() .Label("Lan", GUILayout.Width(describeWidth)) .Pan(() => { tmpLanPair.Lan = (SystemLanguage)EditorGUILayout.EnumPopup(tmpLanPair.Lan); }) .EndHorizontal() .BeginHorizontal() .Label("Key", GUILayout.Width(describeWidth)) .Label(tmpLanPair.key) .Label(EditorGUIUtility.IconContent("editicon.sml"), GUILayout.Width(smallBtnSize)) .EndHorizontal() .Pan(() => { Rect pos = GUILayoutUtility.GetLastRect(); int ctrlId = GUIUtility.GetControlID(hashID, FocusType.Keyboard, pos); { if (DropdownButton(ctrlId, pos, new GUIContent(string.Format("Key: {0}", tmpLanPair.key)))) { int index = -1; for (int i = 0; i < window.lanKeys.Count; i++) { if (window.lanKeys[i] == tmpLanPair.key) { index = i; break; } } SearchablePopup.Show(pos, window.lanKeys.ToArray(), index, (i, str) => { tmpLanPair.key = str; window.Repaint(); }); } } }) .BeginHorizontal() .Label("Val", GUILayout.Width(describeWidth)) .TextField(ref tmpLanPair.Value) .EndHorizontal() .BeginHorizontal() .FlexibleSpace() .Button(() => { //createLanPairFlodon = false; window.AddLanPair(tmpLanPair); //tmpLanPair = null; }, Contents.OK) .EndHorizontal(); }, Styles.BG); }); }
protected override void OnDrawProperty(string label) { var attr = GetAttr <IntPopupAttribute>(); string[] contents = attr.Contents; if (!string.IsNullOrEmpty(attr.ContentMemberName)) { contents = NativeDrawerUtility.GetMemberValue <string[]>(attr.ContentMemberName, DrawerProperty.Target); } int[] values = attr.Values; if (!string.IsNullOrEmpty(attr.ValueMemberName)) { values = NativeDrawerUtility.GetMemberValue <int[]>(attr.ValueMemberName, DrawerProperty.Target); } var value = DrawerProperty.GetValue <int>(); label = label ?? ""; if (attr.IsSearchable) { var valueIndex = Array.IndexOf(values, value); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PrefixLabel(label); Rect btnRect = GUILayoutUtility.GetRect(new GUIContent(contents[valueIndex]), "dropdownbutton"); if (EditorGUI.DropdownButton(btnRect, new GUIContent(contents[valueIndex]), FocusType.Keyboard)) { try { SearchablePopup.Show(btnRect, new Vector2(200, 400), valueIndex, contents, (selected) => { DrawerProperty.Value = values[selected]; }); } catch (ExitGUIException) { lastSearchableWindow = EditorWindow.focusedWindow; throw; } } } EditorGUILayout.EndHorizontal(); if (lastSearchableWindow && lastSearchableWindow != EditorWindow.mouseOverWindow) { if (Event.current.type == EventType.ScrollWheel) { Event.current.Use(); } } } else { EditorGUI.BeginChangeCheck(); { value = EGUILayout.DrawPopup <int>(label, contents, values, value); } if (EditorGUI.EndChangeCheck()) { DrawerProperty.Value = value; } } }
public override void OnGUI() { this.Space(5) .DrawHorizontal(() => { this.Label("Check UIMap Script Name", Styles.toolbar); this.TextField(ref UIMapName); }); this.DrawHorizontal(() => { this.Label("Drag UIMap Gen Directory", Styles.toolbar); this.Label(UIMapDir); Rect rect = GUILayoutUtility.GetLastRect(); if (string.IsNullOrEmpty(UIMapDir)) { rect.DrawOutLine(10, Color.red); } else { rect.DrawOutLine(2, Color.black); } if (rect.Contains(Event.current.mousePosition)) { var drag = EditorTools.DragAndDropTool.Drag(Event.current, rect); if (drag.compelete && drag.enterArera && drag.paths.Length == 1) { string path = drag.paths[0]; if (path.Contains("Assets")) { if (path.IsDirectory()) { UIMapDir = path; } else { UIMapDir = path.GetDirPath(); } } } } }) .DrawHorizontal(() => { this.FlexibleSpace() .Button(() => { if (string.IsNullOrEmpty(UIMapDir)) { EditorWindow.focusedWindow.ShowNotification(new GUIContent("Set UI Map Gen Dir ")); return; } // string uimapGenPath = genpath.CombinePath("MapGen_MVVM.txt"); CreateUIMapGen(uimapGenPath); WriteTxt(UIMapDir.CombinePath(UIMap_CSName), uimapGenPath, null); AssetDatabase.Refresh(); }, "Copy UIMap From Source"); }).Space(30); if (hashID == 0) { hashID = "MVVM_GenCodeView".GetHashCode(); } this.DrawHorizontal(() => { this.Label("Click Choose Panel Type", Styles.toolbar); GUILayout.Label(""); Rect pos = GUILayoutUtility.GetLastRect(); int ctrlId = GUIUtility.GetControlID(hashID, FocusType.Keyboard, pos); { if (DropdownButton(ctrlId, pos, new GUIContent(string.Format("PanelType: {0}", panelType)))) { if (panelTypes == null) { EditorWindow.focusedWindow.ShowNotification(new GUIContent("Fresh Panel Types")); return; } int index = -1; for (int i = 0; i < panelTypes.Count; i++) { if (panelTypes[i] == panelType) { index = i; break; } } SearchablePopup.Show(pos, panelTypes.ToArray(), index, (i, str) => { panelType = str; EditorWindow.focusedWindow.Repaint(); }); } } }) .Space(10) .DrawHorizontal(() => { this.Label("Click Choose Model Type", Styles.toolbar); GUILayout.Label(""); Rect pos = GUILayoutUtility.GetLastRect(); int ctrlId = GUIUtility.GetControlID(hashID, FocusType.Keyboard, pos); { if (DropdownButton(ctrlId, pos, new GUIContent(string.Format("ModelType: {0}", modelType)))) { if (modelTypes == null) { EditorWindow.focusedWindow.ShowNotification(new GUIContent("Fresh Model Types")); return; } int index = -1; for (int i = 0; i < modelTypes.Count; i++) { if (modelTypes[i] == modelType) { index = i; break; } } SearchablePopup.Show(pos, modelTypes.ToArray(), index, (i, str) => { modelType = str; EditorWindow.focusedWindow.Repaint(); }); } } }) .Space(10) .DrawHorizontal(() => { this.Label("Drag Panel Gen Directory", Styles.toolbar); this.Label(PanelGenDir); Rect rect = GUILayoutUtility.GetLastRect(); if (string.IsNullOrEmpty(PanelGenDir)) { rect.DrawOutLine(10, Color.red); } else { rect.DrawOutLine(2, Color.black); } if (rect.Contains(Event.current.mousePosition)) { var drag = EditorTools.DragAndDropTool.Drag(Event.current, rect); if (drag.compelete && drag.enterArera && drag.paths.Length == 1) { string path = drag.paths[0]; if (path.Contains("Assets")) { if (path.IsDirectory()) { PanelGenDir = path; } else { PanelGenDir = path.GetDirPath(); } } } } }) .Space(10) .DrawHorizontal(() => { this.Button(() => { panelTypes = typeof(UIPanel).GetSubTypesInAssemblys().Select((type) => { return(type.FullName); }).ToList(); modelTypes = typeof(IDataModel).GetSubTypesInAssemblys().Select((type) => { return(type.FullName); }).ToList(); }, "Fresh Panel && Model Types") .Space(20) .Button(() => { if (string.IsNullOrEmpty(UIMapDir)) { EditorWindow.focusedWindow.ShowNotification(new GUIContent("Set UI Map Gen Dir ")); return; } if (!File.Exists(UIMapDir.CombinePath(UIMap_CSName))) { EditorWindow.focusedWindow.ShowNotification(new GUIContent("Copy UI Map")); return; } if (string.IsNullOrEmpty(panelType)) { EditorWindow.focusedWindow.ShowNotification(new GUIContent("Choose UI Panel Type ")); return; } if (string.IsNullOrEmpty(modelType)) { EditorWindow.focusedWindow.ShowNotification(new GUIContent("Choose UI Model Type ")); return; } if (string.IsNullOrEmpty(PanelGenDir)) { EditorWindow.focusedWindow.ShowNotification(new GUIContent("Set UI Panel Gen Dir ")); return; } string _modelType = modelType.Split('.').ToList().Last(); string paneltype = panelType.Split('.').ToList().Last(); string vmType = paneltype.Append("ViewModel"); string viewType = paneltype.Append("View"); //string viewPath = genpath.CombinePath("View_MVVM.txt"); //string VMPath = genpath.CombinePath("VM_MVVM.txt"); CreateViewGen(viewGenPath); CreateVMGen(VMGenPath); //v WriteTxt(PanelGenDir.CombinePath(viewType.Append(".cs")), viewGenPath, (str) => { return(str.Replace("#VMType#", vmType).Replace("#PanelType#", paneltype)); } ); //vm WriteTxt(PanelGenDir.CombinePath(vmType.Append(".cs")), VMGenPath, (str) => { string fieldStr = " "; string syncStr = " "; Type t = AppDomain.CurrentDomain.GetAssemblies() .SelectMany((a) => { return(a.GetTypes()); }) .ToList().Find((type) => { return(type.FullName == modelType); }); var fs = t.GetFields(); for (int i = 0; i < fs.Length; i++) { var info = fs[i]; fieldStr = WriteField(fieldStr, info.FieldType, info.Name); syncStr = WriteSyncStr(syncStr, info.Name); } return(str.Replace("#ModelType#", _modelType) .Replace("#FieldString#", fieldStr) .Replace("#SyncModelValue#", syncStr)); } ); WriteMap(UIMapDir.CombinePath(UIMap_CSName), UIMapDir.CombinePath(UIMap_CSName)); AssetDatabase.Refresh(); }, "Gen"); }); }