Exemplo n.º 1
0
 public static void DrawFieldWithLabel(ref PropertyRect propertyRect, SerializedProperty property, bool startNewLine = true, int labelWidth = 150)
 {
     if (startNewLine)
     {
         propertyRect.AllocateLine();
     }
     EditorGUI.LabelField(propertyRect.AllocateWidthFlat(labelWidth), property.displayName);
     EditorGUI.PropertyField(propertyRect.AllocateRestOfLine(), property, EmptyContent);
 }
Exemplo n.º 2
0
        public static void DrawFieldWithLabelPercentage(ref PropertyRect propertyRect, SerializedProperty property, bool startNewLine = true, int labelWidth = 150, float labelWidthPercentage = 0.5f)
        {
            if (startNewLine)
            {
                propertyRect.AllocateLine();
            }
            var halfRect = new PropertyRect(propertyRect.AllocateWidthPrecent(labelWidthPercentage));

            halfRect.AllocateLine();
            EditorGUI.LabelField(halfRect.AllocateWidthFlat(labelWidth), property.displayName);
            EditorGUI.PropertyField(halfRect.AllocateRestOfLine(), property, EmptyContent);
        }
Exemplo n.º 3
0
        public static void DrawArray <T>(ref PropertyRect propertyRect, SerializedProperty property, List <T> cache = null)
        {
            var indexesToDelete = s_indexesPool.Get();

            indexesToDelete.Clear();

            int addNewElementCount = 0;

            // -- Drawing
            // Header [Label - size - plus button]
            propertyRect.AllocateLine();
            using (new GUIEnabledScope(true, true))
            {
                property.isExpanded ^= GUI.Button(propertyRect.AllocateWidthFlat(15), !property.isExpanded ? FoldedButtonContent : ExpandedButtonContent, EditorStyles.boldLabel);
            }
            EditorGUI.LabelField(propertyRect.AllocateWidthWithAscesorFlat(75), property.displayName, EditorStyles.boldLabel);

            int newSize = EditorGUI.IntField(propertyRect.AllocateWidthFlat(50), property.arraySize);

            if (GUI.Button(propertyRect.AllocateRestOfLine(), PlusContent))
            {
                ++addNewElementCount;
            }

            // Draw content
            if (property.isExpanded)
            {
                for (int i = 0; i < property.arraySize; i++)
                {
                    var componentProp = property.GetArrayElementAtIndex(i);
                    propertyRect.AllocateLine(EditorGUI.GetPropertyHeight(componentProp));

                    EditorGUI.BeginChangeCheck();
                    EditorGUI.PropertyField(propertyRect.AllocateWidthWithAscesorFlat(25), componentProp);
                    if (EditorGUI.EndChangeCheck() && cache != null)
                    {
                        cache.Add(componentProp.GetPropertyValue <T>());
                    }

                    if (GUI.Button(propertyRect.AllocateWidthFlat(25), MinusContent))
                    {
                        indexesToDelete.Add(i);
                    }
                }
            }

            ArrayOperations(property, indexesToDelete, addNewElementCount, newSize);
        }