Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Deathslice · Nov 07, 2017 at 01:43 AM · objectinputfieldrecttransformpaneldragging

How to reset the position of the caret in the inputfield after the panel has been dragged?

So I have an inputfield that is the child of a panel and the caret inside the inputfield displays properly when the panel is not dragged. After I drag the panel, the caret disappears and never comes back even when I right click on the inputfield again. I can enter text on the inputfield just fine but the only thing missing is the caret. How can I fix this and why does this happen? If it helps, here is the code for dragging a panel.


 using UnityEngine;
 using UnityEngine.EventSystems;
 
 public class DragPanel : MonoBehaviour, IDragHandler
 {
     private RectTransform dragObjectInternal;
 
     [SerializeField]
     private RectTransform dragAreaInternal;
 
     private Vector2 originalLocalPointerPosition;
     private Vector3 originalPanelLocalPosition;
 
     private void Start()
     {
         dragObjectInternal = GetComponent<RectTransform>();
     }
 
     public void OnBeginDrag(PointerEventData data)
     {
         originalPanelLocalPosition = dragObjectInternal.localPosition;
         RectTransformUtility.ScreenPointToLocalPointInRectangle(dragAreaInternal, data.position, data.pressEventCamera, out originalLocalPointerPosition);
     }
 
     public void OnDrag(PointerEventData data)
     {
         Vector2 localPointerPosition;
 
         if (RectTransformUtility.ScreenPointToLocalPointInRectangle(dragAreaInternal, data.position, data.pressEventCamera, out localPointerPosition))
         {
             Vector3 offsetToOriginal = localPointerPosition - originalLocalPointerPosition;
             dragObjectInternal.localPosition = originalPanelLocalPosition + offsetToOriginal;
         }
 
         ClampToArea();
     }
 
     // Clamp panel to dragArea
     private void ClampToArea()
     {
         Vector3 pos = dragObjectInternal.localPosition;
 
         Vector3 minPosition = dragAreaInternal.rect.min - dragObjectInternal.rect.min;
         Vector3 maxPosition = dragAreaInternal.rect.max - dragObjectInternal.rect.max;
 
         pos.x = Mathf.Clamp(dragObjectInternal.localPosition.x, minPosition.x, maxPosition.x);
         pos.y = Mathf.Clamp(dragObjectInternal.localPosition.y, minPosition.y, maxPosition.y);
 
         dragObjectInternal.localPosition = pos;
     }
 }





Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Nov 07, 2017 at 03:01 AM 0
Share

Well, I'm not sure what might be your problem. However most parts of the new UI system is open source. Here's where the cursor is actually generated. This is actually called from OnFillVBO which is called from UpdateGeometry which is called from Rebuild which is actually called from the Canvas updater when the input field is "dirty". I can't really see where it might go wrong.


$$anonymous$$aybe it's related to this for loop which effectively does nothing since UIVertex is a struct so the addition has no effect on the information stored in the array. Though if the text renders properly, the cursor should also. It's possible, if you have a cursor blink rate set that the blinking coroutine might be ter$$anonymous$$ated maybe because "isFocused" turned false for a moment? It's hard to tell from just looking at the code ^^.

avatar image Deathslice Bunny83 · Nov 07, 2017 at 04:59 AM 0
Share

Here is what I mean.

In this image, the panel is in its original panel with the caret in the inputfield clearly visible.

alt text

In this image, I drag the panel to some arbitrary location, right click on the inputfield and the caret doesn't appear.

alt text

That is the problem I'm having.

avatar image Deathslice Bunny83 · Nov 07, 2017 at 05:16 AM 0
Share

Though interestingly enough if I place the panel on the top or bottom left side of the screen and I right click, the caret appears. Anywhere else it doesn't for some reason.


Edit: If I set the right value in the caret transform to 5 ins$$anonymous$$d of 10, I can move the panel anywhere, right click on the inputfield and the caret appears. However if I set it 5 before moving the panel and then right click on the inputfield, the caret doesn't appear. But if I move it afterwards it works just fine.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

75 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How Can I Drag the Object With Touch ? (Mobile) 4 Answers

Problem with Elastic Rect Transform 0 Answers

How do I send inputfield text to another script? 0 Answers

Fill empty space in parent in UI Layout 1 Answer

Keep Draggable UI window within Canvas? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges