private void DrawMouldingColour(int colourID, int listIndex, bool multipleValues)
        {
            var position = EditorGUILayout.GetControlRect();

            // Draw label
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), new GUIContent("Moulding Colour " + listIndex));

            if (multipleValues)
            {
                // Create box and tooltip.
                GUI.Box(position, new GUIContent("", "Multiple colours selected"));
                var colorRect = new Rect(position.x + 1.0f, position.y + 1.0f, position.width - 2.0f, position.height - 2.0f);
                var lineRect  = new Rect(position.x + 1.0f, position.y + 1.0f + colorRect.height / 2.0f, 10.0f, 1.0f);
                EditorGUI.DrawRect(colorRect, new Color32(209, 209, 209, 255));
                EditorGUI.DrawRect(lineRect, Color.grey);
            }
            else
            {
                var mouldingColourID = (MouldingColour.Id)colourID;
                var colour           = MouldingColour.GetColour(mouldingColourID);

                // Create box and tooltip.
                GUI.Box(position, new GUIContent("", ObjectNames.NicifyVariableName((int)mouldingColourID + " - " + mouldingColourID.ToString())));

                // Draw rects with colour.
                var colorRect = new Rect(position.x + 1.0f, position.y + 1.0f, position.width - 2.0f, position.height - 2.0f - alphaBarHeight);
                var alphaRect = new Rect(position.x + 1.0f, position.y + 1.0f + colorRect.height, Mathf.Round((position.width - 2.0f) * colour.a), alphaBarHeight);
                var blackRect = new Rect(position.x + 1.0f + alphaRect.width, position.y + 1.0f + colorRect.height, position.width - 2.0f - alphaRect.width, alphaBarHeight);
                EditorGUI.DrawRect(colorRect, new Color(colour.r, colour.g, colour.b));
                EditorGUI.DrawRect(alphaRect, Color.white);
                EditorGUI.DrawRect(blackRect, Color.black);
            }

            // Detect click.
            if (Event.current.type == EventType.MouseDown)
            {
                if (position.Contains(Event.current.mousePosition))
                {
                    MouldingColourPicker.Show((c) =>
                    {
                        // Collect all parts to record for undo.
                        foreach (var target in targets)
                        {
                            var brickTarget = (Brick)target;
                            Undo.RegisterFullObjectHierarchyUndo(brickTarget.gameObject, "Changed Material");

                            int indexOffset = 0;
                            foreach (var partTarget in brickTarget.parts)
                            {
                                if (indexOffset <= listIndex && listIndex < indexOffset + partTarget.materialIDs.Count)
                                {
                                    Undo.RegisterFullObjectHierarchyUndo(partTarget.gameObject, "Changed Material");

                                    break;
                                }
                                indexOffset += partTarget.materialIDs.Count;
                            }
                        }

                        // Collect all parts to change the material.
                        foreach (var target in targets)
                        {
                            var brickTarget = (Brick)target;
                            int indexOffset = 0;
                            foreach (var partTarget in brickTarget.parts)
                            {
                                if (indexOffset <= listIndex && listIndex < indexOffset + partTarget.materialIDs.Count)
                                {
                                    // Update material ID.
                                    partTarget.materialIDs[listIndex - indexOffset] = (int)MouldingColour.GetId(c);

                                    // Collect all materials.
                                    LXFMLDoc.Brick.Part.Material[] materials = new LXFMLDoc.Brick.Part.Material[partTarget.materialIDs.Count];
                                    for (var i = 0; i < partTarget.materialIDs.Count; ++i)
                                    {
                                        materials[i] = new LXFMLDoc.Brick.Part.Material()
                                        {
                                            colorId = partTarget.materialIDs[i], shaderId = 0
                                        };
                                    }

                                    // Update the part materials.
                                    ModelImporter.SetMaterials(partTarget, materials, partTarget.legacy);

                                    // Update knobs and tubes of this brick and the bricks it is connected to directly.
                                    var connectedBricks = partTarget.brick.GetConnectedBricks(false);
                                    connectedBricks.Add(partTarget.brick);
                                    foreach (var brick in connectedBricks)
                                    {
                                        foreach (var part in brick.parts)
                                        {
                                            if (!part.legacy && part.connectivity)
                                            {
                                                foreach (var connectionField in part.connectivity.connectionFields)
                                                {
                                                    foreach (var connection in connectionField.connections)
                                                    {
                                                        connection.UpdateKnobsAndTubes();
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }

                                indexOffset += partTarget.materialIDs.Count;
                            }
                        }

                        // Collect all parts to record prefab instance modifications.
                        foreach (var target in targets)
                        {
                            var brickTarget = (Brick)target;
                            if (PrefabUtility.IsPartOfAnyPrefab(brickTarget.gameObject))
                            {
                                PrefabUtility.RecordPrefabInstancePropertyModifications(brickTarget.gameObject);
                            }

                            int indexOffset = 0;
                            foreach (var partTarget in brickTarget.parts)
                            {
                                if (indexOffset <= listIndex && listIndex < indexOffset + partTarget.materialIDs.Count)
                                {
                                    if (PrefabUtility.IsPartOfAnyPrefab(partTarget.gameObject))
                                    {
                                        PrefabUtility.RecordPrefabInstancePropertyModifications(partTarget.gameObject);
                                    }
                                    break;
                                }
                                indexOffset += partTarget.materialIDs.Count;
                            }
                        }
                    },
                                              false,
                                              false,
                                              true
                                              );
                }
            }
        }
        private void DrawMouldingColour(SerializedProperty property, GUIContent label)
        {
            var position = EditorGUILayout.GetControlRect();

            // Draw label
            position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

            if (property.hasMultipleDifferentValues)
            {
                // Create box and tooltip.
                GUI.Box(position, new GUIContent("", "Multiple colours selected"));
                var colorRect = new Rect(position.x + 1.0f, position.y + 1.0f, position.width - 2.0f, position.height - 2.0f);
                var lineRect  = new Rect(position.x + 1.0f, position.y + 1.0f + colorRect.height / 2.0f, 10.0f, 1.0f);
                EditorGUI.DrawRect(colorRect, new Color32(209, 209, 209, 255));
                EditorGUI.DrawRect(lineRect, Color.grey);
            }
            else
            {
                var mouldingColourId = (MouldingColour.Id)property.intValue;
                var colour           = MouldingColour.GetColour(mouldingColourId);

                // Create box and tooltip.
                GUI.Box(position, new GUIContent("", ObjectNames.NicifyVariableName((int)mouldingColourId + " - " + mouldingColourId.ToString())));

                // Draw rects with colour.
                var colorRect = new Rect(position.x + 1.0f, position.y + 1.0f, position.width - 2.0f, position.height - 2.0f - alphaBarHeight);
                var alphaRect = new Rect(position.x + 1.0f, position.y + 1.0f + colorRect.height, Mathf.Round((position.width - 2.0f) * colour.a), alphaBarHeight);
                var blackRect = new Rect(position.x + 1.0f + alphaRect.width, position.y + 1.0f + colorRect.height, position.width - 2.0f - alphaRect.width, alphaBarHeight);
                EditorGUI.DrawRect(colorRect, new Color(colour.r, colour.g, colour.b));
                EditorGUI.DrawRect(alphaRect, Color.white);
                EditorGUI.DrawRect(blackRect, Color.black);
            }

            // Detect click.
            if (Event.current.type == EventType.MouseDown)
            {
                if (position.Contains(Event.current.mousePosition))
                {
                    MouldingColourPicker.Show((c) =>
                    {
                        property.intValue = (int)MouldingColour.GetId(c);

                        // Collect all materials.
                        LXFMLDoc.Brick.Part.Material[] materials = new LXFMLDoc.Brick.Part.Material[materialIDsProp.arraySize];
                        for (var i = 0; i < materialIDsProp.arraySize; ++i)
                        {
                            materials[i] = new LXFMLDoc.Brick.Part.Material()
                            {
                                colorId = materialIDsProp.GetArrayElementAtIndex(i).intValue, shaderId = 0
                            };
                        }

                        // Run through all targeted parts and record them for undo.
                        foreach (var target in targets)
                        {
                            var partTarget = (Part)target;

                            // Register state before updating materials.
                            Undo.RegisterFullObjectHierarchyUndo(partTarget.gameObject, "Changed Material");
                        }

                        // Run through all targeted parts and update them.
                        foreach (var target in targets)
                        {
                            var partTarget = (Part)target;

                            // Update the part materials.
                            ModelImporter.SetMaterials(partTarget, materials, legacyProp.boolValue);

                            // Apply the new colour to the serialized property.
                            property.serializedObject.ApplyModifiedProperties();

                            // Update knobs and tubes of this brick and the bricks it is connected to directly.
                            var connectedBricks = partTarget.brick.GetConnectedBricks(false);
                            connectedBricks.Add(partTarget.brick);
                            foreach (var brick in connectedBricks)
                            {
                                foreach (var part in brick.parts)
                                {
                                    if (!part.legacy)
                                    {
                                        foreach (var connectionField in part.connectivity.connectionFields)
                                        {
                                            foreach (var connection in connectionField.connections)
                                            {
                                                connection.UpdateKnobsAndTubes();
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    },
                                              false,
                                              false,
                                              true
                                              );
                }
            }
        }