private void OnEnable() { if (meshSource == null) { meshSource = new MeshSource(this); } base.wantsMouseMove = true; options.OnEnable(); needsMeshRefresh = true; }
public void Draw(Rect rect, MeshSource meshSource, List <Vector2> uvBuffer, EditorWindow host) { Rect leftBorder = rect; leftBorder.width = 1; Rect cursorRect = rect; cursorRect.width = 10; cursorRect.x -= 5; if (Event.current.type == EventType.MouseDown && cursorRect.Contains(Event.current.mousePosition)) { resize = true; Event.current.Use(); } if (resize && Event.current.type == EventType.MouseDrag) { normalizedPosition = Event.current.mousePosition.x / EditorGUIUtility.currentViewWidth; Event.current.Use(); if (Event.current.type == EventType.MouseDrag) { host.Repaint(); } } if (Event.current.type == EventType.MouseUp) { resize = false; } EditorGUIUtility.AddCursorRect(cursorRect, MouseCursor.ResizeHorizontal); rect = rect.Expand(-4); GUILayout.BeginArea(rect); float labelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 100; EditorGUILayout.LabelField("UV", EditorStyles.boldLabel); EditorGUI.indentLevel++; UVWindowSettings.uvAlpha.value = EditorGUILayout.Slider("Alpha", UVWindowSettings.uvAlpha, 0f, 1f); UVWindowSettings.uvColor.value = EditorGUILayout.ColorField( new GUIContent("Color"), UVWindowSettings.uvColor, showEyedropper: true, showAlpha: false, hdr: false); EditorGUI.BeginChangeCheck(); uvChannel = (UVChannel)EditorGUILayout.EnumPopup("Channel", uvChannel); if (EditorGUI.EndChangeCheck()) { if (meshSource != null) { meshSource.Mesh.GetUVs((int)uvChannel, uvBuffer); if (uvBuffer.Count == 0) { host.ShowNotification(new GUIContent($"No {uvChannel.ToString()} found.")); } else { host.RemoveNotification(); } } } EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.LabelField("Texture", EditorStyles.boldLabel); EditorGUI.indentLevel++; EditorGUI.BeginChangeCheck(); UVWindowSettings.textureAlpha.value = EditorGUILayout.Slider("Alpha", UVWindowSettings.textureAlpha, 0f, 1f); if (EditorGUI.EndChangeCheck()) { previewMaterial.SetFloat("_Alpha", UVWindowSettings.textureAlpha); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Color"); EditorGUI.BeginChangeCheck(); colorChannel = (ColorChannel)GUILayout.Toolbar((int)colorChannel, colorChannelLabels, GUI.skin.button, GUI.ToolbarButtonSize.FitToContents); if (EditorGUI.EndChangeCheck()) { UpdatePreviewMaterialColorMask(); } EditorGUILayout.EndHorizontal(); using (new EditorGUI.DisabledScope(meshSource.HasMaterial == false)) { if (meshSource.HasMaterial) { string[] names = meshSource.Material.GetTexturePropertyNames() .Where(x => meshSource.Material.HasProperty(x)).ToArray(); int selectedIndex = System.Array.IndexOf(names, texturePropertyName); if (selectedIndex == -1) { selectedIndex = 0; } EditorGUI.BeginChangeCheck(); selectedIndex = EditorGUILayout.Popup("Source Map", selectedIndex, names); if (EditorGUI.EndChangeCheck()) { texturePropertyName = names[selectedIndex]; } } else { EditorGUILayout.LabelField("Source Map", "<None>"); } } EditorGUI.indentLevel--; EditorGUIUtility.labelWidth = labelWidth; GUILayout.EndArea(); EditorGUI.DrawRect(leftBorder, new Color32(35, 35, 35, 255)); }