OldBlueWater/BlueWater/Assets/02.Scripts/Skill/ActiveSkill/ActiveSkill.cs

142 lines
4.0 KiB
C#
Raw Normal View History

2023-10-31 07:37:23 +00:00
using System;
using System.Collections;
using Sirenix.OdinInspector;
using UnityEngine;
using UnityEngine.Rendering.Universal;
2023-11-12 18:54:37 +00:00
using UnityEngine.Serialization;
2023-10-31 07:37:23 +00:00
// ReSharper disable once CheckNamespace
namespace BlueWaterProject
{
[Serializable]
2023-11-22 07:20:22 +00:00
public abstract class ActiveSkill : MonoBehaviour
2023-10-31 07:37:23 +00:00
{
#region Properties and variables
2023-11-12 18:54:37 +00:00
[field: SerializeField] public ActiveSkillData ActiveSkillData { get; set; }
// Data
[Title("Indicator Data")]
2023-11-22 07:20:22 +00:00
[SerializeField] protected DecalProjector indicator;
[field: DisableIf("@true")]
[field: SerializeField] public bool IsCasting { get; set; }
[DisableIf("@true")]
2023-11-22 07:20:22 +00:00
[SerializeField] protected bool followMouse;
2023-11-22 07:20:22 +00:00
protected Camera mainCam;
protected Transform user;
2023-11-22 07:20:22 +00:00
protected Collider[] hitColliders;
protected LayerMask groundLayer;
protected float endSkillTime;
// Hash
2023-11-22 07:20:22 +00:00
protected static readonly int FillHash = Shader.PropertyToID("_Fill");
#endregion
#region Unity built-in methods
protected virtual void Awake()
{
InitComponent();
2023-11-22 07:20:22 +00:00
HideIndicator();
BasicSetting();
}
private void Update()
{
if (followMouse)
{
FollowMouse();
}
}
#endregion
#region Custorm methods
private void InitComponent()
{
indicator = GetComponentInChildren<DecalProjector>();
if (indicator == null)
{
print("하위 오브젝트로 DecalProjector 컴포넌트를 찾을 수 없습니다.");
}
mainCam = Camera.main;
}
2023-11-22 07:20:22 +00:00
protected void BasicSetting()
{
transform.localPosition = Vector3.zero;
indicator.scaleMode = DecalScaleMode.InheritFromHierarchy;
2023-11-22 07:20:22 +00:00
indicator.material = new Material(indicator.material);
indicator.material.SetFloat(FillHash, 0f);
2023-11-12 18:54:37 +00:00
hitColliders = new Collider[ActiveSkillData.MaxAttackTargets];
groundLayer = LayerMask.GetMask("Ground");
}
2023-11-22 07:20:22 +00:00
protected void HideIndicator()
{
indicator.enabled = false;
indicator.material.SetFloat(FillHash, 0);
IsCasting = false;
followMouse = false;
}
public IEnumerator ShowIndicator()
{
indicator.transform.position = user.position;
indicator.material.SetFloat(FillHash, 0);
indicator.enabled = true;
while (true)
{
indicator.transform.position = user.position;
yield return null;
}
}
private void InterruptIndicator()
{
HideIndicator();
}
2023-11-12 18:54:37 +00:00
public abstract void Execute(LayerMask targetLayer, Vector3 targetPos, Action action1 = null, Action action2 = null, Action action3 = null);
2023-11-22 07:20:22 +00:00
protected void CastingMove()
{
2023-11-12 18:54:37 +00:00
switch (ActiveSkillData.CastingType)
{
case 0:
break;
case 1:
break;
case 2:
transform.position = user.position;
break;
}
}
protected void FollowMouse()
{
var ray = mainCam.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out var raycastHit, 2000))
{
var userPos = user.position;
var targetPos = (userPos + raycastHit.point) / 2;
var distance = targetPos - userPos;
2023-11-12 18:54:37 +00:00
distance = Vector3.ClampMagnitude((distance * 2), ActiveSkillData.Range);
indicator.transform.position = userPos + distance;
}
}
2023-11-12 18:54:37 +00:00
public void SetUser(Transform value) => user = value;
public float GetEndSkillTime() => endSkillTime;
#endregion
2023-10-31 07:37:23 +00:00
}
}