位置: 编程技术 - 正文

NGUI版虚拟摇杆joystick(虚拟摇杆 安卓)

编辑:rootadmin

推荐整理分享NGUI版虚拟摇杆joystick(虚拟摇杆 安卓),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:虚拟摇杆是什么意思,虚拟摇杆3.0,虚拟摇杆下载安卓,虚拟摇杆手游,虚拟摇杆怎么调,虚拟摇杆3.0,虚拟摇杆3.0,虚拟摇杆3.0,内容如对您有帮助,希望把文章链接给更多的朋友!

view plaincopyusing UnityEngine; using System.Collections; using System.Collections.Generic; [ExecuteInEditMode] public class Joystick : MonoBehaviour { #region Delegate & Event public delegate void JoystickEventHandler(Joystick joystick); /// <summary> /// 开如 /// </summary> public static event JoystickEventHandler On_JoystickMoveStart; /// <summary> /// Occurs when the joystick move. /// </summary> public static event JoystickEventHandler On_JoystickMove; /// <summary> /// thumb偏离中心位置,并牌按住时,每帧的回调 /// </summary> public static event JoystickEventHandler On_JoystickHolding; /// <summary> /// Occurs when the joystick stops move /// </summary> public static event JoystickEventHandler On_JoystickMoveEnd; #endregion #region property [SerializeField] bool isRunInEditor = false; [SerializeField]private string joystickName = "NguiJoystick"; public string JoystickName { get { return this.joystickName; } } [HideInInspector]private bool isLimitInCircle = true; public bool IsLimitInCircle { get { return this.isLimitInCircle; } } [SerializeField]private int radius = ; public int Radius { get{ return this.radius; } } [SerializeField] private float minAlpha = 0.3f; public float MinAlpha { get { return this.minAlpha; } } private Vector2 joystickAxis = Vector2.zero; /// <summary> /// Gets the joystick axis value between -1 & 1... /// </summary> /// <value> /// The joystick axis. /// </value> public Vector2 JoystickAxis { get { return this.joystickAxis; } } private Vector2 lastJoystickAxis = Vector2.zero; public Vector2 LastJoystickAxis { get { return this.lastJoystickAxis; } } bool isForBid = false; /// <summary> /// 判断joystick是否被禁用 /// </summary> public bool IsForBid { get { return this.isForBid; } } bool isHolding = false; public bool IsHolding { get { return this.isHolding; } } #endregion UIWidget root; [SerializeField]UISprite bg; [SerializeField]UISprite thumb; void Awake() { this.name = this.JoystickName; root = this.GetComponent<UIWidget>(); Init(); } // Update is called once per frame void Update () { if (isRunInEditor && Application.isEditor && !Application.isPlaying) { SetJoystickSize(radius); } if (!isForBid && isHolding) { Debug.Log(""); if (On_JoystickHolding != null) { On_JoystickHolding(this); } } } void Init() { bg.transform.localPosition = Vector3.zero; thumb.transform.localPosition = Vector3.zero; SetJoystickSize(radius); Lighting(minAlpha); } #region ngui event ///// <summary> ///// test ///// </summary> //void OnClick () //{ // Debug.Log("mouse pos :" &#; Input.mousePosition &#; " -- touch pos :" &#; ScreenPos_to_NGUIPos(Input.mousePosition)); // thumb.transform.localPosition = ScreenPos_to_NGUIPos(Input.mousePosition); //} void OnPress (bool isPressed) { if (isForBid) { Debug.Log("joystick is forbid!"); return; } Debug.Log("OnPress:" &#; isPressed.ToString()); if(isPressed) { Lighting(1f); CalculateJoystickAxis(); if (On_JoystickMoveStart != null) { On_JoystickMoveStart(this); } isHolding = true; } else { CalculateJoystickAxis(); if (On_JoystickMoveEnd != null) { On_JoystickMoveEnd(this); } thumb.transform.localPosition = Vector3.zero; FadeOut(1f, minAlpha); isHolding = false; } } //void OnDragStart () //{ // if (isForBid) // { // Debug.Log("joystick is forbid!"); // return; // } // Debug.Log("OnDragStart"); // Lighting(1f); // CalculateJoystickAxis(); // if(On_JoystickMoveStart!=null) // { // On_JoystickMoveStart(this); // } // isHolding = true; // Debug.Log(string.Format("time:{0} - axis:{1}", Time.time, joystickAxis)); //} void OnDrag(Vector2 delta) { if (isForBid) { return; } //Debug.Log("OnDrag:"&#;delta.ToString()); CalculateJoystickAxis(); if (On_JoystickMoveStart != null) { On_JoystickMoveStart(this); } } //void OnDragEnd () //{ // if (isForBid) // { // return; // } // Debug.Log("OnDragEnd"); // CalculateJoystickAxis(); // if (On_JoystickMoveEnd != null) // { // On_JoystickMoveEnd(this); // } // thumb.transform.localPosition = Vector3.zero; // FadeOut(1f, minAlpha); // isHolding = false; //} #endregion #region utile /// <summary> /// 计算JoystickAxis /// </summary> /// <returns></returns> void CalculateJoystickAxis() { Vector3 offset = ScreenPos_to_NGUIPos(UICamera.currentTouch.pos); offset -= transform.localPosition; if (isLimitInCircle) { if (offset.magnitude > radius) { offset = offset.normalized * radius; } } thumb.transform.localPosition = offset; lastJoystickAxis = joystickAxis; joystickAxis = new Vector2(offset.x / radius, offset.y / radius); } /// <summary> /// Axis2s the angle. /// </summary> /// <returns> /// The angle. /// </returns> public float Axis2Angle(bool inDegree = true) { float angle = Mathf.Atan2(joystickAxis.x, joystickAxis.y); if (inDegree) { return angle * Mathf.Rad2Deg; } else { return angle; } } /// <summary> /// Axis2s the angle. /// </summary> /// <returns> /// The angle. /// </returns> public float Axis2Angle(Vector2 axis, bool inDegree = true) { float angle = Mathf.Atan2(axis.x, axis.y); if (inDegree) { return angle * Mathf.Rad2Deg; } else { return angle; } } /// <summary> /// 屏幕坐标-->ui坐标 /// </summary> /// <param name="screenPos"></param> /// <returns></returns> Vector3 ScreenPos_to_NGUIPos(Vector3 screenPos) { Vector3 uiPos = UICamera.currentCamera.ScreenToWorldPoint(screenPos); uiPos = UICamera.currentCamera.transform.InverseTransformPoint(uiPos); return uiPos; } /// <summary> /// 屏幕坐标-->ngui坐标 /// </summary> /// <param name="screenPos"></param> /// <returns></returns> Vector3 ScreenPos_to_NGUIPos(Vector2 screenPos) { return ScreenPos_to_NGUIPos(new Vector3(screenPos.x, screenPos.y, 0f)); } /// <summary> /// 设置摇杆的大小 /// </summary> /// <param name="radius"></param> void SetJoystickSize(int radius) { root.width = 2 * radius; root.height = 2 * radius; thumb.width = (int)(f / f * root.width); thumb.height = (int)(f / f * root.height); } /// <summary> /// 点亮摇杆 /// </summary> void Lighting(float alpha) { iTween.Stop(this.gameObject, "value"); root.alpha = alpha; } /// <summary> /// 渐变摇杆的透明度 /// </summary> void FadeOut(float fromAlpha, float toAlpha) { Hashtable itweenArgs = new Hashtable(); itweenArgs.Add("easetype", iTween.EaseType.linear); itweenArgs.Add("from", fromAlpha); itweenArgs.Add("to", toAlpha); itweenArgs.Add("time", 0.5f); itweenArgs.Add("onupdate", "OnFadeOutTween"); iTween.ValueTo(this.gameObject, itweenArgs); } void OnFadeOutTween(float value) { root.alpha = value; } #endregion #region 激活、禁用的控制 List<string> keys = new List<string>(); /// <summary> /// 禁用 /// </summary> /// <returns>返回&#;是,取消这个禁用要用到的key</returns> public string ForbidJosystick() { string key = System.Guid.NewGuid().ToString(); keys.Add(key); isForBid = true; return key; } /// <summary> /// 启用 /// </summary> /// <param name="key"></param> public void ActivizeJosystick(string key) { if(keys.Contains(key)) { keys.Remove(key); } isForBid = true; if(keys.Count==0) { isForBid = false; } } #endregion } 3、demo包,有兴趣的,也可以看看。NGUI版虚拟摇杆joystick(虚拟摇杆 安卓)

下载:

Unity手游之路<十二>手游资源热更新策略探讨

Unity手游之路<十三>手游代码更新策略探讨

unity3d shader 学习笔记1 在unity中我们经常会使用shader,但是从来没有深究过,最近在做项目时遇到相关问题,无从下手,决定系统学习一番,在此前提下把我学习的过程做一个

标签: 虚拟摇杆 安卓

本文链接地址:https://www.jiuchutong.com/biancheng/383553.html 转载请保留说明!

上一篇:unity中可以使一个私有的变量在Inspector面板中显示出来 和 SerializeField的使用(unity或者)

下一篇:Unity手游之路<十二>手游资源热更新策略探讨(手游 unity)

  • 什么情况用已交税金
  • 失控发票账务处理
  • 延期申报后可否延期缴纳税款
  • 视同销售收入是纳税调整项目吗?
  • 小规模纳税人零申报是每季度报吗
  • 图书计入什么费用
  • 投资收益科目在贷方
  • 闲置固定资产如何做账
  • 农产品普通发票抵扣政策
  • 所得税季度预交税率是多少
  • 现金日记账承前页过次页
  • 拆迁补偿费返还政策
  • 发票金额多开了有事吗
  • 金税三期后企业没活路
  • 工商公示纳税总额包含个税吗
  • 本年利润包含增值税吗
  • 企业所得税表样
  • 债券分期还本利息怎么算
  • 贸易公司代采购怎么做账
  • 减半征收企业所得税税率
  • 事业单位收到增值税专用发票抵扣联怎么办
  • 一般纳税人取得3%专票可以抵扣吗
  • 小规模纳税人没有收入怎么报税
  • 视频制作费属于劳务费吗
  • 减免附加税的账户有哪些
  • 蔬菜销售收入免增值税吗
  • 哪些费用可以税前扣除
  • 原材料入库如何分类
  • 销售净利率怎么分析盈利能力
  • 购买方已抵扣申请红票,销售方为开具 购买方如何作废
  • 会计凭证传递的原则及基本程序
  • 防伪税控技术维护费可以全额抵扣吗
  • 增值税进项税额转出的情况有哪些
  • 消防器材怎么做?
  • PHP:Memcached::set()的用法_Memcached类
  • PHP:stream_context_get_params()的用法_Stream函数
  • php的数组函数
  • 新西兰萨摩亚人
  • node.txt
  • 实际退税能退多少
  • 善意取得虚开增值税专用发票处理
  • php数组分为哪两种
  • js点击图片跳转页面
  • php中验证码如何实现登录验证
  • php中实现文件上传需要用到哪几个函数
  • 这几个sql语法的区别
  • 货真价实的话
  • jquery+thinkphp实现跨域抓取数据的方法
  • 公司租赁个人车辆怎么开发票
  • 刚成立的新公司怎么报税
  • 减按10的税率征收个人所得税
  • 计提事业发展基金分录
  • 应收款超过多久未收回可界定为损失
  • 虚开发票是指怎样?
  • mysql 5.7.1
  • 基本户和一般户可以互相转账吗
  • 个体工商户属于个人还是企业
  • 员工报销货款会计分录怎么写
  • 工业企业制造费用包括哪些
  • 计提折旧会计分录怎么做
  • 未开票收入如何申报
  • 增值税附加税减半政策
  • 法院强制执行扣完款就完事了吗
  • 报销人跟领款人有什么区别
  • 非金融企业之间借款账务处理
  • 什么是固定资产?其特征有哪些
  • macbookair安装rosetta
  • windows8怎么关闭广告弹窗
  • rftray.exe - rftray是什么进程 有什么用
  • win8怎么固定桌面
  • win10预览版怎么安装
  • linux开机流程详解
  • unity判断点击ui
  • python 效率优化
  • android布局文件放在哪
  • unity3d 脚本
  • jquery中加载文档的方法
  • 安卓手机加速方法
  • Python实现类似jQuery使用中的链式调用的示例
  • 成品油消费税税目税率表2023
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设