์•ˆ๋…•ํ•˜์„ธ์š”.


OOP์—์„œ ๋ถ€๋ชจ๋ฅผ ์ƒ์†๋ฐ›์€ ์ž์‹์„ ์—…์บ์ŠคํŒ…์ด๋‚˜ ๋‹ค์šด์บ์ŠคํŒ…ํ•ด์„œ ์˜ค๋ฒ„๋ผ์ด๋”ฉ๋œ ๋ณ€์ˆ˜๋ฅผ ํ™œ์šฉํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๋ฌด๊ธฐ ์•„์ดํ…œ์„ ๋””์ž์ธ ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.


์˜ˆ์ปจ๋Œ€, Weapon.WeaponClass์ด๋ž€ ๋ถ€๋ชจ๋Š” ์•„์ดํ…œ์˜ ์ด๋ฆ„, ์„ค๋ช…, ์ฝ”๋“œ, ํƒ€์ž…, ๋“ฑ๊ธ‰์˜ ๋ณ€์ˆ˜๋ฅผ ๊ฐ–๊ณ  ์žˆ๊ณ ์š”. PrintInfo๋กœ ์ด๋ฅผ ์ฝ˜์†”๋กœ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


Melee, Range๋Š” Weapon์„ ์ƒ์†๋ฐ›์•„์„œ, ๊ทผ๊ฑฐ๋ฆฌ ์›๊ฑฐ๋ฆฌ์— ๋”ฐ๋ฅธ ์ถ”๊ฐ€ ํšจ๊ณผ๋“ค(๊ทผ๊ฑฐ๋ฆฌ ์ „ํˆฌ๋ ฅ, ์›๊ฑฐ๋ฆฌ ์ „ํˆฌ๋ ฅ ๊ฐ™์€)์„ ๊ด€๋ฆฌํ•˜๋Š” ๋ณ€์ˆ˜๋ฅผ ๊ฐ–๊ณ  ์ด๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ๊ด€๋ฆฌํ•ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ PrintInfo๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•˜์—ฌ, ๊ทธ๋Ÿฐ ๋ณ€์ˆ˜๋“ค์„ ์ถœ๋ ฅํ•ด์ค๋‹ˆ๋‹ค.


๋˜ํ•œ Magic๋„ Weapon์„ ์ƒ์†๋ฐ›์•„์„œ, ๋งˆ๋ฒ• ์Šคํ‚ฌ์— ๋”ฐ๋ฅธ ์ถ”๊ฐ€ ํšจ๊ณผ๋“ค์„ ๊ด€๋ฆฌํ•˜๋Š” ๋ณ€์ˆ˜๋ฅผ ๊ฐ–๊ณ  ์ด๋ฅผ ๋ฆฌ์ŠคํŠธ๋กœ ๊ด€๋ผํ•˜๋ฉด, PrintInfo๋„ ์˜ค๋ฒ„๋ผ์ด๋”ฉ ํ–ˆ์Šต๋‹ˆ๋‹ค.


์—ฌ๊ธฐ์„œ ์ €๋Š” Dictonary๋กœ key๊ฐ’์„ weapon.weaponclass์— ์žˆ๋Š” int id๋ฅผ ๋ฐ›๊ณ , value๋กœ ๋‹คํ˜•์„ฑ์„ ์ œ๊ณตํ•˜๋Š” weapon.weaponclass๋ฅผ ์ƒ์†๋ฐ›๋Š” ์ž์‹๋“ค์„ ๋„ฃ์œผ๋ คํ–ˆ์Šต๋‹ˆ๋‹ค. ๋‹ค๋งŒ, ์ด๋ ‡๊ฒŒ ํ•˜๋‹ˆ ์˜ค๋ฅ˜๊ฐ€ ๋œจ๋”๋ผ๊ตฌ์š”.


using System.Collections;

using System.Collections.Generic;

using Unity.VisualScripting;

using UnityEngine;


public class WeaponManagement : MonoBehaviour

{

[SerializeField] private MeleeWeapon melee;

[SerializeField] private MagicWeapon magic;

[SerializeField] private RangeWeapon range;

public Dictionary<int, Weapon.WeaponClass> weapon;


private void Start()

{

//Melee

for (int i = 0; i < melee.meleeWeaponList.Count; i++)

{

Weapon.WeaponClass wea = new MeleeWeapon.Melee();

wea = melee.meleeWeaponList[i]; ;

int id = melee.meleeWeaponList[i].ID;

wea.PrintInfo(); //๋‹คํ˜•์„ฑ๋„ ์ œ๋Œ€๋กœ ์ ์šฉ๋จ.

weapon.Add(id, wea); //์—ฌ๊ธฐ์„œ ์˜ค๋ฅ˜ ๋ฐœ์ƒ

}

//Magic

for (int i = 0; i < magic.magicWeaponList.Count; i++)

{

Weapon.WeaponClass wea = magic.magicWeaponList[i];

int id = magic.magicWeaponList[i].ID;

weapon.Add(id, wea);

}

}

}


//MeleeWeapon.

using System.Collections;

using System.Collections.Generic;

using Unity.VisualScripting;

using UnityEngine;

using UnityEngine.UIElements;


[CreateAssetMenu(fileName = "Melee Weapon Data", menuName = "Weapon/Melee Weapon Data", order = 2)]

public class MeleeWeapon : ScriptableObject

{

public List<Melee> meleeWeaponList;


[System.Serializable]

public class Melee : Weapon.WeaponClass

{

public Melee()

{ }


//๋ฐ€๋ฆฌ๋ณ€์ˆ˜

[SerializeField] protected float physicalCritRate;

public float PhysicalCritRate { get { return physicalCritRate; } }


[SerializeField] protected float physicalCritDmg;

public float PhysicalCritDmg { get { return physicalCritDmg; } }


[SerializeField] protected float physicalSpeed;

public float PhysicalSpeed { get { return physicalSpeed; } }


public override void PrintInfo()

{

base.PrintInfo();

Debug.Log("PhysicalCritRate : " + physicalCritRate + "% PhysicalCritDmg : " + physicalCritDmg + "%");

Debug.Log("Physical Speed : " + physicalSpeed);

}

}

}


์ผ๋‹จ Melee, Magic์œผ๋กœ ํ™•์ธํ•ด๋ดค๊ตฌ์š”. weapon.Add(id, wea)์—์„œ ์˜ค๋ฅ˜๊ฐ€ ๋‚ฉ๋‹ˆ๋‹ค.