双击实现文字编辑
2017-12-12 19:58
1176 查看
首先,本功能使用UGUI的InputField实现。
正常来说,InputField是单击便可进行编辑的,所以开始关闭的它的可编辑功能,取消勾选“interactable”即可。
接下来便要实现双击功能,再次附上以前已写好的点击事件:
添加完成编辑事件,关闭可编辑状态:
/// <summary>
/// 添加完成编辑事件
/// </summary>
private void AddEndEditEvent()
{
gom.inp_ZhiDaoYuName.onEndEdit.AddListener(TitleEndEdit);
}
/// <summary>
/// 题目完成编辑事件
/// </summary>
private void TitleEndEdit(string arg0)
{
gom.inp_ZhiDaoYuName.interactable = false;
if (gom.inp_ZhiDaoYuName.text == "")
gom.inp_ZhiDaoYuName.text = "默认值";
}
正常来说,InputField是单击便可进行编辑的,所以开始关闭的它的可编辑功能,取消勾选“interactable”即可。
接下来便要实现双击功能,再次附上以前已写好的点击事件:
using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; public class ClickEvent: MonoBehaviour,IPointerClickHandler { public UnityEvent singleClick = new UnityEvent(); public UnityEvent doubleClick = new UnityEvent(); public UnityEvent rightClick = new UnityEvent(); public UnityEvent middleClick = new UnityEvent(); public void OnPointerClick(PointerEventData eventData) { if (eventData.clickCount == 1 && eventData.button == PointerEventData.InputButton.Left) { singleClick.Invoke(); } else if (eventData.clickCount == 2 && eventData.button == PointerEventData.InputButton.Left) { doubleClick.Invoke(); } else if (eventData.button == PointerEventData.InputButton.Right) { rightClick.Invoke(); } else if (eventData.button == PointerEventData.InputButton.Middle) { middleClick.Invoke(); } } }然后给InputField添加双击事件,将可编辑状态打开,并使内容出于选中状态:
/// <summary> /// 题目双击事件 /// </summary> private void TitleDoubleClick() { gom.inp_ZhiDaoYuName.gameObject.AddComponent<ClickEvent>().doubleClick.AddListener(() => { gom.inp_ZhiDaoYuName.interactable = true; gom.inp_ZhiDaoYuName.Select();//使内容处于选中状态 }); }
添加完成编辑事件,关闭可编辑状态:
/// <summary>
/// 添加完成编辑事件
/// </summary>
private void AddEndEditEvent()
{
gom.inp_ZhiDaoYuName.onEndEdit.AddListener(TitleEndEdit);
}
/// <summary>
/// 题目完成编辑事件
/// </summary>
private void TitleEndEdit(string arg0)
{
gom.inp_ZhiDaoYuName.interactable = false;
if (gom.inp_ZhiDaoYuName.text == "")
gom.inp_ZhiDaoYuName.text = "默认值";
}
相关文章推荐
- 双击文字后实现编辑文本功能
- [网页]双击文字后实现编辑文本功能
- [网页]双击文字后实现编辑文本功能
- 双击文本实现可编辑
- ListControl双击实现可编辑
- 实现列表双击可编辑,异步更新;实现删除的即时移除;
- 实现JTree双击节点的可编辑
- 实现鼠标双击DataGrid的一行,使该行成为编辑状态
- jquery wysiwyg.js实现富文本编辑框,可复制图片及文字
- JS实现双击编辑可修改状态的方法
- 双击文字出现编辑文本框的JS代码,并可编辑成功
- ListControl双击实现可编辑 2010-11-16 11:40
- 双击文本实现可编辑
- bootstrap table实现双击可编辑、添加、删除行功能
- 比较简单的javascript实现input双击后可以编辑
- 不用ajax实现点击文字即可编辑的方法
- 如何实现双击GridView 单元格编辑单元格内容
- JTable只要一双击就进入编辑状态,禁止的方法实现
- JS实现双击编辑可修改
- GridView实现双击进行编辑,更新