Search Unity

Clipboard and Unity

Discussion in 'Scripting' started by Patico, Jul 27, 2014.

  1. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    Hi guys!
    Does anyone know how to get access to the clipboard in Unity for write data? I'd like to add "copy" button for my webplayer.
     
  2. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    Here:

    Code (csharp):
    1.  
    2.     public static void SendToClipboard(string text)
    3.     {
    4.         TextEditor te = new TextEditor();
    5.         te.content = new GUIContent(text);
    6.         te.SelectAll();
    7.         te.Copy();
    8.     }
    9.    
    10.     public static string ReceiveFromClipboard()
    11.     {
    12.         TextEditor te = new TextEditor();
    13.         te.content = new GUIContent("");
    14.         te.SelectAll();
    15.         te.Paste();
    16.         return te.content.text;
    17.     }
    18.  
     
  3. Patico

    Patico

    Joined:
    May 21, 2013
    Posts:
    886
    Wow, it's beautiful and works well!
    Thanks a lot!