Beispiel #1
0
        private void DrawComponent(ComponentWrapper wrapper)
        {
            var  component     = wrapper.Component;
            Type componentType = component.GetType();

            // Header row
            GUILayout.BeginVertical(ComponentRowStyle);
            Texture    icon          = EditorGUIUtility.ObjectContent(component, componentType).image;
            string     componentName = ObjectNames.NicifyVariableName(componentType.Name);
            GUIContent content       = new GUIContent(componentName, icon);

            // Checkbox
            wrapper.Checked = EditorGUILayout.ToggleLeft(content, wrapper.Checked, wrapper.Checked ? ComponentLabelStyle : GUI.skin.label);
            if (wrapper.Checked)
            {
                // Draw property foldout if there are any serialized properties.
                if (wrapper.Properties.Any())
                {
                    wrapper.FoldOut = EditorGUILayout.Foldout(wrapper.FoldOut, componentName + " properties and fields");
                    if (wrapper.FoldOut)
                    {
                        ++EditorGUI.indentLevel;
                        DrawProperties(wrapper.Properties);
                        --EditorGUI.indentLevel;
                    }
                }
                else
                {
                    GUILayout.Label(componentName + " has no serialized properties.");
                }
            }
            GUILayout.EndVertical();
        }
Beispiel #2
0
        private void CopyProperties(ComponentWrapper source, Component target)
        {
            var targetSerializedObject = new SerializedObject(target);

            foreach (var property in source.Properties.Where(p => p.Checked))
            {
                targetSerializedObject.CopyFromSerializedProperty(property.SerializedProperty);
            }
            targetSerializedObject.ApplyModifiedProperties();
        }
Beispiel #3
0
 private void CopyComponent(ComponentWrapper source, Component target)
 {
     CopyProperties(source, target);
 }
Beispiel #4
0
 private void CopyComponentWithUndo(ComponentWrapper source, Component target)
 {
     Undo.RecordObject(target, "Copy component properties");
     CopyComponent(source, target);
     Undo.FlushUndoRecordObjects();
 }