CustomWindows.Texture2DArrayWindowBase
Description
Unity Editor Only
Base class for creating the Create/Configure Array windows
Variables
Variable | Description |
---|---|
_textures | The textures that are assigned in the window Should be updated in tandem with _texturesResizing & _textureErrors |
_texturesResizing | AUTOMATICALLY UPDATES Which textures have been marked as resizing Should be updated in tandem with textures & _textureErrors |
_textureErrors | AUTOMATICALLY UPDATES Which textures have an error that needs to be addressed Should be updated in tandem with textures & _texturesResizing |
_arrayCompressed | Default: true If the output array will be in the format DXT5 (Compressed) or RGBA32 (Uncompressed) Modifiable in the window |
_arrayMipMaps | Default: true If the output array will transfer mipmaps from the inputted textures Modifiable in the window |
_arrayLinear | Default: false If the output array will be linear Recommended in the Built-In Render Pipeline only when including normal maps Not Recommended in URP/HDRP as it will result in brighter textures Modifiable in the window |
_arrayWrapMode | Default: TextureWrapMode.Repeat The Wrap Mode of the output array Modifiable in the window |
_arrayFilterMode | Default: FilterMode.Bilinear The Filter Mode of the output array Modifiable in the window |
_arrayAnisoLevel | Default: 1 The Aniso Level of the output array Modifiable in the window |
_resizeTextures | Default: False If all the inputted textures will be resized to _arrayResolution Modifiable in the window |
_arrayResolution | Default: First Assigned Texture Resolution The resolution that all inputted textures will be resized to if _resizeTextures is enabled Displayed and modifiable in the window when _resizeTextures enabled |
_resizeFilterMode | Default: FilterMode.Bilinear The filter mode used when resizing textures Displayed and modifiable in the window when _resizeTextures enabled or _texturesResizing has any values set to true |
_compressionSettingEnabled | Default: True If the Compression setting appears in the window |
_mipmapsSettingEnabled | Default: True If the Generate Mipmaps setting appears in the window |
_linearSettingEnabled | Default: True If the Linear setting appears in the window |
_wrapModeSettingEnabled | Default: True If the Wrap Mode setting appears in the window |
_filterModeSettingEnabled | Default: True If the Filter Mode setting appears in the window |
_anisoLevelSettingEnabled | Default: True If the Aniso Level setting appears in the window |
_resizeSettingEnabled | Default: True If the Resize Textures setting appears in the window |
_headerStyle | Style used for headers in the GUI |
Example
Custom window example with a create array button
using UnityEngine;
using TextureArrayUtilities.CustomWindows;
#if UNITY_EDITOR
using UnityEditor;
public class CustomArrayWindow : Texture2DArrayWindowBase
{
// Creates the window
protected static void ShowWindow()
{
CustomArrayWindow window = GetWindow<CustomArrayWindow>(false, "Custom Window");
window.Show();
}
// Setting the MenuItem as "Assets/..." will allow opening the window through the right click menu in the Project window
[MenuItem("Assets/CustomArrayWindow")]
static void CreateWindowInProjectContextMenu(MenuCommand command)
{
ShowWindow();
}
// Setting the MenuItem as "Tools/..." for example will allow opening the window through the toolbar
[MenuItem("Tools/CustomArrayWindow")]
static void CreateWindowInToolbar(MenuCommand command)
{
ShowWindow();
}
protected override void OnGUIUpdate()
{
// All the array textures and settings are drawn in base.OnGUIUpdate()
// Everything can be modified through the
base.OnGUIUpdate();
// Example button to create the array in the Assets path
if(GUILayout.Button("Create Array")) {
CreateArray("Assets/TextureArray.asset");
// Close Window
Close();
}
}
}
#endif
CreateGUI
Declaration
protected virtual void CreateGUI()
Description
Called when the GUI is first created
base.CreateGUI(); Must be called before performing operations
protected override void CreateGUI()
{
base.CreateGUI();
// Code executed when GUI first created
}
OnGUIUpdate
Declaration
protected virtual void OnGUIUpdate()
Description
Called every GUI update, used due to other tasks in OnGUI
base.OnGUI(); Will draw the textures, settings, and output sections
protected override void OnGUIUpdate()
{
// All code executed here will be called for each update in OnGUI
// GUI at the top of the window performed before base
base.OnGUIUpdate();
// GUI at the bottom of the window performed after base
}
CalculateElementHeight
Declaration
protected virtual float CalculateElementHeight(int index)
Parameters
Parameter | Description |
---|---|
index | Index of the texture list which the height is being calculated for the ReorderableList GUI |
Returns
Height that the element will use
Description
Calculates the height of an element for the ReorderableList GUI where the textures are assigned
base.CalculateElementHeight(); Must be called before performing operations and will return the pre-calculated height
protected override float CalculateElementHeight(int index)
{
float height = base.CalculateElementHeight(index);
// Calculate element height here
return height;
}
DrawTextureField
Declaration
protected virtual void DrawTextureField(Rect rect, int index, bool isActive, bool isFocused)
Parameters
Parameter | Description |
---|---|
rect | Rect with all the available space in the element Available space is calculated and can be changed in CalculateElementHeight |
index | The index of the current element in the textures list |
isActive | If this element is is being moved or interacted with in the GUI |
isFocused | If this element is selected in the GUI |
Description
Draws a texture element in the textures list
When modifying the height in any way Repaint(); should be called to update it on the same GUI call, otherwise will be updated on the next
protected override float CalculateElementHeight(int index)
{
float height = base.CalculateElementHeight(index);
// Calculate element height here
return height;
}
DrawArraySettings
Declaration
protected virtual void DrawArraySettings()
Description
Draws the settings of the output array. Settings that are enabled here can be toggles with the respective settingEnabled variables
All GUI called here will be drawn within the Array Settings section
base.DrawArraySettings() will draw the settings
protected override void DrawArraySettings()
{
// GUI before the main settings within the Array Settings Section
base.DrawArraySettings();
// GUI after the main settings within the Array Settings Section
}
DrawFinalOutputFields
Declaration
protected virtual void DrawFinalOutputFields()
Description
Draws the details of the output array
All GUI called here will be drawn within the Final Output section
base.DrawFinalOutputFields() will draw the final output details
protected override void DrawFinalOutputFields()
{
// GUI before the main output details the Final Output Section
base.DrawFinalOutputFields();
// GUI after the main output details within the Final Output Section
}
DisplayWarnings
Declaration
protected virtual void DisplayWarnings()
Description
Displays any warnings for array creation
All GUI called here will be drawn within and at the bottom of the Final Output section
base.DisplayWarnings() must be called before showing any extra warnings
protected override void DisplayWarnings()
{
base.DisplayWarnings();
// Display any extra warnings here
// Example
// if(warningCondition) {
// EditorGUILayout.HelpBox("Warning", MessageType.Warning);
// }
}
OnTextureAdd
Declaration
protected virtual void OnTextureAdd(ReorderableList list)
Parameters
Parameter | Description |
---|---|
list The ReorderableList used for displaying the GUI s |
Description
Called when the add button is clicked in the ReorderableList GUI
base.OnTextureAdd() will add a texture to the texture lists and should be called
protected override void OnTextureAdd(ReorderableList list)
{
// Code executed before a texture is added
base.OnTextureAdd(list);
// Code executed after a texture is added
}
OnTextureRemove
Declaration
protected virtual void OnTextureRemove(ReorderableList list)
Parameters
Parameter | Description |
---|---|
list | The ReorderableList used for displaying the GUI |
Description
Called when the remove button or delete key is pressed in the ReorderableList GUI
base.OnTextureRemove() will remove the selected texture from the texture lists and should be called
protected override void OnTextureRemove(ReorderableList list)
{
// Code executed before a texture is removed
base.OnTextureRemove(list);
// Code executed after a texture is removed
}
OnTexturesReorder
Declaration
protected virtual void OnTexturesReorder(ReorderableList list, int oldActiveElement, int newActiveElement)
Parameters
Parameter | Description |
---|---|
list | The ReorderableList used for displaying the GUI |
oldActiveElement | The previous index of the reordered element |
newActiveElement | The new index of the reordered element |
Description
Called when the textures are reordered in the ReorderableList GUI
base.OnTexturesReorder() will handle reordering the texture lists and should be called
protected override void OnTexturesReorder(ReorderableList list, int oldActiveElement, int newActiveElement)
{
// Code executed before a texture is removed
base.OnTexturesReorder(list, oldActiveElement, newActiveElement);
// Code executed after a texture is removed
}
OnDragUpdate
Declaration
protected virtual void OnDragUpdate(Object[] objectReferences)
Parameters
Parameter | Description |
---|---|
objectReferences | The items that are being dragged |
Description
Called every update while anything is dragged over the window
base.OnDragUpdate(); Must be called before performing operations
protected override void OnDragUpdate(Object[] objectReferences)
{
base.OnDragUpdate(objectReferences);
// Handle dragged items
}
OnDragPerform
Declaration
protected virtual void OnDragPerform(Object[] objectReferences)
Parameters
Parameter | Description |
---|---|
objectReferences | The items that are being dragged |
Description
Called when the drag is complete over the window
base.OnDragPerform(); Must be called before performing operations
protected override void OnDragPerform(Object[] objectReferences)
{
base.OnDragPerform(objectReferences);
// Handle dragged items
}
ArrayTexturesExist
Declaration
protected bool ArrayTexturesExist()
Returns
If any textures exist in the list
Description
Checks if any textures exist in the list
CreateArray
Declaration
protected void CreateArray(string path)
Parameters
Parameter | Description |
---|---|
path | The file location that the array will be created within the project folder Should always start with "Assets/" |
Description
Creates the array using the specified textures and settings at a given path
Example creating an array with a button
protected override void OnGUIUpdate()
{
// Draw GUI
base.OnGUIUpdate();
// Example button to create the array in the Assets path
if(GUILayout.Button("Create Array")) {
CreateArray("Assets/TextureArray.asset");
// Close Window
Close();
}
}