public InspectorButtonMethod(InspectorButtonAttribute attribute, object target) { this.attribute = attribute; declaringObject = target; method = ReflectionUtils.GetCachedMethod(target.GetType(), attribute.MethodName); if (method == null) { errorMessage = $"{nameof(InspectorButtonAttribute)} refers to a missing method '{attribute.MethodName}' in '{target.GetType()}' class"; return; } checkIfShouldBeDrawed = ReflectionUtils.GetCachedMethod(target.GetType(), $"__{attribute.MethodName}__"); HasFontAwesomeTitile = DrawerHelper.ContainsFontAwesomeString(attribute.Label); IsCoroutine = method.ReturnType == typeof(IEnumerator); paramsInfos = method.GetParameters(); arguments = new object[paramsInfos.Length]; var title = ObjectNames.NicifyVariableName(attribute.MethodName); accordion = new SimpleAccordion($"{title} Function Arguments", DrawArguments); accordion.drawHeaderCallback = () => SimpleAccordion.DrawDefaultAccordionHeader(accordion, 14, 8); var index = 0; foreach (var param in paramsInfos) { arguments[index] = ReflectionUtils.DefaultValue(param.ParameterType); index++; } }
private void DrawArguments() { EditorGUILayout.BeginVertical(); ParameterInfo param; for (var i = 0; i < paramsInfos.Length; i++) { param = paramsInfos[i]; arguments[i] = DrawerHelper.Draw(ObjectNames.NicifyVariableName(param.Name), arguments[i], param.ParameterType); } EditorGUILayout.EndVertical(); }
internal override Rect OnHeaderGUI() { var rect = base.OnHeaderGUI(); var deleteBtnRect = new Rect(rect.width - 10, rect.y, 14, rect.height); if (DrawerHelper.FAButton(deleteBtnRect, FA.plus, FAOption.FontSize(14))) { property.arraySize++; if (!IsExpanded) { IsExpanded = true; } } return(rect); }
public static Rect DrawDefaultAccordionHeader(SimpleAccordion accordion, string icon, int height = 20, int fontSize = 14) { if (accordion.headerStyle == null) { accordion.headerStyle = new GUIStyle(AssetReferences.AccordionHeader); } accordion.headerStyle.fontSize = fontSize; GUILayout.Box(accordion.Title, accordion.headerStyle, GUILayout.ExpandWidth(true), GUILayout.Height(height)); var rect = GUILayoutUtility.GetLastRect(); DrawerHelper.FAIcon(rect, icon, FAOption.TextAnchor(TextAnchor.MiddleLeft), //FAOption.FontSize(fontSize), FAOption.Padding(new RectOffset(5, 0, 0, 0)) ); return(rect); }
private Rect DrawLocalizedLanguageHeader(LocalizedLanguage language, int index, int languagesCount, bool drawRemoveButton = false) { var icon = accordion.IsExpanded ? FA.angle_double_down : FA.angle_double_right; var rect = EditorGUILayout.BeginVertical(); var boxTitle = new GUIContent(language.LanguageName); GUILayout.Box(boxTitle, AssetReferences.AccordionHeader, GUILayout.ExpandWidth(true), GUILayout.Height(20)); DrawerHelper.FAIcon(rect, icon, FAOption.TextAnchor(TextAnchor.UpperLeft), FAOption.FontSize(20), FAOption.Padding(new RectOffset(5, 0, 0, 0))); EditorGUILayout.BeginHorizontal(); GUILayout.Space(100); // draw translation progress bar if (language.isBeingAutoTranslated) { var r = GUILayoutUtility.GetRect(250, 32); EditorGUI.ProgressBar(r, language.translationProgress, string.Empty); } GUILayout.FlexibleSpace(); // draw google translate button if (index > 0 && selectedTab == 0) { if (GUI.Button(new Rect(rect.width - 82, rect.y, 24, rect.height), AssetReferences.GoogleTranslateIcon, EditorStyles.label)) { AutoTranslateAllKeyOfLanguage(language); } } GUILayout.Space(10); // draw up arrow if (index > 0 && DrawerHelper.FAButton(new Rect(rect.width - 58, rect.y, 24, rect.height), FA.arrow_up)) { SwapLanguagesPosition(index, index - 1); } GUILayout.Space(10); // draw down arrao if (index < languagesCount - 1 && DrawerHelper.FAButton(new Rect(rect.width - 34, rect.y, 24, rect.height), FA.arrow_down)) { SwapLanguagesPosition(index, index + 1); } GUILayout.Space(10); // draw remove button if (drawRemoveButton && DrawerHelper.FAButton(new Rect(rect.width - 10, rect.y, 24, rect.height), FA.trash, FAOption.TextColor(Color.red))) { script.LocalizedLanguages.Remove(language); } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); return(rect); }
private bool HasClickEvent(string icon) { GUILayout.Space(5); return(DrawerHelper.FAButton(icon, FAOption.FontSize(10), FAOption.TextAnchor(TextAnchor.MiddleCenter))); }
public void Draw() { if (method == null) { EditorGUILayout.HelpBox(errorMessage, MessageType.Error); } if (checkIfShouldBeDrawed != null) { if (!(bool)checkIfShouldBeDrawed.Invoke(declaringObject, null)) { return; } } if (attribute.Width != 0 && attribute.Height != 0) { if (attribute.Center) { var rect = EditorUtils.GetCenteredRect(attribute.Width, attribute.Height); if (HasFontAwesomeTitile) { if (DrawerHelper.FAButton(rect, attribute.Label)) { Invoke(); } } else if (GUI.Button(rect, attribute.Label)) { Invoke(); } } else { if (HasFontAwesomeTitile) { if (DrawerHelper.FAButton(attribute.Label, FAOption.FontSize(attribute.Height))) { Invoke(); } } else if (GUILayout.Button(attribute.Label, GUILayout.Width(attribute.Width), GUILayout.Height(attribute.Height))) { Invoke(); } } } else { if (HasFontAwesomeTitile) { if (DrawerHelper.FAButton(attribute.Label, FAOption.FontSize(18))) { Invoke(); } } else if (GUILayout.Button(attribute.Label)) { Invoke(); } } if (HasParams) { accordion.OnGUI(); } }