147 lines
4.2 KiB
C#
147 lines
4.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering.Universal;
|
|
using UnityEngine.Serialization;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace BlueWaterProject
|
|
{
|
|
[Serializable]
|
|
public abstract class ActiveSkill : MonoBehaviour
|
|
{
|
|
#region Properties and variables
|
|
|
|
[field: SerializeField] public ActiveSkillData ActiveSkillData { get; set; }
|
|
|
|
// Data
|
|
[Title("Indicator Data")]
|
|
[SerializeField] protected DecalProjector indicator;
|
|
|
|
[field: DisableIf("@true")]
|
|
[field: SerializeField] public bool IsCasting { get; set; }
|
|
|
|
[DisableIf("@true")]
|
|
[SerializeField] protected bool followMouse;
|
|
|
|
protected Camera mainCam;
|
|
protected Transform user;
|
|
|
|
protected Collider[] hitColliders;
|
|
protected LayerMask floorCheckLayer;
|
|
protected float endSkillTime;
|
|
|
|
// Hash
|
|
protected static readonly int FillHash = Shader.PropertyToID("_Fill");
|
|
|
|
#endregion
|
|
|
|
#region Unity built-in methods
|
|
|
|
protected virtual void Awake()
|
|
{
|
|
InitComponent();
|
|
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;
|
|
}
|
|
|
|
protected void BasicSetting()
|
|
{
|
|
transform.localPosition = Vector3.zero;
|
|
indicator.scaleMode = DecalScaleMode.InheritFromHierarchy;
|
|
indicator.material = new Material(indicator.material);
|
|
indicator.material.SetFloat(FillHash, 0f);
|
|
hitColliders = new Collider[ActiveSkillData.MaxAttackTargets];
|
|
floorCheckLayer = LayerMask.GetMask("Ground") | LayerMask.GetMask("Props");
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
public abstract void Execute(LayerMask targetLayer, Vector3 targetPos, Action action1 = null, Action action2 = null, Action action3 = null);
|
|
|
|
public virtual void Execute(LayerMask targetLayer, Vector3 targetPos, float[] bossMapVertices)
|
|
{
|
|
|
|
}
|
|
|
|
protected void CastingMove()
|
|
{
|
|
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;
|
|
distance = Vector3.ClampMagnitude((distance * 2), ActiveSkillData.Range);
|
|
indicator.transform.position = userPos + distance;
|
|
}
|
|
}
|
|
|
|
public void SetUser(Transform value) => user = value;
|
|
public float GetEndSkillTime() => endSkillTime;
|
|
|
|
#endregion
|
|
}
|
|
} |