Exemple #1
0
        public T GetObject <T>() where T : class
        {
            if (_drawerType == DrawerType.Property)
            {
                return(SerializedPropertyHelper.GetTargetObjectOfProperty(serializedProperty) as T);
            }

            return(serializedObject.targetObject as T);
        }
Exemple #2
0
        public bool Header(string label, bool drawFoldoutButton = true)
        {
            label = AddSpacesToSentence(label, true);

            Rect backgroundRect = new Rect(positionRect.x, positionRect.y, positionRect.width, 22);

            GUIContent content = new GUIContent(label);

            EditorStyles.label.CalcMinMaxWidth(content, out float minLabelWidth, out float maxLabelWidth);

#if UNITY_2019_3_OR_NEWER
            Rect labelRect = new Rect(positionRect.x + NUISettings.textMargin + 15f, positionRect.y - 1, maxLabelWidth,
                                      NUISettings.FIELD_HEIGHT);
#else
            Rect labelRect = new Rect(positionRect.x + NUISettings.textMargin + 15f, positionRect.y + 3, maxLabelWidth,
                                      NUISettings.FIELD_HEIGHT);
#endif

            // If object, check if scriptable or normal
            bool isScriptableObject = false;
            if (_drawerType == DrawerType.Editor)
            {
                isScriptableObject = serializedObject.targetObject is ScriptableObject;
            }

            // Draw background
            Color bgColor = _drawerType == DrawerType.Property ? NUISettings.propertyHeaderColor :
                            isScriptableObject ? NUISettings.scriptableObjectHeaderColor : NUISettings.editorHeaderColor;
            EditorGUI.DrawRect(backgroundRect, bgColor);

            // Draw foldout button
            bool _isExpanded = true;
            _isExpanded =
                IsExpanded; // Due to a bug serializedProperty.isExpanded will not serialize property, use cache instead
            GUI.color = Color.white;
            Rect      foldButtonRect     = new Rect(positionRect.x + 1, positionRect.y + 2, 18f, 18f);
            GUIStyle  foldoutButtonStyle = new GUIStyle();
            Texture2D background         = _isExpanded ? _expandedArrow : _foldedArrow;
            foldoutButtonStyle.normal.background = background;
            foldoutButtonStyle.hover.background  = background;
            foldoutButtonStyle.active.background = background;

            if (GUI.Button(foldButtonRect, "", foldoutButtonStyle))
            {
                IsExpanded  = !IsExpanded;
                _isExpanded = IsExpanded;
            }

            // Draw label
            GUIStyle style = new GUIStyle(EditorStyles.label);
            style.normal.textColor = Color.white;
            EditorGUI.LabelField(labelRect, new GUIContent(label), style);

            // Draw help link
            Rect helpRect = new Rect(labelRect.x + labelRect.width + 5f, positionRect.y + 3, 16, 16);
            DrawEditorTexture(helpRect, "NUI/help");
            if (Event.current.type == EventType.MouseUp && helpRect.Contains(Event.current.mousePosition))
            {
                string fullTypeName = _drawerType == DrawerType.Property
                    ? SerializedPropertyHelper.GetTargetObjectOfProperty(serializedProperty).GetType().FullName
                    : serializedObject.targetObject.GetType().FullName;
                string objectPath = fullTypeName.Replace('.', '/');
                Application.OpenURL($"{NUISettings.DOCUMENTATION_BASE_URL}/{objectPath}");
            }

            AdvancePosition();

            // Apply padding
            positionRect = new Rect(
                positionRect.x + sidePadding,
                positionRect.y,
                positionRect.width - sidePadding * 2f,
                positionRect.height);

            if (_drawerType == DrawerType.Editor && _isExpanded)
            {
                if (serializedObject.targetObject is ScriptableObject)
                {
                    Info("This is a ScriptableObject. All changes are global.");
                }
            }

            SetHeight(totalHeight);
            return(_isExpanded);
        }