public StaticPool() { s_instance = this; objLists = new Dictionary <GameObject, List <GameObject> >(); parent = new GameObject("StaticPool"); GameObject.DontDestroyOnLoad(parent); }
public void SpawnNewEnemy(GameObject enemyObject) { // If the next spawn point in line is not aleady taken if (m_queueEnd.m_occupant == null && m_queueEnd.m_reserved == false) { GameObject enemy = StaticPool.GetObj(enemyObject); enemy.transform.position = m_queueEnd.transform.position; enemy.GetComponent <Enemy>().Reset(); if (m_queueEnd.gameObject.name == "Waypoint 0" || m_queueEnd.gameObject.name == "Waypoint 1" || m_queueEnd.gameObject.name == "Waypoint 2") { enemy.GetComponent <Enemy>().inWarmUp = true; enemy.GetComponent <Enemy>().ChooseBallPowerUp(); } // (GameObject)Instantiate( enemyObject, m_queueEnd.transform.position, Quaternion.identity ); // Turn colliders off when they spawn in the line Collider[] colliders = enemy.GetComponentsInChildren <Collider>(); foreach (Collider col in colliders) { col.enabled = false; } m_queueEnd.m_occupant = enemy; FaceNextWaypoint(enemy.transform, m_queueEnd); // If we aren't at the end of the queue, move the spawnpoint one position back if (m_queueEnd.m_previous != null) { m_queueEnd = m_queueEnd.m_previous; } } }
public Hit Hit(Rect origin, Rect destination, IEnumerable <Box> ignoring = null) { var boxes = StaticPool.GetHashSet <Box>(); var wrap = Rect.Union(origin, destination); _broadPhase.QueryBoxes(wrap, boxes); if (ignoring != null) { boxes.ExceptWith(ignoring); } Hit nearest = new Hit(); foreach (var other in boxes) { var hit = Humper.Hit.Resolve(origin, destination, other); if (hit.IsHit && (!nearest.IsHit || hit.IsNearest(nearest, origin.Position))) { nearest = hit; } } StaticPool.Return(boxes); return(nearest); }
public StaticPool() { s_instance = this; objLists = new Dictionary<GameObject, List<GameObject>>(); parent = new GameObject("StaticPool"); GameObject.DontDestroyOnLoad(parent); }
public void Get_FromEmpty_ReturnDefaultValue() { var pool = new StaticPool <GameObject>(new FakeCreator <GameObject>(), new GameObject(), 0); var result = pool.Get(); Assert.That(result, Is.Null); }
void Shoot() { // print("Shoot - " + prefabProjectile.ToString()); GameObject obj = StaticPool.GetObj(prefabProjectile); obj.GetComponent <ProjectileTwo>().Reset(gameObject, transform.forward); StartCoroutine("Cooldown", cooldownTime); }
public static void Destroy(GameObject obj) { if (obj.HaveTags("pool")) { StaticPool.Destroy(obj); } else { GameObject.Destroy(obj); } }
void gotNextWaypoint() { pointIndex++; if (pointIndex >= WayPoints.points.Length) { StaticPool.Destroy(gameObject); return; } target = WayPoints.points[pointIndex]; }
IEnumerator Cooldown(float time) { shotReady = false; yield return(new WaitForSeconds(time / 2f)); GameObject obj = StaticPool.GetObj(prefabProjectile); obj.GetComponent <ProjectileTwo>().Reset(gameObject, Camera.main.transform.forward); yield return(new WaitForSeconds(time / 2)); m_animator.SetLayerWeight(1, 0f); m_animator.SetBool("Shoot", false); shotReady = true; }
void Start() { // nearPlane = GameObject.Find("NearPlane"); char[] delimChar = new char[1] { '_' }; ballPrefabDict = new Dictionary <string, GameObject> (); for (int i = 0; i < ballPrefabs.Length; i++) { ballPrefabDict.Add(ballPrefabs[i].name.Split(delimChar)[0], ballPrefabs[i]); StaticPool.InitObj(ballPrefabs[i]); } }
public AudioComponent(Game game, string audioFile) : base(game) { Debug.Assert(s_theAudio == null, "You can only construct one AudioComponent"); s_theAudio = this; m_filename = audioFile; m_cuePool = new StaticPool<AudioCue>(MAX_AUDIO_CUE); m_listener = new AudioListener(); #if AUDIO_DEBUG m_numPlaying = 0; m_numFailed = 0; m_numPlayed = 0; m_numStopped = 0; #endif }
public AudioComponent(Game game, string audioFile) : base(game) { Debug.Assert(s_theAudio == null, "You can only construct one AudioComponent"); s_theAudio = this; m_filename = audioFile; m_cuePool = new StaticPool <AudioCue>(MAX_AUDIO_CUE); m_listener = new AudioListener(); #if AUDIO_DEBUG m_numPlaying = 0; m_numFailed = 0; m_numPlayed = 0; m_numStopped = 0; #endif }
void Awake() { if (s_instance == null) { //If I am the fist instance, make me the first Singleton s_instance = this; DontDestroyOnLoad(gameObject); } else { //If a Singleton already exists and you find another reference in scene, destroy it if (s_instance != this) { DestroyImmediate(gameObject); } } }
public static GameObject Instantiate(string name, Vector3 position, Quaternion quat, Transform parent = null, GameObject prefab = null, bool pool = false, float max = Mathf.Infinity) { GameObject aux; if (!pool) { aux = GameObject.Instantiate(prefab, position, quat, parent); aux.name = name; } else { aux = StaticPool.Instantiate(prefab, position, parent, max); aux.AddOnlyOneComponent <MultiTags>(); aux.AddTags("pool"); } return(aux); }
public void MeleeAttack() { foreach (Stats enemy in enemiesToMeleeAttack) { enemy.TakeDamager(3); } if (enemiesToMeleeAttack.Count > 0) { GetComponent <Stats>().StartShake(); GameObject temp = StaticPool.GetObj(slashFXPrefab); temp.transform.SetParent(lookTransform.transform, false); temp.transform.localPosition = (new Vector3(0f, 1f, -1f)); temp.transform.Rotate(0f, 180f, 0f); temp.GetComponentInChildren <ParticleSystem>().enableEmission = true; attackLightFX.SetActive(true); StartCoroutine(Lightflicker(0.4f)); } }
void Awake() { if (_instance == null) { //If I am the fist instance, make me the first Singleton _instance = this; DontDestroyOnLoad(gameObject); staticPool = new StaticPool(); // Fight me } else { //If a Singleton already exists and you find another reference in scene, destroy it if (_instance != this) { Destroy(gameObject); } } }
private void GetMissedShotParticle(Vector3 newPos, Vector3 newRotation) { if (missedShotParticle != null) { // Get paricle and set position/rotation GameObject particle = StaticPool.GetObj(missedShotParticle); particle.transform.position = newPos; particle.transform.rotation = Quaternion.LookRotation(newRotation); // Play the particle ParticleSystem pSystem = particle.GetComponentInChildren <ParticleSystem>(); pSystem.Play(); StartCoroutine(ResetParticle(particle)); } else { Debug.LogWarning(gameObject.name + "'s missing a prefab for it's public particle variable."); } }
/// <summary> /// Gets the hit particle from the static pool, sets it to the right position, and then gets rid of it when it's done playing. /// </summary> /// <param name="newPos">New position.</param> /// <param name="newRotation">New rotation.</param> private void GetHitParticle(Vector3 newPos, Vector3 newRotation, GameObject particlePrefab) { if (particlePrefab != null) { // Get paricle and set position/rotation GameObject particle = StaticPool.GetObj(particlePrefab); particle.transform.position = newPos; particle.transform.rotation = Quaternion.LookRotation(newRotation); // Play the particle ParticleSystem pSystem = particle.GetComponentInChildren <ParticleSystem>(); pSystem.Play(); //networkView.RPC( "NetworkPlayParticle", RPCMode.Others, particle.networkView.viewID ); StartCoroutine(ResetParticle(particle)); } else { Debug.LogWarning(gameObject.name + "'s missing a prefab for it's public particle variable."); } }
void Shoot(ShootData shootData) { // print (shootData.start); Vector3 startPos = shootData.start; if (DebugMode.CENTERSPAWN) { startPos.z -= Camera.main.transform.position.z / 4f; // - nearPlane.transform.position.z; } GameObject ball = StaticPool.GetObj(ballPrefabDict[shootData.color.ToString()]); ball.GetComponent <Ball>().Reset(); ball.transform.position = Camera.main.ScreenToWorldPoint(startPos + Camera.main.transform.forward * 4f); ball.GetComponent <Rigidbody>().velocity = Vector3.zero; PlayerManager.IncreaseShots(shootData.color); Vector3 shootDir = shootData.dest - ball.transform.position; shootDir.Normalize(); if (DebugMode.FORWARDMODE) { ball.GetComponent <Rigidbody>().AddForce(Vector3.forward * (shootStrength + DebugMode.FORCECHANGE)); } else { ball.GetComponent <Rigidbody>().AddForce(shootDir * (shootStrength + DebugMode.FORCECHANGE)); } // Debug.Break(); ball.GetComponent <Rigidbody>().useGravity = DebugMode.GRAVITY; // Destroy (ball, 10f); }
void Awake() { if(s_instance == null) { //If I am the fist instance, make me the first Singleton s_instance = this; DontDestroyOnLoad(gameObject); } else { //If a Singleton already exists and you find another reference in scene, destroy it if(s_instance != this) DestroyImmediate(gameObject); } }
void Throw() { GameObject ball = StaticPool.GetObj(ballPrefab); gameMan.activeBalls.Add(ball.GetComponent <EnemyBall>()); if (gameMan.gamePhaseInt == 1) { gameMan.warmUpBallsThrown += 1; } playerPos = throwDestination.position; float randomX = Random.Range(0.8f, 1.6f); if (curColumn <= 1) { playerPos += new Vector3(-1f * randomX, 0, 0); } else { playerPos += new Vector3(1f * randomX, 0, 0); } if (curRow != 2) { timeToPlayer = 2 * Vector3.Distance(activeFakeBall.transform.position, playerPos) / 18f; } else { timeToPlayer = 2 * Vector3.Distance(activeFakeBall.transform.position, playerPos) / 12f; } if (gameMan.easyMode == false) { timeToPlayer /= 1.33f; } ball.GetComponent <EnemyBall> ().tutorialBall = false; ball.GetComponent <EnemyBall> ().Reset(); ball.GetComponent <EnemyBall> ().ChoosePowerUp(powerUpChoice); ball.transform.position = activeFakeBall.transform.position; //throwPoint.position; ball.transform.rotation = activeFakeBall.transform.rotation; //ball.GetComponent<EnemyBall> ().SetColliderEnableTime( timeToPlayer * 1f / 4f ); if (ball.transform.childCount > 0) { for (int i = 0; i < ball.transform.childCount; i++) { Destroy(ball.transform.GetChild(i).gameObject); } } GameObject particle = activeFakeBall.transform.GetChild(0).gameObject; particle.transform.parent = ball.transform; particle.transform.localPosition = Vector3.zero; float hVel = Vector3.Distance(playerPos, activeFakeBall.transform.position) / timeToPlayer; //float vVel = (4f + 0.5f * -Physics.gravity.y * Mathf.Pow (timeToPlayer, 2) - throwPoint.position.y) / timeToPlayer; float vVel = (0.5f * Physics.gravity.y * Mathf.Pow(timeToPlayer, 2) + activeFakeBall.transform.position.y - playerPos.y) / -timeToPlayer; Vector3 ballDir = (playerPos - activeFakeBall.transform.position).normalized; ballDir *= hVel; ballDir.y = vVel; // /1.5f; Rigidbody ballRB = ball.GetComponent <Rigidbody> (); ballRB.velocity = ballDir; ballRB.AddTorque(Random.insideUnitSphere * 100f); }
void Awake() { staticPool = new StaticPool(); }
void Create() { StaticPool.Instantiate(obj, Vector3.down, gameObject.transform, 2); Invoke("Create", 1f); }
void Awake() { staticPool = new StaticPool(); cam = GameObject.FindGameObjectWithTag("MainCamera").transform; }
void Create() { StaticPool.Instantiate(obj, Vector3.down, gameObject.transform, numberMax); Invoke("Put", time); }
void Put() { StaticPool.Instantiate(obj, Vector3.down, gameObject.transform); Invoke("Put", time); }
void SwitchGameMode(GameMode gm) { switch (gm) { case GameMode.STANDBY: textManager.countdownText.gameObject.SetActive(false); textManager.scoreText.gameObject.SetActive(false); textManager.timerText.gameObject.SetActive(false); textManager.streakText.gameObject.SetActive(false); DeactivateScoreCard(); timer = 30; gamePhaseInt = 0; StaticPool.DestroyAllObjects(); if (plays >= 1) { ReadyToPlay(); textManager.tutorialGameEndingText.gameObject.SetActive(false); } else { displayMan.EnableStandbyCamera(); batHoldBox.SetActive(false); standbyText.SetActive(true); foreach (MeshRenderer mesh in batMeshes) { mesh.enabled = false; } textManager.tutorialGameEndingText.gameObject.SetActive(false); textManager.tutorialScreenText.gameObject.SetActive(true); textManager.tutorialScreenDollarsText.gameObject.SetActive(true); textManager.tutorialPlaysText.gameObject.SetActive(false); textManager.tutorialReadyText.gameObject.SetActive(false); dollarsInserted = 0; textManager.tutorialScreenDollarsText.text = "$" + dollarsInserted.ToString() + "/$" + dollarsNeededToPlay.ToString(); paymentAccepted = false; SendSerialMessage("e"); serialMan.ClearPacketQueueAndBuffer(); ccProcessing.readyToProcess = true; ccProcessing.ResetMagStripeString(); } foreach (Material mat in gridMats) { mat.SetFloat("_Opacity_Slider", 30f); } //gridMats [1].SetFloat ("_Opacity_Slider", 7f); break; case GameMode.COUNTDOWN: displayMan.DisableStandbyCamera(); textManager.tutorialPleaseEnterText.gameObject.SetActive(false); textManager.tutorialScreenDollarsText.gameObject.SetActive(false); textManager.tutorialScreenText.gameObject.SetActive(false); textManager.tutorialGameInProgressText.gameObject.SetActive(true); dollarsInserted = 0; timer = 5f; textManager.countdownText.gameObject.SetActive(true); DisableLoadingBars(); batHoldBox.SetActive(false); textManager.warmUpText.gameObject.SetActive(true); aam.AdjustAimAssist(easyMode); AdjustThrowDestinationHeightForNewPlayer(); AddPlayToDebug(); newHighScore = false; bestStreak = 0; score = 0; streak = 0; streakMultiplier = 1; warmUpBallsThrown = 0; warmUpBallsDone = 0; if (am.loading.isPlaying) { am.loading.Stop(); } break; case GameMode.TUTORIAL: textManager.countdownText.gameObject.SetActive(false); batHoldBox.SetActive(false); break; case GameMode.GAME: aam.ClearOnCourtEnemies(); SwitchGamePhase(GamePhase.WARMUP); GameObject[] staticPoolBalls = GameObject.FindGameObjectsWithTag("Ball"); if (staticPoolBalls.Length >= 1) { foreach (GameObject ball in staticPoolBalls) { ball.SetActive(false); } } am.PlayBackgroundMusic(); timer = gameTimer; textManager.countdownText.gameObject.SetActive(false); //StaticPool.DisableAllObjects(); //StaticPool.DestroyAllObjects(); // Ghetto fix for now. Wasting an allocation somewhere also I think. queueManager.Reset(); break; case GameMode.GAMEOVER: if (score >= GetHighScore()) { SetNewHighScore(score); newHighScore = true; } timer = 3f; textManager.timerText.text = "Time: 0:00"; textManager.scoreText.text = "Score: " + score; textManager.streakText.text = "Streak: " + streak + " (x" + streakMultiplier + ")"; textManager.tutorialGameInProgressText.gameObject.SetActive(false); textManager.tutorialGameEndingText.gameObject.SetActive(true); ActivateScoreCard(); am.PlayAmbientCubeAudio(); am.StopAllCoroutines(); aam.ClearOnCourtEnemies(); break; case GameMode.SCORECARD: timer = 7f; plays--; analyticsManager.StopSession(); analyticsManager.SendAnalyticsData(score, easyMode); break; case GameMode.CONFIG: break; } mode = gm; }
public static IDisposable Subscribe <T>(TimerRule <T> rule, T param, StaticPool pool) { return(pool.Subscribe <T>(rule, param)); }
void SpawnEnemy() { StaticPool.Instantiate(enemyPrefab, enemyPrefab.transform.position); }
void Awake() { s_instance = this; objLists = new Dictionary<GameObject, List<GameObject>>(); parent = transform; GameObject.DontDestroyOnLoad(parent); }
private void OnDestroy() { StaticPool.RemovePool(gameObject); }
public Thread() { GenericThreadPool = new StaticPool(32).Run(); ReceivePool = new StaticPool(32).Run(); SendPool = new StaticPool(32).Run(); }
private void OnCollisionEnter(Collision coll) { StaticPool.Destroy(gameObject); }