using System;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using Object = UnityEngine.Object;
namespace UnityEditor.Rendering
{
/// Class containing constants
public static class CoreEditorConstants
{
/// Speed of additional properties highlight.
public static readonly float additionalPropertiesHightLightSpeed = 0.3f;
/// Standard UI spacing
public static float standardHorizontalSpacing => 5f;
}
/// Class containing style definition
public static class CoreEditorStyles
{
#region Styles
static System.Lazy m_SmallTickbox = new(() => new GUIStyle("ShurikenToggle"));
/// Style for a small checkbox
public static GUIStyle smallTickbox => m_SmallTickbox.Value;
static System.Lazy m_SmallMixedTickbox = new(() => new GUIStyle("ShurikenToggleMixed"));
/// Style for a small checkbox in mixed state
public static GUIStyle smallMixedTickbox => m_SmallMixedTickbox.Value;
static GUIStyle m_MiniLabelButton;
/// Style for a minilabel button
public static GUIStyle miniLabelButton
{
get
{
if (m_MiniLabelButton == null)
{
m_MiniLabelButton = new GUIStyle(EditorStyles.miniLabel)
{
normal = new GUIStyleState
{
background = m_TransparentTexture,
scaledBackgrounds = null,
textColor = Color.grey
}
};
var activeState = new GUIStyleState
{
background = m_TransparentTexture,
scaledBackgrounds = null,
textColor = Color.white
};
m_MiniLabelButton.active = activeState;
m_MiniLabelButton.onNormal = activeState;
m_MiniLabelButton.onActive = activeState;
return m_MiniLabelButton;
}
return m_MiniLabelButton;
}
}
static System.Lazy m_ContextMenuStyle = new(() => new GUIStyle("IconButton"));
/// Context Menu button style
public static GUIStyle contextMenuStyle => m_ContextMenuStyle.Value;
static System.Lazy m_AdditionalPropertiesHighlightStyle = new(() => new GUIStyle { normal = { background = Texture2D.whiteTexture } });
/// Style of a additional properties highlighted background.
public static GUIStyle additionalPropertiesHighlightStyle => m_AdditionalPropertiesHighlightStyle.Value;
/// Help icon style
public static GUIStyle iconHelpStyle => GUI.skin.FindStyle("IconButton") ?? EditorGUIUtility.GetBuiltinSkin(EditorSkin.Inspector).FindStyle("IconButton");
static System.Lazy m_SectionHeaderStyle = new(() => new GUIStyle(EditorStyles.largeLabel) { richText = true, fontSize = 18, fixedHeight = 42 });
/// Style of Section Headers.
public static GUIStyle sectionHeaderStyle => m_SectionHeaderStyle.Value;
static System.Lazy m_SubSectionHeaderStyle = new(() => new GUIStyle(EditorStyles.boldLabel));
/// Style of Sub-Section Headers.
public static GUIStyle subSectionHeaderStyle => m_SubSectionHeaderStyle.Value;
static System.Lazy m_HelpBox = new(() =>
{
var style = new GUIStyle()
{
imagePosition = ImagePosition.ImageLeft,
fontSize = 10,
wordWrap = true,
alignment = TextAnchor.MiddleLeft
};
style.normal.textColor = EditorStyles.helpBox.normal.textColor;
return style;
});
internal static GUIStyle helpBox => m_HelpBox.Value;
#endregion
#region Textures 2D
static Texture2D m_TransparentTexture;
/// 1x1 pixel with red color
public static readonly Texture2D redTexture;
/// 1x1 pixel with green color
public static readonly Texture2D greenTexture;
/// 1x1 pixel with blue color
public static readonly Texture2D blueTexture;
/// PaneOption icon for dark skin
static readonly Texture2D paneOptionsIconDark;
/// PaneOption icon for light skin
static readonly Texture2D paneOptionsIconLight;
/// PaneOption icon
public static Texture2D paneOptionsIcon => EditorGUIUtility.isProSkin ? paneOptionsIconDark : paneOptionsIconLight;
/// Warning icon
public static readonly Texture2D iconWarn;
/// Help icon
public static readonly Texture2D iconHelp;
/// Fail icon
public static readonly Texture2D iconFail;
/// Success icon
public static readonly Texture2D iconSuccess;
/// Complete icon
public static readonly Texture2D iconComplete;
/// Pending icon
public static readonly Texture2D iconPending;
/// RenderPipeline Global Settings icon
public static readonly Texture2D globalSettingsIcon;
///
/// Gets the icon that describes the
///
/// The to obtain the icon from
/// a with the icon for the
internal static Texture2D GetMessageTypeIcon(MessageType messageType)
{
switch (messageType)
{
case MessageType.None:
return null;
case MessageType.Info:
return iconHelp;
case MessageType.Warning:
return iconWarn;
case MessageType.Error:
return iconFail;
default:
throw new ArgumentOutOfRangeException(nameof(messageType), messageType, null);
}
}
#endregion
#region Colors
static readonly Color m_LightThemeBackgroundColor;
static readonly Color m_LightThemeBackgroundHighlightColor;
static readonly Color m_DarkThemeBackgroundColor;
static readonly Color m_DarkThemeBackgroundHighlightColor;
/// Regular background color.
public static Color backgroundColor => EditorGUIUtility.isProSkin ? m_DarkThemeBackgroundColor : m_LightThemeBackgroundColor;
/// Hightlited background color.
public static Color backgroundHighlightColor => EditorGUIUtility.isProSkin ? m_DarkThemeBackgroundHighlightColor : m_LightThemeBackgroundHighlightColor;
#endregion
#region GUIContents
/// Context Menu button icon
public static readonly GUIContent contextMenuIcon;
/// Reset Content
public static readonly GUIContent resetButtonLabel = EditorGUIUtility.TrTextContent("Reset");
/// Reset All content
public static readonly GUIContent resetAllButtonLabel = EditorGUIUtility.TrTextContent("Reset All");
///
/// Empty space content in case that you want to keep the indentation but have nothing to write
///
public static readonly GUIContent empty = EditorGUIUtility.TrTextContent(" ");
#endregion
static CoreEditorStyles()
{
m_TransparentTexture = new Texture2D(1, 1, GraphicsFormat.R8G8B8A8_SRGB, TextureCreationFlags.None)
{
name = "transparent"
};
m_TransparentTexture.SetPixel(0, 0, Color.clear);
m_TransparentTexture.Apply();
paneOptionsIconDark = CoreEditorUtils.LoadIcon("Builtin Skins/DarkSkin/Images", "pane options", ".png");
paneOptionsIconDark.name = "pane options dark skin";
paneOptionsIconLight = CoreEditorUtils.LoadIcon("Builtin Skins/LightSkin/Images", "pane options", ".png");
paneOptionsIconLight.name = "pane options light skin";
m_LightThemeBackgroundColor = new Color(0.7843138f, 0.7843138f, 0.7843138f, 1.0f);
m_LightThemeBackgroundHighlightColor = new Color32(174, 174, 174, 255);
m_DarkThemeBackgroundColor = new Color(0.2196079f, 0.2196079f, 0.2196079f, 1.0f);
m_DarkThemeBackgroundHighlightColor = new Color32(77, 77, 77, 255);
const string contextTooltip = ""; // To be defined (see with UX)
contextMenuIcon = new GUIContent(paneOptionsIcon, contextTooltip);
redTexture = CoreEditorUtils.CreateColoredTexture2D(Color.red, "Red 1x1");
greenTexture = CoreEditorUtils.CreateColoredTexture2D(Color.green, "Green 1x1");
blueTexture = CoreEditorUtils.CreateColoredTexture2D(Color.blue, "Blue 1x1");
iconHelp = CoreEditorUtils.FindTexture("_Help");
iconWarn = CoreEditorUtils.LoadIcon("icons", "console.warnicon", ".png");
iconFail = CoreEditorUtils.LoadIcon("icons", "console.erroricon", ".png");
iconSuccess = EditorGUIUtility.FindTexture("TestPassed");
iconComplete = CoreEditorUtils.LoadIcon("icons", "GreenCheckmark", ".png");
iconPending = EditorGUIUtility.FindTexture("Toolbar Minus");
globalSettingsIcon = EditorGUIUtility.FindTexture("ScriptableObject Icon");
// Make sure that textures are unloaded on domain reloads.
void OnBeforeAssemblyReload()
{
Object.DestroyImmediate(redTexture);
Object.DestroyImmediate(greenTexture);
Object.DestroyImmediate(blueTexture);
Object.DestroyImmediate(m_TransparentTexture);
AssemblyReloadEvents.beforeAssemblyReload -= OnBeforeAssemblyReload;
}
AssemblyReloadEvents.beforeAssemblyReload += OnBeforeAssemblyReload;
}
}
}