Exemplo n.º 1
0
        public void AllocateRestOfLine_WithoutLine()
        {
            int          width        = 512;
            int          heigth       = 512;
            Rect         originalRect = new Rect(0, 0, width, heigth);
            PropertyRect propertyRect = new PropertyRect(originalRect);

            Assert.Throws <InvalidOperationException>(() => propertyRect.AllocateRestOfLine());
        }
Exemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            // Draw label
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), EmptyContent);
            var propertyRect = new PropertyRect(position);
            var indent       = EditorGUI.indentLevel;

            EditorGUI.indentLevel = Math.Max(0, indent - 1);

            var usageProp  = property.FindPropertyRelative("_usageType");
            var accessProp = property.FindPropertyRelative("_accessType");
            var typeProp   = property.FindPropertyRelative("_componentTypeReference");

            propertyRect.AllocateLine();

            EditorGUI.PropertyField(propertyRect.AllocateWidthFlat(50), usageProp, EmptyContent);

            if (((ComponentLinkUsageType)usageProp.GetPropertyValue()) == ComponentLinkUsageType.All)
            {
                EditorGUI.PropertyField(propertyRect.AllocateWidthFlat(40), accessProp, EmptyContent);
            }

            EditorGUI.PropertyField(propertyRect.AllocateRestOfLine(), typeProp, EmptyContent);

            // New custom component
            if (!HasSettedType(property))
            {
                propertyRect.AllocateLine();
                var nameProp = property.FindPropertyRelative("_componentName");
                EditorGUI.PropertyField(propertyRect.AllocateWidthWithAscesorFlat(25), nameProp, EmptyContent);
                using (new GUIEnabledScope(!string.IsNullOrWhiteSpace(nameProp.stringValue)))
                {
                    if (GUI.Button(propertyRect.AllocateRestOfLine(), PlusContent))
                    {
                        ShowCreateComponentWindow(property);
                    }
                }
            }

            EditorGUI.indentLevel = indent;
            EditorGUI.EndProperty();
        }
Exemplo n.º 3
0
        public void AllocateRestOfLine_WholeLine()
        {
            int          width        = 512;
            int          heigth       = 512;
            Rect         originalRect = new Rect(0, 0, width, heigth);
            PropertyRect propertyRect = new PropertyRect(originalRect);

            propertyRect.AllocateLine();
            var rect = propertyRect.AllocateRestOfLine();

            Assert.AreEqual(rect.height, EditorGUIUtility.singleLineHeight);
            Assert.AreEqual(rect.width, width);
        }
Exemplo n.º 4
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            var wasChanged = GUI.changed;

            GUI.changed = false;

            PropertyRect propertyRect = new PropertyRect(position);

            // Draw name
            var nameProp = property.FindPropertyRelative("_name");

            EditorGUI.PropertyField(propertyRect.AllocateLine(), nameProp);

            // Draw array
            var componentsProp = property.FindPropertyRelative("_components");

            s_cache.Clear();
            GUIDrawers.DrawArray(ref propertyRect, componentsProp, s_cache);

            // Draw additional settings
            propertyRect.AllocateLine();
            var parallelScheduling = property.FindPropertyRelative("_parallelSchedule");

            EditorGUI.LabelField(propertyRect.AllocateWidthFlat(105), s_parallelContent);
            EditorGUI.PropertyField(propertyRect.AllocateWidthFlat(25), parallelScheduling, EmptyContent);
            var structuralChanges = property.FindPropertyRelative("_hasStructuralChanges");

            EditorGUI.LabelField(propertyRect.AllocateWidthFlat(115), s_structuralChangesContent);
            EditorGUI.PropertyField(propertyRect.AllocateWidthFlat(25), structuralChanges, EmptyContent);

            propertyRect.AllocateLine();
            var queryField = property.FindPropertyRelative("_queryField");

            EditorGUI.LabelField(propertyRect.AllocateWidthFlat(75), s_queryFieldContent);
            EditorGUI.PropertyField(propertyRect.AllocateRestOfLine(), queryField, EmptyContent);

            propertyRect.AllocateLine();
            var sharedFilter = property.FindPropertyRelative("_sharedFilter").GetPropertyValue <SharedComponentFilter>();

            EditorGUI.LabelField(propertyRect.AllocateWidthFlat(75), s_sharedFilterContent);

            if (sharedFilter.IsValid)
            {
                EditorGUI.LabelField(propertyRect.AllocateWidthWithAscesorFlat(25), sharedFilter.FilterName, s_BoldLabelStyle);
            }
            else
            {
                EditorGUI.LabelField(propertyRect.AllocateWidthWithAscesorFlat(25), EmptyContent);
            }

            if (!sharedFilter.IsValid && GUI.Button(propertyRect.AllocateRestOfLine(), PlusContent))
            {
                SharedComponentFilterWindow.ShowWindow((name, declaration) =>
                {
                    property.serializedObject.ApplyModifiedProperties();
                    sharedFilter.FilterName           = name;
                    sharedFilter.ComponentDeclaration = declaration;
                    property.serializedObject.Update();
                });
            }
            else if (sharedFilter.IsValid && GUI.Button(propertyRect.AllocateRestOfLine(), MinusContent))
            {
                sharedFilter.Invalid();
            }

            EditorGUI.EndProperty();

            if (GUI.changed)
            {
                // We can have some structural changes so we need to sync with Unity serialized side
                property.serializedObject.ApplyModifiedProperties();
                SystemLambdaAction systemLambdaAction = property.GetPropertyValue() as SystemLambdaAction;
                systemLambdaAction?.PropertiesChanged(s_cache);
                property.serializedObject.Update();
            }

            GUI.changed |= wasChanged;
        }