private void Awake() { if (instance == null) { instance = this; } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // /// </summary> /// <returns> // IEnumerator /// </returns> private IEnumerator DelayedExplosion() { // Delay float normalizedTime = 0f; while (normalizedTime <= 1f) { normalizedTime += Time.deltaTime / CannisterLeakTime; yield return(null); } // Stop leaking & explode if (_CannisterLeakEffect != null) { _CannisterLeakEffect.Stop(); } ExplosionEffectStencil = ObjectPooling.Spawn(ExplosionEffectStencil.gameObject, ExplosionEffectTransform.position, ExplosionEffectTransform.rotation).GetComponent <ParticleSystem>(); ExplosionEffectStencil.Play(); // Camera shake if (_Player == null) { _Player = GameManager.Instance.Players[0]; } if (_Player != null) { _Player.CameraRTS.ExplosionShake(ExplosionEffectTransform.position, ExplosionRadius); } // Hide/despawn the unit _ObjectState = WorldObjectStates.Default; ObjectPooling.Despawn(gameObject); }
//****************************************************************************************************************************** // // FUNCTIONS // //****************************************************************************************************************************** //////////////////////////////////////////////////////////////////////////////////////////////////////////////// protected override void ProjectileRaycast() { base.ProjectileRaycast(); // Play particle effect stream if (FiringEffect != null && !_FlamethrowerStreamIsPlaying) { // Spawn _FlamethrowerStreamEffect = ObjectPooling.Spawn(FiringEffect).GetComponentInChildren <ParticleSystem>(); _FlamethrowerStreamEffect.GetComponentInChildren <ParticleBasedDamage>().SetWeaponAttached(this); _FlamethrowerStreamEffect.transform.position = _MuzzleLaunchPoints[_MuzzleIterator].position; _FlamethrowerStreamEffect.transform.rotation = _MuzzleLaunchPoints[_MuzzleIterator].rotation; // Play _FlamethrowerStreamEffect.Stop(); var main = _FlamethrowerStreamEffect.main; main.duration = FiringDuration; _FlamethrowerStreamEffect.Play(); _FlamethrowerStreamIsPlaying = true; if (LoopingFire) { // Despawn the effect AutoDespawn auto = _FlamethrowerStreamEffect.GetComponentInParent <AutoDespawn>(); StartCoroutine(StopFlamethrowerStream()); StartCoroutine(auto.DelayedDespawnSeconds((int)FiringDuration)); } } }
private void OnValidate() { if (objPooling == null) { objPooling = GetComponent <ObjectPooling>(); } }
public static void Fire(Transform transform, ObjectPooling pool) { GameObject Obj = pool.GetObjFromPool(); Obj.transform.position = transform.position; Obj.SetActive(true); }
/// <summary> // Play the second to fourth music tracks. /// </summary> public void PlayTrack() { // Reset song played counter int playedCount = 0; // Resets all the tracks to playable again if all the tracks have been played for (int i = 0; i < _TracksPlayed.Length - 1; i++) { if (_TracksPlayed[i] == true) { playedCount++; } } // Reset the tracks to false so they can be played again if (playedCount == _TrackCount) { for (int i = 0; i < _TracksPlayed.Length - 1; i++) { _TracksPlayed[i] = false; } // Set the first track to true so it only ever gets played once _TracksPlayed[0] = true; } // Set to false to find a new track to play bool foundTrack = false; // Searches for a new track to play while (foundTrack) { // Generate random number int i = Random.Range(1, _TrackCount); // If the track found hasn't been played if (_TracksPlayed[i] == false) { // Create pooled game object for the music GameObject musicObj = ObjectPooling.Spawn(Resources.Load <GameObject>(_TrackPath[i])); // Grab the source for the music to play from AudioSource musicSource = musicObj.GetComponent <AudioSource>(); Debug.Assert(_TrackPath == null, "_TrackPath is null, check file paths."); // Play the music musicSource.Play(); // Set to true foundTrack = true; // Set track to true to indicate its been played _TracksPlayed[i] = true; // Start coroutine StartCoroutine(UpdateTracks(musicSource)); break; } } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called each frame. /// </summary> private void Update() { if (_Upgrade != null && _CameraAttached != null) { // Only show widget if the upgrade is currently being built if (_Upgrade.IsUpgrading()) { // Update text to show how much time is remaining in the build int time = (int)_Upgrade.UpgradeTimeRemaining(); string healthString = time.ToString(); _TextComponent.text = healthString; // Set world space position Vector3 pos = _Upgrade.GetBuildingAttached().transform.position + Offsetting; pos.y = pos.y + _Upgrade.GetBuildingAttached().GetObjectHeight(); transform.position = pos; // Constantly face the widget towards the camera transform.LookAt(2 * transform.position - _CameraAttached.transform.position); } // Destroy prefab instance as we no longer need it anymore else { ObjectPooling.Despawn(this.gameObject); } } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called when this object is created. /// </summary> private void Start() { // Get all player entities Players = new List <Player>(); GameObject[] objs = GameObject.FindGameObjectsWithTag("Player"); foreach (var item in objs) { Players.Add(item.GetComponent <Player>()); } // Preload objects foreach (var pGameObj in PreloadGameObjects) { ObjectPooling.PreLoad(pGameObj.gameObject, pGameObj.size); } foreach (var pObj in PreloadWorldObjects) { ObjectPooling.PreLoad(pObj.worldObject.gameObject, pObj.size); } foreach (var pProj in PreloadProjectiles) { ObjectPooling.PreLoad(pProj.projectile.gameObject, pProj.size); } foreach (var pParticle in PreloadParticles) { ObjectPooling.PreLoad(pParticle.particle.gameObject, pParticle.size); } // Starting cinematic WaveManager.Instance.CinematicOpening.StartCinematic(); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called each frame. /// </summary> private void Update() { if (_WorldObject != null && _CameraAttached != null) { // Only show widget if the object is currently being built (or in queue) if (_WorldObject.GetObjectState() == Abstraction.WorldObjectStates.Building || _WorldObject.GetObjectState() == Abstraction.WorldObjectStates.InQueue) { // Update text to show how much time is remaining in the build int time = (int)_WorldObject.GetCurrentBuildTimeRemaining(); string healthString = time.ToString(); _TextComponent.text = healthString; // Set world space position Vector3 pos = _WorldObject.transform.position + Offsetting; pos.y = pos.y + _WorldObject.GetObjectHeight(); transform.position = pos; // Constantly face the widget towards the camera transform.LookAt(2 * transform.position - _CameraAttached.transform.position); } // Destroy prefab instance as we no longer need it anymore else { ObjectPooling.Despawn(this.gameObject); } } }
private void ReturnToPooling() { deltaTime = 0.0f; velocity = new Vector2(6.0f, 0.0f); renderer.flipX = false; ObjectPooling.ReturnProjectile(this); }
private void Awake() { instance = this; FillObject(100, standBlock, poolStandBlock); FillObject(3, fistBlock, poolFistBlock); }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// public void PlaySound(string soundLocation, float pitchMin, float pitchMax) { // Create pooled game object for the sound GameObject soundObj = ObjectPooling.Spawn(Resources.Load <GameObject>(soundLocation)); // Grab the source for the sound to play from AudioSource soundSource = soundObj.GetComponent <AudioSource>(); // Clammp min/max pitch (0, 3) if (pitchMin < 0) { pitchMin = 0f; } if (pitchMax > 3) { pitchMax = 3f; } if (pitchMin > pitchMax) { pitchMin = pitchMax; } if (pitchMax < pitchMin) { pitchMax = pitchMin; } // Randomize the sound's pitch based on the min and max specified soundSource.pitch = Random.Range(pitchMin, pitchMax); // Play the sound soundSource.Play(); // Add the sound object to the List _Sounds.Add(soundSource); }
//****************************************************************************************************************************** // // FUNCTIONS // //****************************************************************************************************************************** //////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called each frame. /// </summary> protected override void Update() { base.Update(); // object is active in the world if (_ObjectState == WorldObjectStates.Active && IsAlive()) { // Show the healthbar if (_HealthBar != null) { _HealthBar.gameObject.SetActive(true); } // Create a healthbar if the unit doesn't have one linked to it else { GameObject healthBarObj = ObjectPooling.Spawn(GameManager.Instance.UnitHealthBar.gameObject); _HealthBar = healthBarObj.GetComponent <UnitHealthBar>(); _HealthBar.SetObjectAttached(this); healthBarObj.gameObject.SetActive(true); healthBarObj.transform.SetParent(GameManager.Instance.WorldSpaceCanvas.gameObject.transform, false); if (_Player == null) { Player plyr = GameManager.Instance.Players[0]; _HealthBar.SetCameraAttached(plyr.PlayerCamera); } else { _HealthBar.SetCameraAttached(_Player.PlayerCamera); } } } }
void Update() { if (RePool()) { ObjectPooling.AddToPool(gameObject); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called each frame. /// </summary> private void Update() { if (_UnitAttached != null && _CameraAttached != null) { // Unit is alive - display the widget if (_UnitAttached.IsInWorld() && _UnitAttached.GetVeterancyLevel() > 0) { // Update text _TextComponent.text = _UnitAttached.GetVeterancyLevel().ToString(); // Set world space position Vector3 pos = _UnitAttached.transform.position + Offsetting; pos.y = pos.y + _UnitAttached.GetObjectHeight(); transform.position = pos; // Constantly face the widget towards the camera transform.LookAt(2 * transform.position - _CameraAttached.transform.position); } // Object is dead/destroyed else { ObjectPooling.Despawn(gameObject); } } }
void MakeInstance() { if (instance == null) { instance = this; } }
private void Start() { if (instance != null) { Destroy(gameObject); } else { instance = this; DontDestroyOnLoad(gameObject); } poolDictionary = new Dictionary <string, Pool>(); foreach (PoolReference poolRef in poolReferenceList) { Pool newPool = new Pool(poolRef.prefab); //add new pool to dictionary poolDictionary.Add(poolRef.tag, newPool); for (int i = 0; i < poolRef.count; i++) { GameObject spawnedObject = Instantiate(poolRef.prefab); poolDictionary[poolRef.tag].pool.Enqueue(spawnedObject); spawnedObject.SetActive(false); } } }
//****************************************************************************************************************************** // // FUNCTIONS // //****************************************************************************************************************************** //////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called when this object is created. /// </summary> protected override void Start() { base.Start(); // Initialize _ObjectHeight = ObjectHeight; if (HasABuildingQueue) { _BuildingQueue = new List <Abstraction>(); } // Create upgrade instances & replace the selectable reference for (int i = 0; i < Selectables.Count; i++) { if (Selectables[i] != null) { // Check if the selectable option is an upgrade tree UpgradeTree tree = Selectables[i].GetComponent <UpgradeTree>(); if (tree != null) { // Replace reference with the runtime version UpgradeTree newTree = ObjectPooling.Spawn(tree.gameObject).GetComponent <UpgradeTree>(); Selectables[i] = newTree; } } } }
public PoolPart(string name, PoolObject prefab, int count, ObjectPooling ferula) { this.name = name; this.prefab = prefab; this.count = count; this.ferula = ferula; }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // /// </summary> protected override void OnActiveState() { base.OnActiveState(); // Create new mines (does it for both small & large minefields) for (int i = 0; i < MineVectorObjects.Count; i++) { // Initialize Vector3 spawnPosition = MineVectorObjects[i].transform.position; Mine mine = ObjectPooling.Spawn(MineStencil.gameObject, spawnPosition).GetComponent <Mine>(); if (mine != null) { mine.SetTeam(Team); mine.SetAttachedMineField(this); } _UndetonatedMineList.Add(mine); } // Upgrade all the undetonated mines if (LargeMineField) { for (int i = 0; i < _UndetonatedMineList.Count; i++) { ///_UndetonatedMineList[i].Upgrade(explosionRadius, damage, damagefalloff); } } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // Called every frame. Scales down the unit's transform if its dead & // Despawn when finished. /// </summary> private void UpdateDeathShrinker() { // Check if the unit should be shrinking if (_StartShrinking && !IsAlive() && ShrinkWhenDestroyed) { // Get in the cold ass water transform.localScale -= Vector3.one * ShrinkSpeed * Time.deltaTime; if (transform.localScale.x < 0.01f) { // Deselect / De-highlight if (_Player) { _Player.RemoveFromSelection(this); } SetIsHighlighted(false); SetIsSelected(false); // MAXIMUM shrinkage _StartShrinking = false; // This is so that the next time the object is spawned - it is at its default state already _ObjectState = WorldObjectStates.Default; // Despawn the object transform.localScale = new Vector3(1f, 1f, 1f); ObjectPooling.Despawn(gameObject); } } }
//for ease of writing/reading //returns true if the object is in the pool public static bool IsInPool(this GameObject objToVerify, ObjectPooling pool) { if (pool.Objects.Contains(objToVerify)) { return(true); } return(false); }
public static GameObject GetFromPool(Vector2 position, ObjectPooling pool) { GameObject Obj = pool.GetObjFromPool(); Obj.transform.position = position; Obj.SetActive(true); return(Obj); }
void Start() { game = this; audioSource = GetComponent <AudioSource>(); camera = GetComponent <Camera>(); cam = GetComponent <CameraShake>(); objectPool = GetComponent <ObjectPooling>(); }
//returns true if the pool cantains the object public static bool Contains(this ObjectPooling pool, GameObject objToVerify) { if (pool.Objects.Contains(objToVerify)) { return(true); } return(false); }
private void OnEnable() { Ammo = 100; UpdateFillBar(); bullets = GameObject.Find("BulletsSpawn").GetComponent <ObjectPooling>(); Debug.Log("fill bar reset"); audioHandler = GetComponent <ObjectAudioHandler>(); }
private void Start() { _pooling = ObjectPooling.Singleton; foreach (var p in pools) { ObjectPooling.Singleton.GeneratePool(p); } }
private void CreateNewEnvironmentTileWithObjectPooling(Vector3 position) { _activeEnvironmentTile = ObjectPooling.ReturnObjectFromPool(0, position, Quaternion.identity); _activeEnvironmentTile.GetComponent <EnvironmentTileContentManager>().CreatePickupsAndEnemies(); #if UNITY_EDITOR EndlessRunnerGameManager.DisplayDebugMessage("New environment tile enabled from object pool."); #endif }
// Start is called before the first frame update void Awake() { op = this; if (dict == null) { dict = new Dictionary <string, Data>(); } }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> // A coroutine that waits for the seconds specified then attempts to repool // the particle effect (or destroyed entirely if re-pooling isn't possible) /// </summary> /// <param name="particleEffect"></param> /// <param name="delay"></param> IEnumerator ParticleDespawn(ParticleSystem particleEffect, float delay) { // Delay yield return(new WaitForSeconds(delay)); // Despawn the system ObjectPooling.Despawn(particleEffect.gameObject); }
void Awake() { spawner = this; int amount = 0; for (int i = 0; i < pools.Length; i++) { pools[i].Initialize(); amount += pools[i].poolSize; } activePoolObjects = new Dictionary<GameObject, bool>(); }
// Use this for initialization void Start() { instance = this; for (int i = 0; i < poolAmount; i++) { GameObject go = (GameObject) Instantiate(pooledObject,transform.position,transform.rotation); go.SetActive(false); pooledObjects.Add(go); } }
/*Everything related to creating the dungeon itself */ void Awake() { newEnemyWeights = new Dictionary<string, int>(); newEnemyWeights.Add("aggressive", 3); newEnemyWeights.Add("smart", 3); newEnemyWeights.Add("turret", 1); newEnemyWeights.Add("zombie", 2); newEnemyWeights.Add("worm", 2); Application.targetFrameRate = 60 ; QualitySettings.vSyncCount = 0; scale = Accessiblescale; stage = new Stage(floorMaterials, wallMaterials, FBuilder); //TODO: place rooms first. stage._addRooms(); stage.PlaceHalls(); stage.createDoors(); stage.removeDeadEnds(); stage.Create(); spawnPlayer(); Player = GameObject.FindWithTag("Player").transform; maxEnemies = (Player.gameObject.GetComponent<PlayerController>().getCurrentFloor() + 1) * enemiesPerLevel; numEnemies = 0; enemyWeights = new float[6, 3]; enemyWeights[0, 0] = 0.5f; enemyWeights[0, 1] = 1f; enemyWeights[0, 2] = 0; enemyWeights[1, 0] = 0.4f; enemyWeights[1, 1] = 0.8f; enemyWeights[1, 2] = 1f; enemyWeights[2, 0] = 0.35f; enemyWeights[2, 1] = 0.7f; enemyWeights[2, 2] = 1f; enemyWeights[3, 0] = 0.35f; enemyWeights[3, 1] = 0.7f; enemyWeights[3, 2] = 1f; enemyWeights[4, 0] = 0.35f; enemyWeights[4, 1] = 0.7f; enemyWeights[4, 2] = 0.3f; enemyWeights[5, 0] = 0.35f; enemyWeights[5, 1] = 0.35f; enemyWeights[5, 2] = 0.3f; pool = GameObject.Find("ObjectPool").GetComponent<ObjectPooling>(); }
void Awake() { current = this; }
protected void StartBody() { //Automatically attach the player & various components player = GameObject.FindGameObjectWithTag("Player"); health_controller = GetComponent<HealthController>(); anim = GetComponent<Animator>(); AggroState = false; RBody = GetComponent<Rigidbody>(); gun = transform.FindChild("Gun Location"); combo_controller = GameObject.FindGameObjectWithTag("Combo").GetComponent<ComboController>(); PC = player.GetComponent<PlayerController>(); pool = GameObject.Find("ObjectPool").GetComponent<ObjectPooling>(); }