同步移动到示例文件
This commit is contained in:
100
Samples~/ConfigUIElement/Scripts/ConfigTextInputField.cs
Normal file
100
Samples~/ConfigUIElement/Scripts/ConfigTextInputField.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace LRC
|
||||
{
|
||||
/// <summary>
|
||||
/// һ<><D2BB><EFBFBD><EFBFBD>ͨ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
public class ConfigTextInputField : ConfigSelectableItem
|
||||
{
|
||||
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD>
|
||||
|
||||
#if UNITY_EDITOR
|
||||
public string editorInput;
|
||||
#endif
|
||||
|
||||
public TMP_InputField targetInput;
|
||||
|
||||
|
||||
public override bool AllowInput
|
||||
{
|
||||
get => base.AllowInput;
|
||||
set
|
||||
{
|
||||
if (targetInput != null)
|
||||
targetInput.readOnly = !value;
|
||||
base.AllowInput = value;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
protected override void OnValidate()
|
||||
{
|
||||
base.OnValidate();
|
||||
#if UNITY_EDITOR
|
||||
if (targetInput != null)
|
||||
targetInput.text = editorInput;
|
||||
#endif
|
||||
}
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
targetInput.onSelect.AddListener(a =>
|
||||
{
|
||||
WhenStartEdit();
|
||||
});
|
||||
targetInput.onValueChanged.AddListener(o =>
|
||||
{
|
||||
if(double.TryParse(o, out var value))
|
||||
SetValue(value);
|
||||
});
|
||||
targetInput.onEndEdit.AddListener(delegate
|
||||
{
|
||||
WhenEndEdit();
|
||||
});
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ʵ<EFBFBD><EFBFBD>
|
||||
|
||||
protected override void SetValue(object newValue)
|
||||
{
|
||||
base.SetValue(newValue);
|
||||
}
|
||||
|
||||
public override void RefreshValueWithoutEvent(object newValue, bool forceSet = false)
|
||||
{
|
||||
base.RefreshValueWithoutEvent(newValue, forceSet);
|
||||
}
|
||||
|
||||
protected override void Initialization_ChildConstruction(UIBehaviour component)
|
||||
{
|
||||
base.Initialization_ChildConstruction(component);
|
||||
|
||||
if (component is TMP_InputField inputField)
|
||||
{
|
||||
if (targetInput != null)
|
||||
targetInput = inputField;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void RefreshFormatValue(object newValue)
|
||||
{
|
||||
base.RefreshFormatValue(newValue);
|
||||
targetInput.text = newValue.ToString();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user