// // Copyright (c) 2017 Anthony Marmont. All rights reserved. // Licensed for use under the Unity Asset Store EULA. See https://unity3d.com/legal/as_terms for full license information. // #pragma warning disable using System; using System.Runtime.CompilerServices; using UnityEngine; namespace AssetIcons { /// /// Used to specify that this member controls the 's assets' icon. /// /// /// In this example, we are using AssetIcons to draw a simple on a . /// /// using AssetIcons; /// using UnityEngine; /// /// [CreateAssetMenu(menuName = "Item")] /// public class Item : ScriptableObject /// { /// [AssetIcon] /// public Sprite Icon; /// } /// /// We can also use CSS styling to modify the graphics drawn by this attribute. In this example we are going to remove the max size limit on icons and tint it purple. /// /// using AssetIcons; /// using UnityEngine; /// /// [CreateAssetMenu(menuName = "Item")] /// public class Item : ScriptableObject /// { /// [AssetIcon(maxSize: 256)] /// public Sprite Icon; /// /// [AssetIcon(maxSize: 256, layer: -1, tint: "#000000ee")] /// public Color GenerateBackground() /// { /// return Color.black; /// } /// } /// /// /// /// This attribute can be placed on: /// /// The can be placed on the same member multiple times to draw the same graphic multiple times. /// /// [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)] public sealed class AssetIconAttribute : PropertyAttribute { private readonly AssetIconsStyle style; private readonly string filePath; private readonly int lineNumber; /// /// A style defined in the constructor of the . /// public AssetIconsStyle Style { get { return style; } } /// /// The local file path where this attribute is implemented. /// /// /// This field only has a value in the editor and will return null outside of the editor. /// /// public string FilePath { get { return filePath; } } /// /// The line number where this attribute implemented. /// /// /// This field only has a value in the editor and will return -1 outside of the editor. /// /// public int LineNumber { get { return lineNumber; } } /// /// Marks a field to be used as a graphic for a custom icon. /// /// An expression that's evaluated to determine the width of the icon. /// An expression that's evaluated to determine the height of the icon. /// An expression that's evaluated to determine a horizontal offset of the icon. /// An expression that's evaluated to determine a vertical offset of the icon. /// A value used to determine the max size of the icon. /// An anchor that all difference in scale is orientated around. /// A value used to determine the aspect of the icon. /// An expression that's evaluated to whether the icon should be displayed. /// A tint to apply to the icon. /// A value used to determine the layer of the icon. /// A font style to use on all rendered text. /// An anchor for all rendered text. /// A camera projection for all rendered Prefabs. /// The line number that this attribute is implemented. Indended for compiler usage. /// The local file path that this attribute is implemented. Indended for compiler usage. public AssetIconAttribute( string width = "100%", string height = "100%", string x = "0", string y = "0", int maxSize = 64, IconAnchor anchor = IconAnchor.Center, IconAspect aspect = IconAspect.Fit, string display = "true", string tint = IconColor.White, int layer = 0, FontStyle fontStyle = FontStyle.Normal, IconAnchor textAnchor = IconAnchor.Center, IconProjection projection = IconProjection.Perspective, #if UNITY_EDITOR && (!NET_2_0 && !NET_2_0_SUBSET && UNITY_2017_1_OR_NEWER) [CallerLineNumber] #endif int lineNumber = -1, #if UNITY_EDITOR && (!NET_2_0 && !NET_2_0_SUBSET && UNITY_2017_1_OR_NEWER) [CallerFilePath] #endif string filePath = null ) { style = new AssetIconsStyle() { Width = width, Height = height, X = x, Y = y, MaxSize = maxSize, Anchor = anchor, Aspect = aspect, Tint = tint, Layer = layer, FontStyle = fontStyle, Projection = projection, Display = display, TextAnchor = textAnchor, }; this.lineNumber = lineNumber; this.filePath = filePath; } } } #pragma warning restore