UIGrid实现卡牌曲线层叠效果
来源:互联网 发布:js如何实现继承 编辑:程序博客网 时间:2024/06/05 15:36
先上一张效果图.原理就是动态修改grid下每个节点的Y轴坐标和旋转角度
// 枚举类型加入Curve排序方式 public enum Arrangement { Horizontal, Vertical, CellSnap, Curve } /// <summary> /// 曲线旋转差值 /// </summary> public float CurveAngleD_val = 1f; /// <summary> /// 曲线坐标递减 /// </summary> public float CurveY_D_val = 2f; /// <summary> /// 卡牌基础层级 /// </summary> public int CardBaseDepth = 10;
修改UIGrid中的ResetPosition方法:
// 总数是否为奇数bool isListOdd = list.Count % 2 != 0;// 中间值var midVal = isListOdd ? list.Count / 2 : (list.Count / 2) - 1;if (arrangement == Arrangement.Curve) { // 只有一张牌 放在正中心无旋转 if (list.Count == 1) { t.rotation = Quaternion.identity; if (widget != null) widget.depth = CardBaseDepth*4; pos = new Vector3(cellWidth * x, -cellHeight * y, depth); } else if (list.Count == 2) { float angle = i%2 == 0 ? CurveAngleD_val : -CurveAngleD_val; t.rotation = Quaternion.Euler(new Vector3(0, 0, angle)); if (widget != null) widget.depth = i % 2 == 0 ? CardBaseDepth * 3 : CardBaseDepth * 3 - 5; pos = new Vector3(cellWidth * x, -cellHeight * y, depth); } else { // 总数为奇数 中间卡不旋转 if (isListOdd && i == midVal) { t.rotation = Quaternion.identity; if (widget != null) widget.depth = CardBaseDepth * (list.Count/2 + 1); } else { float angle = 0f; if (isListOdd) {// 奇数 angle = (i < midVal) ? CurveAngleD_val : -CurveAngleD_val; angle = Mathf.Abs(midVal - i) * angle; pos = new Vector3(cellWidth * x, -Mathf.Abs(CurveY_D_val * Mathf.Abs(midVal - i)), depth); if (widget != null) widget.depth = (i < midVal) ? (i+1) * CardBaseDepth : (list.Count-i) * CardBaseDepth - 5; } else {// 偶数 if (i <= midVal) { var idx = Mathf.Abs((midVal - i) + 1); angle = idx * CurveAngleD_val; pos = new Vector3(cellWidth * x, -Mathf.Abs(CurveY_D_val * idx), depth); } else { var idx = Mathf.Abs((midVal - i)); angle = idx * (-CurveAngleD_val); pos = new Vector3(cellWidth * x, -Mathf.Abs(CurveY_D_val * idx), depth); } if (widget != null) widget.depth = (i <= midVal) ? (i + 1) * CardBaseDepth : (list.Count - i) * CardBaseDepth - 5; } t.rotation = Quaternion.Euler(new Vector3(0, 0, angle)); } } }
修改UIGrid下Resetposition修正坐标方法
if (pivot != UIWidget.Pivot.TopLeft) { Vector2 po = NGUIMath.GetPivotOffset(pivot); float fx, fy; if (arrangement == Arrangement.Horizontal || arrangement == Arrangement.Curve) { fx = Mathf.Lerp(0f, maxX * cellWidth, po.x); fy = Mathf.Lerp(-maxY * cellHeight, 0f, po.y); } else { fx = Mathf.Lerp(0f, maxY * cellWidth, po.x); fy = Mathf.Lerp(-maxX * cellHeight, 0f, po.y); } for (int i = 0; i < myTrans.childCount; ++i) { Transform t = myTrans.GetChild(i); if (arrangement == Arrangement.Curve && list.Count > 0) t = list[i]; SpringPosition sp = t.GetComponent<SpringPosition>(); if (sp != null) { if (isListOdd && i == midVal && arrangement == Arrangement.Curve) { // 设置中间卡坐标 if (list.Count <= 1 || pivot == UIWidget.Pivot.Top || pivot == UIWidget.Pivot.Center || pivot == UIWidget.Pivot.Bottom ) { sp.target = Vector3.zero; } else { //sp.target = new Vector3(list[i-1].transform.localPosition.x + cellWidth,0,0); sp.target = new Vector3(cellWidth * i, 0, 0); } } else { sp.target.x -= fx; sp.target.y -= fy; } sp.enabled = true; } else { Vector3 pos = t.localPosition; if (i == midVal && isListOdd && arrangement == Arrangement.Curve) { // 设置中间卡坐标 if (list.Count <= 1 || pivot == UIWidget.Pivot.Top || pivot == UIWidget.Pivot.Center || pivot == UIWidget.Pivot.Bottom) { pos = Vector3.zero; } else { pos = new Vector3(cellWidth * i, 0, 0); } } else { pos.x -= fx; pos.y -= fy; } t.localPosition = pos; } } }
0 0
- UIGrid实现卡牌曲线层叠效果
- css z-index 属性实现层叠效果
- 自定义 ViewGroup 实现子 View 层叠效果
- SSRS实现层叠隐藏显示效果
- uigrid
- WinForm 控件实现半透明效果,并可层叠显示
- layer-list实现图层叠加的效果
- 图片层叠并滚动效果的实现之ImageCoverFlow
- Android层叠式卡片效果实现!(高大上)
- jQuery实现图片卡片层叠式切换效果
- box-shadow实现曲线投影效果
- iOS 贝塞尔曲线实现圆角效果
- 实现纸张的曲线投影效果
- 贝塞尔曲线实现球形一变二动画效果
- Android贝塞尔曲线实现Loading效果
- PathMeasure + 贝塞尔曲线实现过山车效果
- 贝塞尔曲线的艺术---弹性效果实现
- Path使用--二阶贝塞尔曲线实现水波效果
- DOM 解析 XML
- ThinkPad E550禁用触摸板
- Spring InitializingBean和init-method
- 第十六周项目—点结构体2
- uboot常用的环境变量
- UIGrid实现卡牌曲线层叠效果
- 【Android】IntentService & HandlerThread源码解析
- javascript学习——constructor、prototype、_proto_的区别
- java开发中的思维
- 离开代码多年后,突然的心痒痒
- 扫描线填充算法
- Android之SeekBar(0在中间)
- 安装ruby
- hssfworkbook导出excel的问题