feat: object pooling

main
tiendat3699 2024-03-06 18:09:17 +07:00
parent a6e330bbca
commit 1912f52b83
15 changed files with 393 additions and 2606 deletions

View File

@ -952,10 +952,9 @@
"fileId": "9crXsAtjdEQIcD0a2IceFl" "fileId": "9crXsAtjdEQIcD0a2IceFl"
}, },
{ {
"__type__": "cad12cEubBIXb2NvvCon5Ge", "__type__": "b14f8NWzRJDNL9eRfPhDx3G",
"_name": "", "_name": "",
"_objFlags": 0, "_objFlags": 0,
"__editorExtras__": {},
"node": { "node": {
"__id__": 1 "__id__": 1
}, },
@ -963,21 +962,11 @@
"__prefab": { "__prefab": {
"__id__": 70 "__id__": 70
}, },
"maxSpeed": 100,
"rigidbody": {
"__id__": 67
},
"collider": {
"__id__": 65
},
"trail": {
"__id__": 3
},
"_id": "" "_id": ""
}, },
{ {
"__type__": "cc.CompPrefabInfo", "__type__": "cc.CompPrefabInfo",
"fileId": "c1lmpQL0VK3q2DI79nkPRA" "fileId": "69msKyk8NLHqP+rm4QOaXF"
}, },
{ {
"__type__": "cc.PrefabInfo", "__type__": "cc.PrefabInfo",

View File

@ -1,12 +0,0 @@
{
"ver": "1.1.0",
"importer": "directory",
"imported": true,
"uuid": "4b7ba894-d27b-4472-9a6b-5a08f677f44f",
"files": [],
"subMetas": {},
"userData": {
"compressionType": {},
"isRemoteBundle": {}
}
}

View File

@ -1,707 +0,0 @@
[
{
"__type__": "cc.Prefab",
"_name": "Easy Obstacle 1",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"persistent": false
},
{
"__type__": "cc.Node",
"_name": "Easy Obstacle 1",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [
{
"__id__": 2
},
{
"__id__": 4
},
{
"__id__": 6
},
{
"__id__": 17
},
{
"__id__": 28
}
],
"_active": true,
"_components": [
{
"__id__": 39
},
{
"__id__": 41
}
],
"_prefab": {
"__id__": 43
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "Waypoint L",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 3
},
"_lpos": {
"__type__": "cc.Vec3",
"x": -75,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "de8VqIuyVFIJIRj77PlLqI",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.Node",
"_name": "Waypoint R",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 5
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 75,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "8ezI4xD7dPB7nmq1CTcPMa",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.Node",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_prefab": {
"__id__": 7
},
"__editorExtras__": {}
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 6
},
"asset": {
"__uuid__": "f49ff774-8d49-42fd-81de-aeb7f53d03f5",
"__expectedType__": "cc.Prefab"
},
"fileId": "a0kYAhzm5AAa3h8r/fe/j5",
"instance": {
"__id__": 8
},
"targetOverrides": null
},
{
"__type__": "cc.PrefabInstance",
"fileId": "e633jfzBlG8YZuWVy1ieV8",
"prefabRootNode": {
"__id__": 1
},
"mountedChildren": [],
"mountedComponents": [],
"propertyOverrides": [
{
"__id__": 9
},
{
"__id__": 11
},
{
"__id__": 12
},
{
"__id__": 13
},
{
"__id__": 14
},
{
"__id__": 16
}
],
"removedComponents": []
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 10
},
"propertyPath": [
"_name"
],
"value": "Obstacle"
},
{
"__type__": "cc.TargetInfo",
"localID": [
"a0kYAhzm5AAa3h8r/fe/j5"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 10
},
"propertyPath": [
"_lpos"
],
"value": {
"__type__": "cc.Vec3",
"x": 75,
"y": -80,
"z": 0
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 10
},
"propertyPath": [
"_lrot"
],
"value": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": -0.7071067811865475,
"w": 0.7071067811865476
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 10
},
"propertyPath": [
"_euler"
],
"value": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": -90
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 15
},
"propertyPath": [
"_restitution"
],
"value": 0.3
},
{
"__type__": "cc.TargetInfo",
"localID": [
"7egu3Zm5tHjb52E6fmax1G"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 15
},
"propertyPath": [
"_friction"
],
"value": 2
},
{
"__type__": "cc.Node",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_prefab": {
"__id__": 18
},
"__editorExtras__": {}
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 17
},
"asset": {
"__uuid__": "f49ff774-8d49-42fd-81de-aeb7f53d03f5",
"__expectedType__": "cc.Prefab"
},
"fileId": "a0kYAhzm5AAa3h8r/fe/j5",
"instance": {
"__id__": 19
},
"targetOverrides": null
},
{
"__type__": "cc.PrefabInstance",
"fileId": "369FaOtYlAMoSc+EHcwivl",
"prefabRootNode": {
"__id__": 1
},
"mountedChildren": [],
"mountedComponents": [],
"propertyOverrides": [
{
"__id__": 20
},
{
"__id__": 22
},
{
"__id__": 23
},
{
"__id__": 24
},
{
"__id__": 25
},
{
"__id__": 27
}
],
"removedComponents": []
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 21
},
"propertyPath": [
"_name"
],
"value": "Obstacle"
},
{
"__type__": "cc.TargetInfo",
"localID": [
"a0kYAhzm5AAa3h8r/fe/j5"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 21
},
"propertyPath": [
"_lpos"
],
"value": {
"__type__": "cc.Vec3",
"x": -75,
"y": -80,
"z": 0
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 21
},
"propertyPath": [
"_lrot"
],
"value": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": -0.7071067811865475,
"w": 0.7071067811865476
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 21
},
"propertyPath": [
"_euler"
],
"value": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": -90
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 26
},
"propertyPath": [
"_restitution"
],
"value": 0.3
},
{
"__type__": "cc.TargetInfo",
"localID": [
"7egu3Zm5tHjb52E6fmax1G"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 26
},
"propertyPath": [
"_friction"
],
"value": 2
},
{
"__type__": "cc.Node",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_prefab": {
"__id__": 29
},
"__editorExtras__": {}
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 28
},
"asset": {
"__uuid__": "f49ff774-8d49-42fd-81de-aeb7f53d03f5",
"__expectedType__": "cc.Prefab"
},
"fileId": "a0kYAhzm5AAa3h8r/fe/j5",
"instance": {
"__id__": 30
},
"targetOverrides": null
},
{
"__type__": "cc.PrefabInstance",
"fileId": "c5w6eyXR5HprwDgmS1eEzX",
"prefabRootNode": {
"__id__": 1
},
"mountedChildren": [],
"mountedComponents": [],
"propertyOverrides": [
{
"__id__": 31
},
{
"__id__": 33
},
{
"__id__": 34
},
{
"__id__": 35
},
{
"__id__": 36
},
{
"__id__": 38
}
],
"removedComponents": []
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 32
},
"propertyPath": [
"_name"
],
"value": "Obstacle"
},
{
"__type__": "cc.TargetInfo",
"localID": [
"a0kYAhzm5AAa3h8r/fe/j5"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 32
},
"propertyPath": [
"_lpos"
],
"value": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 32
},
"propertyPath": [
"_lrot"
],
"value": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": -0.7071067811865475,
"w": 0.7071067811865476
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 32
},
"propertyPath": [
"_euler"
],
"value": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": -90
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 37
},
"propertyPath": [
"_restitution"
],
"value": 0.3
},
{
"__type__": "cc.TargetInfo",
"localID": [
"7egu3Zm5tHjb52E6fmax1G"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 37
},
"propertyPath": [
"_friction"
],
"value": 2
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 40
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 100
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "95+Xig555LLYmKXCqZB+hR"
},
{
"__type__": "c8e705yAJlBEKcUg/gyt/xJ",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 42
},
"targets": [
{
"__id__": 6
},
{
"__id__": 17
},
{
"__id__": 28
}
],
"waypoints": [
{
"__id__": 4
},
{
"__id__": 2
}
],
"speed": 1,
"selectedObstacle": null,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "9d9KKHmPlB6JUx7ketBzxb"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "8bAB5AG0pEMal3JgTX45pf",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": [
{
"__id__": 28
},
{
"__id__": 17
},
{
"__id__": 6
}
]
}
]

View File

@ -1,13 +0,0 @@
{
"ver": "1.1.43",
"importer": "prefab",
"imported": true,
"uuid": "f30b309a-4220-4c22-b3d5-ac450258eb77",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "Easy Obstacle 1"
}
}

View File

@ -1,697 +0,0 @@
[
{
"__type__": "cc.Prefab",
"_name": "Easy Obstacle 2",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"persistent": false
},
{
"__type__": "cc.Node",
"_name": "Easy Obstacle 2",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [
{
"__id__": 2
},
{
"__id__": 4
},
{
"__id__": 6
},
{
"__id__": 17
},
{
"__id__": 28
}
],
"_active": true,
"_components": [
{
"__id__": 39
},
{
"__id__": 41
}
],
"_prefab": {
"__id__": 43
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 200,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "Waypoint L",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 3
},
"_lpos": {
"__type__": "cc.Vec3",
"x": -60,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "de8VqIuyVFIJIRj77PlLqI",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.Node",
"_name": "Waypoint R",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 5
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 60,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "8ezI4xD7dPB7nmq1CTcPMa",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.Node",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_prefab": {
"__id__": 7
},
"__editorExtras__": {}
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 6
},
"asset": {
"__uuid__": "f49ff774-8d49-42fd-81de-aeb7f53d03f5",
"__expectedType__": "cc.Prefab"
},
"fileId": "a0kYAhzm5AAa3h8r/fe/j5",
"instance": {
"__id__": 8
},
"targetOverrides": null
},
{
"__type__": "cc.PrefabInstance",
"fileId": "d5MUuJhTtHPqoYxWAJkdvs",
"prefabRootNode": {
"__id__": 1
},
"mountedChildren": [],
"mountedComponents": [],
"propertyOverrides": [
{
"__id__": 9
},
{
"__id__": 11
},
{
"__id__": 12
},
{
"__id__": 13
},
{
"__id__": 14
},
{
"__id__": 16
}
],
"removedComponents": []
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 10
},
"propertyPath": [
"_name"
],
"value": "Obstacle"
},
{
"__type__": "cc.TargetInfo",
"localID": [
"a0kYAhzm5AAa3h8r/fe/j5"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 10
},
"propertyPath": [
"_lpos"
],
"value": {
"__type__": "cc.Vec3",
"x": 60,
"y": -90,
"z": 0
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 10
},
"propertyPath": [
"_lrot"
],
"value": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": -0.7071067811865475,
"w": 0.7071067811865476
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 10
},
"propertyPath": [
"_euler"
],
"value": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": -90
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 15
},
"propertyPath": [
"_friction"
],
"value": 2
},
{
"__type__": "cc.TargetInfo",
"localID": [
"7egu3Zm5tHjb52E6fmax1G"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 15
},
"propertyPath": [
"_restitution"
],
"value": 0.3
},
{
"__type__": "cc.Node",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_prefab": {
"__id__": 18
},
"__editorExtras__": {}
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 17
},
"asset": {
"__uuid__": "f49ff774-8d49-42fd-81de-aeb7f53d03f5",
"__expectedType__": "cc.Prefab"
},
"fileId": "a0kYAhzm5AAa3h8r/fe/j5",
"instance": {
"__id__": 19
},
"targetOverrides": null
},
{
"__type__": "cc.PrefabInstance",
"fileId": "e1NT6f+hhFro0n3pDSh9q8",
"prefabRootNode": {
"__id__": 1
},
"mountedChildren": [],
"mountedComponents": [],
"propertyOverrides": [
{
"__id__": 20
},
{
"__id__": 22
},
{
"__id__": 23
},
{
"__id__": 24
},
{
"__id__": 25
},
{
"__id__": 27
}
],
"removedComponents": []
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 21
},
"propertyPath": [
"_name"
],
"value": "Obstacle"
},
{
"__type__": "cc.TargetInfo",
"localID": [
"a0kYAhzm5AAa3h8r/fe/j5"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 21
},
"propertyPath": [
"_lpos"
],
"value": {
"__type__": "cc.Vec3",
"x": 60,
"y": -170,
"z": 0
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 21
},
"propertyPath": [
"_lrot"
],
"value": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": -0.7071067811865475,
"w": 0.7071067811865476
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 21
},
"propertyPath": [
"_euler"
],
"value": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": -90
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 26
},
"propertyPath": [
"_friction"
],
"value": 2
},
{
"__type__": "cc.TargetInfo",
"localID": [
"7egu3Zm5tHjb52E6fmax1G"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 26
},
"propertyPath": [
"_restitution"
],
"value": 0.3
},
{
"__type__": "cc.Node",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_prefab": {
"__id__": 29
},
"__editorExtras__": {}
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 28
},
"asset": {
"__uuid__": "f49ff774-8d49-42fd-81de-aeb7f53d03f5",
"__expectedType__": "cc.Prefab"
},
"fileId": "a0kYAhzm5AAa3h8r/fe/j5",
"instance": {
"__id__": 30
},
"targetOverrides": null
},
{
"__type__": "cc.PrefabInstance",
"fileId": "80I6iQCNhH2LFLQwLhSOR/",
"prefabRootNode": {
"__id__": 1
},
"mountedChildren": [],
"mountedComponents": [],
"propertyOverrides": [
{
"__id__": 31
},
{
"__id__": 33
},
{
"__id__": 34
},
{
"__id__": 35
},
{
"__id__": 36
},
{
"__id__": 38
}
],
"removedComponents": []
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 32
},
"propertyPath": [
"_name"
],
"value": "Obstacle"
},
{
"__type__": "cc.TargetInfo",
"localID": [
"a0kYAhzm5AAa3h8r/fe/j5"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 32
},
"propertyPath": [
"_lpos"
],
"value": {
"__type__": "cc.Vec3",
"x": 60,
"y": -250,
"z": 0
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 32
},
"propertyPath": [
"_lrot"
],
"value": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": -0.7071067811865475,
"w": 0.7071067811865476
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 32
},
"propertyPath": [
"_euler"
],
"value": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": -90
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 37
},
"propertyPath": [
"_friction"
],
"value": 2
},
{
"__type__": "cc.TargetInfo",
"localID": [
"7egu3Zm5tHjb52E6fmax1G"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 37
},
"propertyPath": [
"_restitution"
],
"value": 0.3
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 40
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 100
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "95+Xig555LLYmKXCqZB+hR"
},
{
"__type__": "c8e705yAJlBEKcUg/gyt/xJ",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 42
},
"targets": [],
"waypoints": [
{
"__id__": 4
},
{
"__id__": 2
}
],
"speed": 1,
"selectedObstacle": null,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "9d9KKHmPlB6JUx7ketBzxb"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "8bAB5AG0pEMal3JgTX45pf",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": [
{
"__id__": 28
},
{
"__id__": 17
},
{
"__id__": 6
}
]
}
]

View File

@ -1,13 +0,0 @@
{
"ver": "1.1.43",
"importer": "prefab",
"imported": true,
"uuid": "36df1e3d-a2ea-4b8d-8a5c-fc97275927ed",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "Easy Obstacle 2"
}
}

View File

@ -1,701 +0,0 @@
[
{
"__type__": "cc.Prefab",
"_name": "Easy Obstacle 3",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"persistent": false
},
{
"__type__": "cc.Node",
"_name": "Easy Obstacle 3",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [
{
"__id__": 2
},
{
"__id__": 4
},
{
"__id__": 6
},
{
"__id__": 17
},
{
"__id__": 28
}
],
"_active": true,
"_components": [
{
"__id__": 39
},
{
"__id__": 41
}
],
"_prefab": {
"__id__": 43
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 0,
"y": 200,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.Node",
"_name": "Waypoint L",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 3
},
"_lpos": {
"__type__": "cc.Vec3",
"x": -60,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "de8VqIuyVFIJIRj77PlLqI",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.Node",
"_name": "Waypoint R",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_children": [],
"_active": true,
"_components": [],
"_prefab": {
"__id__": 5
},
"_lpos": {
"__type__": "cc.Vec3",
"x": 60,
"y": 0,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": 0,
"w": 1
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": 0
},
"_id": ""
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "8ezI4xD7dPB7nmq1CTcPMa",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": null
},
{
"__type__": "cc.Node",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_prefab": {
"__id__": 7
},
"__editorExtras__": {}
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 6
},
"asset": {
"__uuid__": "f49ff774-8d49-42fd-81de-aeb7f53d03f5",
"__expectedType__": "cc.Prefab"
},
"fileId": "a0kYAhzm5AAa3h8r/fe/j5",
"instance": {
"__id__": 8
},
"targetOverrides": null
},
{
"__type__": "cc.PrefabInstance",
"fileId": "d5MUuJhTtHPqoYxWAJkdvs",
"prefabRootNode": {
"__id__": 1
},
"mountedChildren": [],
"mountedComponents": [],
"propertyOverrides": [
{
"__id__": 9
},
{
"__id__": 11
},
{
"__id__": 12
},
{
"__id__": 13
},
{
"__id__": 14
},
{
"__id__": 16
}
],
"removedComponents": []
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 10
},
"propertyPath": [
"_name"
],
"value": "Obstacle"
},
{
"__type__": "cc.TargetInfo",
"localID": [
"a0kYAhzm5AAa3h8r/fe/j5"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 10
},
"propertyPath": [
"_lpos"
],
"value": {
"__type__": "cc.Vec3",
"x": -120,
"y": 120,
"z": 0
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 10
},
"propertyPath": [
"_lrot"
],
"value": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": -0.7071067811865475,
"w": 0.7071067811865476
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 10
},
"propertyPath": [
"_euler"
],
"value": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": -90
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 15
},
"propertyPath": [
"_restitution"
],
"value": 0.3
},
{
"__type__": "cc.TargetInfo",
"localID": [
"7egu3Zm5tHjb52E6fmax1G"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 15
},
"propertyPath": [
"_friction"
],
"value": 2
},
{
"__type__": "cc.Node",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_prefab": {
"__id__": 18
},
"__editorExtras__": {}
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 17
},
"asset": {
"__uuid__": "f49ff774-8d49-42fd-81de-aeb7f53d03f5",
"__expectedType__": "cc.Prefab"
},
"fileId": "a0kYAhzm5AAa3h8r/fe/j5",
"instance": {
"__id__": 19
},
"targetOverrides": null
},
{
"__type__": "cc.PrefabInstance",
"fileId": "e1NT6f+hhFro0n3pDSh9q8",
"prefabRootNode": {
"__id__": 1
},
"mountedChildren": [],
"mountedComponents": [],
"propertyOverrides": [
{
"__id__": 20
},
{
"__id__": 22
},
{
"__id__": 23
},
{
"__id__": 24
},
{
"__id__": 25
},
{
"__id__": 27
}
],
"removedComponents": []
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 21
},
"propertyPath": [
"_name"
],
"value": "Obstacle"
},
{
"__type__": "cc.TargetInfo",
"localID": [
"a0kYAhzm5AAa3h8r/fe/j5"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 21
},
"propertyPath": [
"_lpos"
],
"value": {
"__type__": "cc.Vec3",
"x": -60,
"y": -20,
"z": 0
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 21
},
"propertyPath": [
"_lrot"
],
"value": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": -0.7071067811865475,
"w": 0.7071067811865476
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 21
},
"propertyPath": [
"_euler"
],
"value": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": -90
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 26
},
"propertyPath": [
"_restitution"
],
"value": 0.3
},
{
"__type__": "cc.TargetInfo",
"localID": [
"7egu3Zm5tHjb52E6fmax1G"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 26
},
"propertyPath": [
"_friction"
],
"value": 2
},
{
"__type__": "cc.Node",
"_objFlags": 0,
"_parent": {
"__id__": 1
},
"_prefab": {
"__id__": 29
},
"__editorExtras__": {}
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 28
},
"asset": {
"__uuid__": "f49ff774-8d49-42fd-81de-aeb7f53d03f5",
"__expectedType__": "cc.Prefab"
},
"fileId": "a0kYAhzm5AAa3h8r/fe/j5",
"instance": {
"__id__": 30
},
"targetOverrides": null
},
{
"__type__": "cc.PrefabInstance",
"fileId": "80I6iQCNhH2LFLQwLhSOR/",
"prefabRootNode": {
"__id__": 1
},
"mountedChildren": [],
"mountedComponents": [],
"propertyOverrides": [
{
"__id__": 31
},
{
"__id__": 33
},
{
"__id__": 34
},
{
"__id__": 35
},
{
"__id__": 36
},
{
"__id__": 38
}
],
"removedComponents": []
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 32
},
"propertyPath": [
"_name"
],
"value": "Obstacle"
},
{
"__type__": "cc.TargetInfo",
"localID": [
"a0kYAhzm5AAa3h8r/fe/j5"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 32
},
"propertyPath": [
"_lpos"
],
"value": {
"__type__": "cc.Vec3",
"x": -50,
"y": -150,
"z": 0
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 32
},
"propertyPath": [
"_lrot"
],
"value": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": -0.7071067811865475,
"w": 0.7071067811865476
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 32
},
"propertyPath": [
"_euler"
],
"value": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": -90
}
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 37
},
"propertyPath": [
"_restitution"
],
"value": 0.3
},
{
"__type__": "cc.TargetInfo",
"localID": [
"7egu3Zm5tHjb52E6fmax1G"
]
},
{
"__type__": "CCPropertyOverrideInfo",
"targetInfo": {
"__id__": 37
},
"propertyPath": [
"_friction"
],
"value": 2
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 40
},
"_contentSize": {
"__type__": "cc.Size",
"width": 100,
"height": 100
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "95+Xig555LLYmKXCqZB+hR"
},
{
"__type__": "c8e705yAJlBEKcUg/gyt/xJ",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 42
},
"targets": [
{
"__id__": 17
}
],
"waypoints": [
{
"__id__": 4
},
{
"__id__": 2
}
],
"speed": 1,
"selectedObstacle": null,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "9d9KKHmPlB6JUx7ketBzxb"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "8bAB5AG0pEMal3JgTX45pf",
"instance": null,
"targetOverrides": null,
"nestedPrefabInstanceRoots": [
{
"__id__": 28
},
{
"__id__": 17
},
{
"__id__": 6
}
]
}
]

View File

@ -1,13 +0,0 @@
{
"ver": "1.1.43",
"importer": "prefab",
"imported": true,
"uuid": "1f197242-be22-45c5-8050-73114637003e",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "Easy Obstacle 3"
}
}

View File

@ -1,216 +0,0 @@
[
{
"__type__": "cc.Prefab",
"_name": "Obstacle",
"_objFlags": 0,
"_native": "",
"data": {
"__id__": 1
},
"optimizationPolicy": 0,
"persistent": false
},
{
"__type__": "cc.Node",
"_name": "Obstacle",
"_objFlags": 0,
"__editorExtras__": {},
"_parent": null,
"_children": [],
"_active": true,
"_components": [
{
"__id__": 2
},
{
"__id__": 4
},
{
"__id__": 6
},
{
"__id__": 8
}
],
"_prefab": {
"__id__": 10
},
"_lpos": {
"__type__": "cc.Vec3",
"x": -175,
"y": 380,
"z": 0
},
"_lrot": {
"__type__": "cc.Quat",
"x": 0,
"y": 0,
"z": -0.7071067811865475,
"w": 0.7071067811865476
},
"_lscale": {
"__type__": "cc.Vec3",
"x": 1,
"y": 1,
"z": 1
},
"_mobility": 0,
"_layer": 33554432,
"_euler": {
"__type__": "cc.Vec3",
"x": 0,
"y": 0,
"z": -90
},
"_id": ""
},
{
"__type__": "cc.UITransform",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 3
},
"_contentSize": {
"__type__": "cc.Size",
"width": 21,
"height": 31
},
"_anchorPoint": {
"__type__": "cc.Vec2",
"x": 0.5,
"y": 0.5
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "45QTNNbC9OUYDRRzKHu6WV"
},
{
"__type__": "cc.Sprite",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 5
},
"_customMaterial": null,
"_srcBlendFactor": 2,
"_dstBlendFactor": 4,
"_color": {
"__type__": "cc.Color",
"r": 255,
"g": 255,
"b": 255,
"a": 255
},
"_spriteFrame": {
"__uuid__": "8bc52c2c-7db5-4951-9bf1-a38f1914bf0e@f9941",
"__expectedType__": "cc.SpriteFrame"
},
"_type": 0,
"_fillType": 0,
"_sizeMode": 1,
"_fillCenter": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_fillStart": 0,
"_fillRange": 0,
"_isTrimmedMode": true,
"_useGrayscale": false,
"_atlas": null,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "08nypWEwZI2pSnaYoRCRKW"
},
{
"__type__": "cc.BoxCollider2D",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 7
},
"tag": 3,
"_group": 1,
"_density": 1,
"_sensor": false,
"_friction": 0.2,
"_restitution": 0,
"_offset": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_size": {
"__type__": "cc.Size",
"width": 20,
"height": 32
},
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "7egu3Zm5tHjb52E6fmax1G"
},
{
"__type__": "cc.RigidBody2D",
"_name": "",
"_objFlags": 0,
"node": {
"__id__": 1
},
"_enabled": true,
"__prefab": {
"__id__": 9
},
"enabledContactListener": false,
"bullet": false,
"awakeOnLoad": false,
"_group": 1,
"_type": 0,
"_allowSleep": true,
"_gravityScale": 0,
"_linearDamping": 0,
"_angularDamping": 0,
"_linearVelocity": {
"__type__": "cc.Vec2",
"x": 0,
"y": 0
},
"_angularVelocity": 0,
"_fixedRotation": true,
"_id": ""
},
{
"__type__": "cc.CompPrefabInfo",
"fileId": "39ENf+Cn1O95ZEF7CNhWT+"
},
{
"__type__": "cc.PrefabInfo",
"root": {
"__id__": 1
},
"asset": {
"__id__": 0
},
"fileId": "a0kYAhzm5AAa3h8r/fe/j5",
"instance": null,
"targetOverrides": null
}
]

View File

@ -1,13 +0,0 @@
{
"ver": "1.1.43",
"importer": "prefab",
"imported": true,
"uuid": "f49ff774-8d49-42fd-81de-aeb7f53d03f5",
"files": [
".json"
],
"subMetas": {},
"userData": {
"syncNodeName": "Obstacle"
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,19 +1,105 @@
import { _decorator, Component, HingeJoint2D, Node, input, Input, EventMouse, CCFloat } from 'cc'; import {
_decorator,
Component,
HingeJoint2D,
input,
CCFloat,
Input,
EventKeyboard,
KeyCode,
Enum,
EventTouch,
screen,
} from 'cc';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
enum ControllerSide {
Left,
Right,
}
Enum(ControllerSide);
@ccclass('Flipper') @ccclass('Flipper')
export class Flipper extends Component { export class Flipper extends Component {
@property({ visible: true, type: HingeJoint2D }) @property({ visible: true, type: HingeJoint2D })
public _hingeJoint: HingeJoint2D; private _hingeJoint: HingeJoint2D;
@property({ visible: true, type: CCFloat }) @property({ visible: true, type: CCFloat })
public _motorSpeedActive: number; private _motorSpeedActive: number;
@property({ visible: true, type: CCFloat }) @property({ visible: true, type: CCFloat })
public _motorSpeedDeActive: number; private _motorSpeedDeActive: number;
@property({ visible: true, type: ControllerSide })
private side = ControllerSide.Left;
public activeFlipper(): void { protected onLoad(): void {
input.on(Input.EventType.KEY_DOWN, this.onKeyInputDown, this);
input.on(Input.EventType.KEY_UP, this.onKeyInputUp, this);
input.on(Input.EventType.TOUCH_START, this.onTouchStart, this);
input.on(Input.EventType.TOUCH_END, this.onTouchEnd, this);
}
//#region Input Handler
private onKeyInputDown(event: EventKeyboard) {
switch (event.keyCode) {
case KeyCode.KEY_A:
case KeyCode.ARROW_LEFT:
if (this.side == ControllerSide.Left) this.activeFlipper();
break;
case KeyCode.KEY_D:
case KeyCode.ARROW_RIGHT:
if (this.side == ControllerSide.Right) this.activeFlipper();
break;
default:
break;
}
}
private onKeyInputUp(event: EventKeyboard) {
switch (event.keyCode) {
case KeyCode.KEY_A:
case KeyCode.ARROW_LEFT:
if (this.side == ControllerSide.Left) this.deActiveFlipper();
break;
case KeyCode.KEY_D:
case KeyCode.ARROW_RIGHT:
if (this.side == ControllerSide.Right) this.deActiveFlipper();
break;
default:
break;
}
}
private onTouchStart(event: EventTouch) {
if (event.getLocationX() > screen.windowSize.x / 2) {
if (this.side == ControllerSide.Right) {
this.activeFlipper();
}
} else {
if (this.side == ControllerSide.Left) {
this.activeFlipper();
}
}
}
private onTouchEnd(event: EventTouch) {
if (event.getLocationX() > screen.windowSize.x / 2) {
if (this.side == ControllerSide.Right) {
this.deActiveFlipper();
}
} else {
if (this.side == ControllerSide.Left) {
this.deActiveFlipper();
}
}
}
//#endregion
private activeFlipper(): void {
this._hingeJoint.motorSpeed = this._motorSpeedActive; this._hingeJoint.motorSpeed = this._motorSpeedActive;
} }
public deActiveFlipper(): void { private deActiveFlipper(): void {
this._hingeJoint.motorSpeed = this._motorSpeedDeActive; this._hingeJoint.motorSpeed = this._motorSpeedDeActive;
} }
} }

View File

@ -1,4 +1,6 @@
import { _decorator, Component, Node } from 'cc'; import { _decorator, Component, Prefab } from 'cc';
import ObjectPool from '../Pool/ObjectPool';
import Utilities from '../Utilities/Utilities';
const { ccclass, property } = _decorator; const { ccclass, property } = _decorator;
@ccclass('GameManager') @ccclass('GameManager')
@ -9,9 +11,25 @@ export class GameManager extends Component {
return GameManager._instance; return GameManager._instance;
} }
@property({ type: Prefab, visible: true })
private _ballPrefab: Prefab;
private _ballPool: ObjectPool;
public highestStreak: number; public highestStreak: number;
public score = 0; public score = 0;
protected onLoad(): void {
this._ballPool = new ObjectPool(this._ballPrefab, 10, false);
}
protected async start() {
while (true) {
const ball = this._ballPool.get(this.node);
ball.setWorldPosition(this.node.worldPosition);
await Utilities.delay(1000);
}
}
public onRevive() { public onRevive() {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }

View File

@ -1,9 +1,8 @@
import { Component, Node, Prefab, __private, director, instantiate } from 'cc'; import { Component, Node, Prefab, __private, director, instantiate } from 'cc';
export default class ObjectPool<T extends Component> { export default class ObjectPool {
private _inactives: Node[] = []; private _inactives: Node[] = [];
private _actives: Node[] = []; private _actives: Node[] = [];
private _classConstructor: string;
private _prefab: Prefab; private _prefab: Prefab;
private _expandable; private _expandable;
@ -19,8 +18,7 @@ export default class ObjectPool<T extends Component> {
return this.countInactive + this.countActive; return this.countInactive + this.countActive;
} }
constructor(classConstructor: string, prefab: Prefab, size: number, expandable = true) { constructor(prefab: Prefab, size: number, expandable = true) {
this._classConstructor = classConstructor;
this._expandable = expandable; this._expandable = expandable;
this._prefab = prefab; this._prefab = prefab;
for (let i = 0; i < size; ++i) { for (let i = 0; i < size; ++i) {
@ -30,7 +28,20 @@ export default class ObjectPool<T extends Component> {
} }
} }
public get<T>(parent?: Node): T { public get(parent?: Node): Node;
public get<T extends Component>(
parent?: Node,
classConstructor?:
| __private._types_globals__Constructor<T>
| __private._types_globals__AbstractedConstructor<T>,
): T;
public get<T extends Component>(
parent?: Node,
classConstructor?:
| __private._types_globals__Constructor<T>
| __private._types_globals__AbstractedConstructor<T>,
): T | Node {
let obj: Node = null; let obj: Node = null;
let p = parent || director.getScene(); let p = parent || director.getScene();
if (this._inactives.length > 0) { if (this._inactives.length > 0) {
@ -44,21 +55,31 @@ export default class ObjectPool<T extends Component> {
obj.setParent(p); obj.setParent(p);
this._actives.push(obj); this._actives.push(obj);
} else { } else {
obj = this._actives[0]; obj = this._actives.shift();
this._actives.push(obj);
} }
const comp = obj.getComponent(this._classConstructor) as any; obj.active = true;
comp.reuse?.(); if (classConstructor) {
return comp as T; return obj.getComponent(classConstructor);
}
return obj;
} }
public release(obj: T) { public release(obj: Node);
public release<T extends Component>(obj: T);
public release<T extends Component>(obj: T | Node) {
if (obj instanceof Node) {
obj.active = false;
const index = this._actives.indexOf(obj);
this._actives.splice(index, 1);
this._inactives.push(obj);
} else {
obj.node.active = false; obj.node.active = false;
const index = this._actives.indexOf(obj.node); const index = this._actives.indexOf(obj.node);
this._actives.splice(index, 1); this._actives.splice(index, 1);
this._inactives.push(obj.node); this._inactives.push(obj.node);
const comp = obj.getComponent(this._classConstructor) as any; }
comp.unuse?.();
} }
public clear() { public clear() {

View File

@ -2,7 +2,7 @@
"ver": "4.0.23", "ver": "4.0.23",
"importer": "typescript", "importer": "typescript",
"imported": true, "imported": true,
"uuid": "aaeff0da-269a-427a-b752-8851ca101b14", "uuid": "52867bd5-250e-493d-971a-57e17661d010",
"files": [], "files": [],
"subMetas": {}, "subMetas": {},
"userData": {} "userData": {}