你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
没有找到相关结果
谷主
赞同来自:
布偶FHY
fatfatson
zycpig22
/// <summary> /// 最小惯性距离 /// /// 未开启惯性优化无效 /// </summary> public float minInertia { set; get; } = 0F; /// <summary> /// 最大惯性距离 /// 未开启惯性优化无效 /// </summary> public float maxInertia { set; get; } = 100000F; /// <summary> /// 是否开启惯性优化 /// </summary> public bool openInertiaOptimize { set; get; } = false;
//惯性优化 //openInertiaOptimize默认关闭,防止你的修改影响到别人 if (openInertiaOptimize) { v2 = v2 < minInertia + 1 ? minInertia + 1 : v2; v2 = v2 > maxInertia ? maxInertia : v2; }
float UpdateTargetAndDuration(float pos, int axis) { float v = _velocity[axis]; float duration = 0; if (pos > 0) pos = 0; else if (pos < -_overlapSize[axis]) pos = -_overlapSize[axis]; else { //以屏幕像素为基准 float v2 = Mathf.Abs(v) * _velocityScale; //在移动设备上,需要对不同分辨率做一个适配,我们的速度判断以1136分辨率为基准 if (Stage.touchScreen) v2 *= 1136f / Mathf.Max(Screen.width, Screen.height); //惯性优化 //openInertiaOptimize默认关闭,防止你的修改影响到别人 if (openInertiaOptimize) { v2 = v2 < minInertia + 1 ? minInertia + 1 : v2; v2 = v2 > maxInertia ? maxInertia : v2; } //这里有一些阈值的处理,因为在低速内,不希望产生较大的滚动(甚至不滚动) float ratio = 0; if (_pageMode || !Stage.touchScreen) { if (v2 > 500) ratio = Mathf.Pow((v2 - 500) / 500, 2); } else { if (v2 > 1000) ratio = Mathf.Pow((v2 - 1000) / 1000, 2); } if (ratio != 0) { if (ratio > 1) ratio = 1; v2 *= ratio; v *= ratio; _velocity[axis] = v; //算法:v*(_decelerationRate的n次幂)= 60,即在n帧后速度降为60(假设每秒60帧)。 duration = Mathf.Log(60 / v2, _decelerationRate) / 60; //计算距离要使用本地速度 //理论公式貌似滚动的距离不够,改为经验公式 //float change = (int)((v/ 60 - 1) / (1 - _decelerationRate)); float change = (int)(v * duration * 0.4f); pos += change; } } if (duration < TWEEN_TIME_DEFAULT) duration = TWEEN_TIME_DEFAULT; _tweenDuration[axis] = duration; return pos; }
要回复问题请先登录或注册
5 个回复
谷主
赞同来自:
布偶FHY
赞同来自:
谷主
赞同来自:
fatfatson
赞同来自:
zycpig22
赞同来自:
我采取办法是在Fairgui的ScrollpPane类里加上三个属性
然后在UpdateTargetAndDuration方法里加上
整个UpdateTargetAndDuration方法对比
之后设置三个新加的属性,配合原有的decelerationRate就能实现想要的功能。
我这里是设置成1000和2000。