用C#重写Unity3D的Joystick

本文档介绍了一个C#脚本Joystick.cs,用于创建可移动的触摸摇杆,处理触摸输入、点击和阶段。该摇杆支持死区控制,可以进行归一化处理。同时,它也可以作为TouchPad使用,允许手指在任意位置触摸并跟踪相对运动,而不移动图形。
摘要由CSDN通过智能技术生成
/// <summary>
//Joystick.cs
//Penelope iPhone Tutorial
//
//Joystick creates a movable joystick (via GUITexture) that
//handles touch input, taps, and phases. Dead zones can control
//where the joystick input gets picked up and can be normalized.]
//
//Optionally, you can enable the touchPad property from the editor
//to treat this Joystick as a TouchPad. A TouchPad allows the finger 
//to touch down at any point and it tracks the movement relatively
//without moving the graphic.
/// </summary>

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(GUITexture))]

//A simple class for bounding how far the GUITexture will move
public class Boundary
{
	public Vector2 min = Vector2.zero;
	public Vector2 max = Vector2.zero;
}

public class Joystick : MonoBehaviour {
	private static Joystick[] joysticks;				//A static collection of all joysticks			
	private static bool enumeratedJoysticks = false;
	private static float tapTimeDelta = 0.3f;			//Time allowed between taps

	public bool touchPad;								//Is this a TouchPad?
	public Rect touchZone;
	public Vector2 deadZone = Vector2.zero;				//Control when position is output
	public bool normalize = false;						//Normalize output after the dead-done
	public Vector2 position;							//[-1,1] in x,y
	public int tapCount;								//Current tap count

	private int lastFingerId = -1;						//Finger last used for this joystick
	private float tapTimeWindow;						//how much time there is left for a tap to occur
	pr
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值