Author Topic: Input widget highlighting, copy paste etc  (Read 8858 times)

Helk

  • Guest
Input widget highlighting, copy paste etc
« on: April 12, 2012, 05:08:59 PM »
Hi, I am considering using NGUI I have tried the demo version and it is great. However I noticed that when you select an input box the text disappears, you cannot copy paste etc. Is there any planned support for this? Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Input widget highlighting, copy paste etc
« Reply #1 on: April 13, 2012, 02:57:58 PM »
The text only disappears if you want it to, but there is no support for copy/paste, and unless Unity adds the ability to access the clipboard in the future, there is nothing I can do.

sgonchar

  • Guest
Re: Input widget highlighting, copy paste etc
« Reply #2 on: August 17, 2012, 01:03:47 PM »
FYI: we ran into the same issue, found a work around here. I know it's an older topic but it may help.

http://answers.unity3d.com/questions/266244/how-can-i-add-copypaste-clipboard-support-to-my-ga.html

We couldn't use Ctrl+V because its intercepted elsewhere, but if you connect to some other key combination you can get at System Copy Buffer.

Note: it's using undocumented functionality, GUIUtility doesn't officially have a "systemCopyBuffer".
Note: typeof isn't something you want to use if you're converting to Flash.
Note: System.Reflection likely doesn't work the same in Flash ether.

Cheers.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Input widget highlighting, copy paste etc
« Reply #3 on: August 17, 2012, 06:55:11 PM »
Interesting... thanks for sharing! But yeah, I certainly can't use undocumented functionality in NGUI itself.

huminado

  • Guest
Re: Input widget highlighting, copy paste etc
« Reply #4 on: June 14, 2013, 07:53:54 PM »
Interesting... thanks for sharing! But yeah, I certainly can't use undocumented functionality in NGUI itself.

Okay -- sorry for re-awakening this thread.


Is there any way to do this using GUILayout.TextArea()?  I notice that if I use this code ctrl-V works fine for pasting from the clipboard, even on webplayer:

      string plainText = "some text";

      plainText = GUILayout.TextArea( plainText, GUILayout.ExpandHeight(false)  );

If I could figure out how to hide the textarea and give it focus, it could be a rudimentary editor that can copy into input in Update() of UICamera.cs

Has this already been attempted?

shokinhan

  • Guest
Re: Input widget highlighting, copy paste etc
« Reply #5 on: June 15, 2013, 05:29:33 AM »
I have implemented ctrl+c,ctrl+v on webplayer, but I don't know how to implement section text!!!

huminado

  • Guest
Re: Input widget highlighting, copy paste etc
« Reply #6 on: June 15, 2013, 12:26:26 PM »
I have implemented ctrl+c,ctrl+v on webplayer, but I don't know how to implement section text!!!

oh.. can you please post example code how to do this??  I don't care about the highlighting only the copy/paste.

huminado

  • Guest
Re: Input widget highlighting, copy paste etc
« Reply #7 on: June 15, 2013, 12:48:12 PM »
also if anyone has done this using the TextEditor class, that should have all the functionality built-in.

huminado

  • Guest
Re: Input widget highlighting, copy paste etc
« Reply #8 on: June 15, 2013, 02:12:10 PM »
Here is my (crappy, but functional) solution.  It brings up the GUILayout.TextArea to modify the label, if useGUItextEditInstead is set to true (and the myCamera is the camera for the input object).

It also hides the TextArea if the parent object has localScale<0.02 (which I tried using transform.lossyScale, but it didn't work and I don't know why).

Changes to UIInput.cs:

   public bool useGUItextEditInstead   =   false;
   public Camera myCamera;

   void OnGUI()
   {
      // mostly to get ctrl-v to work in the webplayer
      if ( ( myCamera!=null || useGUItextEditInstead ) && ( transform.parent.localScale.x > 0.02f || transform.parent.localScale.y > 0.02f  ) )   {
         
           Vector2 selectedObjScreenPos =   myCamera.WorldToScreenPoint ( transform.position );    //   Event.current.mousePosition;
         if ( ( selectedObjScreenPos.y <= Screen.height ) && ( selectedObjScreenPos.y >= 0 ) )   {
            selectedObjScreenPos.y   =   Screen.height-selectedObjScreenPos.y;
         }
           Vector2 convertedGUIPos = GUIUtility.ScreenToGUIPoint(selectedObjScreenPos);
           GUI.BeginGroup(new Rect(convertedGUIPos.x, convertedGUIPos.y-100, label.lineWidth, 100));
      label.text = GUILayout.TextArea( label.text );
           GUI.EndGroup();
         
      }
      
   }


shokinhan

  • Guest
Re: Input widget highlighting, copy paste etc
« Reply #9 on: June 16, 2013, 09:48:15 AM »
The Code is the fuction for section text ?



loofou

  • Guest
Re: Input widget highlighting, copy paste etc
« Reply #10 on: June 19, 2013, 07:10:56 AM »
This is something i wrote a while ago. Should still work. Just append it to the same GameObject your UIInput is on.

https://docs.google.com/file/d/0B0m9Fxe6-AAQaEFja1EwenRUb2M/edit?usp=sharing

galuodo

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 65
    • View Profile
Re: Input widget highlighting, copy paste etc
« Reply #11 on: June 19, 2013, 07:01:02 PM »
I have a idea, but I don't have time. So if someone want to implement such function, I will share my idea

ninuson

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: Input widget highlighting, copy paste etc
« Reply #12 on: November 30, 2014, 05:04:01 AM »
I know I'm replying on a dead topic, but I thought maybe others would like to know the simple solution to this problem. I've had the same issue trying to copy some text in my game directly to the clipboard by a click of a button. This is the code I ended up using:

  1. string text = "the text we want to copy to clipboard";
  2.  
  3. TextEditor te = new TextEditor();
  4. te.content = new GUIContent(text);
  5. te.SelectAll();
  6. te.Copy();

This works for me both in Editor, PC standalone and web player.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Input widget highlighting, copy paste etc
« Reply #13 on: November 30, 2014, 05:53:06 AM »
Dead for a reason. :P

Copy/paste functionality is already a part of NGUI. There is no need for your code. Also note NGUITools.clipboard.