OldBlueWater/BlueWater/Assets/02.Scripts/Player/Cannon.cs
NTG 278868a690 #Closes #101 #102 #103 #111 #117 #118
+ 부스터 사용시 집중선(SpeedLines) 기능 추가
+ 부스터 사용시 카메라 흔들림 효과 기능 추가
+ 부스터 사용시 포스트프로세싱(Vignette) 기능 추가
+ 부스터 소진시 내부적인 추가 부스터 시간 추가
+ 추가 부스터까지 소진시 부스터 쿨타임 적용
  ㄴ 기존의 이동속도보다 2배 느려지는 기능 추가
+ ShipPlayer(배) 모델링 변경
  ㄴ Hand_Painted_Boats(에셋 이름)
+ 배 변경에 따른 대포(Cannon) 변경 및 로직 수정
  ㄴ 대포의 발사 각도 변경
  ㄴ 대포의 스피드 변경
+ 배의 움직임 로직 변경
  ㄴ 일정한 속도로 회전
  ㄴ Rigidbody Freeze Rotation
+ 중형 물고기 모델링 추가
  ㄴ HammerHeadShark(망치머리상어) 추가
  ㄴ Stingray(가오리) 추가

+ Layer(PostProcessing) 추가
+ VisualFeedbackManager에 포스트 프로세싱 기능 관련 추가
2024-01-15 02:24:48 +09:00

90 lines
3.5 KiB
C#

using Sirenix.OdinInspector;
using Unity.Mathematics;
using UnityEngine;
using Random = UnityEngine.Random;
// ReSharper disable once CheckNamespace
namespace BlueWaterProject
{
public class Cannon : MonoBehaviour
{
[Title("초기화 방식")]
[SerializeField] private bool autoInit = true;
[Title("캐논 변수")]
[SerializeField] private GameObject projectileObj;
[SerializeField] private Transform firePos;
[Range(0f, 0.5f)]
[SerializeField] private float fireAngle = 0.2f;
[SerializeField] private float speed = 75f;
[SerializeField] private float height = 20f;
[SerializeField] private Vector2 randomCatch = new(1, 4);
[Title("캐논 발사 카메라 효과")]
[SerializeField] private float cameraShakePower = 2f;
[SerializeField] private float cameraShakeDuration = 0.3f;
private float cannonRadius;
private LayerMask boidsLayer;
private void Awake()
{
if (autoInit)
{
Init();
}
}
[Button("셋팅 초기화")]
private void Init()
{
projectileObj = Utils.LoadFromFolder<GameObject>("Assets/05.Prefabs/Particles/GrenadeFire", "GrenadeFireOBJ", ".prefab");
firePos = transform.Find("FirePos");
cannonRadius = projectileObj.GetComponent<SphereCollider>()?.radius ??
projectileObj.GetComponent<ParticleWeapon>().colliderRadius;
boidsLayer = LayerMask.GetMask("Boids");
}
public void Fire(float chargingGauge)
{
VisualFeedbackManager.Inst.CameraShake(CameraManager.Inst.OceanCamera.BaseShipCam, cameraShakePower, cameraShakeDuration);
var addAngle = chargingGauge * fireAngle;
var firePosRotation = firePos.rotation.eulerAngles;
firePosRotation.x -= addAngle;
var projectile = Instantiate(projectileObj, firePos.position, Quaternion.Euler(firePosRotation));
var particleWeapon = projectile.GetComponent<ParticleWeapon>();
particleWeapon.onHitAction.AddListener(HandleCannonHit);
//projectile.GetComponent<Rigidbody>().AddForce(projectile.transform.forward * (chargingGauge * speed));
projectile.GetComponent<Rigidbody>().velocity = projectile.transform.forward * speed;
}
private void HandleCannonHit(RaycastHit hit, float power)
{
if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Water"))
{
var start = hit.point;
var direction = Vector3.down;
var radius = cannonRadius;
var maxDistance = height;
if (Physics.SphereCast(start, radius, direction, out var hitInfo, maxDistance,
boidsLayer, QueryTriggerInteraction.Collide))
{
Debug.DrawRay(start, direction * height, Color.green, 3f);
var hitBoids = hitInfo.collider.GetComponentInParent<Boids>();
hitBoids.CatchBoid(Random.Range((int)randomCatch.x, (int)randomCatch.y));
}
else
{
Debug.DrawRay(start, direction * height, Color.red, 3f);
}
}
else
{
hit.transform.GetComponent<IDamageable>()?.TakeDamage(power);
}
}
}
}