图片 滚动切换效果(一)
打算做个图片切换,百度了下,发现有很多案例,比如
这次,我也尝试做一下
很直白,没特效。图片是sprite 2d 方式操作的。
发上来的主要目的,是给大家制作类似切换,参考,当然不是参考 动画效果,这个我后期 第二版本开始逐步加。
//触发缓动 void OnSetTween() { OnStartTween(); //0.1范围内 自动归0 OnZero(); OnTweenMoveScroll(); FingerUpPoint = Grid.position = embattleVector3; } void OnStartTween() { ///****超过右边***** 向左/// if (embattleVector3.x > 0) { Scenario = 0; embattleVector3.x -= speetScenario; FingerUpPoint = Grid.position = embattleVector3; return; } } //松开鼠标移动中处理 void OnTweenMoveScroll() { //向左 if (embattleVector3.x < 0) { float embattleFloat = Mathf.Abs(embattleVector3.x); if (embattleFloat > 0 && embattleFloat < 2) { Scenario = 0; embattleVector3.x += speetScenario; FingerUpPoint = Grid.position = embattleVector3; return; } switch (maxScenario) { case 0: OnRightZero(0, 0); break; case 1: OnRightZero(5, 1); OnTweenSubMove(2, 5, 1, true); break; case 2: OnRightZero(10, 2); if (OnTweenSubMove(2, 5, 1, true)) { if (OnTweenSubMove(5, 7, 2, false)) { OnTweenSubMove(7, 10, 2, true); } } break; case 3: OnRightZero(15, 3); if (OnTweenSubMove(2, 5, 1, true)) { if (OnTweenSubMove(5, 7, 2, false)) { if (OnTweenSubMove(7, 10, 2, true)) { if (OnTweenSubMove(10, 12, 3, false)) { OnTweenSubMove(12, 15, 3, true); } } } } break; case 4: OnRightZero(20, 4); //暂时不写 break; default: break; } } } bool OnTweenSubMove(int min, int max, int Scen, bool sign) { bool re = true; float embattleFloat = Mathf.Abs(embattleVector3.x); if (embattleFloat > min && embattleFloat < max) { re = false; Scenario = Scen; if (sign) { embattleVector3.x -= speetScenario; } else { embattleVector3.x += speetScenario; } OnLeftZero(); FingerUpPoint = Grid.position = embattleVector3; } return re; } //右边归零 void OnRightZero(int sizeEmbattle, int Scenarios) { if (embattleVector3.x < 0) { float embattleFloat = Mathf.Abs(embattleVector3.x); if (embattleFloat >= sizeEmbattle) { Scenario = Scenarios; embattleVector3.x += speetScenario; OnLeftZero(); FingerUpPoint = Grid.position = embattleVector3; } } } //左边归零 void OnLeftZero() { float embattleFloat = Mathf.Abs(embattleVector3.x); embattleFloat = widthscenario * Scenario - embattleFloat; if (embattleFloat < speetScenario) { embattleFloat = embattleVector3.x = -widthscenario * Scenario; FingerUpPoint = Grid.position = embattleVector3; triggerTween = false; return; } } //0.1范围内 自动归0 void OnZero() { float embattleFloat = Mathf.Abs(embattleVector3.x); if (embattleFloat < speetScenario) { embattleFloat = embattleVector3.x = 0; FingerUpPoint = Grid.position = embattleVector3; triggerTween = false; return; } }
对于效果不足的地方,下一节我会逐渐完善。好了,新年开始,恢复精神,继续努力工作。