Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

I use custom inputfield class have these problems

Discussion in 'Scripting' started by andrew-yu-ho, Jan 26, 2020.

  1. andrew-yu-ho

    andrew-yu-ho

    Joined:
    Mar 29, 2019
    Posts:
    4
    I want to use this custom class but encounter these problems:
    1. During execution, this custom Inputfield object loses focus?
    Cannot enter characters in the field
    How to fix it?
    2. Why are some functions of the custom inputfield disabled in the Inspector?

    This is my test code, searched from the Internet~
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.EventSystems;
    4. using System;
    5. using System.ComponentModel;
    6. using UnityEngine.Events;
    7. using UnityEngine.Serialization;
    8.  
    9. public class CustomInputField : InputField
    10. {
    11.      public bool Focused = false;
    12.      public bool Deactivated = false;
    13.  
    14.  
    15.     new public void ActivateInputField()
    16.     {
    17.         Focused = true;
    18.         base.ActivateInputField();
    19.     }
    20.  
    21.     public override void OnDeselect(BaseEventData eventData)
    22.     {
    23.         Deactivated = true;
    24.         DeactivateInputField();
    25.         base.OnDeselect(eventData);
    26.     }
    27.  
    28.     public override void OnPointerClick(PointerEventData eventData)
    29.     {
    30.         if (Deactivated)
    31.         {
    32.             MoveTextEnd(true);
    33.             Deactivated = false;
    34.         }
    35.         base.OnPointerClick(eventData);
    36.     }
    37.  
    38.     protected override void LateUpdate()
    39.     {
    40.         base.LateUpdate();
    41.         if (Focused)
    42.         {
    43.             MoveTextEnd(true);
    44.             Focused = false;
    45.         }
    46.     }
    47. }


     
    Last edited: Jan 26, 2020
  2. andrew-yu-ho

    andrew-yu-ho

    Joined:
    Mar 29, 2019
    Posts:
    4
    The problem I want to solve has been solved by the properties of the <Input Field TMP >
    -onFocusSlecteall: Fasle


    Solve problems indirectly