Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Modular 3D Text - Complete ingame ui sytem

Discussion in 'Assets and Asset Store' started by Ferdowsur, Feb 4, 2020.

  1. CoreCoder

    CoreCoder

    Joined:
    Jun 11, 2015
    Posts:
    41
    using TinyGiantStudio.Text;

    Code (CSharp):
    1.  
    2.     void ShowAvailableScenes(List<SceneLoaderManager.Scene> availableScenes)
    3.     {
    4. foreach (SceneLoaderManager.Scene scene in availableScenes)
    5.         {
    6.             GameObject button = Instantiate(buttonTemplate, transform);
    7. Modular3DText buttonComponent = button.GetComponent<Modular3DText>(); // Get the button component
    8.             Text buttonText = button.GetComponentInChildren<Text>();
    9. buttonComponent.onClick.AddListener(() => SceneLoaderManager.Load(scene));
    10.             button.SetActive(true);
    11.         }
    12. }
    13.  
    How would I get this working? If I run a UI button it works but when converting it to use your 3D buttons the onClick.AddListener errors out.
    Severity Code Description Project File Line Suppression State
    Error CS1061 'Modular3DText' does not contain a definition for 'onClick' and no accessible extension method 'onClick' accepting a first argument of type 'Modular3DText' could be found (are you missing a using directive or an assembly reference?) Assembly-CSharp E:\dev\Unity\AsteroidMaze\AsteroidMaze\Assets\Scripts\Scene\SceneSelector.cs 55 Active
     
  2. Ferdowsur

    Ferdowsur

    Joined:
    Feb 7, 2017
    Posts:
    223
    Hi,
    On the 7th line, you are getting the Text component of the button. You need to get the button component. The button component holds the onClick and other UnityEvents.
    Code (CSharp):
    1. Button buttonComponent = button.GetComponent<Button >(); // Get the button component
     
  3. CoreCoder

    CoreCoder

    Joined:
    Jun 11, 2015
    Posts:
    41
    So you dont have to access Modular3DText directive for the button or the button Text? Because every time I call Button I get a :
    NullReferenceException: Object reference not set to an instance of an object
    SceneSelector.ShowAvailableScenes (System.Collections.Generic.List`1[T] availableScenes) (at Assets/Scripts/Scene/SceneSelector.cs:41)
    SceneSelector.Update () (at Assets/Scripts/Scene/SceneSelector.cs:23).

    Here is the complete file.

    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. using UnityEngine.UI;
    4. using UnityEngine.SceneManagement;
    5. using TinyGiantStudio.Text;
    6. using Button = UnityEngine.UI.Button;
    7.  
    8. public class SceneSelector : MonoBehaviour
    9. {
    10.     public GameObject buttonTemplate; // Assign a button prefab in the Inspector
    11.     //public TextMeshProUGUI buttonText;
    12.     public GameObject JumpMenu;                     // UI Hyper Jump menu
    13.  
    14.     void Update()
    15.     {
    16.         if (Input.GetKey(KeyCode.LeftAlt) && Input.GetKeyDown(KeyCode.W))
    17.         {
    18.  
    19.             JumpMenu.SetActive(true);
    20.  
    21.             Debug.Log("Warp Key Combination Pressed - Again!");                                         // DEBUG DEBUG EDBUG
    22.             List<SceneLoaderManager.Scene> availableScenes = SceneLoaderManager.GetAvailableScenes();
    23.             ShowAvailableScenes(availableScenes);
    24.         }
    25.     }
    26.  
    27.     void ShowAvailableScenes(List<SceneLoaderManager.Scene> availableScenes)
    28.     {
    29.         //Remove all previous buttons
    30.         //foreach (Transform child in transform)
    31.         //{
    32.         //    Destroy(child.gameObject);
    33.         //}
    34.  
    35.         // Create a new button for each available scene
    36.         foreach (SceneLoaderManager.Scene scene in availableScenes)
    37.         {
    38.             GameObject button = Instantiate(buttonTemplate, transform);
    39.  
    40.             Button buttonComponent = button.GetComponent<Button>(); // Get the button component
    41.             Text buttonText = button.GetComponentInChildren<Text>();
    42.  
    43.             buttonComponent.onClick.AddListener(() => SceneLoaderManager.Load(scene));
    44.  
    45.             // Make the button visible
    46.             button.SetActive(true);
    47.         }
    48.     }
    49.  
    50. }
    Basically this file will get the surrounding galaxy names(scenes) and insantiate the buttons with the galaxy names that the player can warp / jump to.
     
  4. Ferdowsur

    Ferdowsur

    Joined:
    Feb 7, 2017
    Posts:
    223
    Remove line 6. That's changing which Button script you are using.
     
  5. CoreCoder

    CoreCoder

    Joined:
    Jun 11, 2015
    Posts:
    41
    So I got it to instantiate the buttons but how do I access the text component on the 3D buttons? If I use unities UI I dont get an error on Text buttonText = .... but if I dont use unities UI it can not find the namespace for the Text object. So using Modular3DText buttonText = ... does not trigger an error but it also wont access the 3DButton text component. Here is the code again and I do appreciate your help.
    Code (CSharp):
    1. using System.Collections.Generic;
    2. using UnityEngine;
    3. //using UnityEngine.UI;
    4. using UnityEngine.SceneManagement;
    5. using TinyGiantStudio.Text;
    6. //using Button = UnityEngine.UI.Button;
    7.  
    8. public class SceneSelector : MonoBehaviour
    9. {
    10.     public GameObject buttonTemplate; // Assign a button prefab in the Inspector
    11.     //public TextMeshProUGUI buttonText;
    12.     public GameObject JumpMenu;                     // UI Hyper Jump menu
    13.  
    14.     void Update()
    15.     {
    16.         if (Input.GetKey(KeyCode.LeftAlt) && Input.GetKeyDown(KeyCode.W))
    17.         {
    18.  
    19.             JumpMenu.SetActive(true);
    20.  
    21.             Debug.Log("Warp Key Combination Pressed - Again!");                                         // DEBUG DEBUG EDBUG
    22.             List<SceneLoaderManager.Scene> availableScenes = SceneLoaderManager.GetAvailableScenes();
    23.             ShowAvailableScenes(availableScenes);
    24.         }
    25.     }
    26.  
    27.     void ShowAvailableScenes(List<SceneLoaderManager.Scene> availableScenes)
    28.     {
    29.         //Remove all previous buttons
    30.         //foreach (Transform child in transform)
    31.         //{
    32.         //    Destroy(child.gameObject);
    33.         //}
    34.  
    35.         // Create a new button for each available scene
    36.         foreach (SceneLoaderManager.Scene scene in availableScenes)
    37.         {
    38.             GameObject button = Instantiate(buttonTemplate, transform);
    39.  
    40.             TinyGiantStudio.Text.Button buttonComponent = button.GetComponent<TinyGiantStudio.Text.Button>(); // Get the button component
    41.             //Text buttonText = button.GetComponentInChildren<Text>();
    42.             Modular3DText buttonText = button.GetComponentInChildren<Modular3DText>();
    43.            
    44.             buttonComponent.onClick.AddListener(() => SceneLoaderManager.Load(scene));
    45.  
    46.             // Make the button visible
    47.             button.SetActive(true);
    48.         }
    49.     }
    50.  
    51. }
    upload_2023-5-18_9-14-51.png
     
  6. Ferdowsur

    Ferdowsur

    Joined:
    Feb 7, 2017
    Posts:
    223
    The button has a variable called Text. You can use that to get it.

    So, your line 42
    Code (CSharp):
    1. Modular3DText buttonText = button.GetComponentInChildren<Modular3DText>();
    will be

    Code (CSharp):
    1. Modular3DText buttonText = buttonComponent.Text;
     
  7. Ferdowsur

    Ferdowsur

    Joined:
    Feb 7, 2017
    Posts:
    223
    Modular 3D Text - Version 4.0.2
    • Removed max vertices limit on combined text. So, large texts are not split into smaller ones. It can be turned on/off via the inspector.
    • Undo fixed for Grid Layout's Justice alignment setting.
    • Undo fix for creating a list.
    • Text inspector performance slightly improved.
     
  8. CoreCoder

    CoreCoder

    Joined:
    Jun 11, 2015
    Posts:
    41
    I see now how it access the components. I like the Modular 3D text it's very nicely done. One suggestion is to put some examples in the documentation how to access the components, code examples would help a lot. Thank you sir.
     
  9. Ferdowsur

    Ferdowsur

    Joined:
    Feb 7, 2017
    Posts:
    223
    Glad to hear you like it. I will spend this week adding more examples for your type of use cases.
    Feel free to ask me if you need further assistance. Always happy to help.

    Edit: Documentations have been updated.
     
    Last edited: Jun 3, 2023 at 11:22 AM
  10. krakendono

    krakendono

    Joined:
    Jun 5, 2016
    Posts:
    14
    I see that the asset is deprecated on the unity asset store what happened?
     
    chgeorgiadis likes this.
  11. Ferdowsur

    Ferdowsur

    Joined:
    Feb 7, 2017
    Posts:
    223
    You must have followed a dead link to the old version. Please use this one: Link
     
  12. Ferdowsur

    Ferdowsur

    Joined:
    Feb 7, 2017
    Posts:
    223
    Modular 3D Text - Version 4.0.3
    This update focuses on improving the experience for programmers.

    Summary:
    • Added more buttons to easily reach relevant documentation.
    • The asset uses custom inspectors to reduce clutter and make the design aspect easier. Often variables can be renamed slightly for clarity. Now, tooltips for these variables also include variable names.
    • Code refactoring for inputfield.cs, list.cs, Button.cs, and HorizontalSelector.cs have been done for a consistent naming scheme among the asset.
    A full list of changes can be found here.
     
  13. Ferdowsur

    Ferdowsur

    Joined:
    Feb 7, 2017
    Posts:
    223
    Please note, years of updates have made the version list here cluttered and difficult to navigate. So, they have been moved to the documentation site. This will make it easier to keep track of everything.

    Please check the version list here for change history with dates and full details.