+ 기본적인 배에서 포쏘는 로직 완료
우클릭 - 발사 모드 온/오프
좌클릭 Hold - 발사 게이지 충전
좌클릭 중단 - 발사
+ 대포 발사시 카메라 흔들림 효과 추가
+ 대포 재장선시 UI 추가
+ 대포 재장전시 공격하면 사운드 및 UI 흔들림 효과 추가
+ 카메라 고정으로 변경
This commit is contained in:
NTG 2023-12-18 04:50:44 +09:00
parent 22de879e35
commit b95f9de49e
7 changed files with 1054 additions and 126 deletions

File diff suppressed because it is too large Load Diff

View File

@ -9,6 +9,9 @@ namespace BlueWaterProject
[SelectionBase] [SelectionBase]
public class ShipPlayer : Player public class ShipPlayer : Player
{ {
[Title("초기화 방식")]
[SerializeField] private bool autoInit = true;
[Title("쉽의 기본 설정")] [Title("쉽의 기본 설정")]
[Tooltip("최대 스피드")] public float maxSpeed = 10f; [Tooltip("최대 스피드")] public float maxSpeed = 10f;
[Tooltip("가속 수치")] public float acceleration = 2f; [Tooltip("가속 수치")] public float acceleration = 2f;
@ -35,10 +38,12 @@ namespace BlueWaterProject
[SerializeField] private LayerMask waterLayer; [SerializeField] private LayerMask waterLayer;
[Button("셋팅 초기화")]
private void Init() private void Init()
{ {
rb = GetComponent<Rigidbody>(); rb = GetComponent<Rigidbody>();
playerInput = GetComponent<PlayerInput>(); playerInput = GetComponent<PlayerInput>();
cannon = transform.Find("Cannon").GetComponent<Cannon>();
directionIndicator = transform.Find("DirectionIndicator").gameObject; directionIndicator = transform.Find("DirectionIndicator").gameObject;
directionIndicator.SetActive(false); directionIndicator.SetActive(false);
@ -51,7 +56,11 @@ namespace BlueWaterProject
protected override void Awake() protected override void Awake()
{ {
base.Awake(); base.Awake();
Init();
if (autoInit)
{
Init();
}
} }
protected override void OnEnable() protected override void OnEnable()
@ -187,10 +196,17 @@ namespace BlueWaterProject
private void ChargeCannon() private void ChargeCannon()
{ {
if (!isFireMode || isReloading) return; if (!isFireMode) return;
chargingCannon = true; if (isReloading)
chargingGauge = 0f; {
StartCoroutine(UiManager.Inst.OceanUi.ProcessBar.ShakeSliderCoroutine());
}
else
{
chargingCannon = true;
chargingGauge = 0f;
}
} }
private void FireCannon() private void FireCannon()
@ -223,14 +239,19 @@ namespace BlueWaterProject
private IEnumerator CannonCoolDown(float waitTime) private IEnumerator CannonCoolDown(float waitTime)
{ {
var time = 0f; var time = 0f;
UiManager.Inst.OceanUi.ProcessBar.SetSliderValue(0f);
UiManager.Inst.OceanUi.ProcessBar.SetActiveReloadSlider(true);
while (time <= waitTime) while (time <= waitTime)
{ {
time += Time.deltaTime; time += Time.deltaTime;
var sliderValue = time > 0 ? time / waitTime : 0f;
UiManager.Inst.OceanUi.ProcessBar.SetSliderValue(sliderValue);
yield return null; yield return null;
} }
isReloading = false; isReloading = false;
UiManager.Inst.OceanUi.ProcessBar.SetActiveReloadSlider(false);
} }
#endregion #endregion

View File

@ -8,16 +8,24 @@ namespace BlueWaterProject
{ {
public class OceanCamera : MonoBehaviour public class OceanCamera : MonoBehaviour
{ {
[Title("초기화 방식")]
[SerializeField] private bool autoInit = true;
[field: Title("카메라")]
[field: SerializeField] public CinemachineVirtualCamera BaseShipCam { get; private set; } [field: SerializeField] public CinemachineVirtualCamera BaseShipCam { get; private set; }
private List<CinemachineVirtualCamera> cineCamList; private List<CinemachineVirtualCamera> cineCamList;
private GameObject cineCams; private GameObject cineCams;
private const int CINE_CAM_NUM = 1; private const int CINE_CAM_NUM = 1;
private void Awake() private void Awake()
{ {
if (autoInit)
{
Init();
}
CameraManager.Inst.OceanCamera = this; CameraManager.Inst.OceanCamera = this;
CameraManager.Inst.MainCam = Camera.main; CameraManager.Inst.MainCam = Camera.main;
} }

View File

@ -1,7 +1,9 @@
using System; using System;
using System.Collections;
using Sirenix.OdinInspector; using Sirenix.OdinInspector;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
using Random = UnityEngine.Random;
// ReSharper disable once CheckNamespace // ReSharper disable once CheckNamespace
namespace BlueWaterProject namespace BlueWaterProject
@ -12,12 +14,21 @@ namespace BlueWaterProject
[field: SerializeField] public GameObject Obj { get; set; } [field: SerializeField] public GameObject Obj { get; set; }
[field: SerializeField] public Image Fill { get; set; } [field: SerializeField] public Image Fill { get; set; }
[field: SerializeField] public Transform PreviousGaugeLine { get; set; } [field: SerializeField] public Transform PreviousGaugeLine { get; set; }
[field: SerializeField] public Slider ReloadSlider { get; set; }
[field: SerializeField] public float ShakeDuration { get; set; } = 0.5f;
[field: SerializeField] public float ShakePower { get; set; } = 10f;
private AudioSource reloadingAttackSound;
private bool isShaking;
public ProcessBar(GameObject obj, Image fill, Transform previousGaugeLine) public ProcessBar(GameObject obj, Image fill, Transform previousGaugeLine, Slider reloadSlider)
{ {
Obj = obj; Obj = obj;
Fill = fill; Fill = fill;
PreviousGaugeLine = previousGaugeLine; PreviousGaugeLine = previousGaugeLine;
ReloadSlider = reloadSlider;
reloadingAttackSound = ReloadSlider.GetComponent<AudioSource>();
SetFillAmount(0f); SetFillAmount(0f);
} }
@ -26,17 +37,55 @@ namespace BlueWaterProject
public void SetPosition(Vector3 value) => Obj.transform.position = value; public void SetPosition(Vector3 value) => Obj.transform.position = value;
public void SetFillAmount(float value) => Fill.fillAmount = value; public void SetFillAmount(float value) => Fill.fillAmount = value;
public void SetRotateZ(float value) => PreviousGaugeLine.rotation = Quaternion.Euler(0f, 0f, value); public void SetRotateZ(float value) => PreviousGaugeLine.rotation = Quaternion.Euler(0f, 0f, value);
public void SetActiveReloadSlider(bool value) => ReloadSlider.gameObject.SetActive(value);
public void SetSliderValue(float value) => ReloadSlider.value = value;
public IEnumerator ShakeSliderCoroutine()
{
if (isShaking) yield break;
isShaking = true;
reloadingAttackSound.Play();
var time = 0f;
var sliderOriginalPos = ReloadSlider.transform.localPosition;
while (time < ShakeDuration)
{
if (!ReloadSlider.gameObject.activeSelf)
{
ReloadSlider.transform.localPosition = sliderOriginalPos;
isShaking = false;
yield break;
}
time += Time.deltaTime;
var shakeAmount = Random.Range(-1f, 1f) * ShakePower;
ReloadSlider.transform.localPosition = new Vector3(sliderOriginalPos.x + shakeAmount, sliderOriginalPos.y, sliderOriginalPos.z);
yield return null;
}
ReloadSlider.transform.localPosition = sliderOriginalPos;
isShaking = false;
}
} }
public class OceanUi : MonoBehaviour public class OceanUi : MonoBehaviour
{ {
[Title("초기화 방식")]
[SerializeField] private bool autoInit = true;
[field: Title("UI")]
[field: SerializeField] public ProcessBar ProcessBar { get; set; } [field: SerializeField] public ProcessBar ProcessBar { get; set; }
[field: SerializeField] public Image CannonFill { get; set; } [field: SerializeField] public Image CannonFill { get; set; }
[SerializeField] private Vector3 processBarOffset = Vector3.zero;
private Canvas canvas; private Canvas canvas;
private void Awake() private void Awake()
{ {
if (autoInit)
{
Init();
}
UiManager.Inst.OceanUi = this; UiManager.Inst.OceanUi = this;
ProcessBar.SetActive(false); ProcessBar.SetActive(false);
} }
@ -46,7 +95,8 @@ namespace BlueWaterProject
if (ProcessBar.Obj.activeSelf) if (ProcessBar.Obj.activeSelf)
{ {
var mousePos = Input.mousePosition; var mousePos = Input.mousePosition;
ProcessBar.SetPosition(mousePos); var result = mousePos + processBarOffset;
ProcessBar.SetPosition(result);
} }
} }
@ -63,7 +113,9 @@ namespace BlueWaterProject
var processBar = canvas.transform.Find("ProcessBar").gameObject; var processBar = canvas.transform.Find("ProcessBar").gameObject;
var fill = processBar.transform.Find("Fill").GetComponent<Image>(); var fill = processBar.transform.Find("Fill").GetComponent<Image>();
var previousGaugeLine = processBar.transform.Find("PreviousGaugeLine").transform; var previousGaugeLine = processBar.transform.Find("PreviousGaugeLine").transform;
ProcessBar = new ProcessBar(processBar, fill, previousGaugeLine); var reloadSlider = processBar.transform.Find("ReloadSlider").GetComponent<Slider>();
ProcessBar = new ProcessBar(processBar, fill, previousGaugeLine, reloadSlider);
ProcessBar.SetActiveReloadSlider(false);
} }
} }
} }

View File

@ -1,3 +1,4 @@
using System;
using Sirenix.OdinInspector; using Sirenix.OdinInspector;
using UnityEngine; using UnityEngine;
@ -6,10 +7,25 @@ namespace BlueWaterProject
{ {
public class Cannon : MonoBehaviour public class Cannon : MonoBehaviour
{ {
[Title("초기화 방식")]
[SerializeField] private bool autoInit = true;
[Title("캐논 변수")]
[SerializeField] private GameObject projectileObj; [SerializeField] private GameObject projectileObj;
[SerializeField] private Transform firePos; [SerializeField] private Transform firePos;
[SerializeField] private float speed = 2000f;
public float speed = 2000f; [Title("캐논 발사 카메라 효과")]
[SerializeField] private float cameraShakePower = 0.5f;
[SerializeField] private float cameraShakeDuration = 0.5f;
private void Awake()
{
if (autoInit)
{
Init();
}
}
[Button("셋팅 초기화")] [Button("셋팅 초기화")]
private void Init() private void Init()
@ -20,6 +36,7 @@ namespace BlueWaterProject
public void Fire(float chargingGauge) public void Fire(float chargingGauge)
{ {
VisualFeedbackManager.Inst.CameraShake(CameraManager.Inst.OceanCamera.BaseShipCam, cameraShakePower, cameraShakeDuration);
var projectile = Instantiate(projectileObj, firePos.position, Quaternion.identity); var projectile = Instantiate(projectileObj, firePos.position, Quaternion.identity);
projectile.GetComponent<Rigidbody>().AddForce(transform.forward * (chargingGauge * speed)); projectile.GetComponent<Rigidbody>().AddForce(transform.forward * (chargingGauge * speed));
} }

View File

@ -24156,7 +24156,7 @@ AudioSource:
OutputAudioMixerGroup: {fileID: 0} OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: 79c3cb7a26813d146b07c293b0324039, type: 3} m_audioClip: {fileID: 8300000, guid: 79c3cb7a26813d146b07c293b0324039, type: 3}
m_PlayOnAwake: 1 m_PlayOnAwake: 1
m_Volume: 1 m_Volume: 0.5
m_Pitch: 1 m_Pitch: 1
Loop: 0 Loop: 0
Mute: 0 Mute: 0

View File

@ -9551,7 +9551,7 @@ AudioSource:
OutputAudioMixerGroup: {fileID: 0} OutputAudioMixerGroup: {fileID: 0}
m_audioClip: {fileID: 8300000, guid: a76b32836dc7cc44aa9a52f0694ee199, type: 3} m_audioClip: {fileID: 8300000, guid: a76b32836dc7cc44aa9a52f0694ee199, type: 3}
m_PlayOnAwake: 1 m_PlayOnAwake: 1
m_Volume: 1 m_Volume: 0.5
m_Pitch: 1 m_Pitch: 1
Loop: 0 Loop: 0
Mute: 0 Mute: 0