Search Unity

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,103
    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: Jul 30, 2019
  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,103
  4. JohnEvelyn

    JohnEvelyn

    Joined:
    Oct 28, 2016
    Posts:
    8

    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,103
    @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,103
    diliupg likes this.
  7. joseGuate97

    joseGuate97

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

    AlanMattano

    Joined:
    Aug 22, 2013
    Posts:
    1,103
    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,103
    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. }
     
unityunity