Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Add Info Text Notes into the inspector

Discussion in 'Scripting' started by AlanMattano, Aug 29, 2014.

  1. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Updated # 2023
    FAST WAY

    1. Make a C# script: CommentInformationNote
    2. Copy and paste this code.

    Code (CSharp):
    1. #if UNITY_EDITOR
    2. using UnityEngine;
    3.  
    4. /* **************************************************************************
    5. * 2023 Alan Mattanó, Soaring Stars lab }}
    6. *
    7. * Overall, this script allows you to add notes
    8. * or comments to GameObjects in the Unity Editor,
    9. * making it easier to communicate essential information
    10. * about GameObjects or their components to other developers
    11. *
    12. *           WARNING: DO NOT MODIFY
    13. *           you will lose all data
    14. *
    15. * By wrapping the script inside the #if UNITY_EDITOR directive,
    16. * it will only be compiled and executed in the Unity Editor.
    17. * When you build your project, the script will be excluded from the build,
    18. * and it won't impact the final game. It may need to add using UnityEditor;
    19. * at the beginning of the script if you encounter any issues with the
    20. * #if UNITY_EDITOR directive.
    21. * ************************************************************************/
    22.  
    23. [AddComponentMenu("Miscellaneous/README Info Note")]
    24. public class CommentInformationNote : MonoBehaviour
    25. {
    26.     [TextArea(17,1000)]
    27.     public string comment = "Information Here.";
    28.  
    29.     void Awake()
    30.     {
    31.         comment = null;
    32.        
    33.         // Assuming you want to destroy this script component
    34.         Destroy(this);
    35.     }
    36. }
    37. #endif

    • Place the script into the game object.
    • Notice that you can use Add Component in the Inspector.
    • Do not change the script because you can lose all your data.
    • DONE

    By wrapping the script inside the #if UNITY_EDITOR directive, it will only be compiled and executed in the Unity Editor. When you build your project, the script will be excluded from the build and won't impact the final game.

    Note that comment = null since it is not necessary for this purpose.

    Remember that you may need to add using UnityEditor; at the beginning of the script if you encounter any issues with the #if UNITY_EDITOR directive.


    ------------------------------------------------------------------------------------------------------------------------------






    Update # 2019





    Update # 2018

    Now on GitHub: Unity Inspector Info Text Note
    Allows creating info text notes into the inspector.

    Just drag and drop the script InspectorNote.cs or find it in the component > miscellaneous > Inspector Text Info Note section.

    upload_2019-1-23_16-26-27.png

    --------------------------------------------------------------------------------------------------------------------------------------
    Update # 2017.

    You can start adding a title note to the script that includes important information. It will be visible in the inspector by using new Unity functions as for example:

    Code (CSharp):
    1. System.Collections.Generic;
    2.  
    3. public class YourScriptName: MonoBehaviour
    4. {
    5.         [Space]
    6.         [Header("   INSPECTOR TITLE NOTE ")]
    7.         [Space]
    8.         [Header("Second line note explanation shown in inspector")]
    9.         [Space(25)]
    10.  
    11.         public bool mybool;
    12.  
    13.         [Space]
    14.         [Header("OUTPUTS")]
    15.         [Space]
    16.         [Tooltip("This is a pop up note hovering over the var in inspector")]
    17.         public float myInputFloat;
    18.  
    19.         [Space]
    20.         [Header("INPUTS")]
    21.         [Space]
    22.         public bool myOutputBool = true;
    23.  
    24.  
    25.         void Start ()
    26.         {
    27.  
    28.         }
    29. }


    --------------------------------------------------------------------------------------------------------------------------------------

    Asset # 2016.
    Now, a beter way, is to download a better fantastic tool at:

    https://www.assetstore.unity3d.com/en/#!/content/51884
    Inspector Notes: add text notes to your GameObjects.

    Is it a .dll but is much stable, simple and faster.


    --------------------------------------------------------------------------------------------------------------------------------------

    Learning C# 2014.
    For adding simple information, version, info into your Inspector, including warnings attentions etc... I made this code.

    I ask Unity in the feedback zone the ability to read notes in the inspector panel. In case you want to vote.
    And a Wiki section answering to the question: Adding notes to the inspector? So you can improve my code.


    First, make a C# file name "InfoTextNote" open Mono and add this script.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. /***************************************************
    6. *   This file let you add text into the inspector
    7. * has a 2° reference file in Assets "Editor" folder,
    8. * name:  AddInspectorText
    9. **************************************************/
    10.  
    11. public class InfoTextNote : MonoBehaviour
    12. {
    13.  
    14.         public bool isReady = true;
    15.         public string TextInfo = "Text here... " +
    16.                 "/n Press Lock when finish.";
    17.  
    18.         public void SwitchToggle ()
    19.         {
    20.                 isReady = !isReady;
    21.         }
    22.  
    23.         void Start ()
    24.         {
    25.                 this.enabled = false; // Disable thi component when game start
    26.         }
    27. }



    Then make a "Editor" folder and a new C# file name AddInspectorText.
    Now add this code into it:


    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEditor;
    4.  
    5. /* AlanMattano}}2014*/
    6.  
    7. [CustomEditor(typeof(InfoTextNote))]
    8. public class AddInspectorText : Editor {
    9.  
    10.     private int c = 0;
    11.     private string buttonText = "Start typing";
    12.     private int MaxSizeInt = 5;
    13.     private int[] IntArray = new int[] { 0, 1, 2, 3, 4 };
    14.     private string[] MaxSizeString = new string[] { "Line Label", "Box Text ", "Box Info", "Box Warning", "Box Error" };
    15.  
    16.  
    17.     public override void OnInspectorGUI()
    18.     {
    19.         InfoTextNote inMyScript = (InfoTextNote)target;
    20.  
    21.         if ( inMyScript.TextInfo == "Start writting text here... " +
    22.            "/n Press Lock when finish." )
    23.             ShowLogMessage() ;// se podria agregar alguna funcin en especial
    24.  
    25.         if ( !inMyScript.isReady ) {
    26.  
    27.             //DrawDefaultInspector();// Unity function
    28.  
    29.             switch (MaxSizeInt)
    30.             {
    31.             case 0:
    32.                 if (EditorGUILayout.Toggle(inMyScript.isReady)) inMyScript.SwitchToggle();                                    // Toggle
    33.                 EditorGUILayout.LabelField(inMyScript.TextInfo);        // A small line text
    34.                 break;
    35.             case 1:
    36.                 if ( GUILayout.Button(buttonText)) inMyScript.SwitchToggle();    //
    37.                 EditorGUILayout.HelpBox(inMyScript.TextInfo, MessageType.None);  // This is a small box
    38.                 break;
    39.             case 2:
    40.                 if ( GUILayout.Button(buttonText)) inMyScript.SwitchToggle();    //
    41.                 EditorGUILayout.HelpBox(inMyScript.TextInfo, MessageType.Info);  // This is a help box
    42.                 break;
    43.             case 3:
    44.                 if ( GUILayout.Button(buttonText)) inMyScript.SwitchToggle();
    45.                 EditorGUILayout.HelpBox(inMyScript.TextInfo, MessageType.Warning);// This is a Warning box
    46.                 break;
    47.             case 4:
    48.                 if ( GUILayout.Button(buttonText)) inMyScript.SwitchToggle();     //
    49.                 EditorGUILayout.HelpBox(inMyScript.TextInfo, MessageType.Error);  // This is a Error box
    50.                 break;
    51.             default:
    52.                 if ( GUILayout.Button(buttonText)) inMyScript.SwitchToggle();            // Button
    53.                 EditorGUILayout.HelpBox(inMyScript.TextInfo, MessageType.Info);            // This is a help box
    54.                 break;
    55.             }
    56.         }else{
    57.  
    58.             //DrawDefaultInspector();// for debug
    59.  
    60.             buttonText = "Lock !";
    61.             // Button
    62.             if ( GUILayout.Button(buttonText)) inMyScript.SwitchToggle();
    63.  
    64.  
    65.             // Text
    66.             inMyScript.TextInfo = EditorGUILayout.TextArea (inMyScript.TextInfo);
    67.  
    68.  
    69.             // selection
    70.             MaxSizeInt = EditorGUILayout.IntPopup("Text Type :", MaxSizeInt, MaxSizeString, IntArray);
    71.  
    72.             // warning
    73.             EditorGUILayout.HelpBox( " Press LOCK at the top when finish. ", MessageType.Warning); // A Warning box
    74.         }
    75.     }
    76.  
    77.     void ShowLogMessage() {
    78.         c++;
    79.         if (c==1) {
    80.  
    81.             Debug.Log (" Need to add text " + "\n");
    82.         }
    83.     }
    84. }



    Now you are ready!

    In the inspector click Add Component and the type : info, text or note and select the script the script InfoTextNote each time you need it!

    Hope it help you.

    Place make me know if you improve this code.



     
    Last edited: Apr 15, 2023
    alecmak, Kshesho, seansteezy and 2 others like this.
  2. myibmaccount

    myibmaccount

    Joined:
    Nov 10, 2012
    Posts:
    12
    Thanks. I am using this as a way to track changes to gameobject settings. Big Help.
     
  3. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    LJPowell likes this.
  4. JohnEvelyn

    JohnEvelyn

    Joined:
    Oct 28, 2016
    Posts:
    9

    This is such a a massive help - I have huge chains of components that need configuring so adding notes to them to detail how to set them up is brilliant.

    Thank you!
     
    AlanMattano likes this.
  5. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    @JohnEvelyn

    You can start adding a title note to the script that includes important information. It will be visible in the inspector by using new Unity functions as for example:

    Code (CSharp):
    1. System.Collections.Generic;
    2.  
    3. public class YourScriptName: MonoBehaviour
    4. {
    5.         [Space]
    6.         [Header("   INSPECTOR TITLE NOTE ")]
    7.         [Space]
    8.         [Header("Second line note explanation shown in inspector")]
    9.         [Space(25)]
    10.  
    11.         public bool mybool;
    12.  
    13.         [Space]
    14.         [Header("OUTPUTS")]
    15.         [Space]
    16.         [Tooltip("This is a pop up note hovering over the var in inspector")]
    17.         public float myInputFloat;
    18.  
    19.         [Space]
    20.         [Header("INPUTS")]
    21.         [Space]
    22.         public bool myOutputBool = true;
    23.  
    24.  
    25.         void Start ()
    26.         {
    27.          
    28.         }
    29. }
     
  6. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    diliupg likes this.
  7. joseGuate97

    joseGuate97

    Joined:
    Mar 1, 2018
    Posts:
    57
    Simple, yet so amazing!!! Worked like a charm. Thank you.
     
    diliupg and AlanMattano like this.
  8. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    I make a video so it is easy to understand. Please report bugs.
     
    diliupg likes this.
  9. AlanMattano

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,501
    Is not working in 2019.3.0f5

    So I'musing:
    Code (CSharp):
    1. using UnityEngine;
    2.  
    3. [AddComponentMenu("Miscellaneous/Info Note")]
    4. public class InfoNote : MonoBehaviour
    5. {
    6.     [TextArea]
    7.     public string TextInfo = "Type your message here and press enter to send";
    8.  
    9.     private void Awake()
    10.     {
    11.         this.enabled = false; // Disable this component when game start
    12.     }
    13. }
     
  10. Tom-Mensink

    Tom-Mensink

    Joined:
    Jul 27, 2017
    Posts:
    17
    This works nicely, however the information texts are still serialized into the build application. Although it looks nicer with this solution, it is the same as having just a component with a public string. How to prevent extra bytes in the code and at the same time show it in the editor? If possible at all. At least we could clear both strings like this in Awake():

    Code (CSharp):
    1. // Free up space
    2. TextInfo = null;
    3. spaceMessage = null;
    4.  
     
    Last edited: Feb 19, 2021
    AlanMattano likes this.
  11. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,533
    For those worried about the text ending up in the executable, the easiest solution is to make the field [NonSerialized].

    Here's the code again with that attribute:
    Code (CSharp):
    1. using UnityEngine;
    2. [AddComponentMenu("Miscellaneous/Info Note")]
    3. public class InfoNote : MonoBehaviour
    4. {
    5.     [TextArea] [System.NonSerialized]
    6.     public string TextInfo = "Type your message here and press enter to send";
    7.  
    8. }
    But you'll have to write a custom Property Drawer to make the NonSerialized field appear in inspector.
     
    AlanMattano likes this.