Unity3d:地铁跑酷操控解析
来源:互联网 发布:辣妈韦雪淘宝店网址 编辑:程序博客网 时间:2024/04/29 03:18
1.用于记录每次操作的开始点和结束点、开始时间和结束时间
public class Swipe
{// Fields
public Vector3 end;
public float endTime;
public Vector3 start;
public float startTime;
}
2.四个滑动方向的枚举
public enum SwipeDir
{
Up,
Down,
Left,
Right,
None
}
3.监听Touch输入,得到输入的Swipe
public void HandleControls()
{
if (!this._paused && (Input.touchCount > 0))
{
Touch touch = Input.touches[0];
if (touch.phase == TouchPhase.Began)
{
this.currentSwipe = new Swipe();
this.currentSwipe.start = (Vector3) touch.position;
this.currentSwipe.startTime = Time.time;
}
if ((((touch.phase == TouchPhase.Moved) || (touch.phase == TouchPhase.Ended)) || (touch.phase == TouchPhase.Canceled)) && (this.currentSwipe != null))
{
this.currentSwipe.endTime = Time.time;
this.currentSwipe.end = (Vector3) touch.position;
SwipeDir swipeDir = this.AnalyzeSwipe(this.currentSwipe);
if (swipeDir != SwipeDir.None)
{
if (this.characterState != null)
{
this.characterState.HandleSwipe(swipeDir);
}
this.currentSwipe = null;
}
}
if ((touch.phase == TouchPhase.Ended) && (this.currentSwipe != null))
{
this.currentSwipe.endTime = Time.time;
this.currentSwipe.end = (Vector3) touch.position;
if ((this.AnalyzeSwipe(this.currentSwipe) == SwipeDir.None) && (this.characterState != null))
{
this.HandleTap();
}
}
}
}
4.处理、分析得到是Swip;通过向量的点乘,得到沿上下左右四个方向上分量做多的那个方向,作为最终结果。
private SwipeDir AnalyzeSwipe(Swipe swipe)
{
Vector3 b = Camera.main.ScreenToWorldPoint(new Vector3(swipe.start.x, swipe.start.y, 2f));
if (Vector3.Distance(Camera.main.ScreenToWorldPoint(new Vector3(swipe.end.x, swipe.end.y, 2f)), b) < this.swipe.distanceMin)
{
return SwipeDir.None;
}
Vector3 lhs = swipe.end - swipe.start;
SwipeDir none = SwipeDir.None;
float num2 = 0f;
float num3 = Vector3.Dot(lhs, Vector3.up);
if (num3 > num2)
{
num2 = num3;
none = SwipeDir.Up;
}
num3 = Vector3.Dot(lhs, Vector3.down);
if (num3 > num2)
{
num2 = num3;
none = SwipeDir.Down;
}
num3 = Vector3.Dot(lhs, Vector3.left);
if (num3 > num2)
{
num2 = num3;
none = SwipeDir.Left;
}
num3 = Vector3.Dot(lhs, Vector3.right);
if (num3 > num2)
{
num2 = num3;
none = SwipeDir.Right;
}
return none;
}
地铁跑酷的操控手感灰常好,多多学习,多多借鉴。
欢迎大家一起学习讨论研究~
- Unity3d:地铁跑酷操控解析
- 地铁跑酷操控程序解析
- Unity3d C# 利用SQLDMO操控SQL Server
- 新版地铁跑酷疯狂来袭了
- 地铁
- unity3d AI 学习--个体行为操控(1)
- unity3d之ai操控行为术语中英文对照表
- unity3d AI 学习--个体行为操控(1)--具体行为类(1)
- unity3d AI 学习--个体行为操控(1)--具体行为类(2)
- Samp免流软件以及地铁跑酷的自校验分析
- unity3d解析json
- [unity3d] iTween文档解析
- unity3d解析json
- Unity3d Json解析库
- unity3d AI 学习--个体行为操控(1)--具体行为类(3)-路径跟随和躲避障碍
- 一种基于简单递归思想的易操控xml解析封装(C++)
- 方向盘操控
- 字符串操控
- [隐式图搜索]Knights in FEN UVA10422
- Java中如何检查String中的字符是数字?
- Log4J学习【十五】XML的配置方式练习
- TortoiseGit之下载地址
- java 获取程序执行时间
- Unity3d:地铁跑酷操控解析
- VC++调用webservice (不使用.NET的托管技术)
- 达梦(2)安装后启动服务及生成数据库
- 先为己之不可胜,乘敌之败,一举而平
- Base64编码格式 和 String的转换
- Eclipse RCP开发:使用Maven的Tycho插件打包部署
- IceWarp 即时通讯(IM)服务
- 数据库中跨服务器查询
- jar 转换为 dll