不罗嗦,直接上代码了。
let _ccInputMgr = cc[‘internal’][‘inputManager’];
_ccInputMgr[’_getUnUsedIndex’] = ():number => {
let now = cc.sys.now();
const timeout = cc.macro.TOUCH_TIMEOUT
let temp = _ccInputMgr._indexBitsUsed;
let unused = -1;
let locTouches = _ccInputMgr._touches;
let locTouchesIntDict = _ccInputMgr._touchesIntegerDict;
let locTouchesCache = _ccInputMgr._touchesCache;
for (let i = 0; i < _ccInputMgr._maxTouches; i++) {
if (!(temp & 0x00000001)) {
if (unused === -1){
unused = i;
_ccInputMgr._indexBitsUsed |= (1 << i);
}
} else if (locTouches.length > 5) {
const ccTouch = locTouches[i];
if (ccTouch && (now - ccTouch._lastModified > timeout)) {
const touchID = ccTouch.getID();
delete locTouchesIntDict[touchID];
delete locTouchesCache[touchID];
_ccInputMgr._touchCount--;
if (unused === -1) {
unused = i;
_ccInputMgr._indexBitsUsed |= (1 << i);
} else {
_ccInputMgr._indexBitsUsed &= ~(1 << i);
}
}
}
temp >>= 1;
}
return unused;
}