예제 #1
0
        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++;
            }
        }
        /// <summary>
        /// Draws the localized contents of all created localized languages.
        /// </summary>
        /// <param name="drawElementsCallback">The function whichs will draw the localized contents when the draw area is expanded</param>
        /// <param name="drawRemoveButton">Is sets to <c>true</c> the function draw a remove button whichs allow to delete the localized language</param>
        private void DrawLocalizedContents(Action <LocalizedLanguage> drawElementsCallback, bool drawRemoveButton = false)
        {
            Rect bounds = new Rect(10, 0, splitPane.RightRect.width - 20, position.height - 0);

            GUI.Box(bounds, GUIContent.none, EditorStyles.helpBox);
            GUILayout.BeginArea(bounds);
            rightSplitScroll = GUILayout.BeginScrollView(rightSplitScroll);

            if (script.LanguageCount < NumberOfAvailableLanguage)
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button(AssetReferences.PlusIcon, EditorStyles.label, GUILayout.Width(32), GUILayout.Height(32)))
                {
                    var l = new LocalizedLanguage();
                    l.Language = languageToAdd;
                    script.LocalizedLanguages.Add(l);
                }
                languageToAdd = (Language)EditorGUILayout.EnumPopup(languageToAdd, GUILayout.ExpandWidth(true));
                EditorGUILayout.EndHorizontal();
            }

            GUILayout.Space(10);

            var count = script.LocalizedLanguages.Count;

            for (int i = 0; i < count; i++)
            {
                localizedLanguage = script.LocalizedLanguages[i];

                if (!accordions.TryGetValue(localizedLanguage.Language, out accordion))
                {
                    accordion            = new SimpleAccordion();
                    accordion.IsExpanded = localizedLanguage.isExpanded;
                    accordion.expandStateChangeCallback = (acc) => localizedLanguage.isExpanded = acc.IsExpanded;
                    accordions.Add(localizedLanguage.Language, accordion);
                }

                accordion.drawHeaderCallback = () => { return(DrawLocalizedLanguageHeader(localizedLanguage, i, count, drawRemoveButton)); };


                if (script.LocalizedLanguages.Count(item => item.Language == localizedLanguage.Language) > 1)
                {
                    EditorGUILayout.HelpBox(Strings.LanguageDuplication, MessageType.Error);
                }

                accordion.drawCallback = () =>
                {
                    GUILayout.Space(15);
                    drawElementsCallback.Invoke(localizedLanguage);
                };

                accordion.OnGUI(EditorStyles.helpBox);
            }

            GUILayout.EndScrollView();
            GUILayout.EndArea();
        }
        public InspectorAccordion(string title)
        {
            this.title             = title;
            this.serializedMembers = new List <SerializedMember>();
            this.m_accordion       = new SimpleAccordion(title, OnDrawAccordionContents);
            this.m_accordion.expandStateChangeCallback = (acc) =>
            {
                if (serializedMembers.Any())
                {
                    InspectorData.SetBool(IsExpandedPref, acc.IsExpanded);
                }

                if (onExpandStateChanged != null)
                {
                    onExpandStateChanged.Invoke(this);
                }
            };
        }
예제 #4
0
        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);
        }
예제 #5
0
        internal override void DrawMember()
        {
            if (m_fieldType.IsDefined(CustomDrawerType, true))
            {
                if (m_classDrawer == null)
                {
                    m_classDrawer          = InspectorDrawer.Create(m_fieldInfo.GetValue(DeclaringObject), SerializedProperty.Copy(), false);
                    m_classDrawerAccordion = new SimpleAccordion(DisplayName, () =>
                    {
                        m_classDrawer.OnEnable();
                        m_classDrawer.OnInspectorGUI();
                    });
                    m_classDrawerAccordion.IsExpanded = SerializedProperty.isExpanded;
                    m_classDrawerAccordion.expandStateChangeCallback = acc => SerializedProperty.isExpanded = acc.IsExpanded;

                    m_classDrawerAccordion.drawHeaderCallback = () => SimpleAccordion.DrawDefaultAccordionHeader(m_classDrawerAccordion, FA.code, 14, 8);
                }

                DrawMember(m_classDrawerAccordion.OnGUI);
                return;
            }

            if (IsListOrArray(m_fieldType))
            {
                if (m_reordableAttribute != null)
                {
                    if (m_reorderableList == null)
                    {
                        m_reorderableList = CreateReordableList(SerializedProperty.serializedObject, SerializedProperty);
                    }
                    DrawMember(m_reorderableList.DoLayoutList);
                }
                else
                {
                    DrawMember(DrawCollection);
                }
            }
            else
            {
                DrawMember(DrawPropertyField);
            }
        }
 internal virtual Rect OnHeaderGUI()
 {
     return(SimpleAccordion.DrawDefaultAccordionHeader(Accordion, FA.list_alt, 14, 8));
 }
예제 #7
0
        public static Rect DrawDefaultAccordionHeader(SimpleAccordion accordion, int height = 20, int fontSize = 14)
        {
            var icon = accordion.IsExpanded ? FA.angle_double_down : FA.angle_double_right;

            return(DrawDefaultAccordionHeader(accordion, icon, height, fontSize));
        }