/// <summary> /// Creates a new material parameter GUI. /// </summary> /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of texture type.</param> /// <param name="material">Material the parameter is a part of.</param> /// <param name="layout">Layout to append the GUI elements to.</param> internal MaterialParamTextureGUI(ShaderParameter shaderParam, Material material, GUILayout layout) : base(shaderParam) { LocString title = new LocEdString(shaderParam.name); GUITextureFieldType type = shaderParam.type == ShaderParameterType.Texture2D ? GUITextureFieldType.TextureOrSpriteTexture : GUITextureFieldType.Texture; guiElem = new GUITextureField(type, title); switch (shaderParam.type) { case ShaderParameterType.Texture2D: case ShaderParameterType.Texture3D: case ShaderParameterType.TextureCube: guiElem.OnChanged += (x) => { string path = ProjectLibrary.GetPath(x.UUID); if (!string.IsNullOrEmpty(path)) { if (ProjectLibrary.GetEntry(path) is FileEntry fileEntry) { if (fileEntry.ResourceMetas.Length > 0) { ResourceMeta meta = fileEntry.ResourceMetas[0]; if (meta.ResType == ResourceType.SpriteTexture) { material.SetSpriteTexture(shaderParam.name, x.As <SpriteTexture>()); } else if (meta.ResType == ResourceType.Texture) { material.SetTexture(shaderParam.name, x.As <Texture>()); } } } } else { material.SetTexture(shaderParam.name, null); } EditorApplication.SetDirty(material); }; break; } layout.AddElement(guiElem); }
private static extern void Internal_CreateInstance(GUITextureField instance, GUITextureFieldType type, ref GUIContent title, int titleWidth, string style, GUIOption[] options, bool withTitle);
/// <summary> /// Creates a new texture field element without a label. /// </summary> /// <param name="type">Determines the type of textures should the field accept.</param> /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as /// default layout options. Style will be retrieved from the active GUISkin. If not specified /// default element style is used.</param> /// <param name="options">Options that allow you to control how is the element positioned and sized. This will /// override any similar options set by style.</param> public GUITextureField(GUITextureFieldType type, string style = "", params GUIOption[] options) { GUIContent emptyContent = new GUIContent(); Internal_CreateInstance(this, type, ref emptyContent, 0, style, options, false); }
/// <summary> /// Creates a new texture field element with a label. /// </summary> /// <param name="type">Determines the type of textures should the field accept.</param> /// <param name="title">Content to display on the label.</param> /// <param name="titleWidth">Width of the title label in pixels.</param> /// <param name="style">Optional style to use for the element. Style controls the look of the element, as well as /// default layout options. Style will be retrieved from the active GUISkin. If not specified /// default element style is used.</param> /// <param name="options">Options that allow you to control how is the element positioned and sized. This will /// override any similar options set by style.</param> public GUITextureField(GUITextureFieldType type, GUIContent title, int titleWidth = 100, string style = "", params GUIOption[] options) { Internal_CreateInstance(this, type, ref title, titleWidth, style, options, true); }