private void OverrideGradientTexture(Rect position) { Rect gradient_texture_position = new Rect(position); float modeHeight = 24f; float swatchHeight = 16f; float editSectionHeight = 26f; float gradientTextureHeight = gradient_texture_position.height - 2 * swatchHeight - editSectionHeight - modeHeight; gradient_texture_position.y += modeHeight; gradient_texture_position.y += swatchHeight; gradient_texture_position.height = gradientTextureHeight; Rect r2 = new Rect(gradient_texture_position.x + 1, gradient_texture_position.y + 1, gradient_texture_position.width - 2, gradient_texture_position.height - 2); Texture2D backgroundTexture = TextureHelper.GetBackgroundTexture(); Rect texCoordsRect = new Rect(0, 0, r2.width / backgroundTexture.width, r2.height / backgroundTexture.height); GUI.DrawTextureWithTexCoords(r2, backgroundTexture, texCoordsRect, false); TextureWrapMode wrap_mode = data.preview_texture.wrapMode; data.preview_texture.wrapMode = TextureWrapMode.Clamp; GUI.DrawTexture(r2, data.preview_texture, ScaleMode.StretchToFill, true); GUI.DrawTexture(gradient_texture_position, data.preview_texture, ScaleMode.StretchToFill, false, 0, Color.grey, 1, 1); data.preview_texture.wrapMode = wrap_mode; }
private void DrawBackgroundTexture() { Texture2D backgroundTexture = TextureHelper.GetBackgroundTexture(); Rect texCoordsRect = new Rect(0, 0, gradient_position.width / backgroundTexture.width, gradient_position.height / backgroundTexture.height); GUI.DrawTextureWithTexCoords(gradient_position, backgroundTexture, texCoordsRect, false); }
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { if (!is_init) { Init(prop); } EditorGUI.BeginChangeCheck(); GuiHelper.drawSmallTextureProperty(position, prop, label, editor, DrawingData.currentTexProperty.hasFoldoutProperties); if (EditorGUI.EndChangeCheck()) { Init(prop); } Rect border_position = new Rect(position.x + EditorGUIUtility.labelWidth, position.y, Screen.width - EditorGUIUtility.labelWidth - position.x - EditorGUI.indentLevel * 15 - 10, position.height); Rect gradient_position = new Rect(border_position.x + 1, border_position.y + 1, border_position.width - 2, border_position.height - 2); Texture2D backgroundTexture = TextureHelper.GetBackgroundTexture(); Rect texCoordsRect = new Rect(0, 0, gradient_position.width / backgroundTexture.width, gradient_position.height / backgroundTexture.height); GUI.DrawTextureWithTexCoords(gradient_position, backgroundTexture, texCoordsRect, false); if (data.preview_texture != null) { TextureWrapMode wrap_mode = data.preview_texture.wrapMode; data.preview_texture.wrapMode = TextureWrapMode.Clamp; bool vertical = data.preview_texture.height > data.preview_texture.width; Vector2 pivot = new Vector2(); if (vertical) { pivot = new Vector2(gradient_position.x, gradient_position.y + gradient_position.height); GUIUtility.RotateAroundPivot(-90, pivot); gradient_position.y += gradient_position.height; float h = gradient_position.width; gradient_position.width = gradient_position.height; gradient_position.y += h; gradient_position.height = -h; } GUI.DrawTexture(gradient_position, data.preview_texture, ScaleMode.StretchToFill, true); if (vertical) { GUIUtility.RotateAroundPivot(90, pivot); } GUI.DrawTexture(border_position, data.preview_texture, ScaleMode.StretchToFill, false, 0, Color.grey, 1, 1); data.preview_texture.wrapMode = wrap_mode; } else { GUI.DrawTexture(border_position, Texture2D.whiteTexture, ScaleMode.StretchToFill, false, 0, Color.grey, 1, 1); } if (Event.current.type == EventType.MouseDown && border_position.Contains(Event.current.mousePosition)) { GradientEditor.Open(data, prop, !ThryEditor.currentlyDrawing.currentProperty.options.force_texture_options); } }