private static void SpawnAIPlayerFor(AISpawnPoint spawnPoint) { if (AIPlayerExistsFor(spawnPoint)) { Debug.LogWarning("Could not spawn AI player for: " + spawnPoint); return; } BattlePlayer battlePlayer = ObjectPoolManager.Create <BattlePlayer>(GamePrefabs.Instance.PlayerPrefab, spawnPoint.transform.position, Quaternion.identity, parent: ArenaManager.Instance.LoadedArena.GameObject); // spawn player with substitute AI GameConstants.Instance.ConfigureWithSubstitutePlayerAI(battlePlayer); battlePlayer.SetSkin(GameConstants.Instance.EnemySkin); RecyclablePrefab recyclablePrefab = battlePlayer.GetComponent <RecyclablePrefab>(); Action <RecyclablePrefab> onCleanupCallback = null; onCleanupCallback = (RecyclablePrefab unused) => { recyclablePrefab.OnCleanup -= onCleanupCallback; RemovePlayer(spawnPoint); }; recyclablePrefab.OnCleanup += onCleanupCallback; spawnPointMap_[spawnPoint] = battlePlayer; }
private void Cleanup() { CancelAnimation(); if (battlePlayer_ != null) { battlePlayer_.DustParticleSystem.gameObject.SetActive(true); SetAlpha(1.0f); foreach (Renderer r in battlePlayer_.BodyRenderers) { Color diffuseColor = r.material.GetColor("_DiffuseColor"); r.material = GameConstants.Instance.PlayerOpaqueMaterial; r.material.SetColor("_DiffuseColor", diffuseColor.WithAlpha(1.0f)); r.material.SetFloat("_Metallic", kBaseMetallic); r.shadowCastingMode = ShadowCastingMode.On; } battlePlayer_ = null; } if (recyclablePrefab_ != null) { recyclablePrefab_.OnCleanup -= HandleCleanup; recyclablePrefab_ = null; } }
private void RespawnDummyPlayer(RecyclablePrefab unused) { CleanupDummyPlayer(recycle: false); CoroutineWrapper.DoAfterDelay(3.0f, () => { SpawnDummyPlayer(); }); }
private void HandleCleanup(RecyclablePrefab prefab) { prefab.OnCleanup -= HandleCleanup; BattlePlayer battlePlayer = prefab.GetComponent <BattlePlayer>(); battlePlayerSources_.Remove(battlePlayer); }
private void SpawnDummyPlayer() { BattlePlayer player = ObjectPoolManager.Create <BattlePlayer>(playerPrefab_, Vector3.zero, Quaternion.identity, parent: this.gameObject); player.SetSkin(skin_); dummyPlayerRecyclable_ = player.GetComponentInChildren <RecyclablePrefab>(); dummyPlayerRecyclable_.OnCleanup += RespawnDummyPlayer; OnPlayerSpawned.Invoke(player); }
private int GetPriority(GameObject view) { RecyclablePrefab r = view.GetRequiredComponent <RecyclablePrefab>(); if (r == null) { Debug.LogWarning("Assigning default priority for gameObject: " + view + " because no RecycablePrefab exists!"); return(defaultPriority_); } return(priorityMap_.PriorityForPrefabName(r.PrefabName)); }
private void CleanupDummyPlayer(bool recycle) { if (dummyPlayerRecyclable_ != null) { GameObject recycleReference = dummyPlayerRecyclable_.gameObject; dummyPlayerRecyclable_.OnCleanup -= RespawnDummyPlayer; dummyPlayerRecyclable_ = null; if (recycle) { ObjectPoolManager.Recycle(recycleReference); } } }
private static void SpawnPlayer(Player player) { IList <PlayerSpawnPoint> spawnPoints = ArenaManager.Instance.LoadedArena.PlayerSpawnPoints; PlayerSpawnPoint spawnPoint = spawnPoints.GetClamped(RegisteredPlayers.AllPlayers.IndexOf(player)); if (PlayerExistsFor(player)) { Debug.LogWarning("Could not spawn player for: " + player); return; } BattlePlayer battlePlayer = ObjectPoolManager.Create <BattlePlayer>(GamePrefabs.Instance.PlayerPrefab, spawnPoint.transform.position, Quaternion.identity, parent: ArenaManager.Instance.LoadedArena.GameObject); battlePlayer.gameObject.name = string.Format("BattlePlayer ({0})", player); if (player.Input != null) { battlePlayer.Init(new BattlePlayerInputDeviceDelegate(player.Input), player.Skin); } else { // spawn player with substitute AI battlePlayer.SetSkin(player.Skin); GameConstants.Instance.ConfigureWithSubstitutePlayerAI(battlePlayer); } // face battle player forward battlePlayer.transform.localRotation = Quaternion.Euler(0, 180, 0); RecyclablePrefab recyclablePrefab = battlePlayer.GetComponent <RecyclablePrefab>(); Action <RecyclablePrefab> onCleanupCallback = null; onCleanupCallback = (RecyclablePrefab unused) => { recyclablePrefab.OnCleanup -= onCleanupCallback; RemovePlayer(player); }; recyclablePrefab.OnCleanup += onCleanupCallback; battlePlayer.PlaySpawnTransition(); playerMap_[player] = battlePlayer; }
private void RecycleSelf(RecyclablePrefab unused) { ObjectPoolManager.Recycle(this); }
private void HandleCleanup(RecyclablePrefab unused) { Cleanup(); }