Skip to content

Commit 4c5cf92

Browse files
no message
1 parent 7da4f3e commit 4c5cf92

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

LSQuickScripts/Example Project/LSQuickScripts Examples/Public/LSQuickScripts/LSQuickScripts.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ui {"widget":"label", "label":"LSQuickScripts v2.15"}
1+
//@ui {"widget":"label", "label":"LSQuickScripts v2.16"}
22
//@ui {"widget":"label", "label":"By Max van Leeuwen"}
33
//@ui {"widget":"label", "label":"-"}
44
//@ui {"widget":"label", "label":"Place on top of scene ('On Awake')"}
@@ -423,11 +423,12 @@
423423
// -
424424
//
425425
//
426-
// getAllComponents(componentName (optional) [string], startObj (optional) [SceneObject], dontIncludeStartObj (optional) [bool]) : Array (Components)
426+
// getAllComponents(componentName (optional) [string], startObj (optional) [SceneObject], dontIncludeStartObj (optional) [bool], maxCount (optional) [number]) : Array (Components)
427427
// Returns an array containing all components of type componentNames, also those on child objects.
428-
// If no componentName is given, it returns SceneObjects.
428+
// If no componentName is given, it returns SceneObjects instead.
429429
// If no startObj is given, it searches the whole scene.
430430
// If dontIncludeStartObj is true, the startObj will not be included in the final list.
431+
// If maxCount is given, the search stops after having found a specific amount of components.
431432
//
432433
// Example
433434
// var components = getAllComponents("Component.VFXComponent")
@@ -1692,8 +1693,9 @@ global.measureWorldPos = function(screenPos, screenTrf, cam, dist){
16921693

16931694

16941695

1695-
global.getAllComponents = function(componentName, startObj, dontIncludeStartObj){
1696+
global.getAllComponents = function(componentName, startObj, dontIncludeStartObj, maxCount){
16961697
var found = [];
1698+
if(maxCount == null) maxCount = Infinity;
16971699

16981700
function scanSceneObject(obj){
16991701
if(dontIncludeStartObj && obj.isSame(startObj)) return;
@@ -1708,26 +1710,30 @@ global.getAllComponents = function(componentName, startObj, dontIncludeStartObj)
17081710
var comps = obj.getComponents(componentName);
17091711
for(var j = 0; j < comps.length; j++){
17101712
found.push(comps[j]);
1713+
if(found.length >= maxCount) return;
17111714
}
17121715
}
17131716

17141717
function iterateObj(obj){
17151718
for(var i = 0; i < obj.getChildrenCount(); i++){
17161719
var child = obj.getChild(i);
1717-
scanSceneObject(child)
1720+
scanSceneObject(child);
1721+
if(found.length >= maxCount) return;
17181722
iterateObj(child);
17191723
}
17201724
}
17211725

17221726
if(startObj){ // start at specific object if it exists
1723-
if(isNull(startObj)) throw new Error("Starting Object does not exist! It might have been deleted.");
1727+
if(isNull(startObj)) return found; // no starting object, return empty list
17241728
scanSceneObject(startObj);
1729+
if(found.length >= maxCount.length) return found;
17251730
iterateObj(startObj);
17261731
}else{ // go through whole scene
17271732
var rootObjectsCount = global.scene.getRootObjectsCount();
17281733
for(var i = 0; i < rootObjectsCount; i++){
17291734
var rootObj = global.scene.getRootObject(i);
17301735
scanSceneObject(rootObj);
1736+
if(found.length >= maxCount) return found;
17311737
iterateObj(rootObj);
17321738
}
17331739
}

LSQuickScripts/LSQuickScripts.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//@ui {"widget":"label", "label":"LSQuickScripts v2.15"}
1+
//@ui {"widget":"label", "label":"LSQuickScripts v2.16"}
22
//@ui {"widget":"label", "label":"By Max van Leeuwen"}
33
//@ui {"widget":"label", "label":"-"}
44
//@ui {"widget":"label", "label":"Place on top of scene ('On Awake')"}
@@ -423,11 +423,12 @@
423423
// -
424424
//
425425
//
426-
// getAllComponents(componentName (optional) [string], startObj (optional) [SceneObject], dontIncludeStartObj (optional) [bool]) : Array (Components)
426+
// getAllComponents(componentName (optional) [string], startObj (optional) [SceneObject], dontIncludeStartObj (optional) [bool], maxCount (optional) [number]) : Array (Components)
427427
// Returns an array containing all components of type componentNames, also those on child objects.
428-
// If no componentName is given, it returns SceneObjects.
428+
// If no componentName is given, it returns SceneObjects instead.
429429
// If no startObj is given, it searches the whole scene.
430430
// If dontIncludeStartObj is true, the startObj will not be included in the final list.
431+
// If maxCount is given, the search stops after having found a specific amount of components.
431432
//
432433
// Example
433434
// var components = getAllComponents("Component.VFXComponent")
@@ -1692,8 +1693,9 @@ global.measureWorldPos = function(screenPos, screenTrf, cam, dist){
16921693

16931694

16941695

1695-
global.getAllComponents = function(componentName, startObj, dontIncludeStartObj){
1696+
global.getAllComponents = function(componentName, startObj, dontIncludeStartObj, maxCount){
16961697
var found = [];
1698+
if(maxCount == null) maxCount = Infinity;
16971699

16981700
function scanSceneObject(obj){
16991701
if(dontIncludeStartObj && obj.isSame(startObj)) return;
@@ -1708,26 +1710,30 @@ global.getAllComponents = function(componentName, startObj, dontIncludeStartObj)
17081710
var comps = obj.getComponents(componentName);
17091711
for(var j = 0; j < comps.length; j++){
17101712
found.push(comps[j]);
1713+
if(found.length >= maxCount) return;
17111714
}
17121715
}
17131716

17141717
function iterateObj(obj){
17151718
for(var i = 0; i < obj.getChildrenCount(); i++){
17161719
var child = obj.getChild(i);
1717-
scanSceneObject(child)
1720+
scanSceneObject(child);
1721+
if(found.length >= maxCount) return;
17181722
iterateObj(child);
17191723
}
17201724
}
17211725

17221726
if(startObj){ // start at specific object if it exists
1723-
if(isNull(startObj)) throw new Error("Starting Object does not exist! It might have been deleted.");
1727+
if(isNull(startObj)) return found; // no starting object, return empty list
17241728
scanSceneObject(startObj);
1729+
if(found.length >= maxCount.length) return found;
17251730
iterateObj(startObj);
17261731
}else{ // go through whole scene
17271732
var rootObjectsCount = global.scene.getRootObjectsCount();
17281733
for(var i = 0; i < rootObjectsCount; i++){
17291734
var rootObj = global.scene.getRootObject(i);
17301735
scanSceneObject(rootObj);
1736+
if(found.length >= maxCount) return found;
17311737
iterateObj(rootObj);
17321738
}
17331739
}

0 commit comments

Comments
 (0)