public void Remove(ObjectToPool objectToPool) { if (objectToPool.type == ObjectToPool.Type.Enemy) { enemies.Remove(objectToPool.gameObject); } }
public void Add(ObjectToPool objectToPool) { if (objectToPool.type == ObjectToPool.Type.Enemy) { enemies.Add(objectToPool.gameObject); } }
//Pooling을 하는 함수. public void MakePool() { //Pooling 을 하는 작업이다. foreach (KeyValuePair <string, ObjectToPool> iter in m_ObjectToPool) { ObjectToPool itemToPool = iter.Value; for (int j = 0; j < itemToPool.AmountToPool; j++) { GameObject Obj = Instantiate(itemToPool.Obj); Obj.name = itemToPool.ObjName; int PosIndex = Random.Range(0, m_PoolingPos.Length); Obj.transform.position = m_PoolingPos[PosIndex]; Transform Parent_Directory = m_Directory_PooledObject; for (int h = 0; h < m_Directory_PooledObject.childCount; h++) { if (string.Equals(m_Directory_PooledObject.GetChild(h).name, Obj.name)) { Parent_Directory = m_Directory_PooledObject.GetChild(h); break; } } Obj.transform.SetParent(Parent_Directory); Obj.SetActive(false); if (!m_PooledObject.ContainsKey(itemToPool.ObjName)) { m_PooledObject.Add(itemToPool.ObjName, new List <GameObject>()); } m_PooledObject[itemToPool.ObjName].Add(Obj); } } }
public void AddObjectToPool(int _childindex, int _amountToPool, ObjType _objtype, bool _shouldexpand) { Transform Directory_ObjectToPool = transform.GetChild(0); ObjectToPool ObjectToPool = new ObjectToPool(); ObjectToPool.Obj = Directory_ObjectToPool.GetChild(_childindex).gameObject; ObjectToPool.AmountToPool = _amountToPool; //parsing number.name => number[0] / name[1] string objname = ObjectToPool.Obj.name; string[] sp = objname.Split(new char[] { '.' }, 2); if (sp.Length <= 1) { ObjectToPool.ObjName = ObjectToPool.Obj.name; } else { ObjectToPool.ObjName = sp[1]; } ObjectToPool.objType = _objtype; ObjectToPool.ShouldExpand = _shouldexpand; m_ObjectToPool.Add(ObjectToPool.ObjName, ObjectToPool); GameObject Directory = new GameObject(); Directory.name = ObjectToPool.ObjName; Directory.transform.SetParent(m_Directory_PooledObject); }
private void Awake() { //audioManager = FindObjectOfType<AudioManager>(); state = State.Normal; projectilePooled = ObjectToPool.Arrow; Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; }
private GameObject InstantiateGameObject(ObjectToPool objectToPool) { GameObject go = Instantiate(objectToPool.PrefabToPool); PoolOfGameObjects.Add(go); objectToPool.Counter++; return(go); }
private void OnDeath() { ObjectToPool fx = SpawnManager.GetPoolObject("Explode"); fx.transform.position = Position; fx.StartSelfDespawnAfter(1); SpawnManager.EnemyPools[SpawnData.PrefabIndex].Release(this); // Todo add death animation }
public override void ReleaseItem(ObjectToPool item) { base.ReleaseItem(item); if (OnHit != null) { OnHit(); OnHit = null; } }
private void Initialize(ObjectToPool poolObject) { poolObject.pool = new List <GameObject>(); for (int i = 0; i < poolObject.amount; i++) { GameObject newObj = Instantiate(poolObject.gameObject, objectPool); newObj.SetActive(false); poolObject.pool.Add(newObj); } }
public void CreateObjectPool(string keyName) { if (!ObjectsPools.ContainsKey(keyName)) { ObjectPool <ObjectToPool> Pool = new ObjectPool <ObjectToPool>(5, (name) => { int index = 0; for (int j = 0; j < _poolObjects.Length; j++) { if (name == _poolObjects[j].name) { index = j; break; } } ObjectToPool obj = Instantiate(_poolObjects[index]); #if UNITY_EDITOR obj.transform.SetParent(_objectHolder); #endif obj.name = name; if (!_activeObjectToPools.Contains(obj)) { _activeObjectToPools.Add(obj); } return(obj); }, (obj) => { obj.GetItem(obj); if (!_activeObjectToPools.Contains(obj)) { _activeObjectToPools.Add(obj); } }, (obj) => { if (_activeObjectToPools.Contains(obj)) { _activeObjectToPools.Remove(obj); } obj.ReleaseItem(obj); }, keyName); ObjectsPools.Add(keyName, Pool); } }
public GameObject GetPooledObject(string tag) { ObjectToPool objectToPool = null; for (int i = 0; i < GameObjectsToPool.Count; i++) { if (GameObjectsToPool[i].PrefabToPool.tag == tag) { objectToPool = GameObjectsToPool[i]; } } if (objectToPool == null) { return(null); } for (int i = 0; i < PoolOfGameObjects.Count; i++) { if (PoolOfGameObjects[i].tag == tag && PoolOfGameObjects[i].activeSelf == false) { return(PoolOfGameObjects[i]); } } if (objectToPool.Counter < objectToPool.MaxSpawns) { return(InstantiateGameObject(objectToPool)); } else { if (objectToPool.Expand == true) { return(InstantiateGameObject(objectToPool)); } } return(null); }
public virtual void GetItem(ObjectToPool item) { gameObject.SetActive(true); }
public virtual void ReleaseItem(ObjectToPool item) { StopAllCoroutines(); gameObject.SetActive(false); }
private void FireProjectile(ObjectToPool _projectilePrefab, int _objectToPool, Color _baseColor, int _projectileDamage, float _attackRate, int _projectileSplit = 1, float _direction = 0.15f, float _intensity = 0f) { Vector3 projSpawnPoint = transform.position + (direction * _direction) + projectileOffset; GameObject projectile = pooler.GetPooledObject((int)_projectilePrefab); projectile.SetActive(true); projectile.transform.position = projSpawnPoint; projectile.transform.rotation = Quaternion.identity; Projectile projectileScript = projectile.GetComponent <Projectile>(); Vector3 shootingDirection = crossHair.transform.position - projSpawnPoint; shootingDirection.Normalize(); projectile.GetComponent <SpriteRenderer>().color = _baseColor; if (_intensity > 0) { projectile.GetComponent <SpriteRenderer>().material.SetColor("_Color", new Color(_intensity, _intensity, _intensity, 0f)); } projectile.transform.Rotate(0, 0, Mathf.Atan2(shootingDirection.y, shootingDirection.x) * Mathf.Rad2Deg); projectileScript.Owner = this.gameObject; projectileScript.Velocity = shootingDirection * ARROW_BASE_SPEED; projectileScript.ProjectileDamage = _projectileDamage; projectileScript.CritMultiplier = critMultiplierAmount; projectileScript.CritChance = critChance; projectileScript.CanPierce = canPierce; projectileScript.Explosive = isExplosive; projectileScript.Intensity = _intensity; projectileScript.HitEffectToPool = _objectToPool; // Split Arrow Ability for (int i = 1; i <= _projectileSplit / 2; i++) { GameObject projectile2 = pooler.GetPooledObject((int)_projectilePrefab); GameObject projectile3 = pooler.GetPooledObject((int)_projectilePrefab); projectile2.SetActive(true); projectile3.SetActive(true); projectile2.transform.rotation = Quaternion.identity; projectile3.transform.rotation = Quaternion.identity; projectile2.transform.position = projSpawnPoint; projectile3.transform.position = projSpawnPoint; Projectile projectileScript2 = projectile2.GetComponent <Projectile>(); Projectile projectileScript3 = projectile3.GetComponent <Projectile>(); projectile2.GetComponent <SpriteRenderer>().color = _baseColor; projectile3.GetComponent <SpriteRenderer>().color = _baseColor; if (_intensity > 0) { projectile2.GetComponent <SpriteRenderer>().material.SetColor("_Color", new Color(_intensity, _intensity, _intensity, 0f)); projectile3.GetComponent <SpriteRenderer>().material.SetColor("_Color", new Color(_intensity, _intensity, _intensity, 0f)); } Vector3 shootingDirectionPos = Quaternion.AngleAxis(angleVariance * i, Vector3.forward) * shootingDirection; Vector3 shootingDirectionNeg = Quaternion.AngleAxis(-angleVariance * i, Vector3.forward) * shootingDirection; projectile2.transform.Rotate(0, 0, Mathf.Atan2(shootingDirectionPos.y, shootingDirectionPos.x) * Mathf.Rad2Deg); projectileScript2.Owner = this.gameObject; projectileScript2.Velocity = shootingDirectionPos * ARROW_BASE_SPEED; projectileScript2.ProjectileDamage = _projectileDamage; projectileScript2.CritMultiplier = critMultiplierAmount; projectileScript2.CritChance = critChance; projectileScript2.CanPierce = canPierce; projectileScript2.Explosive = isExplosive; projectileScript2.Intensity = _intensity; projectileScript2.HitEffectToPool = _objectToPool; projectile3.transform.Rotate(0, 0, Mathf.Atan2(shootingDirectionNeg.y, shootingDirectionNeg.x) * Mathf.Rad2Deg); projectileScript3.Owner = this.gameObject; projectileScript3.Velocity = shootingDirectionNeg * ARROW_BASE_SPEED; projectileScript3.ProjectileDamage = _projectileDamage; projectileScript3.CritMultiplier = critMultiplierAmount; projectileScript3.CritChance = critChance; projectileScript3.CanPierce = canPierce; projectileScript3.Explosive = isExplosive; projectileScript3.Intensity = _intensity; projectileScript3.HitEffectToPool = _objectToPool; } }
private void ProcessInputs() { crossHair.transform.position = this.transform.position; crossHairInner.transform.position = this.transform.position; switch (state) { case State.Normal: movement = new Vector3(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"), 0.0f); if (movement.magnitude > 1.0f) { movement.Normalize(); } break; case State.Rolling: ROLL_BASE_SPEED -= ROLL_BASE_SPEED * rollSpeedDropMultiplier * Time.deltaTime; if (ROLL_BASE_SPEED < MOVEMENT_BASE_SPEED) { state = State.Normal; } break; } arrowSpawnPoint.transform.position = transform.position + (direction * 0.1f) + projectileOffset; aimingMoveSpeed = Mathf.Clamp(movement.magnitude, 0.0f, 0.9f); Vector3 mouseMovement = new Vector3(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"), 0.0f); aim = aim + mouseMovement; if (aim.magnitude > 1f) // Mouse Distance Limiter { aim.Normalize(); } direction = aim; // - transform.position; endOfAiming = Input.GetButtonUp("Fire"); isAiming = Input.GetButton("Fire"); isAbility = Input.GetButton("Fire2"); if (isAiming) { aimingMoveSpeed *= AIMING_BASE_PENALTY; } if (isAbility) { aimingMoveSpeed *= (AIMING_BASE_PENALTY * 1.5f); } //direction.Normalize(); // Sets the spawnpoint to normalized if (Input.GetKeyDown(KeyCode.Space) && movement.sqrMagnitude > 0) // DASH // { rollDirection = movement; ROLL_BASE_SPEED = startRollSpeed; state = State.Rolling; CreateDust(); } if (Input.GetKeyDown(KeyCode.LeftShift)) { isWalking = true; tempSpeed = MOVEMENT_BASE_SPEED; MOVEMENT_BASE_SPEED = tempSpeed * 0.75f; } if (Input.GetKeyUp(KeyCode.LeftShift)) { isWalking = false; MOVEMENT_BASE_SPEED = tempSpeed; } if (Input.GetKeyDown(KeyCode.Alpha1)) { projectilePooled = ObjectToPool.Arrow; } if (Input.GetKeyDown(KeyCode.Alpha2)) { projectilePooled = ObjectToPool.MagicMis; } if (Input.GetKeyDown(KeyCode.Alpha3)) { projectilePooled = ObjectToPool.MagicRain; } if (Input.GetKeyDown(KeyCode.Alpha4)) { projectilePooled = ObjectToPool.LightPulse; } if (Input.GetKeyDown(KeyCode.Alpha5)) { projectilePooled = ObjectToPool.Snowball; } if (Input.GetKeyDown(KeyCode.Alpha6)) { projectilePooled = ObjectToPool.LightPulse; } if (Input.GetKeyDown(KeyCode.Tab)) { if (useWand) { useWand = false; useBow = true; } else { useBow = false; useWand = true; } } // Spell Mappings if (Input.GetKeyDown(KeyCode.E)) { } if (Input.GetKeyDown(KeyCode.R)) { } }
public void ReleasePoolObject(ObjectToPool obj) { ObjectsPools[obj.name].Release(obj); }