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. viewport设置

    <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable ...

  2. 用 正则表达式 限定XML simpleType 定义

    <xsd:simpleType name="ResTrictions"> <xsd:restriction base="xsd:string" ...

  3. USB驱动开发大全【转】

    本文转载自:http://www.360doc.com/content/12/0504/19/8363527_208666082.shtml 编写USB驱动程序步骤:1所有usb驱动都必须创建主要结构 ...

  4. 通达信5分钟.lc5和.lc1文件格式

    一.通达信日线*.day文件    文件名即股票代码    每32个字节为一天数据    每4个字节为一个字段,每个字段内低字节在前    00 ~ 03 字节:年月日, 整型    04 ~ 07 ...

  5. Web Api 简介

    ASP.NET Web API 简介  ASP.NET MVC 4 包含了 ASP.NET Web API, 这是一个创建可以连接包括浏览器.移动设备等多种客户端的 Http 服务的新框架, ASP. ...

  6. Program.cs

    Program.cs using System; namespace HelloWorld { class Program { [STAThread] static void Main(string[ ...

  7. VS配置路径和宏

    http://blog.csdn.net/puttytree/article/details/7838419

  8. 【Spring】简单的Spring AOP注解示例

    引入相关包: <properties> <spring.version>3.0.5.RELEASE</spring.version> <aspectj.ver ...

  9. MATLAB地图工具箱学习总结(二)大圆和恒向线

    MATLAB地图工具箱学习总结(二)大圆和恒向线 今天要和大家谈一谈大圆.恒向线航道的画法.还是先从案例开始说起,再分别介绍相关的函数. 1                    作业案例:地图投影作 ...

  10. python之初级学习

    一.python安装 1.下载安装包(本人使用python3.5.1) https://www.python.org/downloads/ 2.安装python-3.5.1.exe 本人下载的是pyt ...