IEnumerator DestroyPP(IPrefabComponent pp) { yield return(new WaitForSeconds(delay2)); list.Remove(pp.transform); PrefabManager.instance.Return(pp); }
public static bool CheckInPool(int id, GameObject prefab, Transform parent, out IPrefabComponent component, ref List <IPrefabComponent> pool) { var wasNull = false; component = null; if (pool == null) { pool = new List <IPrefabComponent>(); wasNull = true; } else { wasNull = pool.Count(c => c.Id == id) == 0; if (wasNull == false) { component = pool.FirstOrDefault(c => c.Id == id); component.GameObject.SetActive(true); } } if (wasNull == true) { var go = CreateUiObject( GameHiddenOptions.Instance.GetAnInstantiated(prefab), "clone", parent ); component = go.GetComponent <IPrefabComponent>(); } return(wasNull); }
public static void Return(IPrefabComponent item) { if (prefabs.ContainsKey(item.prefabType)) { ExecuteReturnPoolBehaviours(item); prefabs[item.prefabType].Push(item); } }
private static void ExecuteReturnPoolBehaviours(IPrefabComponent item) { // pool behaviours for returning (ex: disable meshes and colliders, disable gameobject, parent somewhere) var poolBehs = item.gameObject.GetComponents <IPoolBehaviour>(); for (int i = 0; i < poolBehs.Length; i++) { poolBehs[i].OnReturnToPool(); } }
private static void ExecuteSpawnPoolBehaviours(IPrefabComponent item) { // pool behaviours for spawning (ex: enable meshes, colliders, gameobject or initialize some values). var poolBehs = item.gameObject.GetComponents <IPoolBehaviour>(); for (int i = 0; i < poolBehs.Length; i++) { poolBehs[i].OnSpawnFromPool(); } }
void ActivateSelection(IPrefabComponent entity) { if (selection == null) { selection = Instantiate(Selection); } selection.SetActive(true); selection.transform.position = entity.Prefab.transform.position; selection.transform.SetParent(entity.Prefab.transform); }
// only used by debug shit private RigidbodySyncComponent HandleRigidbodySyncSpawn(IPrefabComponent prefab) { var rbSync = prefab.gameObject.GetComponent <RigidbodySyncComponent>(); if (rbSync == null) { Debug.LogError(this.ToString() + " supplid prefab (" + prefab.ToString() + ") is missing a RigidbodySyncComponent!"); return(null); } return(HandleRigidbodySyncSpawn(rbSync, prefab.prefabType)); }
public void Apply(IPrefabComponent entity) { var bullet = entity as BulletSystem; var spirit = Owner as SpiritSystem; var player = spirit.GetOwnerOfType <PlayerSystem>(); var enemies = new Collider[40]; var enemyLayer = 1 << 12; var enemyCount = Physics.OverlapSphereNonAlloc( bullet.Prefab.transform.position, 150, enemies, enemyLayer); spirit.DealDamage(bullet.Target, spirit.DamageInstance); if (bullet.Target == null || enemyCount <= 1) { spirit.ShootSystem.SetTargetReached(bullet); } else { if (bullet.RemainingBounceCount <= 0) { spirit.ShootSystem.SetTargetReached(bullet); } else { bullet.RemainingBounceCount--; for (int enemyIndexInChain = 0; enemyIndexInChain < enemyCount; enemyIndexInChain++) { if (bullet.Target.Prefab == enemies[enemyIndexInChain].gameObject) { if (enemyIndexInChain - 1 >= 0) { bullet.Target = GetEnemyInChain(enemies[enemyIndexInChain - 1].transform.gameObject); } if (enemyIndexInChain + 1 < enemyCount) { bullet.Target = GetEnemyInChain(enemies[enemyIndexInChain + 1].transform.gameObject); } } } } } IHealthComponent GetEnemyInChain(GameObject affectedEnemy) => player.EnemyControlSystem.AllEnemies.Find(enemy => enemy.Prefab == affectedEnemy); }
public static RangeSystem Range(IPrefabComponent owner, double size, CollideWith collideType, Action <IVulnerable> onEntityEnteredRange, Action <IVulnerable> onEntityExitRange) { var range = UnityEngine.Object.Instantiate(ReferenceHolder.Instance.RangePrefab, owner.Prefab.transform); range.transform.localScale = new Vector3((float)size, 0.001f, (float)size); var rangeSystem = range.GetComponent <RangeSystem>(); rangeSystem.Owner = owner; rangeSystem.CollideType = collideType; rangeSystem.EntityEntered += onEntityEnteredRange; rangeSystem.EntityExit += onEntityExitRange; return(rangeSystem); }
public virtual void Return(IPrefabComponent prefab) { #if UNITY_EDITOR // if not playing, use the prefab mode if (!Application.isPlaying) { this.DestroySafe(prefab.gameObject); } else { #endif // if playing, use the pools PrefabManagerPoolSystem.Return(prefab); #if UNITY_EDITOR } #endif }
public void Apply(IPrefabComponent bullet) { var enemyLayer = 1 << 12; var colliders = new Collider[40]; var spirit = Owner as SpiritSystem; var player = spirit.GetOwnerOfType <PlayerSystem>(); var hitTargetCount = Physics.OverlapSphereNonAlloc( bullet.Prefab.transform.position, trait.Range, colliders, enemyLayer); for (int i = 0; i < hitTargetCount; i++) { var findedEnemy = player.EnemyControlSystem.AllEnemies.Find(enemy => colliders[i].transform.gameObject == enemy.Prefab); if (findedEnemy != null) { spirit.DealDamage(findedEnemy, spirit.DamageInstance); } } }
public void Apply(IPrefabComponent entity) { }