스킬 컨트롤러 부분 테스트 작업
This commit is contained in:
@@ -160,24 +160,20 @@ namespace TON
|
||||
attackCollider.EnableCollider(false);
|
||||
}
|
||||
|
||||
public void SkillAttack(string skillId)
|
||||
public bool SkillAttack(string skillId)
|
||||
{
|
||||
animator.Play("Skill Attack");
|
||||
// 스킬 매니저에서 스킬을 쏠 수 있는지 여부를 판단
|
||||
bool canExecute = SkillDataManager.Singleton.CanExecuteSkill(skillId);
|
||||
if (canExecute)
|
||||
{
|
||||
// 스킬 애니메이터 실행
|
||||
animator.Play("Skill Attack");
|
||||
|
||||
// 스킬 생성
|
||||
GameObject skill = ObjectPoolManager.Instance.GetEffect(skillId);
|
||||
// 스킬 매니저에 스킬 발사 요청
|
||||
SkillDataManager.Singleton.ExecuteSkill(skillId, firePoint, lastDirection);
|
||||
}
|
||||
|
||||
// skill.transform.SetParent(firePoint);
|
||||
skill.transform.SetPositionAndRotation(firePoint.position, firePoint.rotation);
|
||||
|
||||
// 🔥 스킬 방향 반전
|
||||
var bulletScale = skill.transform.localScale;
|
||||
bulletScale.x = Mathf.Abs(bulletScale.x) * lastDirection;
|
||||
skill.transform.localScale = bulletScale;
|
||||
|
||||
// 스킬 이동 방향 설정
|
||||
Rigidbody2D skillRb = skill.GetComponent<Rigidbody2D>();
|
||||
skillRb.velocity = new Vector2(lastDirection * 5f, 0f);
|
||||
return canExecute;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class BubblePop : SkillBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 097cc9f5338c42f4dacb309030086af2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class DarknessBall : SkillBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 46951a2e33fdd5a409f1579de9b7acfa
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class EarthSmash : SkillBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 58aa952974ab33d448446d7e947feb10
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class ElementalBurst : SkillBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 251310a05dd69154f930fc61ec1795c7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,12 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class FireBall : SkillBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26dd04ed34a3c4042bfbe12766af2d60
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class IceBall : SkillBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: aa5541b68c81e2347960b5eeaf373bf4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class LeafCutter : SkillBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecd1248961250a0459b097be2a5f840d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,11 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class LeafShuriken : SkillBase
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 88908efcef71610458a84067666b485b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
||||
namespace TON
|
||||
{
|
||||
[System.Serializable]
|
||||
public abstract class SkillBase : PoolAble
|
||||
public class SkillBase : PoolAble
|
||||
{
|
||||
public float SkillCoolDown => SkillData.coolDown;
|
||||
public float CurrentCoolDown { get; protected set; }
|
||||
@@ -15,7 +15,7 @@ namespace TON
|
||||
|
||||
private DamageCalculator damageCalculator = new DamageCalculator();
|
||||
|
||||
private float elapsedTime; // 경과 시간 저장 변수
|
||||
private float elapsedTime = 0f; // 경과 시간 저장 변수
|
||||
public float destoryTime = 2f;
|
||||
|
||||
|
||||
@@ -27,19 +27,43 @@ namespace TON
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
elapsedTime = 0f; // 오브젝트가 활성화될 때 초기화
|
||||
elapsedTime = 0f;
|
||||
}
|
||||
|
||||
public void InvokeExcuteSkill()
|
||||
{
|
||||
InvokeRepeating(nameof(ExecuteSkill), 0f, 1f); // 즉시 실행 후 1초 간격 반복
|
||||
}
|
||||
|
||||
void ExecuteSkill()
|
||||
{
|
||||
if (elapsedTime >= destoryTime)
|
||||
{
|
||||
CancelInvoke(nameof(ExecuteSkill)); // 반복 중지
|
||||
ReleaseObject();
|
||||
return;
|
||||
}
|
||||
|
||||
Debug.Log("SkillBase:: " + SkillData.name);
|
||||
UpdateSkill(Time.deltaTime);
|
||||
elapsedTime += 1.0f;
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
CancelInvoke(nameof(ExecuteSkill)); // 오브젝트 비활성화 시 중지
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
UpdateSkill(Time.deltaTime);
|
||||
elapsedTime += Time.deltaTime; // 경과 시간 누적
|
||||
|
||||
// 2초가 지나면 오브젝트 풀에 반환
|
||||
if (elapsedTime >= destoryTime)
|
||||
{
|
||||
ReleaseObject();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void SetCurrentCoolDown()
|
||||
{
|
||||
CurrentCoolDown = SkillData.coolDown; // 쿨타임 시작
|
||||
}
|
||||
|
||||
public void UpdateSkill(float deltaTime)
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace TON
|
||||
public class SkillDataManager : SingletonBase<SkillDataManager>
|
||||
{
|
||||
public List<SkillData> skillDatas { get; private set; }
|
||||
public List<SkillBase> skillBases { get; private set; }
|
||||
public SerializableDictionary<string, SkillBase> skillInstances { get; private set; }
|
||||
|
||||
protected override void Awake()
|
||||
{
|
||||
@@ -22,12 +22,121 @@ namespace TON
|
||||
{
|
||||
skillDatas = new List<SkillData>();
|
||||
}
|
||||
// skillData를 skillBase로 치환
|
||||
}
|
||||
|
||||
public SkillData GetSkillData(string skillId)
|
||||
public void SetSkillInstances()
|
||||
{
|
||||
return skillDatas.Find(v => v.id == skillId);
|
||||
skillInstances = new SerializableDictionary<string, SkillBase>();
|
||||
// skillData를 skillBase로 치환
|
||||
foreach (var skillData in skillDatas)
|
||||
{
|
||||
skillInstances.Add(skillData.id, InitSkillData(skillData));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 스킬 슬롯에 배치할 수 있는 스킬 수 리턴하는 메소드
|
||||
public int GetActiveSkillCount()
|
||||
{
|
||||
int characterLevel = PlayerDataManager.Singleton.player.level;
|
||||
int availableSkillCount = 0;
|
||||
|
||||
foreach (SkillData skill in skillDatas)
|
||||
{
|
||||
if (skill.requiredLevel <= characterLevel)
|
||||
{
|
||||
availableSkillCount++;
|
||||
}
|
||||
}
|
||||
return availableSkillCount > 3 ? 3 : availableSkillCount;
|
||||
}
|
||||
|
||||
// 스킬 슬롯에 적용해야하는 스킬 리스트 리턴
|
||||
public List<SkillBase> GetActiveSkillInstance()
|
||||
{
|
||||
List<SkillBase> filteredSkills = new List<SkillBase>();
|
||||
|
||||
foreach (SkillData skill in skillDatas)
|
||||
{
|
||||
if (skill.slotNumber == 1 || skill.slotNumber == 2 || skill.slotNumber == 3)
|
||||
{
|
||||
filteredSkills.Add(skillInstances.GetValueOrDefault(skill.id));
|
||||
}
|
||||
}
|
||||
return filteredSkills;
|
||||
}
|
||||
|
||||
// 스킬 쿨타임 설정하는 메소드
|
||||
public void SetCoolTime(string skillId)
|
||||
{
|
||||
if (skillInstances.TryGetValue(skillId, out SkillBase skillBase))
|
||||
{
|
||||
skillBase.SetCurrentCoolDown();
|
||||
}
|
||||
}
|
||||
|
||||
// 스킬 쿨타임 업데이트 메소드
|
||||
public void UpdateSkillCoolDown(string skillId)
|
||||
{
|
||||
if (skillInstances.TryGetValue(skillId, out SkillBase skillBase))
|
||||
{
|
||||
skillBase.UpdateSkill(Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
// 스킬을 실행할 수 있는지 확인
|
||||
public bool CanExecuteSkill(string skillId)
|
||||
{
|
||||
if (skillInstances.TryGetValue(skillId, out SkillBase skill))
|
||||
{
|
||||
return skill.CurrentCoolDown <= 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 스킬의 쿨타임 및 파괴 로직 실행 메소드
|
||||
public void InvokeExcuteSkill(string skillId)
|
||||
{
|
||||
if (skillInstances.TryGetValue(skillId, out SkillBase skill))
|
||||
{
|
||||
skill.InvokeExcuteSkill();
|
||||
}
|
||||
}
|
||||
|
||||
// 스킬 발사(생성) 메소드 추가
|
||||
public void ExecuteSkill(string skillId, Transform firePoint, float lastDirection)
|
||||
{
|
||||
// 스킬 생성
|
||||
GameObject skill = ObjectPoolManager.Instance.GetEffect(skillId);
|
||||
|
||||
skill.transform.SetPositionAndRotation(firePoint.position, firePoint.rotation);
|
||||
|
||||
// 🔥 스킬 방향 반전
|
||||
var bulletScale = skill.transform.localScale;
|
||||
bulletScale.x = Mathf.Abs(bulletScale.x) * lastDirection;
|
||||
skill.transform.localScale = bulletScale;
|
||||
|
||||
// 스킬 이동 방향 설정
|
||||
Rigidbody2D skillRb = skill.GetComponent<Rigidbody2D>();
|
||||
skillRb.velocity = new Vector2(lastDirection * 5f, 0f);
|
||||
|
||||
|
||||
InvokeExcuteSkill(skillId);
|
||||
}
|
||||
|
||||
private SkillBase InitSkillData(SkillData skillData)
|
||||
{
|
||||
SkillBase skill = gameObject.AddComponent<SkillBase>();
|
||||
skill.Init(skillData);
|
||||
return skill;
|
||||
}
|
||||
|
||||
public SkillBase GetSkillData(string skillId)
|
||||
{
|
||||
return skillInstances.GetValueOrDefault(skillId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user