void SpawnProjectileAbility(string projectileName, Vector3 position, Quaternion rotation, Vector3 direction, int layer, int casterPlayerID) { ProjectileVisuals projectile = AbilityProjectilePool.Instance.GetProjectile(projectileName); projectile.transform.position = position; projectile.transform.rotation = rotation; Debug.Log("AbilitySpawner SpawnProjectileAbility position " + position); projectile.gameObject.layer = layer; projectile.Activate(); MoveAbility movement = projectile.GetComponent <MoveAbility>(); if (movement != null) { movement.SetDirection(direction); } Player player = PlayerManager.Instance.GetPlayer(casterPlayerID); AbilityCollider abilityCollider = projectile.GetComponent <AbilityCollider>(); abilityCollider.SetCasterID(casterPlayerID); if (player.hasDoubleDamage) { abilityCollider.ActivateDoubleDamageEffect(player.hasDoubleDamage); } }
void SpawnStaticAbility(string projectileName, Vector3 position, Quaternion rotation, int layer, int casterPlayerID) { Debug.Log("AbilitySpawner Spawning " + projectileName); ProjectileVisuals spawned = AbilityProjectilePool.Instance.GetProjectile(projectileName); spawned.transform.position = position; spawned.transform.rotation = rotation; spawned.Activate(); spawned.gameObject.layer = layer; Player player = PlayerManager.Instance.GetPlayer(casterPlayerID); AbilityCollider abilityCollider = spawned.GetComponent <AbilityCollider>(); if (abilityCollider) { abilityCollider.SetCasterID(casterPlayerID); } if (player.hasDoubleDamage) { abilityCollider.ActivateDoubleDamageEffect(player.hasDoubleDamage); } }
private void Awake() { abilityData = AbilityDataCache.GetDataForAbility(name); effect = GetComponent <AbilityEffect>(); if (GetComponent <AbilityDuration>() != null) { isStatic = true; } else { isStatic = false; } projectileVisuals = GetComponent <ProjectileVisuals>(); }
private void Awake() { duration = AbilityDataCache.GetDataForAbility(name).stats.duration; Debug.Log("AbilityDuration Duration for " + name + " is " + duration); if (duration <= 0f) { Debug.Log("AbilityDuration Warning duration not set for ability " + name); } AbilitySpawnTween tween = GetComponent <AbilitySpawnTween>(); if (tween) { duration += tween.duration; } visuals = GetComponent <ProjectileVisuals>(); }
void InitPool(GameObject template, int size) { ProjectileVisuals[] pool = new ProjectileVisuals[size]; for (int i = 0; i < size; i++) { GameObject go = Instantiate(template, transform); go.name = template.name; ProjectileVisuals visuals = go.GetComponent <ProjectileVisuals>(); pool[i] = visuals; visuals.Deactivate(); } // We will set the config value for the object type we just created to 0 so that we can use this Dictionary to store the current index poolConfig[template.name] = 0; poolMap.Add(template.name, pool); }
private void Awake() { visuals = GetComponent <ProjectileVisuals>(); health = numCollisions; }
private void Awake() { projectileVisuals = GetComponent <ProjectileVisuals>(); }
public ProjectileVisuals GetProjectile(string name) { // Get the current index and length of the specific pool int currentIndex = poolConfig[name]; int poolSize = poolMap[name].Length; // Get the next index currentIndex = (currentIndex + 1) % poolSize; Debug.Log("ObjectPool GetNext " + name + "Current Index is " + currentIndex); ProjectileVisuals poolObject = poolMap[name][currentIndex]; // If the object is not is use return this one to be used if (poolObject.IsActiveOnScreen() == false) { Debug.Log("ObjectPool GetNext found object 1st try at index " + currentIndex); poolConfig[name] = currentIndex; return(poolObject); } // Preferably this part of the should not be called as it is more expensive else { ProjectileVisuals[] pool = poolMap[name]; // First we will loop the pool to check for a free spot Debug.Log("ObjectPool GetNext Looping objects to find unactive. Length " + pool.Length); for (int i = 0; i < pool.Length; i++) { if (pool[i].IsActiveOnScreen() == false) { poolConfig[name] = i; Debug.Log("ObjectPool GetNext found object at index " + i); return(pool[i]); } } // Worst case there was no object that was found so we need to extend the array // so that we can create a new object, this is very expensive so in the ideal case // it should be never called poolSize++; Debug.Log("ObjectPool GetNext Pool size before expansion " + pool.Length); Array.Resize <ProjectileVisuals>(ref pool, poolSize); Debug.Log("ObjectPool GetNext Pool size after expansion " + pool.Length + " original pool size " + poolMap[name].Length); currentIndex = poolSize - 1; Debug.Log("ObjectPool GetNext Adding new object to index " + currentIndex); poolConfig[name] = currentIndex; // Set the name of the new object to the name of the object that was used as a template // for the Instantiate() otherwise the new object it will have "(Clone)" added to it's name pool[currentIndex] = Instantiate(pool[currentIndex - 1], transform); pool[currentIndex].name = pool[currentIndex - 1].name; poolMap[name] = pool; Debug.Log("ObjectPool GetNext Adding new object : " + pool[currentIndex].name); Debug.Log("ObjectPool GetNext free object not found increasing Pull side to " + poolSize); return(pool[currentIndex]); } }