位置: 编程技术 - 正文

NGUI带位置图标的拖动例子

编辑:rootadmin
转载自: 最近由于工作需要学习UNITY3D,对于做PHP的程序猿挑战性灰常大,unity3D国内相关资料少得可怜唉!

推荐整理分享NGUI带位置图标的拖动例子,希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:,内容如对您有帮助,希望把文章链接给更多的朋友!

根据需求做个防“天天爱消除”主界面左右滑动窗体的效果,百度搜到雨凇大神的一个帖子

NGUI研究院之自制 Scroll View实现触摸滚动相册效果(四)

不过效果不怎么理想,没有平滑的spring动画。研究NGUI自带的Example 7 - Scroll View (Panel) 例子

实现了如下效果:

NGUI带位置图标的拖动例子

UIDragSlider.cs: 该脚本扩展了UICenterOnChild.CS的功能!用于灰白点队列的初始化工作以及根据最近中心点的窗体下标控制白点显示的位置。

UIDragSlider.cs

?usingUnityEngine; /// <summary>/// Ever wanted to be able to auto-center on an object within a draggable panel?/// Attach this script to the container that has the objects to center on as its children./// </summary> //[AddComponentMenu("NGUI/Interaction/Center On Child")]publicclassUIDragSlider : MonoBehaviour{ /// <summary> /// The strength of the spring. /// </summary> publicfloatspringStrength = 8f; /// <summary> /// Callback to be triggered when the centering operation completes. /// </summary> publicSpringPanel.OnFinished onFinished; //用来放置灰色、白色小点 publicTransform ponit; //白色的小点 publicGameObject prefabMaskDot; //灰色的小点 publicGameObject prefabBaseDot; //白色小点的临时对象 privateGameObject maskDot; //灰色、白色小点下方的起始位置。 intstart; UIDraggablePanel mDrag; GameObject mCenteredObject; /// <summary> /// Game object that the draggable panel is currently centered on. /// </summary> publicGameObject centeredObject { get{returnmCenteredObject; } } voidOnEnable () { Recenter (); //initSlider (); } voidStart () { initSlider (); } voidOnDragFinished () { if(enabled) Recenter (); } /// <summary> /// Recenter the draggable list on the center-most child. /// </summary> publicvoidRecenter () { if(mDrag == null) { mDrag = NGUITools.FindInParents<UIDraggablePanel> (gameObject); //mDrag = GameObject.Find("UIPanel (Clipped View)").GetComponent<UIDraggablePanel>(); if(mDrag == null) { Debug.LogWarning (GetType () &#; " requires " &#; typeof(UIDraggablePanel) &#; " on a parent object in order to work",this); enabled = false; return; }else{ //mDrag = mDrag.GetComponent<UIDraggablePanel>(); mDrag.onDragFinished = OnDragFinished; //Debug.Log(mDrag.panel); if(mDrag.horizontalScrollBar != null) mDrag.horizontalScrollBar.onDragFinished = OnDragFinished; if(mDrag.verticalScrollBar != null) mDrag.verticalScrollBar.onDragFinished = OnDragFinished; } } if(mDrag.panel == null) return; // Calculate the panel's center in world coordinates Vector4 clip = mDrag.panel.clipRange; Transform dt = mDrag.panel.cachedTransform; Vector3 center = dt.localPosition; center.x &#;= clip.x; center.y &#;= clip.y; center = dt.parent.TransformPoint (center); // Offset this value by the momentum Vector3 offsetCenter = center - mDrag.currentMomentum * (mDrag.momentumAmount * 0.1f); mDrag.currentMomentum = Vector3.zero; floatmin = float.MaxValue; Transform closest = null; Transform trans = transform; // Determine the closest child for(inti = 0, imax = trans.childCount; i < imax; &#;&#;i) { Transform t = trans.GetChild (i); floatsqrDist = Vector3.SqrMagnitude (t.position - offsetCenter); if(sqrDist < min) { min = sqrDist; closest = t; } } if(closest != null) { Debug.Log (closest.gameObject.name); mCenteredObject = closest.gameObject; // Figure out the difference between the chosen child and the panel's center in local coordinates Vector3 cp = dt.InverseTransformPoint (closest.position); Vector3 cc = dt.InverseTransformPoint (center); Vector3 offset = cp - cc; // Offset shouldn't occur if blocked by a zeroed-out scale if(mDrag.scale.x == 0f) offset.x = 0f; if(mDrag.scale.y == 0f) offset.y = 0f; if(mDrag.scale.z == 0f) offset.z = 0f; // Spring the panel to this calculated position SpringPanel.Begin (mDrag.gameObject, dt.localPosition - offset, springStrength).onFinished = onFinished; //两个方法一个设置名字 //获取当前下标 /* int index=0; foreach(Transform child in transform){ if(child.gameObject==closest.gameObject){ Debug.Log("index:"&#;index); setMaskPos(index); } index&#;&#;; } */ //第二个方法需要命名 string[] indexName = closest.gameObject.name.Split ('_'); setMaskPos (int.Parse (indexName [1])); }else mCenteredObject = null; } voidinitSlider () { //因为下方灰色 白色的小点需要根据相册列表的数量来计算居中显示 intsize = transform.childCount; //乘以表示计算所有小点加起来的宽度 intlength = (size - 1) * ; //得到下方灰色 白色 小点的居中起始位置 start = (-length) >> 1; for(inti=0; i< size; i&#;&#;) { //把每一个灰色小点加入3D世界 GameObject hui = (GameObject)Instantiate (prefabBaseDot); //设置灰色小点的父类为另外一个面板 hui.transform.parent = ponit; //设置每一个灰色小点的位置与缩放,总之让它们居中排列显示在相册列表下方。 hui.transform.localPosition = newVector3 (start &#; i * , -f, 0f); hui.transform.localScale = newVector3 (, , 1); //深度 因为是先在屏幕下方绘制4个灰色的小点, 然后在灰色上面绘制白色小点 //表示当前的窗口ID 所以深度是为了设置白色小点在灰色小点之上绘制 hui.GetComponent<UISprite> ().depth = 0; } //把白色小点也加载在3D世界中 maskDot = (GameObject)Instantiate (prefabMaskDot); //设置它的深度高于 灰色小点,让白色小点显示在灰色小点之上 maskDot.GetComponent<UISprite> ().depth = 1; //设置白色小点的开始位置 setMaskPos (0); } voidsetMaskPos (intindex) { maskDot.transform.parent = ponit; maskDot.transform.localPosition = newVector3 (start &#; index * , -f, -f); maskDot.transform.localScale = newVector3 (, , 1); }}把脚本加到UIGrid上面

如有疑问请站内

Unity3D ugui事件监听机制 UGUI控件的事件响应有很多种方式,比如使用组件EventTrigger来添加事件监听,或者实现IDragHandler等接口,或者更直接地继承EventTrigger来进行更灵话的调用

Screen.sleepTimeout=SleepTimeOut.NeverSleep 禁止屏幕锁屏 Screen.

UI Overview——UI概述 我决定翻译uGUI的官方文档,一来是自己可以有一个全面整体的了解,二来是可以方便大家,网上好像也有些翻译,不过语句有点不通顺,总之我要翻译

标签: NGUI带位置图标的拖动例子

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

上一篇:A Type-Safe Event System for Unity3D

下一篇:Unity3D ugui事件监听机制

  • 未达起征点的增值税要交企业所得税吗
  • 企业所得税弥补亏损明细表怎么填写
  • 基本户和一般户的用途
  • 融资租入的固定资产需要计提折旧吗
  • 去年的成本如何调整汇算清缴额
  • 预包装食品是否备案怎么查询
  • 已经认证不能抵扣怎么办
  • 企业捐赠扣除标准,超出部分
  • 进账单填错了用重新开转账支票吗
  • 交汇算清缴所得吗
  • 建筑公司外包工程收入怎么记账
  • 应交增值税减免税额
  • 什么时候计提资本成本
  • 经营性罚款和行政性罚款的区别
  • 案例分析工程发票进项高于销项怎么抵扣?
  • 异地不动产租赁 深圳税务 所得税
  • 企业注销前需要固定资产清理吗
  • 出租不动产什么时候交税
  • 经营性租入的固定资产需要计提折旧吗
  • 平销返利可以作为下期的折扣开票吗?
  • 个人所得税的征收
  • 收到财政扶贫补贴会计分录
  • led电子屏税收编码
  • 企业收到利息收入开发票吗
  • 使用u盘安装linux
  • 股权转让的会计凭证
  • 低值易耗品处理的目的
  • win11不显示桌面,但是有文件夹打开的标志是怎么回事
  • win10蓝屏错误怎么办
  • php字符串定义
  • 个体公司转账给私人
  • flash是什么文件
  • 电脑显示语言栏在哪里
  • 前端框架view
  • 取得短期借款会计科目
  • typora如何设置字体颜色
  • websocket基于http
  • 参加《2022 中国开发者影响力盛典》我的 4 重收获!
  • nmap的命令
  • 货真价实的话
  • 小规模发票跨月冲红怎么做账
  • 年终企业所得税怎么结转
  • 原值净值怎么算
  • 应计入损益的利得有什么
  • 小规模销项税分录
  • 技术服务收入属于什么收入
  • mysqldump定时备份
  • 研发人员的差旅费计入管理费用吗
  • 其他权益工具影响所得税吗
  • 母公司无偿给子公司房屋使用谁交房产税呢
  • 汇算清缴费用调减
  • 到期无法收回的银行承兑汇票计入什么科目
  • 外部审计的构成
  • 外经证报验登记流程
  • 其他收益和其他综合收益区别
  • 代发的工资如何做账
  • 一般纳税人支出都要交税吗
  • 建筑业负数发票不填工程名称和地址可以吗
  • 待认证进项税额和待抵扣进项税额的区别
  • 转账支票填写样本图片
  • 暂估入库后发票来不了会计分录
  • win8.1怎么升级到win11
  • Centos Nginx + Svbversion配置安装方法分享
  • 标签windows
  • driver's
  • scanexplicit.exe - scanexplicit是什么进程 作用是什么
  • win7桌面右键菜单多余选项删除
  • SpriteBuilder Demo学习笔记
  • js三种绑定方式
  • unity集训
  • bootstrap范例
  • 局域网远程开机与远程唤醒
  • javascript+
  • unity 黑洞
  • js中scrollHeight,scrollWidth,scrollLeft,scrolltop等差别介绍
  • jquery的gt
  • pythen开发环境
  • jquery.validate使用详解
  • 北京昌平区租房价格
  • 新税法折旧年限怎么算
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设