Skip to content

10. GUI Interaction

Bryan edited this page May 13, 2024 · 17 revisions

Table of Contents

How can I Interact With the TextureSwapper Data?

To work with the TextureSwapper's data, you need to use specific functions found in the 07. TextureManagement script. You can interact with this system in various ways, whether through custom scripting or with Unity's GUI buttons using the already existing code.

What Variables do I Reference for Texture Swapping Using the TextureManagement Script?

  • TextureManagement Reference: Always reference the TextureManagement script directly. There can be limitless TextureManagement script objects in your scene. Any modifications must account for this variable as you send queries to a TextureManagement script for the TextureSwapper process to act accordingly.

  • "selectedRelationshipIndex" Variable: This is the equivalent of the "Body Part" you wish to swap. Depending on the function you use, you may have to invoke it as a string or integer value. Usually, the functions ask for your Relationship names, allowing the system to understand what Limb Relationship you want to swap at a given time.

  • "selectedTextureToReference" Variable: This is the equivalent of the "Texture Set"/"Skin"/"Texture Variant" you want to use for swapping textures. Always set this variable as an integer value, as this utility works as an index to call the TextureSO components from an array of TexturesSO.

TextureManagement Functions

Texture Swapping Functions

  • SwapTextureProcess (TextureManagement reference, SkeletonRelationships relationship, int selectedTextureToReference): This is the function handling the swapping of textures. You require a "SkeletonRelationships" reference and the current selected texture set index to point to a TexturesSO for the texture-swapping process. This function appears in all instances of texture swapping. To create a method variant for the TextureSwapper system, you must invoke the "SwapTextureProcess" function in your code snippets for the texture-swapping system to take effect during runtime. By default, "selectedTextureToReference" is set as 0.

Name Input Functions

  • SwapTextureSearchRelationship (TextureManagement reference, string relationshipName, int selectedTextureToReference): Invoke Relationship objects from the SkeletonSO reference via name and pass these references to the "SwapTextureProcess" function automatically. By default, "selectedTextureToReference" is set as 0.

    • SearchRelationship(TextureManagement reference, string relationshipName): Search and return a Relationship based on an input name.
  • SwapTextureSearchRelationshipAsync(TextureManagement reference, string relationshipName, int selectedTextureToReference): For all instances of the TextureSwapper process, you either this function or the "SwapTextureRelationshipAsync", as it minimizes slowdowns provoked by the texturing system. This code will run asynchronously to the TextureManagement script to liberate the main thread. This task is not multithreading but a Coroutine. By default, "selectedTextureToReference" is set as 0.

Relationship Input Functions

  • SwapTextureRelationship(TextureManagement reference, SkeletonRelationships relationship, int selectedTextureToReference) Swap a texture based on an input relationship without searching it.

  • SwapTextureRelationshipAsync(TextureManagement reference, SkeletonRelationships relationship, int selectedTextureToReference): For all instances of the TextureSwapper process, you either this function or the "SwapTextureSearchRelationshipAsync", as it minimizes slowdowns provoked by the texturing system. This code will run asynchronously to the TextureManagement script to liberate the main thread. This task is not multithreading but a Coroutine. By default, "selectedTextureToReference" is set as 0.

  • SwapTextureAsync(TextureManagement reference, SkeletonRelationships relationship, int selectedTextureToReference): The coroutine in charge of invoking the "SwapTextureProcess" function. By default, "selectedTextureToReference" is set as 0.

Texture Swapping GUI Functions

Function Callers

  • SwapTextureRunProcess(GameObject go): Runs the TextureSwapper process from an input GameObject. Reference this function if you want to run code from the 07. TextureManagement script. To utilize this function, you must have a "TextMeshProUGUI" as the child of your parent object while also naming the "TextMeshProUGUI" GameObject as the Relationship name you want to swap. In later steps of the process, we will teach you how you can set up this system automatically.

TextureSO GUI Navigation

  • IncreaseScrollerRelationships: Increases the index of the currently selected Relationship/Body Part in the GUI if invoked. This function is most useful in buttons or other interactable objects that scroll through menu options.

  • DecreaseScrollerRelationships: Decreases the index of the currently selected Relationship/Body Part in the GUI if invoked. This function is most useful in buttons or other interactable objects that scroll through menu options.

  • ManageRelationshipsTextMeshPro: Manages the TextMeshProUGUI components associated with the Skeleton's Relationships and their displayed text in the GUI based on the parameters configured in the 07. TextureManagement script.

Relationship GUI Navigation

  • IncreaseScrollerTextures: Increases the index of the currently selected TextureSO/"Texture Sets" in the GUI if invoked. This function is most useful in buttons or other interactable objects that scroll through menu options.

  • DecreaseScrollerTextures: Decreases the index of the currently selected TextureSO/"Texture Sets" in the GUI if invoked. This function is most useful in buttons or other interactable objects that scroll through menu options.

  • ManageTexturesTextMeshPro: Manages the TextMeshProUGUI components associated with the TextureSO assets and their displayed text in the GUI based on the parameters configured in the 07. TextureManagement script.

End Result

For reference, here are the "Texture Limb Limits" configurations.

TextureSwapperTrigger Script

The TextureSwapperTrigger script is an exemplary component bundled with the TextureSwapper system for the user to understand how to create its own TextureSwapper variant scripts.

As mentioned in the What Variables do I Reference for Texture Swapping Using the TextureManagement Script? segment of this page, the TextureSwapperTrigger only uses the 3 variables necessary to proceed its functionality along with the "SwapTextureSearchRelationshipAsync" function.

By any chance, if you input an incorrect relationship or texture reference, the TextureSwapper system will not proceed with your request. This failsafe is imperative to catch any errors in Unity's Runtime.

Even though this section of the user manual seems quite intricate, the TextureSwapperTrigger script allows users to experience and read firsthand how the code activates with the TextureSwapper system, 3 Variables, and 1 function call is all you need to start swapping textures on demand.