Unity 框架(一)
当项目需求中,后期可能接入多种输入设备的时候,可以借鉴一下以下代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System; public abstract class TInputBase : MonoBehaviour{ public event InputSchemeEventHandler InputSchemeEvent; public abstract InputSchemeEventArgs HandleInput(); public delegate void InputSchemeEventHandler(TInputBase sender, TInputBase.InputSchemeEventArgs inputArgs); //Packaging Input data
protected InputSchemeEventArgs GetInputData(GameObject currentObject,EnumList.InputResultTypes inputStyle)
{
return new InputSchemeEventArgs
{
CurrentGazeObject = currentObject, Style = inputStyle,
};
} //Notify delegates during the update method
protected void NotifyDelegates(InputSchemeEventArgs data)
{
if (InputSchemeEvent != null)
{
this.InputSchemeEvent(this, data);
}
} void Update()
{
if (this.HandleInput() != null)
{
this.NotifyDelegates(this.HandleInput());
}
} //Args (input args)
public class InputSchemeEventArgs : EventArgs
{
public GameObject CurrentGazeObject; public EnumList.InputResultTypes Style;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System; public abstract class TInputBase : MonoBehaviour{ public event InputSchemeEventHandler InputSchemeEvent; public abstract InputSchemeEventArgs HandleInput(); public delegate void InputSchemeEventHandler(TInputBase sender, TInputBase.InputSchemeEventArgs inputArgs); //Packaging Input data
protected InputSchemeEventArgs GetInputData(GameObject currentObject,EnumList.InputResultTypes inputStyle)
{
return new InputSchemeEventArgs
{
CurrentGazeObject = currentObject, Style = inputStyle,
};
} //Notify delegates during the update method
protected void NotifyDelegates(InputSchemeEventArgs data)
{
if (InputSchemeEvent != null)
{
this.InputSchemeEvent(this, data);
}
} void Update()
{
if (this.HandleInput() != null)
{
this.NotifyDelegates(this.HandleInput());
}
} //Args (input args)
public class InputSchemeEventArgs : EventArgs
{
public GameObject CurrentGazeObject; public EnumList.InputResultTypes Style;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class TKeyboardInput : TInputBase { InputSchemeEventArgs inputNoop;
public GameObject rayLaunchPoint; public override InputSchemeEventArgs HandleInput ()
{
inputNoop = null;
Ray ray = new Ray(rayLaunchPoint.transform.position, rayLaunchPoint.transform.forward);
Debug.DrawLine(ray.origin, ray.origin + (ray.direction * 800f), Color.yellow);
RaycastHit hit;
if (Physics.Raycast(ray,out hit,800f)) { if (Input.GetKeyDown(KeyCode.Space)){
inputNoop = base.GetInputData(hit.collider.gameObject,EnumList.InputResultTypes.ClickDown);
}
if (Input.GetKey(KeyCode.Space)){
inputNoop = base.GetInputData(hit.collider.gameObject,EnumList.InputResultTypes.Clicking);
}
if (Input.GetKeyUp(KeyCode.Space)){
inputNoop = base.GetInputData(hit.collider.gameObject,EnumList.InputResultTypes.ClickUp);
}
}
return inputNoop;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public abstract class TClickBase : MonoBehaviour { public abstract void HandleClick (TInputBase.InputSchemeEventArgs inputArgs);
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class TDaydreamInput : TInputBase { public override InputSchemeEventArgs HandleInput ()
{
//Debug.Log ("Daydream 手柄输入");
return null;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class TestFocusEvents : TClickBase { public override void HandleClick (TInputBase.InputSchemeEventArgs inputArgs)
{
if (inputArgs.Style.Equals(EnumList.InputResultTypes.ClickDown)) {
if (inputArgs.CurrentGazeObject.name=="Cube") {
Debug.Log ("click down cube");
}
}
if (inputArgs.Style.Equals(EnumList.InputResultTypes.Clicking)) {
if (inputArgs.CurrentGazeObject.name=="Cube") {
Debug.Log ("clicking cube");
}
}
if (inputArgs.Style.Equals(EnumList.InputResultTypes.ClickUp)) {
if (inputArgs.CurrentGazeObject.name=="Cube") {
Debug.Log ("click up cube");
}
}
}
void Start()
{
TController.register = this;
}
}
Unity 框架(一)的更多相关文章
- Unity框架入门
介绍Unity框架之前,先要说几个概念DIP依赖倒置原则.IOC控制反转.DI依赖注入 DIP是设计原则之一,定义:上层不应该依赖于底层,两者都依赖于抽象: 抽象不依赖于细节,细节应该依赖于抽象. 像 ...
- 深入理解IOC模式及Unity框架
研究了下,有几篇博客确实已经说得很清楚了 1.IoC模式:http://www.cnblogs.com/qqlin/archive/2012/10/09/2707075.html 这篇博客是通过一个 ...
- [Solution] AOP原理解析及Castle、Autofac、Unity框架使用
本节目录: AOP介绍 AOP基本原理 AOP框架 Castle Core Castle Windsor Autofac Unity AOP介绍 面向切面编程(Aspect Oriented Prog ...
- [Solution] DI原理解析及Castle、Unity框架使用
本节目录 DI介绍 DI基本原理 DI框架 Castle Windsor Unity Autofac Spring.Net DI介绍 控制反转(Inversion of Control,英文缩写为Io ...
- 基于xlua和mvvm的unity框架
1.框架简介 这两天在Github上发现了xlua的作者车雄生前辈开源的一个框架—XUUI,于是下载下来学习了一下.XUUI基于xlua,又借鉴了mvvm的设计概念.xlua是目前很火的unity热更 ...
- AOP原理解析及Castle、Autofac、Unity框架使用
转自:https://www.cnblogs.com/neverc/p/5241466.html AOP介绍 面向切面编程(Aspect Oriented Programming,英文缩写为AOP), ...
- IOC模式及Unity框架文章收藏
1.IoC模式:http://www.cnblogs.com/qqlin/archive/2012/10/09/2707075.html 通过Unity实现IOC容器. 2.深入理解DIP.IoC.D ...
- 【Unity--Apwork框架】AOP编程--拦截,用于缓存和异常处理(Unity框架的拦截注入-Interception)
第一步:定义拦截行为:CachingBehavior 和 ExceptionLoggingBehavior 他们都继承接口:IInterceptionBehavior (程序集 Microsoft.P ...
- IAR搭建unity框架
1. 新建工程 2. 增加组 unit,并加入相应源码 3. 增加需要测试的API源文件 4. 编写相应的测试用例 编译,download and debug view->TerminalIO ...
- 依赖注入Unity框架
依赖注入和控制反转是对同一件事情的不同描述,从某个方面讲,就是它们描述的角度不同.依赖注入是从应用程序的角度在描述,可以把依赖注入描述完整点:应用程序依赖容器创建并注入它所需要的外部资源:而控制反转是 ...
随机推荐
- (转载)Mac系统下利用ADB命令连接android手机并进行文件操作
Mac系统下利用ADB命令连接android手机并进行文件操作 标签: Mac adb android 2016-03-14 10:09 5470人阅读 评论(1) 收藏 举报 分类: Androi ...
- Caffe学习--Layer分析
Caffe_Layer 1.基本数据结构 //Layer层主要的的参数 LayerParamter layer_param_; // protobuf内的layer参数 vector<share ...
- 优动漫PAINT简简单单绘画绣球花
本文分享使用优动漫PAINT简简单单绘画绣球花教程: 相关资讯还可以关注http://www.dongmansoft.com 最后告诉你绣球花的花语,还是很和谐美好的呢! 绣球花没有茉莉花的芳香四溢, ...
- Maven copy方式列举
maven copy有很多种方法: 1.maven-antrun-plugin (使用ant复制) <build> <finalName>flex</finalName& ...
- WPF 内部的5个窗口之 MediaContextNotificationWindow
原文:WPF 内部的5个窗口之 MediaContextNotificationWindow 本文告诉大家在 WPF 内部的5个窗口的 MediaContextNotificationWindow 是 ...
- OpenResty.spec
Name: openresty Version: 1.13.6.1 Release: 2%{?dist} Summary: OpenResty, scalable web platform by ex ...
- linux 安装 redis3.0
下载 解压 进入目录 编译 $ wget http://download.redis.io/releases/redis-3.2.0.tar.gz $ tar xzf redis-3.0.0.tar. ...
- Qt之图形(绘制漂亮的圆弧)
简述 综合前面对二维绘图的介绍,想必我们对一些基本绘图有了深入的了解,下面我们来实现一些漂亮的图形绘制. 简述 圆形 效果 源码 弧形 效果 源码 文本 效果 源码 旋转 效果 源码 圆形 经常地,我 ...
- hadoop-15-Ambari进行HDP、zookeeper安装
hadoop-15-Ambari进行HDP.zookeeper安装 1,登陆server_1:8080 admin/admin 2,命名:Hdp_cluster 3,输入HDP.HDP_Utils 地 ...
- unix中文件I/O
在unix中可用的文件I/O函数包含打开文件,读文件,写文件等. Unix系统中的大多数文件I/O须要用到5个函数:open,read,write,lseek,close. 这里要说明的是read,w ...