/// <summary> /// Get the points and spawn enemies in it /// Then add the enemy to the spawned enemies list /// </summary> void Spawn() { if (!PhotonNetwork.isMasterClient) { return; } List <TDS_SpawningInformation> _spawnInformations = pointsManager.GetSpawningInformations(waveNumber); if (_spawnInformations.Count == 0) { waveNumber++; OnNextWave?.Invoke(); } for (int i = 0; i < _spawnInformations.Count; i++) { TDS_Enemy _enemy = PhotonNetwork.Instantiate(((EnemyName)_spawnInformations[i].PrefabId).ToString(), _spawnInformations[i].SpawnPosition + Vector3.up, Quaternion.identity, 0).GetComponent <TDS_Enemy>(); if (enemyCanvas && (lifeBarName != string.Empty)) { Vector3 _pos = new Vector3(_enemy.transform.position.x, .1f, _enemy.transform.position.z); Quaternion _rotation = Quaternion.Euler(90, 0, 0); TDS_FilledBar _bar = PhotonNetwork.Instantiate(lifeBarName, _pos, _rotation, 0).GetComponent <TDS_FilledBar>(); _bar.SetCanvas(enemyCanvas); _enemy.SetLifeBar(_bar); } _enemy.SetOwner(this); spawnedEnemies.Add(_enemy); } }
/// <summary> /// Constructor of the TDS_SpawningInformation class /// Set the enemy resources name as the name of the enemy in argument /// </summary> /// <param name="_e">enemy</param> public TDS_SpawningInformations(TDS_Enemy _e) { enemyResourceName = _e.EnemyName; enemyCount = new int[4] { 0, 0, 1, 1 }; }
/// <summary> /// Instantiate the splitting enemies at their splitting position /// CALL IN ANIMATION /// </summary> private void SplitSiamese() { if (!PhotonNetwork.isMasterClient) { return; } List <TDS_Enemy> _spawnedEnemies = new List <TDS_Enemy>(); TDS_Enemy _e = null; for (int i = 0; i < splitingEnemiesNames.Length; i++) { _e = PhotonNetwork.Instantiate(splitingEnemiesNames[i], transform.position + splitingPosition[i], Quaternion.identity, 0).GetComponent <TDS_Enemy>(); if (_e != null) { if (Area) { Area.AddEnemy(_e); } _spawnedEnemies.Add(_e); } } TDS_UIManager.Instance.SetBossLifeBar(_spawnedEnemies.ToArray(), splittingPortrait); if (Area) { Area.RemoveEnemy(this); } PhotonNetwork.Destroy(this.gameObject); }
/// <summary> /// Stops the preparing throw, if preparing one. /// </summary> /// <returns>Returns true if canceled the throw, false if there was nothing to cancel.</returns> public bool StopAiming() { if (!isAiming && aimCoroutine == null) { return(false); } if (isAiming) { isAiming = false; } // Fix all kinds of aiming-related things if (targetObject) { targetObject = null; } if (targetEnemy) { targetEnemy = null; } if (aimCoroutine != null) { StopCoroutine(aimCoroutine); aimCoroutine = null; } // Reset back speed coefficient. SpeedCoef /= aimingSpeedCoef; // Desactivate aim target TDS_UIManager.Instance.DesctivateJugglerAimTarget(); return(true); }
// OnTriggerEnter is called when the GameObject collides with another GameObject private void OnTriggerEnter(Collider other) { if (!other.gameObject.HasTag("Enemy")) { return; } // If collider is among of linked enemies one, make him disappear TDS_Enemy _enemy = null; if ((_enemy = enemies.FirstOrDefault(e => e.Collider == other)) != null) { if (spawnerArea != null) { spawnerArea.RemoveEnemy(_enemy); } PhotonNetwork.Destroy(other.gameObject); disappearCounter++; // Destroy this GameObject is every enemies has been destroyed if (disappearCounter == enemies.Length) { Destroy(gameObject); } } }
/// <summary> /// Add a new enemy to the list of spawned enemies /// </summary> /// <param name="_enemy">Enemy to add</param> public void AddEnemy(TDS_Enemy _enemy) { if (_enemy && !spawnedEnemies.Contains(_enemy)) { spawnedEnemies.Add(_enemy); _enemy.Area = this; } }
/// <summary> /// Increases the suffured damages score. /// </summary> /// <param name="_enemy">Enemy inflicting damages.</param> /// <param name="_damages">Amount of suffured damages.</param> public void IncreaseSuffuredScore(TDS_Enemy _enemy, int _damages) { string[] _enemyTags = _enemy.gameObject.GetTagNames().Intersect(enemiesTags).ToArray(); foreach (string _tag in _enemyTags) { EnemiesSuffuredDmgs[_tag] += _damages; } }
/// <summary> /// SpawnEnemies using Enemies Info /// Spawn at a position, with a state, etc... /// </summary> /// <param name="_enemiesInfo"></param> public void SpawnEnemiesUsingInfos(List <TDS_EnemyInfo> _enemiesInfo) { foreach (TDS_EnemyInfo _info in _enemiesInfo) { TDS_Enemy _enemy = PhotonNetwork.Instantiate(((EnemyName)_info.EnemyType).ToString(), _info.EnemyPosition, Quaternion.identity, 0).GetComponent <TDS_Enemy>(); _enemy.SetOwner(this); spawnedEnemies.Add(_enemy); } }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (!owner) { owner = animator.GetComponent <TDS_Enemy>(); } if (!owner) { return; } owner.SetEnemyState(0); }
public override void ApplyAttackBehaviour(TDS_Enemy _caster) { if (!PhotonNetwork.isMasterClient) { return; } if (_caster.Agent.IsMoving) { _caster.Agent.StopAgent(); } _caster.StartCoroutine(DashingCoroutine(_caster)); }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) //{ // //} // OnStateExit is called when a transition ends and the state machine finishes evaluating this state override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (!owner) { owner = animator.GetComponent <TDS_Enemy>(); } if (!owner) { return; } owner.ActivateEnemyAfterTaunt(); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (!PhotonNetwork.isMasterClient) { return; } if (owner == null) { owner = animator.GetComponent <TDS_Enemy>(); } owner.SetEnemyState(EnemyState.None); }
/// <summary> /// Increases the inflicted damages score. /// </summary> /// <param name="_enemy">Enemy taking damages.</param> /// <param name="_damages">Amount of inflicted damages.</param> public void IncreaseInflictedScore(TDS_Enemy _enemy, int _damages) { string[] _enemyTags = _enemy.gameObject.GetTagNames().Intersect(enemiesTags).ToArray(); foreach (string _tag in _enemyTags) { EnemiesInflictedDmgs[_tag] += _damages; if (_enemy.IsDead) { KnockoutEnemiesAmount++; } } }
public TDS_Enemy SpawnEnemy() { if (!PhotonNetwork.isMasterClient) { return(null); } //ESSAYER DE VOIR POUR FAIRE SPAWN UN TYPE D'ENEMY EN PARTICULIER //Pour le moment, random enemy TDS_Enemy _enemy = EnemiesSpawnable[(int)UnityEngine.Random.Range(0, EnemiesSpawnable.Count - 1)]; PhotonView _enemyId = PhotonNetwork.Instantiate(_enemy.PrefabName.ToString(), spawnPosition + Vector3.up, Quaternion.identity, 0).GetComponent <PhotonView>(); return(_enemy); }
/// <summary> /// Remove the enemy from the spawnedEnemies list and add it to the dead enemies list /// If there is no more enemies, call the event OnNextWave /// </summary> /// <param name="_removedEnemy">Enemy to remove from the spawnedEnemies list</param> public void RemoveEnemy(TDS_Enemy _removedEnemy) { if (!PhotonNetwork.isMasterClient) { return; } spawnedEnemies.Remove(_removedEnemy); deadEnemies.Add(_removedEnemy); if (spawnedEnemies.Count == 0) { waveIndex++; OnNextWave?.Invoke(); } }
// OnStateUpdate is called on each Update frame between OnStateEnter and OnStateExit callbacks //override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) //{ // //} // OnStateExit is called when a transition ends and the state machine finishes evaluating this state override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (!PhotonNetwork.isMasterClient) { return; } if (owner == null) { owner = animator.GetComponent <TDS_Enemy>(); } owner.SetAnimationState((int)EnemyAnimationState.Idle); owner.StartCoroutine(owner.ApplyRecoveryTime(recoveryTime)); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (!PhotonNetwork.isMasterClient) { return; } if (!owner) { owner = animator.GetComponent <TDS_Enemy>(); } if (!owner) { return; } owner.ComputePath(); }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (!PhotonNetwork.isMasterClient) { return; } if (!owner) { owner = animator.GetComponent <TDS_Enemy>(); } if (!owner) { return; } wanderingCoroutine = owner.StartCoroutine(owner.Wander()); }
/// <summary> /// Instantiate enemy Life bar /// Link it to the enemy /// </summary> /// <param name="_enemy"></param> public void SetEnemyLifebar(TDS_Enemy _enemy) { if (enemyHealthBar == null || !canvasWorld) { return; } Vector3 _offset = (Vector3.up * .2f) - Vector3.forward; TDS_EnemyLifeBar _healthBar = Instantiate(enemyHealthBar, _enemy.transform.position + _offset, Quaternion.identity, canvasWorld.transform).GetComponent <TDS_EnemyLifeBar>(); _healthBar.SetOwner(_enemy, _offset); _healthBar.UpdateLifeBar(_enemy.HealthCurrent); _healthBar.Background.gameObject.SetActive(false); _enemy.HealthBar = _healthBar; _enemy.OnTakeDamage += _healthBar.UpdateLifeBar; _enemy.OnHeal += _healthBar.UpdateLifeBar; }
/// <summary> /// Draw the split settings /// </summary> private void DrawSplittingSettings() { if (IsEnemyUnfolded) { EditorGUILayout.Space(); EditorGUILayout.BeginVertical("Box"); //Draw a header for the enemy spinning settings if (TDS_EditorUtility.Button("Splitting Enemies", "Wrap / unwrap splitting enemies", TDS_EditorUtility.HeaderStyle)) { AreSplittingSettingsUnfolded = !areSplittingSettingsUnfolded; } if (areSplittingSettingsUnfolded) { EditorGUILayout.Space(); for (int i = 0; i < splitingEnemiesNames.arraySize; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(splitingEnemiesNames.GetArrayElementAtIndex(i).stringValue, TDS_EditorUtility.HeaderStyle); GUITools.ActionButton("X", RemoveSettingsAtIndex, i, Color.white, Color.black, "Remove this spliting enemy"); Repaint(); serializedObject.ApplyModifiedProperties(); EditorGUILayout.EndHorizontal(); } EditorGUILayout.Space(); TDS_Enemy _e = null; _e = EditorGUILayout.ObjectField("Add Splitting Enemy", _e, typeof(TDS_Enemy), false) as TDS_Enemy; if (_e != null) { splitingEnemiesNames.InsertArrayElementAtIndex(0); splitingEnemiesNames.GetArrayElementAtIndex(0).stringValue = _e.EnemyName; splitingPosition.InsertArrayElementAtIndex(0); splitingPosition.GetArrayElementAtIndex(0).vector3Value = Vector3.forward; Repaint(); } EditorGUILayout.Space(); TDS_EditorUtility.ObjectField("Splitting Portrait", "Portrait of the splitting enemies", splittingPortrait, typeof(GameObject)); serializedObject.ApplyModifiedProperties(); } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); } }
public override void ApplyAttackBehaviour(TDS_Enemy _caster) { if (thrownObjectName == string.Empty) { return; } GameObject _thrownObject = PhotonNetwork.Instantiate(thrownObjectName, _caster.HandsTransform.position, _caster.transform.rotation, 0); //Debug.LogError("Stop!"); if (!_thrownObject) { return; } TDS_Throwable _throwable = _thrownObject.GetComponent <TDS_Throwable>(); if (_throwable) { _throwable.HitBox.HittableTags = _caster.HitBox.HittableTags; _caster.GrabObject(_throwable); if (_throwable.ThrowableAttackEffectType == AttackEffectType.BringCloser) { _throwable.ObjectDurability = 1; //_throwable.HitBox.OnTouch += () => _caster.SetAnimationState((int)EnemyAnimationState.BringTargetCloser); _throwable.HitBox.OnStopAttack += _caster.NoTargetToBrought; } _caster.ThrowObject(_caster.PlayerTarget.transform.position); if (!_caster.IsFacingRight) { _thrownObject.transform.Rotate(Vector3.up, 180); _thrownObject.transform.localScale = new Vector3(_thrownObject.transform.localScale.x, _thrownObject.transform.localScale.y, _thrownObject.transform.localScale.z * -1); } } else if (_thrownObject.GetComponent <TDS_Projectile>()) { Vector3 _dir = _caster.IsFacingRight ? Vector3.right : Vector3.left; TDS_Projectile _proj = _thrownObject.GetComponent <TDS_Projectile>(); _proj.HitBox.HittableTags = _caster.HitBox.HittableTags; _proj.HitBox.Activate(this, _caster); _proj.StartProjectileMovement(_dir, MaxRange); } }
/// <summary> /// Makes the character aim for a throw. When releasing the throw button, throw the selected object. /// If the cancel throw button is pressed, cancel the throw, as it name indicate it. /// </summary> /// <returns></returns> protected virtual IEnumerator Aim() { // Activate aiming target and set its default position TDS_UIManager.Instance.ActivateJugglerAimTarget(); aimTargetTransform.anchoredPosition = TDS_Camera.Instance.Camera.WorldToScreenPoint(ThrowAimingPoint); // While holding the throw button, aim a position while (controller.GetButton(ButtonType.Aim)) { // Aim while holding the button AimMethod(); yield return(null); if (controller.GetButtonDown(ButtonType.Shoot) && canShoot) { if (targetObject) { targetObject = null; } if (targetEnemy) { targetEnemy = null; } TDS_UIManager.Instance.SetJugglerAimTargetAnim(JugglerAimTargetAnimState.Neutral); IsPlayable = false; canShoot = false; SetAnimOnline(PlayerAnimState.Throw); if (CurrentThrowableAmount == 0) { break; } } } StopAiming(); yield break; }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (!PhotonNetwork.isMasterClient) { return; } if (!owner) { owner = animator.GetComponent <TDS_Enemy>(); } if (!owner) { return; } if (animator.GetFloat("animationState") != 0) { owner.SetAnimationState(0); } attackingCoroutine = owner.StartCoroutine(owner.CastAttack()); }
/// <summary> /// Get an enemy in the spawned enemies list and remove it /// Go on next wave when all the enemies are killed /// </summary> /// <param name="_enemy">enemy to remove</param> public void RemoveEnemy(TDS_Enemy _enemy) { int _index = spawnedEnemies.IndexOf(spawnedEnemies.Where(e => e.PhotonViewElementID == _enemy.PhotonViewElementID).FirstOrDefault()); spawnedEnemies.RemoveAt(_index); destroyingEnemies.Add(_enemy); if (_enemy.LifeBar) { PhotonNetwork.Destroy(_enemy.LifeBar.gameObject); } if (spawnedEnemies.Count == 0) { ClearDeadEnemies(); if (!isLooping) { waveNumber++; } OnNextWave?.Invoke(); } }
public override void ApplyAttackBehaviour(TDS_Enemy _caster) { caster = _caster; caster.Agent.Speed = spinningSpeed; casterInitialRadius = caster.Agent.Radius; caster.Agent.Radius = spinningRadius; if (spinningPositions == null || spinningPositions.Length == 0) { TDS_Bounds _bounds = TDS_Camera.Instance.CurrentBounds; spinningPositions = new Vector3[5] { new Vector3(_bounds.XMin + 1, 0, _bounds.ZMax - 1), new Vector3(_bounds.XMin + 1, 0, _bounds.ZMin + 1), new Vector3(_bounds.XMax - 1, 0, _bounds.ZMax - 1), new Vector3(_bounds.XMax - 1, 0, _bounds.ZMin + 1), new Vector3((_bounds.XMin + _bounds.XMax) / 2, 0, (_bounds.ZMin + _bounds.ZMax) / 2) }; } caster.Agent.OnDestinationReached += GoNextSpinningPosition; GoNextSpinningPosition(); }
/// <summary> /// Edit wave element /// Edit type and number of enemies /// </summary> /// <param name="_element">Element to Edit</param> void ShowWaveElementSettings(TDS_WaveElement _element) { // COLOR GUI.color = Color.blue; EditorGUILayout.HelpBox("Wave Element", MessageType.None); GUI.color = Color.white; // ENEMIES AND COUNT TDS_Enemy _enemy = null; _enemy = EditorGUILayout.ObjectField(_enemy, typeof(TDS_Enemy), false) as TDS_Enemy; if (_enemy != null && !_element.EnemiesSpawn.Any(e => e.SpawningEnemy == _enemy)) { _element.AddElement(_enemy); } for (int i = 0; i < _element.EnemiesSpawn.Count; i++) { EditorGUILayout.LabelField(_element.EnemiesSpawn[i].SpawningEnemy.PrefabName.ToString()); _element.EnemiesSpawn[i].NumberOfEnemies = EditorGUILayout.IntSlider("Enemy count", _element.EnemiesSpawn[i].NumberOfEnemies, 0, 10); GUITools.ActionButton("Remove Element", _element.RemoveElement, i, Color.white, Color.black); } }
// OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { if (!PhotonNetwork.isMasterClient) { return; } if (!owner) { owner = animator.GetComponent <TDS_Enemy>(); } if (!owner) { return; } if (!owner.PlayerTarget) { owner.SearchTarget(); } owner.TakeDecision(); }
/// <summary> /// Set the boss lifebar's subowners /// and set the game object to active /// and add the event on take damages and heal /// </summary> /// <param name="_subonwers"></param> public void SetBossLifeBar(TDS_Enemy[] _subonwers, GameObject _portrait = null) { if (!bossHealthBar) { return; } bossHealthBar.SetSubOwners(_subonwers); bossHealthBar.gameObject.SetActive(true); if (_portrait != null) { bossHealthBar.SetBossPortrait(_portrait); } for (int i = 0; i < _subonwers.Length; i++) { TDS_Enemy _e = _subonwers[i]; _e.OnTakeDamage += bossHealthBar.UpdateLifeBar; _e.OnHeal += bossHealthBar.UpdateLifeBar; _e.OnDie += bossHealthBar.DestroyLifeBar; } }
private IEnumerator DashingCoroutine(TDS_Enemy _caster) { if (!PhotonNetwork.isMasterClient) { yield break; } _caster.GetComponent <Animator>().ResetTrigger("StopDashing"); Vector3 _originalPosition = _caster.transform.position; Vector3 _endPosition = _originalPosition; if (isDashingForward) { _endPosition += (_caster.IsFacingRight ? Vector3.right : -Vector3.right) * dashingDistance; } else { _endPosition -= (_caster.IsFacingRight ? Vector3.right : -Vector3.right) * dashingDistance; } _endPosition.x = Mathf.Clamp(_endPosition.x, TDS_Camera.Instance.CurrentBounds.XMin + _caster.Agent.Radius, TDS_Camera.Instance.CurrentBounds.XMax - _caster.Agent.Radius); if (_caster is TDS_MightyMan _mightyManIn) { _mightyManIn.IsDashing = true; } while (_caster.IsAttacking && Vector3.Distance(_caster.transform.position, _endPosition) > 0) { _caster.transform.position = Vector3.MoveTowards(_caster.transform.position, _endPosition, Time.deltaTime * dashingSpeed * 10); yield return(null); } if (_caster is TDS_MightyMan _mightyManOut) { _mightyManOut.IsDashing = false; } _caster.SetAnimationState((int)EnemyAnimationState.StopDashing); if (_caster.IsAttacking) { _caster.StopAttack(); } }
/// <summary> /// Constructor of TDS_RandomSpawningInformations based on the construcor of TDS_SpawningInformations /// </summary> /// <param name="_e">selected enemy</param> public TDS_RandomSpawningInformations(TDS_Enemy _e) : base(_e) { }