public static float GetPropertyHeight (SerializedProperty _arrayProperty, eArrayOptions _options)
		{
			int _count				= _arrayProperty.arraySize;
			bool _showArraySize		= (_options & eArrayOptions.SHOW_ARRAY_SIZE) != 0;
			float _singleLineHeight	= EditorGUIUtility.singleLineHeight;
			float _totalHeight		= 0f;

			// Height for array name
			_totalHeight		+= _singleLineHeight + kSpacingPixels;

			// Is foldout enabled, then dont show the rest of the elements
			if (_arrayProperty.isExpanded)
			{
				// If we showing array size then we need to consider it
				if (_showArraySize && _count != 0)
					_totalHeight	+= (EditorGUIUtility.singleLineHeight + kSpacingPixels);

				// If there are no elements then we will show button to add elements
				if (_count == 0)
				{
					// Add height of button and extra spacing
					_totalHeight	+= (EditorGUIUtility.singleLineHeight + kSpacingPixels);
				}
				// We do have contents within array
				else
				{
					// Includes height for each element, height of edit bar, spacing
					for (int _iter = 0; _iter < _count; _iter++)
						_totalHeight+= EditorGUI.GetPropertyHeight(_arrayProperty.GetArrayElementAtIndex(_iter)) + EditorGUIUtility.singleLineHeight + kSpacingPixels;
				}
			}
			
			return _totalHeight;
		}
예제 #2
0
        public static float GetPropertyHeight(SerializedProperty _arrayProperty, eArrayOptions _options)
        {
            int _count				= _arrayProperty.arraySize;
            bool _showArraySize		= (_options & eArrayOptions.SHOW_ARRAY_SIZE) != 0;
            float _singleLineHeight	= EditorGUIUtility.singleLineHeight;
            float _totalHeight		= 0f;

            // Height for array name
            _totalHeight		+= _singleLineHeight + kSpacingPixels;

            // Is foldout enabled, then dont show the rest of the elements
            if (_arrayProperty.isExpanded)
            {
                // If we showing array size then we need to consider it
                if (_showArraySize && _count != 0)
                    _totalHeight	+= (EditorGUIUtility.singleLineHeight + kSpacingPixels);

                // If there are no elements then we will show button to add elements
                if (_count == 0)
                {
                    // Add height of button and extra spacing
                    _totalHeight	+= (EditorGUIUtility.singleLineHeight + kSpacingPixels);
                }
                // We do have contents within array
                else
                {
                    // Includes height for each element, height of edit bar, spacing
                    for (int _iter = 0; _iter < _count; _iter++)
                        _totalHeight+= EditorGUI.GetPropertyHeight(_arrayProperty.GetArrayElementAtIndex(_iter)) + EditorGUIUtility.singleLineHeight + kSpacingPixels;
                }
            }

            return _totalHeight;
        }
예제 #3
0
        public static void Draw(SerializedProperty _arrayProperty, GUIContent _label, eArrayOptions _options)
        {
            bool _showNameWithFoldout = (_options & eArrayOptions.SHOW_NAME_WITH_FOLDOUT) != 0;
            bool _showArraySize       = (_options & eArrayOptions.SHOW_ARRAY_SIZE) != 0;
            int  _count = _arrayProperty.arraySize;
            int  _originalIndentLevel = EditorGUI.indentLevel;

            // GUI styles
            GUIStyle _buttonStyle = EditorStyles.miniButton;

            // Show array name
            if (_showNameWithFoldout)
            {
                _arrayProperty.isExpanded = EditorGUILayout.Foldout(_arrayProperty.isExpanded, _label);

                // Update indentation
                EditorGUI.indentLevel++;
            }
            else
            {
                EditorGUILayout.LabelField(_label);
            }

            // Is foldout enabled, then dont show the rest of the elements
            if (!_arrayProperty.isExpanded)
            {
                // Reset indentation to original value
                EditorGUI.indentLevel = _originalIndentLevel;
                return;
            }

            // Show array size
            if (_showArraySize && _count != 0)
            {
                // Check if size value changes
                EditorGUI.BeginChangeCheck();
                int _newSize = EditorGUILayout.IntField("Size", _count);

                if (EditorGUI.EndChangeCheck())
                {
                    _arrayProperty.arraySize = _newSize;
                }
            }

            // If there are no elements then return size of add button
            if (_count == 0)
            {
                if (GUILayout.Button("Add new product", GUILayout.Height(kButtonHeight)))
                {
                    _arrayProperty.InsertArrayElementAtIndex(0);
                }
            }
            else
            {
                // Show array elements if it is expanded
                GUIStyle _subviewStyle = new GUIStyle("ProgressBarBack");

                if (_arrayProperty.isExpanded)
                {
                    for (int _iter = 0; _iter < _count; _iter++)
                    {
                        GUILayout.BeginVertical(GUIContent.none, _subviewStyle);
                        {
                            // Show each element
                            EditorGUILayout.PropertyField(_arrayProperty.GetArrayElementAtIndex(_iter));

                            // Show buttons
                            GUILayout.BeginHorizontal();
                            {
                                GUILayout.FlexibleSpace();

                                if (GUILayout.Button("+", _buttonStyle, GUILayout.MinWidth(40)))
                                {
                                    _arrayProperty.InsertArrayElementAtIndex(_iter);
                                    break;
                                }

                                if (GUILayout.Button("-", _buttonStyle, GUILayout.MinWidth(40)))
                                {
                                    _arrayProperty.DeleteArrayElementAtIndex(_iter);
                                    break;
                                }
                            }
                            GUILayout.EndHorizontal();
                        }
                        GUILayout.EndVertical();
                    }
                }
            }

            // Reset indentation to original value
            EditorGUI.indentLevel = _originalIndentLevel;
        }
		public static void Draw (Rect _position, SerializedProperty _arrayProperty, GUIContent _label, eArrayOptions _options)
		{
			int _originalIndentLevel	= EditorGUI.indentLevel;
			int _count					= _arrayProperty.arraySize;
			bool _showNameWithFoldout	= (_options & eArrayOptions.SHOW_NAME_WITH_FOLDOUT) != 0;
			bool _showArraySize			= (_options & eArrayOptions.SHOW_ARRAY_SIZE) != 0;

			// Height used for primitive properties and buttons
			float _singleLineHeight		= EditorGUIUtility.singleLineHeight;
			
			// Calculate rect
			float _positionY			= _position.y;

			// Rect for array name
			Rect _nameRect				= new Rect(_position.x, _positionY, _position.width, _singleLineHeight);
			_positionY					+= (_singleLineHeight + kSpacingPixels);
			
			// Show array name
			if (_showNameWithFoldout)
			{
				_arrayProperty.isExpanded	= EditorGUI.Foldout(_nameRect, _arrayProperty.isExpanded, _label);

				// Indent to next level
				EditorGUI.indentLevel++;
			}
			else
			{
				EditorGUI.LabelField(_nameRect, _label);
			}

			// Is foldout enabled, then dont show the rest of the elements
			if (!_arrayProperty.isExpanded)
			{
				// Reset indentation level
				EditorGUI.indentLevel	= _originalIndentLevel;
				return;
			}

			// Show array size
			if (_showArraySize && _count != 0)
			{
				// Rect for array Length
				Rect _sizeRect		= new Rect(_position.x, _positionY, _position.width, _singleLineHeight);
				_positionY			+= (_singleLineHeight + kSpacingPixels);

				// Check if size value changes
				EditorGUI.BeginChangeCheck();
				int _newSize		= EditorGUI.IntField(_sizeRect, "Size", _count);

				if (EditorGUI.EndChangeCheck())
					_arrayProperty.arraySize	= _newSize;
			}			

			// If there are no elements then we will show button to add elements
			if (_count == 0)
			{
				// Rect for add button
				Rect _addButtonRect	= new Rect(_position.x, _positionY, _position.width, _singleLineHeight);
				_positionY			+= (_singleLineHeight + kSpacingPixels);

				if (GUI.Button(_addButtonRect, "Add"))
					_arrayProperty.InsertArrayElementAtIndex(0);
			}
			else
			{
				// If there are elements then we will show its contents
				for (int _iter = 0; _iter < _count; _iter++)
				{
					// Get element property
					SerializedProperty _elementProperty	= _arrayProperty.GetArrayElementAtIndex(_iter);
					float _elementHeight				= EditorGUI.GetPropertyHeight(_elementProperty);

					// Rect for element, edit buttons
					Rect _elementRect		= new Rect(_position.x, _positionY, _position.width, _elementHeight);
					_positionY				+= _elementHeight;
					Rect _deleteButtonRect	= new Rect(_position.x + _position.width - kEditButtonWidth, _positionY, 
					                                  kEditButtonWidth, _singleLineHeight);
					Rect _addButtonRect		= new Rect(_deleteButtonRect.x - kEditButtonWidth, _positionY, 
					                                kEditButtonWidth, _singleLineHeight);
					_positionY				+= _singleLineHeight + kSpacingPixels;

					// Grouping element and buttons
					EditorGUI.PropertyField(_elementRect,
					                        _elementProperty, 
					                        new GUIContent("# " + (_iter + 1).ToString() + ":"), 
					                        true);
					
					if (GUI.Button(_addButtonRect, "+"))
					{
						_arrayProperty.InsertArrayElementAtIndex(0);
						break;
					}
					
					if (GUI.Button(_deleteButtonRect, "-"))
					{
						_arrayProperty.DeleteArrayElementAtIndex(_iter);
						break;
					}
				}
			}

			// Reset indentation level
			EditorGUI.indentLevel	= _originalIndentLevel;
		}
예제 #5
0
        public static void Draw(Rect _position, SerializedProperty _arrayProperty, GUIContent _label, eArrayOptions _options)
        {
            int _originalIndentLevel	= EditorGUI.indentLevel;
            int _count					= _arrayProperty.arraySize;
            bool _showNameWithFoldout	= (_options & eArrayOptions.SHOW_NAME_WITH_FOLDOUT) != 0;
            bool _showArraySize			= (_options & eArrayOptions.SHOW_ARRAY_SIZE) != 0;

            // Height used for primitive properties and buttons
            float _singleLineHeight		= EditorGUIUtility.singleLineHeight;

            // Calculate rect
            float _positionY			= _position.y;

            // Rect for array name
            Rect _nameRect				= new Rect(_position.x, _positionY, _position.width, _singleLineHeight);
            _positionY					+= (_singleLineHeight + kSpacingPixels);

            // Show array name
            if (_showNameWithFoldout)
            {
                _arrayProperty.isExpanded	= EditorGUI.Foldout(_nameRect, _arrayProperty.isExpanded, _label);

                // Indent to next level
                EditorGUI.indentLevel++;
            }
            else
            {
                EditorGUI.LabelField(_nameRect, _label);
            }

            // Is foldout enabled, then dont show the rest of the elements
            if (!_arrayProperty.isExpanded)
            {
                // Reset indentation level
                EditorGUI.indentLevel	= _originalIndentLevel;
                return;
            }

            // Show array size
            if (_showArraySize && _count != 0)
            {
                // Rect for array Length
                Rect _sizeRect		= new Rect(_position.x, _positionY, _position.width, _singleLineHeight);
                _positionY			+= (_singleLineHeight + kSpacingPixels);

                // Check if size value changes
                EditorGUI.BeginChangeCheck();
                int _newSize		= EditorGUI.IntField(_sizeRect, "Size", _count);

                if (EditorGUI.EndChangeCheck())
                    _arrayProperty.arraySize	= _newSize;
            }

            // If there are no elements then we will show button to add elements
            if (_count == 0)
            {
                // Rect for add button
                Rect _addButtonRect	= new Rect(_position.x, _positionY, _position.width, _singleLineHeight);
                _positionY			+= (_singleLineHeight + kSpacingPixels);

                if (GUI.Button(_addButtonRect, "Add"))
                    _arrayProperty.InsertArrayElementAtIndex(0);
            }
            else
            {
                // If there are elements then we will show its contents
                for (int _iter = 0; _iter < _count; _iter++)
                {
                    // Get element property
                    SerializedProperty _elementProperty	= _arrayProperty.GetArrayElementAtIndex(_iter);
                    float _elementHeight				= EditorGUI.GetPropertyHeight(_elementProperty);

                    // Rect for element, edit buttons
                    Rect _elementRect		= new Rect(_position.x, _positionY, _position.width, _elementHeight);
                    _positionY				+= _elementHeight;
                    Rect _deleteButtonRect	= new Rect(_position.x + _position.width - kEditButtonWidth, _positionY,
                                                      kEditButtonWidth, _singleLineHeight);
                    Rect _addButtonRect		= new Rect(_deleteButtonRect.x - kEditButtonWidth, _positionY,
                                                    kEditButtonWidth, _singleLineHeight);
                    _positionY				+= _singleLineHeight + kSpacingPixels;

                    // Grouping element and buttons
                    EditorGUI.PropertyField(_elementRect,
                                            _elementProperty,
                                            new GUIContent("# " + (_iter + 1).ToString() + ":"),
                                            true);

                    if (GUI.Button(_addButtonRect, "+"))
                    {
                        _arrayProperty.InsertArrayElementAtIndex(0);
                        break;
                    }

                    if (GUI.Button(_deleteButtonRect, "-"))
                    {
                        _arrayProperty.DeleteArrayElementAtIndex(_iter);
                        break;
                    }
                }
            }

            // Reset indentation level
            EditorGUI.indentLevel	= _originalIndentLevel;
        }
		public static void Draw (SerializedProperty _arrayProperty, GUIContent _label, eArrayOptions _options)
		{
			bool _showNameWithFoldout	= (_options & eArrayOptions.SHOW_NAME_WITH_FOLDOUT) != 0;
			bool _showArraySize			= (_options & eArrayOptions.SHOW_ARRAY_SIZE) != 0;
			int _count					= _arrayProperty.arraySize;
			int _originalIndentLevel	= EditorGUI.indentLevel;

			// GUI styles
			GUIStyle _buttonStyle		= EditorStyles.miniButton;
			
			// Show array name
			if (_showNameWithFoldout)
			{
				_arrayProperty.isExpanded = EditorGUILayout.Foldout(_arrayProperty.isExpanded, _label);

				// Update indentation
				EditorGUI.indentLevel++;
			}
			else
			{
				EditorGUILayout.LabelField(_label);
			}

			// Is foldout enabled, then dont show the rest of the elements
			if (!_arrayProperty.isExpanded)
			{
				// Reset indentation to original value
				EditorGUI.indentLevel	= _originalIndentLevel;
				return;
			}

			// Show array size
			if (_showArraySize && _count != 0)
			{
				// Check if size value changes
				EditorGUI.BeginChangeCheck();
				int _newSize		= EditorGUILayout.IntField("Size", _count);
				
				if (EditorGUI.EndChangeCheck())
					_arrayProperty.arraySize	= _newSize;
			}
			
			// If there are no elements then return size of add button
			if (_count == 0)
			{
				if (GUILayout.Button("Add new product", GUILayout.Height(kButtonHeight)))
					_arrayProperty.InsertArrayElementAtIndex(0);
			}
			else
			{
				// Show array elements if it is expanded
				GUIStyle _subviewStyle		= new GUIStyle("ProgressBarBack");

				if (_arrayProperty.isExpanded) 
				{
					for (int _iter = 0; _iter < _count; _iter++) 
					{
						GUILayout.BeginVertical(GUIContent.none, _subviewStyle);
						{
							// Show each element
							EditorGUILayout.PropertyField(_arrayProperty.GetArrayElementAtIndex(_iter));
							
							// Show buttons 
							GUILayout.BeginHorizontal();
							{
								GUILayout.FlexibleSpace();
								
								if (GUILayout.Button("+", _buttonStyle, GUILayout.MinWidth(40)))
								{
									_arrayProperty.InsertArrayElementAtIndex(_iter);
									break;
								}
								
								if (GUILayout.Button("-", _buttonStyle, GUILayout.MinWidth(40)))
								{
									_arrayProperty.DeleteArrayElementAtIndex(_iter);
									break;
								}
							}
							GUILayout.EndHorizontal();
						}
						GUILayout.EndVertical();
					}
				}
			}

			// Reset indentation to original value
			EditorGUI.indentLevel	= _originalIndentLevel;
		}