Improve logic for getting all berries

This commit is contained in:
Lncvrt committed 2026-03-06 10:27:16 -07:00
1 parent c9b469a5a0
commit 3f6849060f
5 files changed
+16 -89

No files matched your search

+2 -23
View File
@@ -328,16 +328,7 @@ public class AutoGamePlayer : MonoBehaviour {
if (!pausePanel.activeSelf && rb.gravityScale != 100f * canvasRect.lossyScale.y) rb.gravityScale = 100f * canvasRect.lossyScale.y;
foreach (AudioSource audio in FindObjectsByType<AudioSource>(FindObjectsSortMode.None)) audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SpeedyBerry"))
.Concat(GameObject.FindGameObjectsWithTag("CoinBerry"))
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
.ToArray();
var allBerries = Tools.GetAllBerries(berryParent.transform);
if (!pausePanel.activeSelf) foreach (GameObject berry in allBerries) {
if (berry.GetComponent<RectTransform>().anchoredPosition.y < -(canvasRect.rect.height / 2) - berry.GetComponent<RectTransform>().rect.height) {
@@ -389,19 +380,7 @@ public class AutoGamePlayer : MonoBehaviour {
antiLeft = 0f;
UpdateStats(0, 1);
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SpeedyBerry"))
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
.ToArray();
foreach (GameObject berry in allBerries) {
noGravityBerries.Remove(berry.GetInstanceID());
Destroy(berry);
}
foreach (GameObject berry in Tools.GetAllBerries(berryParent.transform)) Destroy(berry);
}
void UpdateStats(BigInteger scoreAddAmount, BigInteger attemptAddAmount) {
+2 -24
View File
@@ -494,16 +494,7 @@ public class CustomGamePlayer : MonoBehaviour {
if (!pausePanel.activeSelf && rb.gravityScale != 100f * canvasRect.lossyScale.y) rb.gravityScale = 100f * canvasRect.lossyScale.y;
foreach (AudioSource audio in FindObjectsByType<AudioSource>(FindObjectsSortMode.None)) audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SpeedyBerry"))
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
.Concat(GameObject.FindGameObjectsWithTag("NothingBerry"))
.ToArray();
var allBerries = Tools.GetAllBerries(berryParent.transform);
if (!pausePanel.activeSelf) foreach (GameObject berry in allBerries) {
if (berry.GetComponent<RectTransform>().anchoredPosition.y < -(canvasRect.rect.height / 2) - berry.GetComponent<RectTransform>().rect.height) {
@@ -558,20 +549,7 @@ public class CustomGamePlayer : MonoBehaviour {
antiLeft = 0f;
UpdateStats(0, 1);
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SpeedyBerry"))
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
.Concat(GameObject.FindGameObjectsWithTag("NothingBerry"))
.ToArray();
foreach (GameObject berry in allBerries) {
noGravityBerries.Remove(berry.GetInstanceID());
Destroy(berry);
}
foreach (GameObject berry in Tools.GetAllBerries(berryParent.transform)) Destroy(berry);
}
void UpdateStats(BigInteger scoreAddAmount, BigInteger attemptAddAmount) {
+2 -24
View File
@@ -274,16 +274,7 @@ public class GamePlayer : MonoBehaviour {
if (!pausePanel.activeSelf && rb.gravityScale != 100f * canvasRect.lossyScale.y) rb.gravityScale = 100f * canvasRect.lossyScale.y;
foreach (AudioSource audio in FindObjectsByType<AudioSource>(FindObjectsSortMode.None)) audio.pitch = speedyLeft > 0f ? 1.3f : 1f;
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SpeedyBerry"))
.Concat(GameObject.FindGameObjectsWithTag("CoinBerry"))
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
.ToArray();
var allBerries = Tools.GetAllBerries(berryParent.transform);
if (!pausePanel.activeSelf) foreach (GameObject berry in allBerries) {
if (berry.GetComponent<RectTransform>().anchoredPosition.y < -(canvasRect.rect.height / 2) - berry.GetComponent<RectTransform>().rect.height) {
@@ -338,20 +329,7 @@ public class GamePlayer : MonoBehaviour {
antiLeft = 0f;
UpdateStats(0, 1);
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SpeedyBerry"))
.Concat(GameObject.FindGameObjectsWithTag("CoinBerry"))
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
.ToArray();
foreach (GameObject berry in allBerries) {
noGravityBerries.Remove(berry.GetInstanceID());
Destroy(berry);
}
foreach (GameObject berry in Tools.GetAllBerries(berryParent.transform)) Destroy(berry);
}
void UpdateStats(BigInteger scoreAddAmount, BigInteger attemptAddAmount) {
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using MikeSchweitzer.WebSocket;
using Newtonsoft.Json.Linq;
@@ -292,16 +291,7 @@ public class MultiplayerGamePlayer : MonoBehaviour {
if (!pausePanel.activeSelf && rb.gravityScale != 100f * canvasRect.lossyScale.y) rb.gravityScale = 100f * canvasRect.lossyScale.y;
ProcessSpawns();
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SpeedyBerry"))
.Concat(GameObject.FindGameObjectsWithTag("CoinBerry"))
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
.Concat(GameObject.FindGameObjectsWithTag("AntiBerry"))
.Concat(GameObject.FindGameObjectsWithTag("GoldenBerry"))
.ToArray();
var allBerries = Tools.GetAllBerries(berryParent.transform);
foreach (GameObject berry in allBerries) {
if (berry.GetComponent<RectTransform>().anchoredPosition.y < -(canvasRect.rect.height / 2) - berry.GetComponent<RectTransform>().rect.height) Destroy(berry);
@@ -339,13 +329,7 @@ public class MultiplayerGamePlayer : MonoBehaviour {
slownessLeft = 0f;
UpdateStats(0, 1);
GameObject[] allBerries = GameObject.FindGameObjectsWithTag("NormalBerry")
.Concat(GameObject.FindGameObjectsWithTag("PoisonBerry"))
.Concat(GameObject.FindGameObjectsWithTag("SlowBerry"))
.Concat(GameObject.FindGameObjectsWithTag("UltraBerry"))
.Concat(GameObject.FindGameObjectsWithTag("RandomBerry"))
.ToArray();
foreach (GameObject berry in allBerries) Destroy(berry);
foreach (GameObject berry in Tools.GetAllBerries(berryParent.transform)) Destroy(berry);
}
void UpdateStats(BigInteger scoreAddAmount, BigInteger attemptAddAmount) {
+8
View File
@@ -153,4 +153,12 @@ public static class Tools {
CustomIconLoader.Init(new[] { waitingForCustomIcon });
}
}
public static GameObject[] GetAllBerries(Transform berryParent) {
GameObject[] children = new GameObject[berryParent.childCount];
for (int i = 0; i < berryParent.childCount; i++) {
children[i] = berryParent.GetChild(i).gameObject;
}
return children;
}
}