ngui中 代码调用按钮事件

好烦人啊这个问题, 我弄完发上来

这个问题解决了一半 发现可以用 按钮绑定来解决这个问题,并且更安全方便快速

直接在按钮上添加一个 key binding 指定按键 搞定

不过看了一下源代码,好像这个binding实际上就是一个委托,哈哈,这样实际上两个问题都解决了@.@

using UnityEngine;

/// <summary>
/// This class makes it possible to activate or select something by pressing a key (such as space bar for example).
/// </summary> [AddComponentMenu("Game/UI/Key Binding")]
public class UIKeyBinding : MonoBehaviour
{
public enum Action
{
PressAndClick,
Select,
} public enum Modifier
{
None,
Shift,
Control,
Alt,
} /// <summary>
/// Key that will trigger the binding.
/// </summary> public KeyCode keyCode = KeyCode.None; /// <summary>
/// Modifier key that must be active in order for the binding to trigger.
/// </summary> public Modifier modifier = Modifier.None; /// <summary>
/// Action to take with the specified key.
/// </summary> public Action action = Action.PressAndClick; bool mIgnoreUp = false;
bool mIsInput = false; /// <summary>
/// If we're bound to an input field, subscribe to its Submit notification.
/// </summary> void Start ()
{
UIInput input = GetComponent<UIInput>();
mIsInput = (input != null);
if (input != null) EventDelegate.Add(input.onSubmit, OnSubmit);
} /// <summary>
/// Ignore the KeyUp message if the input field "ate" it.
/// </summary> void OnSubmit () { if (UICamera.currentKey == keyCode && IsModifierActive()) mIgnoreUp = true; } /// <summary>
/// Convenience function that checks whether the required modifier key is active.
/// </summary> bool IsModifierActive ()
{
if (modifier == Modifier.None) return true; if (modifier == Modifier.Alt)
{
if (Input.GetKey(KeyCode.LeftAlt) ||
Input.GetKey(KeyCode.RightAlt)) return true;
}
else if (modifier == Modifier.Control)
{
if (Input.GetKey(KeyCode.LeftControl) ||
Input.GetKey(KeyCode.RightControl)) return true;
}
else if (modifier == Modifier.Shift)
{
if (Input.GetKey(KeyCode.LeftShift) ||
Input.GetKey(KeyCode.RightShift)) return true;
}
return false;
} /// <summary>
/// Process the key binding.
/// </summary> void Update ()
{
if (keyCode == KeyCode.None || !IsModifierActive()) return; if (action == Action.PressAndClick)
{
if (UICamera.inputHasFocus) return; UICamera.currentTouch = UICamera.controller;
UICamera.currentScheme = UICamera.ControlScheme.Mouse;
UICamera.currentTouch.current = gameObject; if (Input.GetKeyDown(keyCode))
{
UICamera.Notify(gameObject, "OnPress", true);
} if (Input.GetKeyUp(keyCode))
{
UICamera.Notify(gameObject, "OnPress", false);
UICamera.Notify(gameObject, "OnClick", null);
}
UICamera.currentTouch.current = null;
}
else if (action == Action.Select)
{
if (Input.GetKeyUp(keyCode))
{
if (mIsInput)
{
if (!mIgnoreUp && !UICamera.inputHasFocus)
{
UICamera.selectedObject = gameObject;
}
mIgnoreUp = false;
}
else
{
UICamera.selectedObject = gameObject;
}
}
}
}
}

ngui中 代码调用按钮事件(后来改成了按钮绑定键盘..)的更多相关文章

  1. asp.net中用回车代替按钮事件

    第一步,先编写简单的页面代码,这里我们只需要一个按钮就足够了.当然,还有按钮事件. <html> <head> <title>测试绑定enter</title ...

  2. WordPress页面函数功能代码调用大全

    WordPress模板基本文件 style.css 样式表文件index.php 主页文件single.php 日志单页文件page.php 页面文件archvie.php 分类和日期存档页文件sea ...

  3. wcf 中客户端调用之死 感悟 wcf与原来的webservice2.0 的客户端调用区别(wcf调用完不关闭的话那就把web服务搞死了)

    说到wcf,本人也是刚刚使用所以不是很熟悉 在做项目的时候采用webservice+客户端程序架构 写了一个wcf中的webservice之后,又写了很多的客户端exe程序,有的是轮询调用这个webs ...

  4. DuiLib逆向分析の按钮事件定位

    目录 DuiLib逆向分析の按钮事件定位 0x00 前言 DuiLib介绍 DuiLib安装 DuiLib Hello,World! Duilib逆向分析之定位按钮事件 碎碎念 第一步:获取xml布局 ...

  5. GO学习笔记 - 包内首字母大写的名称是被导出的,才能被其它包代码调用!

    在GO语言的任意包内,如果名称的首字母是大写的,意味着这个名称被导出,在其它包中可以使用“包名.名称”方式来调用,如果名称首字母不是大写,那么只能在这个包内部使用!这个概念还真是和以往接触的编程语言的 ...

  6. 新建一个Activity通过按钮打开它,再通过按钮关闭它

    首先需要创建一个供打开和关闭的Activity,先在scr下当前项目的包中创建一个新类Activity1, 并选择让其继承自Activity类,如下图所示: 之后配置AndroidMainifest. ...

  7. 解决引用类型为什么打出的是地址值,又怎么改成输出属性值(toString()底层)

    一丶toString的源码解析: 一丶object的toString的源码解析: 集合中toString源码分析: 小结: 改成输出属性值 在父类中重写toString();方法 快捷键:Alt+In ...

  8. JS调用水晶报表打印翻页按钮事件

    默认的水晶报表打印按钮.翻页按钮太小,并且样式不好调整,考虑自己做一个按钮,然后调用水晶报表的按钮事件. 在实际操作中发现可以在.net按钮的服务器端事件中调用翻页方法: CrystalReportV ...

  9. JS事件 鼠标单击事件( onclick )通常与按钮一起使用。onclick是鼠标单击事件,当在网页上单击鼠标时,就会发生该事件。同时onclick事件调用的程序块就会被执行

    鼠标单击事件( onclick ) onclick是鼠标单击事件,当在网页上单击鼠标时,就会发生该事件.同时onclick事件调用的程序块就会被执行,通常与按钮一起使用. 比如,我们单击按钮时,触发  ...

随机推荐

  1. Install Jenkins Slave as Windows Service

    https://wiki.jenkins-ci.org/display/JENKINS/Installing+Jenkins+as+a+Windows+service SC 直接创建windows s ...

  2. Maximo7自定义实现WebService

    最近很多人在群里聊这个话题,我就也一个hello world来实现一下. 1.自定义一个类,继承于AppService 代码如下:

  3. 报表控件NCreport教程:报表高级设计

    本次文章中将讲解NCreport一些高级功能的应用,我们会先定义一个组,接下来会添加summary变量到示例报表中. 一.对summary添加变量 对于提供的数量和总量来说,变量是特殊的数值项,它们每 ...

  4. Swift3.0都有哪些变化

    从写第一篇Swift文章的时候到现在Swift已经从1.2发展到了今天的3.0,这期间由于Swift目前还在发展阶段并不能向下兼容,因此第一篇文章中的部分代码在当前的Xcode环境中已经无法运行.在W ...

  5. SQL Server2014,附加数据库失败,错误为:5120的解决方法

    在SQL Server 2014附加数据库的时候,报错为: 无法打开物理文件XXX,操作系统错误5(拒绝访问),SQL Server 错误5120 解决方法:  我的电脑→管理→服务和应用程序→ 服务 ...

  6. [课程设计]Scrum 3.8 多鱼点餐系统开发进度(留言反馈系统设计)

    Scrum 3.8 多鱼点餐系统开发进度(留言反馈系统设计) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题:餐厅到店点餐系统 ...

  7. Uva 1629 切蛋糕

    题目链接:https://vjudge.net/contest/146179#problem/B 题意:一个矩形蛋糕上有好多个樱桃,现在要做的就是切割最少的距离,切出矩形形状的小蛋糕,让每个蛋糕上都有 ...

  8. 瘋子C语言笔记(结构体/共用体/枚举篇)

    (一)结构体类型 1.简介: 例: struct date { int month; int day; int year; }; struct student { int num; char name ...

  9. 【Python】Python3中的str和bytes

    参考文章:Python 3的bytes/str之别 len()函数计算的是str的字符数,如果换成bytes,len()函数就计算字节数 >>> len('ABC') 3 >& ...

  10. 准备阶段-mongodb数据库安装

    具体安装步骤,请参阅 mongoDB(win7_64位)使用手册1.0