캐릭터 모델 작성 및 스킬 버블 시스템 제작중 1

This commit is contained in:
지용훈 2023-11-12 17:29:41 +09:00
parent 75ac817c80
commit 849cf63e2e
17 changed files with 406 additions and 74 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: fd43d4ef45c8644b29b8f128a42af5a4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,40 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniRx;
public class BattleCharacter : MonoBehaviour
{
public CharacterModel.Data Data { get; private set; } = null;
public short UID { get; private set; } = 0;
public int SKILL_TIME { get; private set; } = 0;
public void Initialize(CharacterModel.Data data, short uid)
{
Data = data;
UID = uid;
SKILL_TIME = 0;
}
public void UpdateBattleTime(int t)
{
SKILL_TIME += t;
CheckSkill();
}
void CheckSkill()
{
if(Data.GetStat(CharacterModel.Data.eSTAT.SPD) <= SKILL_TIME)
{
MessageBroker.Default.Publish<BattleManager.Message>(new BattleManager.Message()
{
BattleEvent = BattleManager.eBATTLE_EVENT.SPAWN_SKILL,
Source = this,
}) ;
SKILL_TIME = 0;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9da7f45aa275148288c5956311d60b54
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniRx;
public partial class BattleManager
{
[SerializeField]
SkillBubbleManager mSkillManager = null;
public enum eBATTLE_EVENT
{
SPAWN_SKILL,
RUN_SKILL,
}
public struct Message
{
public eBATTLE_EVENT BattleEvent;
public BattleCharacter Source;
}
public void Awake()
{
OnMessageBroker();
}
void OnMessageBroker()
{
MessageBroker.Default.Receive<Message>().Subscribe(msg =>
{
switch(msg.BattleEvent)
{
case eBATTLE_EVENT.SPAWN_SKILL:
mSkillManager.SpawnSkill(msg.Source);
break;
}
}).AddTo(this);
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e2b35ac764b7a4bf494ec51168810fab
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -8,10 +8,10 @@ using DarkTonic.MasterAudio;
using System.Collections;
#if UNITY_EDITOR
// PackageManager 관련 코드
// PackageManager ???? ????
#endif
public class BattleManager : MonoBehaviour
public partial class BattleManager : MonoBehaviour
{
public GameObject HeroUnit;
public Transform[] MonsterPositions = new Transform[3];
@ -21,37 +21,37 @@ public class BattleManager : MonoBehaviour
public GameObject NumberPrefab;
public GameObject CriticalPrefab;
public TextMeshProUGUI stageClearText;
public Image darkPanel; // 다크 커튼 이미지를 담을 변수
public Image darkPanel; // ???? ???? ???????? ???? ????
public float CriticalRate; // 치명타 확률(10000분율)
public float CriticalDamage; // 치명타 배율(10000분율)
public int HeroDamag; // 영웅 공격력
public float CriticalRate; // ?????? ????(10000????)
public float CriticalDamage; // ?????? ????(10000????)
public int HeroDamag; // ???? ??????
private List<Transform> aliveMonsters = new List<Transform>();
private bool stageCleared = false;
private bool isHeroAttacking = false;
public string playlistName = "Bgm";
// 스프라이트 랜더러 배열 추가
// ?????????? ?????? ???? ????
private SpriteRenderer[] spriteRenderers;
private void Start()
{
// 처음에 모든 몬스터를 생존 몬스터 리스트에 추가
// ?????? ???? ???????? ???? ?????? ???????? ????
foreach (Transform monsterPos in MonsterPositions)
{
aliveMonsters.Add(monsterPos);
}
// NumberPrefab의 자식 오브젝트 수를 가져옵니다.
// NumberPrefab?? ???? ???????? ???? ??????????.
int childCount = NumberPrefab.transform.childCount;
// 스프라이트 랜더러 배열 초기화
// ?????????? ?????? ???? ??????
spriteRenderers = new SpriteRenderer[childCount];
// 각 자식 오브젝트의 스프라이트 랜더러 컴포넌트를 배열에 할당
// ?? ???? ?????????? ?????????? ?????? ?????????? ?????? ????
for (int i = 0; i < childCount; i++)
{
Transform child = NumberPrefab.transform.GetChild(i);
@ -78,18 +78,18 @@ public class BattleManager : MonoBehaviour
isHeroAttacking = true;
HeroUnit.SetActive(true);
// 영웅의 공격 애니메이션
// ?????? ???? ??????????
Sequence attackSequence = DOTween.Sequence();
attackSequence.Append(HeroUnit.transform.DOLocalMoveY(-700, 0.25f).SetEase(Ease.OutCubic));
attackSequence.AppendCallback(() =>
{
// 공격 애니메이션이 끝나면 몬스터에게 피해를 입힙니다.
// ???? ???????????? ?????? ?????????? ?????? ????????.
DealDamageToMonster();
});
attackSequence.Append(HeroUnit.transform.DOLocalMoveY(-1500, 0.15f).SetEase(Ease.OutCubic));
attackSequence.OnComplete(() =>
{
// 애니메이션 종료 후 공격을 허용
// ?????????? ???? ?? ?????? ????
isHeroAttacking = false;
HeroUnit.SetActive(false);
});
@ -104,24 +104,24 @@ public class BattleManager : MonoBehaviour
int randomMonsterIndex = Random.Range(0, aliveMonsters.Count);
Transform targetMonster = aliveMonsters[randomMonsterIndex];
float randomNumber = Random.Range(0, HeroDamag); // 0부터 영웅 공격력만큼의 피해를 적용
float randomNumber = Random.Range(0, HeroDamag); // 0???? ???? ???????????? ?????? ????
// 랜덤 값을 생성하여 크리티컬 확률과 비교
float randomValue = Random.Range(0, 10000); // 0부터 9999까지의 랜덤 값
// ???? ???? ???????? ???????? ?????? ????
float randomValue = Random.Range(0, 10000); // 0???? 9999?????? ???? ??
bool isCritical = randomValue<= CriticalRate;
int resultNumber = 0;
int randomSoundIndex = Random.Range(1, 4); // 1부터 3까지의 랜덤한 정수 생성
int randomSoundIndex = Random.Range(1, 4); // 1???? 3?????? ?????? ???? ????
string soundName = "Hot_Type2_" + randomSoundIndex.ToString(); // 사운드 이름 생성
string soundName = "Hot_Type2_" + randomSoundIndex.ToString(); // ?????? ???? ????
MasterAudio.PlaySound(soundName, 0.7f, null);
int randomVoiceIndex = Random.Range(1, 13); // 1부터 12까지의 랜덤한 정수 생성
int randomVoiceIndex = Random.Range(1, 13); // 1???? 12?????? ?????? ???? ????
string voiceName = "Voice_HERO_01_Combo_1_" + randomVoiceIndex.ToString(); // 사운드 이름 생성
string voiceName = "Voice_HERO_01_Combo_1_" + randomVoiceIndex.ToString(); // ?????? ???? ????
MasterAudio.PlaySound(voiceName, 0.7f, null);
@ -138,32 +138,32 @@ public class BattleManager : MonoBehaviour
resultNumber = (int)randomNumber;
}
// HitEffectPrefab 오브젝트를 복제하여 이펙트를 표시할 오브젝트 생성
// HitEffectPrefab ?????????? ???????? ???????? ?????? ???????? ????
GameObject hitEffectPosition = Instantiate(HitEffectPrefab, targetMonster.position, Quaternion.identity);
hitEffectPosition.SetActive(true);
Destroy(hitEffectPosition, 0.5f); // 일정 시간 후에 제거
Destroy(hitEffectPosition, 0.5f); // ???? ???? ???? ????
if (resultNumber == 0)
{
// 몬스터 위치로 미스 이펙트 발생
// ?????? ?????? ???? ?????? ????
ShowMissDamage(targetMonster.position + new Vector3(0, 1.4f, 0), targetMonster);
}
else
{
ShowNumberDamage(targetMonster.position + new Vector3(0, 1.4f, 0), targetMonster, resultNumber, isCritical);
// HitEffectPrefab 오브젝트를 복제하여 이펙트를 표시할 오브젝트 생성
// HitEffectPrefab ?????????? ???????? ???????? ?????? ???????? ????
}
}
}
private void ShowMissDamage(Vector3 monsterPosition, Transform targetMonster)
{
// 몬스터 위치로 미스 이펙트 생성
// ?????? ?????? ???? ?????? ????
GameObject missObject = Instantiate(MissPrefab, monsterPosition, Quaternion.identity);
missObject.SetActive(true);
// 미스 애니메이션
// ???? ??????????
missObject.transform.localScale = Vector3.one * 1.5f;
missObject.transform.DOScale(Vector3.one * 0.3f, 0.4f).SetEase(Ease.OutCubic);
missObject.transform.DOMoveY(missObject.transform.position.y + 1, 0.5f).SetEase(Ease.OutCubic).OnComplete(() =>
@ -177,7 +177,7 @@ public class BattleManager : MonoBehaviour
GameObject CriObject = Instantiate(CriticalPrefab, monsterPosition, Quaternion.identity);
CriObject.SetActive(true);
// 크리 애니메이션
// ???? ??????????
CriObject.transform.localScale = Vector3.one * 1.5f;
CriObject.transform.DOScale(Vector3.one * 0.3f, 0.4f).SetEase(Ease.OutCubic);
CriObject.transform.DOMoveY(CriObject.transform.position.y + 1, 0.5f).SetEase(Ease.OutCubic).OnComplete(() =>
@ -188,13 +188,13 @@ public class BattleManager : MonoBehaviour
private void ShowNumberDamage(Vector3 monsterPosition, Transform targetMonster, int damage, bool isCritical)
{
// 떨림 효과 추가
// ???? ???? ????
targetMonster.DOPunchPosition(new Vector3(10, 0, 0), 0.2f);
// damage를 문자열로 변환
// damage?? ???????? ????
string damageString = damage.ToString();
// 서로 떨어진 위치 조절값
// ???? ?????? ???? ??????
float xOffset = 0;
if (isCritical)
@ -206,18 +206,18 @@ public class BattleManager : MonoBehaviour
xOffset += 1.1f;
}
float totalWidth = ((damageString.Length-1) * xOffset); // 전체 너비
float totalWidth = ((damageString.Length-1) * xOffset); // ???? ????
// 부모 오브젝트 생성
// ???? ???????? ????
GameObject digitObject = new GameObject("HitNumber");
// 숫자 위치를 monsterPosition을 기준으로 설정 (로컬 포지션)
// ???? ?????? monsterPosition?? ???????? ???? (???? ??????)
digitObject.transform.localPosition = new Vector3(monsterPosition.x, monsterPosition.y - 2f, monsterPosition.z);
// 애니메이션 및 위치 설정
// ?????????? ?? ???? ????
for (int i = 0; i < damageString.Length; i++)
{
int digit = int.Parse(damageString[i].ToString()); // 자릿수를 추출
int digit = int.Parse(damageString[i].ToString()); // ???????? ????
if (digit >= 0 && digit < spriteRenderers.Length)
{
@ -225,28 +225,28 @@ public class BattleManager : MonoBehaviour
{
digit += 10;
}
// 숫자 스프라이트 랜더러 설정
// ???? ?????????? ?????? ????
SpriteRenderer digitSpriteRenderer = spriteRenderers[digit];
// 숫자 스프라이트 복제
GameObject digitImageObject = new GameObject("DigitImage"); // 새 게임 오브젝트 생성
// ???? ?????????? ????
GameObject digitImageObject = new GameObject("DigitImage"); // ?? ???? ???????? ????
//digitImageObject.transform.position = digitObject.transform.position;
// 스프라이트 랜더러 추가 및 설정
// ?????????? ?????? ???? ?? ????
SpriteRenderer newRenderer = digitImageObject.AddComponent<SpriteRenderer>();
newRenderer.sprite = digitSpriteRenderer.sprite;
// Order 값을 300으로 설정
// Order ???? 300???? ????
newRenderer.sortingOrder = 300;
// x 위치 조절하여 중앙 정렬된 상태에서 배치
// x ???? ???????? ???? ?????? ???????? ????
float xPos = -totalWidth / 2 + i * xOffset;
digitImageObject.transform.localPosition = new Vector3(xPos, 0, 0);
// 스케일 조절 (크기 동일하게)
// ?????? ???? (???? ????????)
digitImageObject.transform.localScale = Vector3.one * 1.0f;
// 부모 설정
// ???? ????
digitImageObject.transform.SetParent(digitObject.transform);
}
else
@ -257,39 +257,39 @@ public class BattleManager : MonoBehaviour
if (isCritical)
{
ShowCriEffect(targetMonster.position + new Vector3(0, 1.8f, 0), targetMonster);
digitObject.transform.localScale = Vector3.one * 0.5f; // 크기 설정
digitObject.transform.localScale = Vector3.one * 0.5f; // ???? ????
digitObject.transform.DOScale(Vector3.one * 0.2f, 0.3f).SetEase(Ease.OutCubic);
digitObject.transform.DOMoveY(digitObject.transform.position.y + 2, 0.5f).SetEase(Ease.OutCubic).OnComplete(() =>
{
Destroy(digitObject); // 스프라이트 랜더러를 가진 게임 오브젝트를 제거합니다.
Destroy(digitObject); // ?????????? ???????? ???? ???? ?????????? ??????????.
});
}
else
{
// digitObject를 기준으로 애니메이션 설정
digitObject.transform.localScale = Vector3.one * 0.5f; // 크기 설정
// digitObject?? ???????? ?????????? ????
digitObject.transform.localScale = Vector3.one * 0.5f; // ???? ????
digitObject.transform.DOScale(Vector3.one * 0.3f, 0.3f).SetEase(Ease.OutCubic);
digitObject.transform.DOMoveY(digitObject.transform.position.y + 2, 0.5f).SetEase(Ease.OutCubic).OnComplete(() =>
{
Destroy(digitObject); // 스프라이트 랜더러를 가진 게임 오브젝트를 제거합니다.
Destroy(digitObject); // ?????????? ???????? ???? ???? ?????????? ??????????.
});
}
// 몬스터의 HP 게이지 감소 처리
// ???????? HP ?????? ???? ????
MonsterHealth monsterHealth = targetMonster.GetComponentInChildren<MonsterHealth>();
if (monsterHealth != null && !monsterHealth.IsDead)
{
monsterHealth.TakeDamage(damage); // damage 만큼 감소
monsterHealth.TakeDamage(damage); // damage ???? ????
// 만약 몬스터의 HP가 0 이하면
// ???? ???????? HP?? 0 ??????
if (monsterHealth.CurrentHealth <= 0)
{
// 몬스터를 리스트에서 제거
// ???????? ?????????? ????
aliveMonsters.Remove(targetMonster);
// 남은 몬스터가 없으면 StageClear 효과 표시
// ???? ???????? ?????? StageClear ???? ????
if (aliveMonsters.Count == 0 && !stageCleared)
{
stageCleared = true;
@ -305,31 +305,31 @@ public class BattleManager : MonoBehaviour
private void ShowStageClearAnimation()
{
// 텍스트 활성화 및 초기화
// ?????? ?????? ?? ??????
stageClearText.gameObject.SetActive(true);
HeroUnit.SetActive(false);
stageClearText.transform.localScale = Vector3.zero;
// Scale 애니메이션
// Scale ??????????
stageClearText.transform.DOScale(Vector3.one, 0.5f).SetEase(Ease.OutBack).OnComplete(() =>
{
// 텍스트 흔들림 애니메이션
// ?????? ?????? ??????????
stageClearText.transform.DOShakePosition(1.0f, new Vector3(0, 10, 0), 10, 90, false, true).OnComplete(() =>
{
// 텍스트 페이드 아웃 애니메이션
// ?????? ?????? ???? ??????????
CanvasGroup canvasGroup = stageClearText.GetComponent<CanvasGroup>();
canvasGroup.DOFade(0, 0.5f).OnComplete(() =>
{
// 다크 커튼 이미지 활성화
// ???? ???? ?????? ??????
darkPanel.gameObject.SetActive(true);
// 어두움 효과 애니메이션 (투명도를 0에서 1로 변경)
// ?????? ???? ?????????? (???????? 0???? 1?? ????)
DOVirtual.Float(0, 1.0f, 1.0f, (fadeValue) =>
{
darkPanel.color = new Color(0, 0, 0, fadeValue);
}).OnComplete(() =>
{
// 다음 씬 호출
// ???? ?? ????
MasterAudio.PlaySound("BGM_VAILAGE", 0);
MasterAudio.PlaylistsMuted = false;
SceneManager.LoadScene(4);

View File

@ -0,0 +1,60 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
public class SkillBubbleManager : MonoBehaviour
{
public List<SkillData> mListSkill = new List<SkillData>(10);
Queue<SkillData> mQSkillDataPool = new Queue<SkillData>(10);
public void Initialize()
{
for(int i=0; i<10; ++i)
{
mQSkillDataPool.Enqueue(new SkillData());
}
}
public void SpawnSkill(BattleCharacter character)
{
var existSkill = GetExistSkill(character);
if(null != existSkill)
{
existSkill.OnStack();
return;
}
var newSkill = GetNewSkillData();
newSkill.Set(character);
mListSkill.Add(newSkill);
}
public void RemoveSkill(int idx)
{
mListSkill.RemoveAt(idx);
}
SkillData GetExistSkill(BattleCharacter character)
{
var skill = mListSkill.FirstOrDefault((item) => item.Owner == character);
if (null == skill)
return null;
if (false == skill.IsStackable())
return null;
return skill;
}
SkillData GetNewSkillData()
{
if (mQSkillDataPool.Count <= 0)
{
mQSkillDataPool.Enqueue(new SkillData());
}
return mQSkillDataPool.Dequeue();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 576636a482c29486cb2a622bcb12b953
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,34 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SkillData
{
public const int MAX_STACK = 5;
public BattleCharacter Owner { get; private set; } = null;
public int StackCnt { get; set; } = 0;
public void Reset()
{
Owner = null;
StackCnt = 1;
}
public void Set(BattleCharacter owner)
{
Owner = owner;
StackCnt = 1;
}
public bool IsStackable()
{
return StackCnt < MAX_STACK;
}
public void OnStack()
{
StackCnt++;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: fedc6dc1b6439435586cf6bf5259ab37
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e4f2a12c7a4454e4fa2e2b23f2a9dc4b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public partial class CharacterModel
{
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8dc698d1cb2fa4b6ebfb636046a6fe33
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,89 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniRx;
public partial class CharacterModel : BaseModel
{
ReactiveCollection<Data> mDatas = new ReactiveCollection<Data>(new List<Data>(10));
public IReadOnlyCollection<Data> Datas => mDatas;
public class Data
{
public enum eSTAT
{
_START_,
_BASE_START_,
ATK, //공격력
DEF, //방어력
HP, //체력
CRI_RATE, //치명타 확률
CRI, //치명타 피해량
SPD, //속도
_BASE_END_,
_SUPPROT_START_,
SKILL_DMG, //스킬 피해량
CC_REGIST, //상태이상 저항
CC_HIT, //상태이상 적중
FINAL_DMG_UP, //최종 피해량 증가
FINAL_DMG_DOWN, //받는 피해 경감
FIX_DMG_UP, //고정 피해 추가
FIX_DMG_DOWN, //고정 피해 방어
CRI_REGIST, //치명타 저항
HP_RECOVERY, //생명력 재생량
HP_RECOVERY_UP, //회복 효과 증가
_SUPPORT_END_,
_SPECIAL_START_,
ATTRIBUTE, //속성
JOB, //직업
SEX, //성별
AGGRO, //어그로
_SPECIAL_END_,
_END_,
}
public int Level { get; set; } = 1;
public string Name { get; set; } = string.Empty;
public int SkillID { get; set; } = 0;
Dictionary<eSTAT, int> mDicStat = null;
public Data()
{
mDicStat = new Dictionary<eSTAT, int>((int)eSTAT._END_);
}
public void Initialize()
{
#region [TEST]
for (var e = eSTAT._START_; e <= eSTAT._END_; ++ e)
{
if(e <= eSTAT._BASE_END_)
{
mDicStat.TryAdd(e, Random.Range(100, 150));
}
else if(e <= eSTAT._SUPPORT_END_)
{
mDicStat.TryAdd(e, Random.Range(1, 10));
}
else if(e <= eSTAT._SPECIAL_END_)
{
mDicStat.TryAdd(e, Random.Range(1, 5));
}
}
#endregion[TEST]
}
public int GetStat(eSTAT e)
{
mDicStat.TryGetValue(e, out var stat);
return stat;
}
}
}

View File

@ -1,13 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UniRx;
public class CharacterModel : BaseModel
{
public IntReactiveProperty mLevel = new IntReactiveProperty(0);
public IReadOnlyReactiveProperty<int> Level => mLevel;
}