void OnGUI() { DoContextMenu(); GUILayout.Label("Quick Material", EditorStyles.boldLabel); Rect r = GUILayoutUtility.GetLastRect(); int left = Screen.width - 68; GUILayout.BeginHorizontal(GUILayout.MaxWidth(Screen.width - 74)); GUILayout.BeginVertical(); m_QueuedMaterial = (Material)EditorGUILayout.ObjectField(m_QueuedMaterial, typeof(Material), true); GUILayout.Space(2); if (GUILayout.Button("Apply (Ctrl+Shift+Click)")) ApplyMaterial(MeshSelection.topInternal, m_QueuedMaterial); GUI.enabled = editor != null && MeshSelection.selectedFaceCount > 0; if (GUILayout.Button("Match Selection")) { m_QueuedMaterial = EditorMaterialUtility.GetActiveSelection(); } GUI.enabled = true; GUILayout.EndVertical(); GUI.Box(new Rect(left, r.y + r.height + 2, 64, 64), ""); var previewTexture = EditorMaterialUtility.GetPreviewTexture(m_QueuedMaterial); if (previewTexture != null) { GUI.Label(new Rect(left + 2, r.y + r.height + 4, 60, 60), previewTexture); } else { GUI.Box(new Rect(left + 2, r.y + r.height + 4, 60, 60), ""); GUI.Label(new Rect(left + 2, r.height + 28, 120, 32), "None\n(Texture)"); } GUILayout.EndHorizontal(); GUILayout.Space(4); GUI.backgroundColor = PreferenceKeys.proBuilderDarkGray; UI.EditorGUIUtility.DrawSeparator(2); GUI.backgroundColor = Color.white; GUILayout.Label("Material Palette", EditorStyles.boldLabel); EditorGUI.BeginChangeCheck(); m_CurrentPaletteIndex = EditorGUILayout.Popup("", m_CurrentPaletteIndex, m_AvailablePalettes_Str); if (EditorGUI.EndChangeCheck()) { MaterialPalette newPalette = null; // Add a new material palette if (m_CurrentPaletteIndex >= m_AvailablePalettes.Length) { string path = AssetDatabase.GenerateUniqueAssetPath("Assets/Material Palette.asset"); newPalette = FileUtility.LoadRequired<MaterialPalette>(path); EditorGUIUtility.PingObject(newPalette); } else { newPalette = m_AvailablePalettes[m_CurrentPaletteIndex]; } SetMaterialPalette(newPalette); } EditorGUI.BeginChangeCheck(); s_CurrentPalette = (MaterialPalette)EditorGUILayout.ObjectField(s_CurrentPalette, typeof(MaterialPalette), false); if (EditorGUI.EndChangeCheck()) SetMaterialPalette(s_CurrentPalette); GUILayout.Space(4); Material[] materials = CurrentPalette; m_ViewScroll = GUILayout.BeginScrollView(m_ViewScroll); for (int i = 0; i < materials.Length; i++) { if (i == 10) { GUILayout.Space(2); GUI.backgroundColor = PreferenceKeys.proBuilderLightGray; UI.EditorGUIUtility.DrawSeparator(1); GUI.backgroundColor = Color.white; GUILayout.Space(2); } GUILayout.BeginHorizontal(); if (i < 10) { if (GUILayout.Button("Alt + " + (i == 9 ? 0 : (i + 1)).ToString(), EditorStyles.miniButton, GUILayout.MaxWidth(58))) ApplyMaterial(MeshSelection.topInternal, materials[i]); } else { if (GUILayout.Button("Apply", EditorStyles.miniButtonLeft, GUILayout.MaxWidth(44))) ApplyMaterial(MeshSelection.topInternal, materials[i]); GUI.backgroundColor = Color.red; if (GUILayout.Button("", EditorStyles.miniButtonRight, GUILayout.MaxWidth(14))) { Material[] temp = new Material[materials.Length - 1]; System.Array.Copy(materials, 0, temp, 0, materials.Length - 1); materials = temp; SaveUserMaterials(materials); return; } GUI.backgroundColor = Color.white; } EditorGUI.BeginChangeCheck(); materials[i] = (Material)EditorGUILayout.ObjectField(materials[i], typeof(Material), false); if (EditorGUI.EndChangeCheck()) SaveUserMaterials(materials); GUILayout.EndHorizontal(); } if (GUILayout.Button("Add")) { Material[] temp = new Material[materials.Length + 1]; System.Array.Copy(materials, 0, temp, 0, materials.Length); materials = temp; SaveUserMaterials(materials); } GUILayout.EndScrollView(); }