125 lines
4.2 KiB
C#
125 lines
4.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Assets.Scripts.UI.Control
|
|
{
|
|
public class PFUIInputField: PFUIComponentBase
|
|
{
|
|
[SerializeField]
|
|
private InputField mInnerInputField;
|
|
private Outline outline;
|
|
private bool isSelected = false;
|
|
|
|
public string Text
|
|
{
|
|
get
|
|
{
|
|
return this.mInnerInputField.text;
|
|
}
|
|
set
|
|
{
|
|
this.mInnerInputField.text = value;
|
|
}
|
|
}
|
|
|
|
|
|
public void OnSelect(BaseEventData eventData)
|
|
{
|
|
if (this.gameObject.activeInHierarchy == false)
|
|
{
|
|
return;
|
|
}
|
|
|
|
isSelected = true;
|
|
//throw new NotImplementedException();
|
|
this.mInnerInputField.OnSelect(eventData);
|
|
//var image = this.transform.GetComponent<Image>();
|
|
// var png = Resources.Load<Sprite>("Images/ipt-1");
|
|
//image.sprite = png;
|
|
outline.enabled = true;
|
|
ColorUtility.TryParseHtmlString("#F93086", out Color color);
|
|
|
|
outline.effectColor = color;
|
|
}
|
|
|
|
public void OnDeselect(BaseEventData eventData)
|
|
{
|
|
if(this.gameObject.activeInHierarchy == false)
|
|
{
|
|
return;
|
|
}
|
|
|
|
isSelected = false;
|
|
this.mInnerInputField.OnDeselect(eventData);
|
|
//var image = this.transform.GetComponent<Image>();
|
|
//var png1 = Resources.Load<Sprite>("Images/ipt-0");
|
|
//image.sprite = png1;
|
|
outline.enabled = false;
|
|
}
|
|
|
|
void Awake()
|
|
{
|
|
Material material = null;
|
|
if (material == null)
|
|
{
|
|
material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
|
}
|
|
var rect = ((RectTransform)transform).rect;
|
|
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, Math.Min(rect.height*0.7f, 50f), 0));
|
|
gameObject.GetComponent<Image>().material = material;
|
|
|
|
outline = this.GetComponent<Outline>();
|
|
if (outline == null)
|
|
{
|
|
outline = this.gameObject.AddComponent<Outline>();
|
|
outline.effectDistance = new Vector2(2, 2);
|
|
outline.enabled = false;
|
|
}
|
|
|
|
UIManager.AddEvent(this.mInnerInputField.gameObject, EventTriggerType.PointerClick, new UnityAction<BaseEventData>(this.OnSelect));
|
|
UIManager.AddEvent(this.mInnerInputField.gameObject, EventTriggerType.Select, new UnityAction<BaseEventData>(this.OnSelect));
|
|
UIManager.AddEvent(this.mInnerInputField.gameObject, EventTriggerType.Deselect, new UnityAction<BaseEventData>(this.OnDeselect));
|
|
UIManager.AddEvent(this.mInnerInputField.gameObject, EventTriggerType.PointerEnter, new UnityAction<BaseEventData>((e) =>
|
|
{
|
|
if (isSelected)
|
|
{
|
|
return;
|
|
}
|
|
outline.enabled = true;
|
|
ColorUtility.TryParseHtmlString("#6E6E7D", out Color color);
|
|
outline.effectColor = color;
|
|
}));
|
|
|
|
UIManager.AddEvent(this.mInnerInputField.gameObject, EventTriggerType.PointerExit, new UnityAction<BaseEventData>(e =>
|
|
{
|
|
if (isSelected)
|
|
{
|
|
return;
|
|
}
|
|
//outline = this.gameObject.AddComponent<Outline>();
|
|
outline.enabled = false;
|
|
}));
|
|
}
|
|
|
|
public void SetValidate(bool value)
|
|
{
|
|
if (value)
|
|
{
|
|
this.mInnerInputField.GetComponent<Text>().color = Color.white;
|
|
}
|
|
else
|
|
{
|
|
ColorUtility.TryParseHtmlString("#F93086", out Color color);
|
|
this.mInnerInputField.GetComponent<Text>().color = color;
|
|
}
|
|
}
|
|
}
|
|
}
|