public override void OnInspectorGUI() { var context = (DataContext)this.target; EditorGUI.BeginChangeCheck(); var contextType = (ContextType)EditorGUILayout.EnumPopup(this.lblType, context.type); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(this.target, "Select Context Type"); context.type = contextType; } if (context.type == ContextType.None) { context.Clear(); GUILayout.Label(BindingDefine.NO_CONTEXT_TYPE); } else if (context.type == ContextType.MonoBehaviour) { EditorGUI.BeginChangeCheck(); var contextViewModel = (ViewModelBehaviour)EditorGUILayout.ObjectField(this.lblContext, (Object)context.viewModel, typeof(ViewModelBehaviour), true); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(this.target, "Select ViewModel"); context.viewModel = contextViewModel; } if (context.viewModel.GetCachedType() != null) { GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); EditorGUILayout.LabelField("<color=blue>[" + context.viewModel.GetCachedType().FullName + "]</color>", EditorGUIHelper.RichText()); GUILayout.EndHorizontal(); } } else if (context.type == ContextType.Property) { EditorGUI.BeginChangeCheck(); var contextViewModel = (ViewModelBehaviour)EditorGUILayout.ObjectField(this.lblContext, (Object)context.viewModel, typeof(ViewModelBehaviour), true); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(this.target, "Select ViewModel"); context.viewModel = contextViewModel; } var viewMembers = context.viewModel.GetAllMembers(false, true, false, false, MemberTypes.Field, MemberTypes.Property); var dataMembers = context.viewModel.GetAllMembers(false, false, false, false, MemberTypes.Field, MemberTypes.Property); if (dataMembers != null) { if (string.IsNullOrEmpty(context.propertyName)) { context.propertyName = dataMembers[0]; } else { for (var i = 0; i < dataMembers.Length; i++) { if (dataMembers[i] == context.propertyName) { this.selected = i; break; } } } GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Space(5); var newSelected = EditorGUILayout.Popup("Field/Property", this.selected, viewMembers); GUILayout.EndVertical(); if (this.selected != newSelected) { Undo.RecordObject(this.target, "Select Contenxt Member"); context.propertyName = dataMembers[newSelected]; this.selected = newSelected; } if (EditorGUIHelper.QuickPickerButton()) { ContextBrowser.Browse(this.selected, dataMembers, viewMembers, selectedMember => { Undo.RecordObject(this.target, "Select Context Member"); context.propertyName = selectedMember; FilterPopup.Close(); }); } GUILayout.EndHorizontal(); MemberInfo curMember = context.viewModel.GetMemberInfo(dataMembers[this.selected], MemberTypes.Property, MemberTypes.Field); if (curMember != null) { var attributes = curMember.GetCustomAttributes(typeof(UIManPropertyAttribute), false); if (attributes == null || attributes.Length == 0) { GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); GUILayout.Label("<color=red>None observable field/property!</color>", EditorGUIHelper.RichText()); GUILayout.EndHorizontal(); } } GUILayout.EndVertical(); } if (Event.current.type == EventType.Repaint) { FilterPopup.SetPopupRect(GUILayoutUtility.GetLastRect()); } } }
public void DrawBindingField(BindingField field) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(new GUIContent(field.label)); var curMemberName = field.member; if (string.IsNullOrEmpty(curMemberName)) { curMemberName = BindingDefine.SELECT_MEMBER; } var viewMembers = this.binder.GetMembers(false, true, false, false, MemberTypes.Field, MemberTypes.Property); var dataMembers = this.binder.GetMembers(false, false, false, false, MemberTypes.Field, MemberTypes.Property); if (dataMembers == null) { EditorGUILayout.LabelField("<color=red>No target context found!</color>", EditorGUIHelper.RichText()); GUILayout.EndHorizontal(); } else { ArrayUtility.Insert(ref dataMembers, 0, "<None>"); ArrayUtility.Insert(ref viewMembers, 0, "<None>"); var selectedIndex = 0; for (var i = 0; i < dataMembers.Length; i++) { if (curMemberName == dataMembers[i]) { selectedIndex = i; break; } } GUILayout.Space(-7); EditorGUILayout.BeginVertical(); GUILayout.Space(5); var newSelectedIndex = EditorGUILayout.Popup(selectedIndex, viewMembers); if (newSelectedIndex != selectedIndex) { Undo.RecordObject(this.target, "Select Binder Member"); selectedIndex = newSelectedIndex; field.member = dataMembers[selectedIndex]; Apply(); } EditorGUILayout.EndVertical(); if (EditorGUIHelper.QuickPickerButton()) { ContextBrowser.Browse(this, field, selectedIndex, true, true, false); } GUILayout.EndHorizontal(); MemberInfo curMember = this.binder.GetMemberInfo(dataMembers[selectedIndex], MemberTypes.Property, MemberTypes.Field); if (curMember != null) { var attributes = curMember.GetCustomAttributes(typeof(UIManPropertyAttribute), false); if (attributes == null || attributes.Length == 0) { GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); GUILayout.Label("<color=red>None observable field!</color>", EditorGUIHelper.RichText()); GUILayout.EndHorizontal(); } } } GUILayout.EndVertical(); }
public override void OnInspectorGUI() { UIManConfig config = target as UIManConfig; if (screenPath == null || dialogPath == null || bgPath == null) { screenPath = new PathBrowser(config.screenPrefabFolder, rootUrl); dialogPath = new PathBrowser(config.dialogPrefabFolder, rootUrl); bgPath = new PathBrowser(config.backgroundRootFolder, rootUrl); } LableHelper.TitleLabel("UIMan Configuration"); LineHelper.Draw(Color.blue); EditorGUILayout.Space(); GUILayout.BeginVertical("Box"); config.screenPrefabFolder = screenPath.Draw(screenGUI); config.dialogPrefabFolder = dialogPath.Draw(dialogGUI); config.backgroundRootFolder = bgPath.Draw(bgGUI); GUILayout.EndVertical(); GUILayout.BeginHorizontal("Box"); GUILayout.Label("<b>Warning:</b> This configuration use to set default path of prefabs/images for UI, all url must be child of Unity's Resources folder\n\n" + "If you don't want to use this fault path for your Screen/Dialog, apply UIDescriptor to your class to define custom path", EditorGUIHelper.RichText(true)); GUILayout.EndHorizontal(); EditorUtility.SetDirty(target); }
public override void OnInspectorGUI() { var config = this.target as UIManConfig; if (this.namespaceField == null || this.screenPath == null || this.dialogPath == null || this.bgPath == null) { this.namespaceField = new TextFieldHelper(config.classNamespace); this.screenPath = new PathBrowser(config.screenPrefabFolder, Application.dataPath); this.dialogPath = new PathBrowser(config.dialogPrefabFolder, Application.dataPath); this.bgPath = new PathBrowser(config.backgroundRootFolder, Application.dataPath); this.animPath = new PathBrowser(config.animRootFolder, Application.dataPath); } LabelHelper.TitleLabel("UIMan Configuration"); LineHelper.Draw(Color.blue); EditorGUILayout.Space(); GUILayout.BeginVertical("Box"); config.classNamespace = this.namespaceField.Draw(this.namespaceGUI); config.screenPrefabFolder = this.screenPath.Draw(this.screenGUI); config.dialogPrefabFolder = this.dialogPath.Draw(this.dialogGUI); config.backgroundRootFolder = this.bgPath.Draw(this.bgGUI); config.animRootFolder = this.animPath.Draw(this.animRootGUI); GUILayout.EndVertical(); GUILayout.BeginHorizontal("Box"); GUILayout.Label("<b>Warning:</b> This configuration use to set default path of prefabs/images for UI, destination folder must be child of Unity's Resources folder.\n\n" + "If you don't want to use this default path for your Screen/Dialog, apply UIDescriptor to your class to define custom path.", EditorGUIHelper.RichText(true)); GUILayout.EndHorizontal(); EditorUtility.SetDirty(this.target); }
public override void OnInspectorGUI() { DataContext context = (DataContext)target; context.type = (ContextType)EditorGUILayout.EnumPopup(lblType, context.type); if (context.type == ContextType.NONE) { context.Clear(); GUILayout.Label(BindingDefine.NO_CONTEXT_TYPE); } else if (context.type == ContextType.MONO_BEHAVIOR) { context.viewModel = (ViewModelBehaviour)EditorGUILayout.ObjectField(lblContext, (Object)context.viewModel, typeof(ViewModelBehaviour), true); if (context.viewModel.GetCachedType() != null) { GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); EditorGUILayout.LabelField("<color=blue>[" + context.viewModel.GetCachedType().FullName + "]</color>", EditorGUIHelper.RichText()); GUILayout.EndHorizontal(); } } else if (context.type == ContextType.PROPERTY) { context.viewModel = (ViewModelBehaviour)EditorGUILayout.ObjectField(lblContext, (Object)context.viewModel, typeof(ViewModelBehaviour), true); string[] members = context.viewModel.GetAllMembers(MemberTypes.Field, MemberTypes.Property, MemberTypes.Field); if (members != null) { if (string.IsNullOrEmpty(context.propertyName)) { context.propertyName = members [0]; } else { for (int i = 0; i < members.Length; i++) { if (members [i] == context.propertyName) { selected = i; break; } } } GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); GUILayout.BeginVertical(); GUILayout.Space(5); int newSelected = EditorGUILayout.Popup("Field/Property", selected, members); GUILayout.EndVertical(); if (selected != newSelected) { context.propertyName = members [newSelected]; selected = newSelected; } if (EditorGUIHelper.QuickPickerButton()) { ContextBrowser.Browse(members, selectedMember => { context.propertyName = selectedMember; FilterPopup.Close(); }); } GUILayout.EndHorizontal(); MemberInfo curMember = context.viewModel.GetMemberInfo(members [selected], MemberTypes.Property, MemberTypes.Field); if (curMember != null) { object[] attributes = curMember.GetCustomAttributes(typeof(UIManProperty), false); if (attributes == null || attributes.Length == 0) { GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); GUILayout.Label("<color=red>None observable field/property!</color>", EditorGUIHelper.RichText()); GUILayout.EndHorizontal(); } } GUILayout.EndVertical(); } if (Event.current.type == EventType.Repaint) { FilterPopup.SetPopupRect(GUILayoutUtility.GetLastRect()); } } }
public void DrawBindingField(BindingField field) { GUILayout.BeginVertical(); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(new GUIContent(field.label)); string curMemberName = field.member; if (string.IsNullOrEmpty(curMemberName)) { curMemberName = BindingDefine.SELECT_MEMBER; } string[] members = binder.GetMembers(MemberTypes.Field, MemberTypes.Property); if (members == null) { EditorGUILayout.LabelField("<color=red>No target context found!</color>", EditorGUIHelper.RichText()); GUILayout.EndHorizontal(); } else { ArrayUtility.Insert(ref members, 0, "Null"); int selectedIndex = 0; for (int i = 0; i < members.Length; i++) { if (curMemberName == members [i]) { selectedIndex = i; break; } } GUILayout.Space(-7); EditorGUILayout.BeginVertical(); GUILayout.Space(5); int newSelectedIndex = EditorGUILayout.Popup(selectedIndex, members); if (newSelectedIndex != selectedIndex) { selectedIndex = newSelectedIndex; field.member = members [selectedIndex]; Apply(); } EditorGUILayout.EndVertical(); if (EditorGUIHelper.QuickPickerButton()) { ContextBrowser.Browse(this, field); } GUILayout.EndHorizontal(); MemberInfo curMember = binder.GetMemberInfo(members [selectedIndex], MemberTypes.Property, MemberTypes.Field); if (curMember != null) { object[] attributes = curMember.GetCustomAttributes(typeof(UIManProperty), false); if (attributes == null || attributes.Length == 0) { GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(" "); GUILayout.Label("<color=red>None observable field!</color>", EditorGUIHelper.RichText()); GUILayout.EndHorizontal(); } } } GUILayout.EndVertical(); }