drag1

(function ($) {
$.dragDrop=function (p) {
var cols=$(p.accepter),//accepter集
ground=[],//坐标空间
t,//被拖动元素
m={
},//被拖动元素属性集
tip=$("<div style='position:absolute;height:4px;overflow:hidden; background:#F30'></div>"),//占位元素
clone,
fly,//拖动启动开关
base,//被选中的垒
ball, //用于定位的accepter中对象
mark,//最后一次插入的相对对象
above=true,

befordrag=function (v) {
v.stopPropagation();
v.preventDefault();
m={
ex:v.clientX,ey:v.clientY+$(document).scrollTop(),x:t.position().left,y:t.position().top,w:t.outerWidth(true),h:t.outerHeight(true)
};
$(document).mousemove(ondrag).mouseup(afterdrag);
if(document.body.setCapture) {
t.get(0).setCapture();
t.get(0).onmousewheel=mousewheel
}
},
ondrag=function (v) {
v.preventDefault();
if(!fly) {
fly=true;
//将可移动元素的坐标存储到ground集合中。
makeGround();
tip.insertBefore(t);
mark=t.get(0);
//拖动元素的副文本样式
clone=t.clone().css({
"position":"absolute","opacity":0.5,"left":m.x,"top":m.y,"width":m.w,"z-index":125058687
}).insertAfter(t);
};

selectBase(v.clientX+$(document).scrollLeft(),v.clientY+$(document).scrollTop());
clone.css({
"left":v.clientX-m.ex+m.x,"top":v.clientY-m.ey+m.y+$(document).scrollTop()
});
//if($(base[3]).children().index(ball[3])==-1)
{//修正除IE8、firefox、chrome下的光标与拖动中的对象的显示异常
tip.insertBefore(ball[3]);
clone.insertAfter(ball[3]);

}


if(p.ondrag || typeof p.ondrag=="function")
{
p.ondrag(v,t,base[3],ball[3]);
}
},
//初始绑定事件
cols.find(p.target).each(function (i,o) {

(p.handle?$(o).find(p.handle):$(o)).mousedown(function (v) {
t=$(o);
befordrag(v)
})
});
### `linearDrag` 介绍 在 Unity 的 2D 物理系统中,`linearDrag` 是 `Rigidbody2D` 组件的一个属性。它用于模拟物体在移动时受到的线性阻力,也就是物体在流体(如空气或水)中运动时所受到的阻碍作用。`linearDrag` 的值越大,物体受到的阻力就越大,其速度衰减得也就越快;反之,`linearDrag` 的值越小,物体受到的阻力就越小,速度衰减得就越慢。 例如,一个 `linearDrag` 值为 0 的物体,在没有其他外力作用的情况下,会以恒定的速度一直运动下去;而一个 `linearDrag` 值较大的物体,在获得一个初始速度后,会很快停止运动。 ### 与 `ForceMode2D.Force` 的关联 当使用 `ForceMode2D.Force` 模式向 `Rigidbody2D` 施加力时,`linearDrag` 会影响物体的运动状态。`ForceMode2D.Force` 模式会持续地向刚体施加力,使刚体产生加速度并改变其速度。而 `linearDrag` 会根据物体的当前速度产生一个反向的阻力,这个阻力会抵消一部分施加的力,从而影响物体的最终运动速度和加速度。 以下是一个简单的示例代码,展示了 `linearDrag` 与 `ForceMode2D.Force` 的使用: ```csharp using UnityEngine; public class DragAndForceExample : MonoBehaviour { public Rigidbody2D rb; public float forceAmount = 10f; public float linearDragValue = 1f; void Start() { rb = GetComponent<Rigidbody2D>(); rb.linearDrag = linearDragValue; } void FixedUpdate() { Vector2 force = new Vector2(forceAmount, 0f); rb.AddForce(force, ForceMode2D.Force); } } ``` 在这个示例中,首先设置了 `Rigidbody2D` 的 `linearDrag` 属性,然后在 `FixedUpdate` 方法中使用 `ForceMode2D.Force` 模式向刚体施加一个水平方向的力。由于 `linearDrag` 的存在,物体不会无限制地加速,而是会在某个速度达到平衡,此时施加的力与阻力相等。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值