From 6d6899cdfbcd662cf83ccaceaaee580e521bd258 Mon Sep 17 00:00:00 2001 From: Ahmad Nadil <13521024@std.stei.itb.ac.id> Date: Fri, 10 May 2024 13:59:28 +0700 Subject: [PATCH] feat: skill binding --- Assets/CutScene/SkillCutscene.prefab | 56 +++++++++++++++++++++++-- Assets/Input/PlayerInput.cs | 43 ++++++++++++++++++- Assets/Input/PlayerInput.inputactions | 33 ++++++++++++++- Assets/Script/CutScene/SkillCutscene.cs | 10 ++++- Assets/Script/Player/PlayerHealth.cs | 13 +++++- ProjectSettings/TagManager.asset | 1 + 6 files changed, 147 insertions(+), 9 deletions(-) diff --git a/Assets/CutScene/SkillCutscene.prefab b/Assets/CutScene/SkillCutscene.prefab index ad9ad4b8..d47a246e 100644 --- a/Assets/CutScene/SkillCutscene.prefab +++ b/Assets/CutScene/SkillCutscene.prefab @@ -16,7 +16,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!4 &2783708759929244023 Transform: m_ObjectHideFlags: 0 @@ -25,7 +25,7 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 4367631758843000650} serializedVersion: 2 - m_LocalRotation: {x: 0.006339182, y: 0.9922343, z: -0.1103796, w: 0.05698475} + m_LocalRotation: {x: 0.006339187, y: 0.9922343, z: -0.11037962, w: 0.056984782} m_LocalPosition: {x: 2, y: 3.02, z: 2.74} m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 @@ -88,7 +88,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!4 &3030952519788483427 Transform: m_ObjectHideFlags: 0 @@ -123,9 +123,13 @@ PlayableDirector: value: {fileID: 0} - key: {fileID: 8124107451091541054, guid: 7fe47e08f5fb5d94c835fdb7afac2307, type: 2} value: {fileID: 0} + - key: {fileID: -4635569635243348185, guid: 7fe47e08f5fb5d94c835fdb7afac2307, type: 2} + value: {fileID: 2025367535191240120} m_ExposedReferences: m_References: - 6b2a83ff5aa4eae4b9dc6f3bd077530e: {fileID: 752569290355959979} + - ab17d5a144597064080982c447844faa: {fileID: 0} + - eaf98763e7fc7a042936dab964949b29: {fileID: 0} --- !u!1 &8016630728440501698 GameObject: m_ObjectHideFlags: 0 @@ -230,9 +234,11 @@ GameObject: serializedVersion: 6 m_Component: - component: {fileID: 5830000008808023940} + - component: {fileID: 6431157513740141078} + - component: {fileID: 2025367535191240120} m_Layer: 0 m_Name: SkillCutscene - m_TagString: Untagged + m_TagString: SkillCutscene m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 @@ -254,3 +260,45 @@ Transform: - {fileID: 2783708759929244023} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &6431157513740141078 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8737592062568205315} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 76055dead16e1844cb0d263df451e436, type: 3} + m_Name: + m_EditorClassIdentifier: +--- !u!114 &2025367535191240120 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 8737592062568205315} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: e52de21a22b6dd44c9cc19f810c65059, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Events: + m_Signals: + - {fileID: 11400000, guid: e3ed75ed698e80a468f330e87b6cab6a, type: 2} + m_Events: + - m_PersistentCalls: + m_Calls: + - m_Target: {fileID: 6431157513740141078} + m_TargetAssemblyTypeName: SkillCutscene, Assembly-CSharp + m_MethodName: EndSkillCutscene + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 diff --git a/Assets/Input/PlayerInput.cs b/Assets/Input/PlayerInput.cs index 66b3e589..2c37fbcc 100644 --- a/Assets/Input/PlayerInput.cs +++ b/Assets/Input/PlayerInput.cs @@ -98,6 +98,15 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable ""processors"": """", ""interactions"": """", ""initialStateCheck"": false + }, + { + ""name"": ""Skill"", + ""type"": ""Button"", + ""id"": ""feae7806-0a87-4a53-9a19-fbe8d4bd5ebc"", + ""expectedControlType"": ""Button"", + ""processors"": """", + ""interactions"": """", + ""initialStateCheck"": false } ], ""bindings"": [ @@ -269,7 +278,7 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable { ""name"": """", ""id"": ""a061e425-1521-4518-a642-2321104a77d5"", - ""path"": ""<Gamepad>/buttonWest"", + ""path"": ""<Gamepad>/buttonEast"", ""interactions"": """", ""processors"": """", ""groups"": """", @@ -353,6 +362,28 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable ""action"": ""Reload"", ""isComposite"": false, ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""5ed5be33-9514-475d-b16d-86f3707296ad"", + ""path"": ""<Keyboard>/q"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Skill"", + ""isComposite"": false, + ""isPartOfComposite"": false + }, + { + ""name"": """", + ""id"": ""5b42ae9f-c05b-4663-8641-0063c7a73eff"", + ""path"": ""<Gamepad>/leftTrigger"", + ""interactions"": """", + ""processors"": """", + ""groups"": """", + ""action"": ""Skill"", + ""isComposite"": false, + ""isPartOfComposite"": false } ] }, @@ -885,6 +916,7 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable m_OnFoot_Interact = m_OnFoot.FindAction("Interact", throwIfNotFound: true); m_OnFoot_OpenTerminal = m_OnFoot.FindAction("OpenTerminal", throwIfNotFound: true); m_OnFoot_Sprint = m_OnFoot.FindAction("Sprint", throwIfNotFound: true); + m_OnFoot_Skill = m_OnFoot.FindAction("Skill", throwIfNotFound: true); // UI m_UI = asset.FindActionMap("UI", throwIfNotFound: true); m_UI_Navigate = m_UI.FindAction("Navigate", throwIfNotFound: true); @@ -966,6 +998,7 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable private readonly InputAction m_OnFoot_Interact; private readonly InputAction m_OnFoot_OpenTerminal; private readonly InputAction m_OnFoot_Sprint; + private readonly InputAction m_OnFoot_Skill; public struct OnFootActions { private @PlayerInput m_Wrapper; @@ -978,6 +1011,7 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable public InputAction @Interact => m_Wrapper.m_OnFoot_Interact; public InputAction @OpenTerminal => m_Wrapper.m_OnFoot_OpenTerminal; public InputAction @Sprint => m_Wrapper.m_OnFoot_Sprint; + public InputAction @Skill => m_Wrapper.m_OnFoot_Skill; public InputActionMap Get() { return m_Wrapper.m_OnFoot; } public void Enable() { Get().Enable(); } public void Disable() { Get().Disable(); } @@ -1011,6 +1045,9 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable @Sprint.started += instance.OnSprint; @Sprint.performed += instance.OnSprint; @Sprint.canceled += instance.OnSprint; + @Skill.started += instance.OnSkill; + @Skill.performed += instance.OnSkill; + @Skill.canceled += instance.OnSkill; } private void UnregisterCallbacks(IOnFootActions instance) @@ -1039,6 +1076,9 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable @Sprint.started -= instance.OnSprint; @Sprint.performed -= instance.OnSprint; @Sprint.canceled -= instance.OnSprint; + @Skill.started -= instance.OnSkill; + @Skill.performed -= instance.OnSkill; + @Skill.canceled -= instance.OnSkill; } public void RemoveCallbacks(IOnFootActions instance) @@ -1184,6 +1224,7 @@ public partial class @PlayerInput: IInputActionCollection2, IDisposable void OnInteract(InputAction.CallbackContext context); void OnOpenTerminal(InputAction.CallbackContext context); void OnSprint(InputAction.CallbackContext context); + void OnSkill(InputAction.CallbackContext context); } public interface IUIActions { diff --git a/Assets/Input/PlayerInput.inputactions b/Assets/Input/PlayerInput.inputactions index d8326886..01acc75a 100644 --- a/Assets/Input/PlayerInput.inputactions +++ b/Assets/Input/PlayerInput.inputactions @@ -76,6 +76,15 @@ "processors": "", "interactions": "", "initialStateCheck": false + }, + { + "name": "Skill", + "type": "Button", + "id": "feae7806-0a87-4a53-9a19-fbe8d4bd5ebc", + "expectedControlType": "Button", + "processors": "", + "interactions": "", + "initialStateCheck": false } ], "bindings": [ @@ -247,7 +256,7 @@ { "name": "", "id": "a061e425-1521-4518-a642-2321104a77d5", - "path": "<Gamepad>/buttonWest", + "path": "<Gamepad>/buttonEast", "interactions": "", "processors": "", "groups": "", @@ -331,6 +340,28 @@ "action": "Reload", "isComposite": false, "isPartOfComposite": false + }, + { + "name": "", + "id": "5ed5be33-9514-475d-b16d-86f3707296ad", + "path": "<Keyboard>/q", + "interactions": "", + "processors": "", + "groups": "", + "action": "Skill", + "isComposite": false, + "isPartOfComposite": false + }, + { + "name": "", + "id": "5b42ae9f-c05b-4663-8641-0063c7a73eff", + "path": "<Gamepad>/leftTrigger", + "interactions": "", + "processors": "", + "groups": "", + "action": "Skill", + "isComposite": false, + "isPartOfComposite": false } ] }, diff --git a/Assets/Script/CutScene/SkillCutscene.cs b/Assets/Script/CutScene/SkillCutscene.cs index e806ebf2..4a4595f0 100644 --- a/Assets/Script/CutScene/SkillCutscene.cs +++ b/Assets/Script/CutScene/SkillCutscene.cs @@ -6,11 +6,17 @@ public class SkillCutscene : MonoBehaviour { public void StartSkillCutscene() { - gameObject.SetActive(true); + foreach (Transform child in transform) + { + child.gameObject.SetActive(true); + } } public void EndSkillCutscene() { - gameObject.SetActive(false); + foreach (Transform child in transform) + { + child.gameObject.SetActive(false); + } } } diff --git a/Assets/Script/Player/PlayerHealth.cs b/Assets/Script/Player/PlayerHealth.cs index 5ae72020..66578f2f 100644 --- a/Assets/Script/Player/PlayerHealth.cs +++ b/Assets/Script/Player/PlayerHealth.cs @@ -22,7 +22,9 @@ public class PlayerHealth : MonoBehaviour private float durationTimer; public bool isDead = false; - // Start is called before the first frame update + + public InputManager inputManager; + private GameObject skillCutscene; void Start() { health = maxHealth; @@ -33,6 +35,8 @@ public class PlayerHealth : MonoBehaviour } frontHealthBar.color = Color.red; overlay.color = new Color(overlay.color.r, overlay.color.g, overlay.color.b, 0f); + inputManager = gameObject.GetComponent<InputManager>(); + skillCutscene = GameObject.FindGameObjectWithTag("SkillCutscene"); } // Update is called once per frame @@ -68,6 +72,13 @@ public class PlayerHealth : MonoBehaviour overlay.color = new Color(overlay.color.r, overlay.color.g, overlay.color.b, tempAlpha); } } + if (inputManager.onFoot.Skill.triggered) + { + Debug.Log("Skill"); + RestoreHealth(maxHealth * 0.25f); + Debug.Log(GameObject.FindGameObjectWithTag("SkillCutscene")); + GameObject.FindGameObjectWithTag("SkillCutscene").GetComponent<SkillCutscene>().StartSkillCutscene(); + } } public void UpdateHealthUI() diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 05f383e4..8356ca58 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -23,6 +23,7 @@ TagManager: - Gate - Shopkeeper - AzathothAtkPoint + - SkillCutscene layers: - Default - TransparentFX -- GitLab