I want to use this custom class but encounter these problems:
- During execution, this custom Inputfield object loses focus?
Cannot enter characters in the field
How to fix it? - Why are some functions of the custom inputfield disabled in the Inspector?
This is my test code, searched from the Internet~
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using System;
using System.ComponentModel;
using UnityEngine.Events;
using UnityEngine.Serialization;
public class CustomInputField : InputField
{
public bool Focused = false;
public bool Deactivated = false;
new public void ActivateInputField()
{
Focused = true;
base.ActivateInputField();
}
public override void OnDeselect(BaseEventData eventData)
{
Deactivated = true;
DeactivateInputField();
base.OnDeselect(eventData);
}
public override void OnPointerClick(PointerEventData eventData)
{
if (Deactivated)
{
MoveTextEnd(true);
Deactivated = false;
}
base.OnPointerClick(eventData);
}
protected override void LateUpdate()
{
base.LateUpdate();
if (Focused)
{
MoveTextEnd(true);
Focused = false;
}
}
}