/// <summary> /// Draw texture selector /// </summary> private void DrawSelectorEditor(TextureEditContainer tec, TextureSelectType type, bool drawEditor = true) { // Draw label string labelMsg; switch (type) { case TextureSelectType.Default: labelMsg = "Texture Selector"; break; case TextureSelectType.Cliff: labelMsg = "Cliff Selector"; break; case TextureSelectType.Multi: labelMsg = ""; break; default: labelMsg = ""; break; } GUILayout.Label(labelMsg, EditorStyles.boldLabel); Rect position = EditorGUILayout.BeginVertical(EditorStyles.helpBox, new GUILayoutOption[0]); // Settings Color tempBackColor = GUI.backgroundColor; const int imgSize = 50; const int spacing = 4; float totalSpacing = (float)spacing; position.width = Screen.width - (20.0f + spacing * 2.0f); // Set position Rect current = position; current.width = current.height = imgSize; current.x += spacing; current.y += spacing; // Get amount of columns int columnCount = (int)((position.width - (2 * spacing)) / (spacing + imgSize)); for (int i = 0; i < component.TerrainData.splatPrototypes.Length; i++) { GUI.backgroundColor = TP.Colors.UnSelectedColor; if (i > 0 && i % columnCount == 0) { // Do new line totalSpacing += imgSize + spacing; current.x = position.x + spacing; current.y = position.y + totalSpacing; } else if (i != 0) { current.x += imgSize + spacing; } switch (type) { case TextureSelectType.Default: // Set colour if (i == component.Textures.SelectedTexture) { GUI.backgroundColor = TP.Colors.SelectedPaintTextureColor; } else if (i == component.Textures.SelectedCliffBrush && component.Ramp.Active) { GUI.backgroundColor = Color.Lerp(TP.Colors.UnSelectedColor, TP.Colors.SelectedCliffTextureColor, 0.3f); } if (GUI.Button(current, component.TerrainData.splatPrototypes[i].texture)) { // Set selected texture if (component.Textures.SelectedCliffBrush == i) { component.Textures.SelectedCliffBrush = component.Textures.SelectedTexture; } component.Textures.SelectedTexture = i; } break; case TextureSelectType.Cliff: // Set colour if (i == component.Textures.SelectedCliffBrush) { GUI.backgroundColor = TP.Colors.SelectedCliffTextureColor; } else if (i == component.Textures.SelectedTexture) { GUI.backgroundColor = Color.Lerp(TP.Colors.UnSelectedColor, TP.Colors.SelectedPaintTextureColor, 0.3f); } if (GUI.Button(current, component.TerrainData.splatPrototypes[i].texture)) { // Set selected texture if (component.Textures.SelectedTexture == i) { component.Textures.SelectedTexture = component.Textures.SelectedCliffBrush; } component.Textures.SelectedCliffBrush = i; } break; case TextureSelectType.Multi: if (component.Textures.IsSelected(i)) { GUI.backgroundColor = TP.Colors.SelectedCliffTextureColor; } if (GUI.Button(current, component.TerrainData.splatPrototypes[i].texture)) { if (component.Textures.IsSelected(i)) { component.Textures.SelectedTextures &= ~(1 << i); } else { component.Textures.SelectedTextures |= 1 << i; } } break; } } // Reset settings GUI.backgroundColor = tempBackColor; totalSpacing += imgSize + spacing; current.x = position.x + spacing; current.y = position.y + totalSpacing; current.width = position.width; GUILayout.Space(totalSpacing); if (drawEditor) { switch (type) { case TextureSelectType.Default: DrawTextureEditor(tec, component.Textures.SelectedTexture); break; case TextureSelectType.Cliff: DrawTextureEditor(tec, component.Textures.SelectedCliffBrush); break; case TextureSelectType.Multi: //DrawTextureEditor(tec, component.Textures.SelectedTexture); break; } } EditorGUILayout.EndVertical(); }
/// <summary> /// Draw texture selector /// </summary> private void DrawSelectorEditor(TextureEditContainer tec, TextureSelectType type, bool drawEditor = true) { // Draw label string labelMsg; switch (type) { case TextureSelectType.Default: labelMsg = "Texture Selector"; break; case TextureSelectType.Cliff: labelMsg = "Cliff Selector"; break; case TextureSelectType.Multi: labelMsg = ""; break; default: labelMsg = ""; break; } GUILayout.Label(labelMsg, EditorStyles.boldLabel); Rect position = EditorGUILayout.BeginVertical(EditorStyles.helpBox, new GUILayoutOption[0]); // Settings Color tempBackColor = GUI.backgroundColor; const int imgSize = 50; const int spacing = 4; float totalSpacing = (float)spacing; position.width = Screen.width - (20.0f + spacing * 2.0f); // Set position Rect current = position; current.width = current.height = imgSize; current.x += spacing; current.y += spacing; // Get amount of columns int columnCount = (int)((position.width - (2 * spacing)) / (spacing + imgSize)); for (int i = 0; i < component.TerrainData.splatPrototypes.Length; i++) { GUI.backgroundColor = TP.Colors.UnSelectedColor; if (i > 0 && i % columnCount == 0) { // Do new line totalSpacing += imgSize + spacing; current.x = position.x + spacing; current.y = position.y + totalSpacing; } else if (i != 0) { current.x += imgSize + spacing; } switch (type) { case TextureSelectType.Default: // Set colour if (i == component.Textures.SelectedTexture) { GUI.backgroundColor = TP.Colors.SelectedPaintTextureColor; } else if (i == component.Textures.SelectedCliffBrush && component.Ramp.Active) { GUI.backgroundColor = Color.Lerp(TP.Colors.UnSelectedColor, TP.Colors.SelectedCliffTextureColor, 0.3f); } if (GUI.Button(current, component.TerrainData.splatPrototypes[i].texture)) { // Set selected texture if (component.Textures.SelectedCliffBrush == i) { component.Textures.SelectedCliffBrush = component.Textures.SelectedTexture; } component.Textures.SelectedTexture = i; } break; case TextureSelectType.Cliff: // Set colour if (i == component.Textures.SelectedCliffBrush) { GUI.backgroundColor = TP.Colors.SelectedCliffTextureColor; } else if (i == component.Textures.SelectedTexture) { GUI.backgroundColor = Color.Lerp(TP.Colors.UnSelectedColor, TP.Colors.SelectedPaintTextureColor, 0.3f); } if (GUI.Button(current, component.TerrainData.splatPrototypes[i].texture)) { // Set selected texture if (component.Textures.SelectedTexture == i) { component.Textures.SelectedTexture = component.Textures.SelectedCliffBrush; } component.Textures.SelectedCliffBrush = i; } break; case TextureSelectType.Multi: if (component.Textures.IsSelected(i)) { GUI.backgroundColor = TP.Colors.SelectedCliffTextureColor; } if (GUI.Button(current, component.TerrainData.splatPrototypes[i].texture)) { if (component.Textures.IsSelected(i)) { component.Textures.SelectedTextures &= ~(1 << i); } else { component.Textures.SelectedTextures |= 1 << i; } } break; } } // Reset settings GUI.backgroundColor = tempBackColor; totalSpacing += imgSize + spacing; current.x = position.x + spacing; current.y = position.y + totalSpacing; current.width = position.width; GUILayout.Space(totalSpacing); if (drawEditor) { switch (type) { case TextureSelectType.Default: DrawTextureEditor(tec, component.Textures.SelectedTexture); break; case TextureSelectType.Cliff: DrawTextureEditor(tec, component.Textures.SelectedCliffBrush); break; case TextureSelectType.Multi: //DrawTextureEditor(tec, component.Textures.SelectedTexture); break; } } EditorGUILayout.EndVertical(); }