From e44264d66f2068dc53f341e5bb19684e2e3409db Mon Sep 17 00:00:00 2001 From: Baptiste Date: Sun, 9 Jul 2023 21:33:35 -0400 Subject: [PATCH] ajout event animation, ajout classe Root qui sert de transition entre la classe Entity et l'animator. --- .../BaseStick/baseStick_attack.anim | 9 ++++- .../ClawClawRough/ClawClawRough_attack.anim | 9 ++++- .../Monsters/ClawClawRough_monster.prefab | 14 +++++++ Assets/Prefabs/baseArcher.prefab | 16 +++++++- Assets/Prefabs/baseStick.prefab | 14 +++++++ Assets/Scripts/Ally/Ally.cs | 8 +--- Assets/Scripts/Ally/Archer.cs | 18 +-------- Assets/Scripts/Opponent/Opponent.cs | 7 ---- Assets/Scripts/Root.cs | 37 +++++++++++++++++++ Assets/Scripts/Root.cs.meta | 11 ++++++ 10 files changed, 109 insertions(+), 34 deletions(-) create mode 100644 Assets/Scripts/Root.cs create mode 100644 Assets/Scripts/Root.cs.meta diff --git a/Assets/Animations/BaseStick/baseStick_attack.anim b/Assets/Animations/BaseStick/baseStick_attack.anim index a92a0b4..22aa2e9 100644 --- a/Assets/Animations/BaseStick/baseStick_attack.anim +++ b/Assets/Animations/BaseStick/baseStick_attack.anim @@ -2066,4 +2066,11 @@ AnimationClip: script: {fileID: 0} m_HasGenericRootTransform: 1 m_HasMotionFloatCurves: 0 - m_Events: [] + m_Events: + - time: 0.6166667 + functionName: ShotProjectile + data: + objectReferenceParameter: {fileID: 0} + floatParameter: 0 + intParameter: 0 + messageOptions: 0 diff --git a/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_attack.anim b/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_attack.anim index 01ab6f5..42ba174 100644 --- a/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_attack.anim +++ b/Assets/Animations/Monsters/ClawClawRough/ClawClawRough_attack.anim @@ -4962,4 +4962,11 @@ AnimationClip: script: {fileID: 0} m_HasGenericRootTransform: 1 m_HasMotionFloatCurves: 0 - m_Events: [] + m_Events: + - time: 0.65 + functionName: Attack + data: + objectReferenceParameter: {fileID: 0} + floatParameter: 0 + intParameter: 0 + messageOptions: 0 diff --git a/Assets/Prefabs/Monsters/ClawClawRough_monster.prefab b/Assets/Prefabs/Monsters/ClawClawRough_monster.prefab index 7f38384..8264e43 100644 --- a/Assets/Prefabs/Monsters/ClawClawRough_monster.prefab +++ b/Assets/Prefabs/Monsters/ClawClawRough_monster.prefab @@ -497,6 +497,7 @@ GameObject: - component: {fileID: 4594931196062474192} - component: {fileID: 3579562406765713002} - component: {fileID: 2002611158446544964} + - component: {fileID: 7161153261079215068} m_Layer: 0 m_Name: root m_TagString: Untagged @@ -562,6 +563,19 @@ SortingGroup: m_SortingLayerID: 0 m_SortingLayer: 0 m_SortingOrder: 2 +--- !u!114 &7161153261079215068 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1531129202202440418} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c0fbd934c179894458914437255781c4, type: 3} + m_Name: + m_EditorClassIdentifier: + _entity: {fileID: 313037212318601125} --- !u!1 &1776168629768863343 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/baseArcher.prefab b/Assets/Prefabs/baseArcher.prefab index e69e1fd..f2f1688 100644 --- a/Assets/Prefabs/baseArcher.prefab +++ b/Assets/Prefabs/baseArcher.prefab @@ -527,7 +527,6 @@ MonoBehaviour: _speed: 0 _attack_damage: 10 _attack_speed: 2 - _arrow: {fileID: 6962989255644195630, guid: 869a03bba705e8d4485aa73daad773dc, type: 3} --- !u!1 &6962989255710846697 GameObject: m_ObjectHideFlags: 0 @@ -686,6 +685,7 @@ GameObject: m_Component: - component: {fileID: 6962989255883535387} - component: {fileID: 6962989255883535384} + - component: {fileID: 8020346774049635274} m_Layer: 0 m_Name: root m_TagString: Untagged @@ -735,6 +735,20 @@ Animator: m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorStateOnDisable: 0 m_WriteDefaultValuesOnDisable: 0 +--- !u!114 &8020346774049635274 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6962989255883535386} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c0fbd934c179894458914437255781c4, type: 3} + m_Name: + m_EditorClassIdentifier: + _entity: {fileID: 5998513223176943995} + _projectile: {fileID: 6962989255644195630, guid: 869a03bba705e8d4485aa73daad773dc, type: 3} --- !u!1 &6962989255885988245 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Prefabs/baseStick.prefab b/Assets/Prefabs/baseStick.prefab index 209a766..b1bfea4 100644 --- a/Assets/Prefabs/baseStick.prefab +++ b/Assets/Prefabs/baseStick.prefab @@ -685,6 +685,7 @@ GameObject: m_Component: - component: {fileID: 6962989255883535387} - component: {fileID: 6962989255883535384} + - component: {fileID: 5665233094155356672} m_Layer: 0 m_Name: root m_TagString: Untagged @@ -734,6 +735,19 @@ Animator: m_AllowConstantClipSamplingOptimization: 1 m_KeepAnimatorStateOnDisable: 0 m_WriteDefaultValuesOnDisable: 0 +--- !u!114 &5665233094155356672 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6962989255883535386} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: c0fbd934c179894458914437255781c4, type: 3} + m_Name: + m_EditorClassIdentifier: + _entity: {fileID: 8585520847943034727} --- !u!1 &6962989255885988245 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Ally/Ally.cs b/Assets/Scripts/Ally/Ally.cs index 212691d..b5e2438 100644 --- a/Assets/Scripts/Ally/Ally.cs +++ b/Assets/Scripts/Ally/Ally.cs @@ -24,13 +24,7 @@ public class Ally : Entity //Attack Cooldown if(AttackSpeed < AttackSpeedWait) { - Enemy.Hit(AttackDamage); - - //Kill if no hp - if(Enemy.Hp <= 0) { - IsEnemyDetected = false; - Enemy.Death(); - } + Animation.PlayAttackAnim(); AttackSpeedWait = 0f; } diff --git a/Assets/Scripts/Ally/Archer.cs b/Assets/Scripts/Ally/Archer.cs index d60b2e9..9c82bc1 100644 --- a/Assets/Scripts/Ally/Archer.cs +++ b/Assets/Scripts/Ally/Archer.cs @@ -5,17 +5,9 @@ using UnityEngine; public class Archer : Ally { - [SerializeField] - private GameObject _arrow; - - private Rigidbody2D _rigidbodyAlly; - private Rigidbody2D _rigidbodyOpponent; - public override void Start() { base.Start(); - - _rigidbodyAlly = GetComponent(); Animation = gameObject.AddComponent(); } @@ -23,7 +15,6 @@ public class Archer : Ally { if(IsEnemyDetected) { - _rigidbodyOpponent = Enemy.GetComponent(); AttackEnemy(); } @@ -37,14 +28,7 @@ public class Archer : Ally Animation.PlayAttackAnim(); - GameObject _newArrow = Instantiate(_arrow, _rigidbodyAlly.position, Quaternion.identity); - - //Warning : the Speed of the arrow is equal to the speed of this unit, if this unit need to move, use an other variable ! - _newArrow.GetComponent().Damage = AttackDamage; - _newArrow.GetComponent().EnemySpeed = Enemy.Speed; - _newArrow.GetComponent().VectorStart = _rigidbodyAlly.position; - _newArrow.GetComponent().VectorEnd = _rigidbodyOpponent.position; - _newArrow.GetComponent().Target = Enemy; + AttackSpeedWait = 0f; diff --git a/Assets/Scripts/Opponent/Opponent.cs b/Assets/Scripts/Opponent/Opponent.cs index 0f23f7b..19e8221 100644 --- a/Assets/Scripts/Opponent/Opponent.cs +++ b/Assets/Scripts/Opponent/Opponent.cs @@ -36,13 +36,6 @@ public class Opponent : Entity { Animation.PlayAttackAnim(); - Enemy.Hit(AttackDamage); - - //Kill if no hp - if(Enemy.Hp <= 0) { - Enemy.Death(); - } - AttackSpeedWait = 0f; } diff --git a/Assets/Scripts/Root.cs b/Assets/Scripts/Root.cs new file mode 100644 index 0000000..6dacc7a --- /dev/null +++ b/Assets/Scripts/Root.cs @@ -0,0 +1,37 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class Root : MonoBehaviour +{ + + [SerializeField] + private Entity _entity; + [SerializeField] + private GameObject _projectile; + + void Attack() { + _entity.Enemy.Hit( _entity.AttackDamage); + if(_entity.Enemy.Hp <= 0) { + _entity.Enemy.Death(); + _entity.IsEnemyDetected = false; + } + } + + void ShotProjectile() { + Rigidbody2D _rigidbodyAlly; + Rigidbody2D _rigidbodyOpponent; + _rigidbodyAlly = _entity.GetComponent(); + _rigidbodyOpponent = _entity.Enemy.GetComponent(); + + GameObject _newArrow = Instantiate(_projectile, _rigidbodyAlly.position, Quaternion.identity); + + //Warning : the Speed of the arrow is equal to the speed of this unit, if this unit need to move, use an other variable ! + _newArrow.GetComponent().Damage = _entity.AttackDamage; + _newArrow.GetComponent().EnemySpeed = _entity.Enemy.Speed; + _newArrow.GetComponent().VectorStart = _rigidbodyAlly.position; + _newArrow.GetComponent().VectorEnd = _rigidbodyOpponent.position; + _newArrow.GetComponent().Target = _entity.Enemy; + + } +} diff --git a/Assets/Scripts/Root.cs.meta b/Assets/Scripts/Root.cs.meta new file mode 100644 index 0000000..c14f8ac --- /dev/null +++ b/Assets/Scripts/Root.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c0fbd934c179894458914437255781c4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: