Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

How to make a multi line textfield for editor?

Discussion in 'Scripting' started by pspdude, Oct 7, 2012.

  1. pspdude

    pspdude

    Joined:
    Dec 17, 2011
    Posts:
    43
    So, I was going through the scripting reference in VS, and I came across textarea in the editor section, and I thought that would be very useful, but as I was trying to write it in C#, I have no clue of how to use it.
     
  2. pspdude

    pspdude

    Joined:
    Dec 17, 2011
    Posts:
    43
    Bump?
     
  3. SkaredCreations

    SkaredCreations

    Joined:
    Sep 29, 2010
    Posts:
    296
    If you're talking about displaying a textarea in the Inspector panel for a string variable of your component then you can create a script like this (this script must reside in a folder called "Editor" in your project):

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4.  
    5. [CustomEditor(typeof(Test))] // 'Test' here is your component class name
    6. public class TestUI : Editor {
    7.    
    8.     public override void OnInspectorGUI ()
    9.     {
    10.         Test test = target as Test;
    11.         EditorGUILayout.LabelField("My field");
    12.         test.myField = EditorGUILayout.TextArea(test.myField);
    13.     }
    14. }
    15.  
    If you're talking about using a textarea in the GUI on your game play then take a look at the reference page
     
    Grooooo likes this.
  4. pspdude

    pspdude

    Joined:
    Dec 17, 2011
    Posts:
    43
    Can you give a little more info on this? Like, how to set it up properly? Cause I have no clue of how to use this :S

    This is the script
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEditor;
    4.  
    5. [CustomEditor(typeof(Note))]
    6. public class Note : MonoBehaviour {
    7.        
    8.     //The Skin/Background of the GUIStyle
    9.      public GUISkin mycustomSkin;
    10.     //The Text Of The Note
    11.     public string Text = "Insert Your Text Here!";
    12.    
    13.     void Start () {
    14.    
    15.         //AutoSet the Name
    16.         transform.name = "Note";
    17.        
    18.         //If there is no collider on the note add one
    19.         if (collider == null) {
    20.            
    21.             Debug.LogError ("No Collider On Note " + name + ". Add A Collider!");
    22.            
    23.         }
    24.        
    25.     }
    26.  
    27.     void OnGUI()
    28.     {
    29.         Text = EditorGUI.TextArea(new Rect(10, 10, 200, 100), Text);
    30.  
    31.  
    32.     }
    33.  
    34.  
    35.        
    36. }
    37.  
     
  5. Deleted User

    Deleted User

    Guest

unityunity