-
Notifications
You must be signed in to change notification settings - Fork 0
Feature: 무기 합성 시스템 기초 로직 #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b88d09f
8eb8eea
c601541
5dfcd5c
ccdc839
3736068
fceb148
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!114 &11400000 | ||
| MonoBehaviour: | ||
| m_ObjectHideFlags: 0 | ||
| m_CorrespondingSourceObject: {fileID: 0} | ||
| m_PrefabInstance: {fileID: 0} | ||
| m_PrefabAsset: {fileID: 0} | ||
| m_GameObject: {fileID: 0} | ||
| m_Enabled: 1 | ||
| m_EditorHideFlags: 0 | ||
| m_Script: {fileID: 11500000, guid: bf84d2193e2760c4c9f107ed9dfb64cb, type: 3} | ||
| m_Name: testWeaponA | ||
| m_EditorClassIdentifier: | ||
| WeaponIcon: {fileID: 10907, guid: 0000000000000000f000000000000000, type: 0} | ||
| weaponName: A | ||
| weaponInfo: AA | ||
| weaponCount: 100 | ||
| Damage: 0 | ||
| isUnlock: 1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| %YAML 1.1 | ||
| %TAG !u! tag:unity3d.com,2011: | ||
| --- !u!114 &11400000 | ||
| MonoBehaviour: | ||
| m_ObjectHideFlags: 0 | ||
| m_CorrespondingSourceObject: {fileID: 0} | ||
| m_PrefabInstance: {fileID: 0} | ||
| m_PrefabAsset: {fileID: 0} | ||
| m_GameObject: {fileID: 0} | ||
| m_Enabled: 1 | ||
| m_EditorHideFlags: 0 | ||
| m_Script: {fileID: 11500000, guid: bf84d2193e2760c4c9f107ed9dfb64cb, type: 3} | ||
| m_Name: testWeaponC | ||
| m_EditorClassIdentifier: | ||
| WeaponIcon: {fileID: 10901, guid: 0000000000000000f000000000000000, type: 0} | ||
| weaponName: C | ||
| weaponInfo: CC | ||
| weaponCount: 0 | ||
| Damage: 0 | ||
| isUnlock: 1 |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| using UnityEngine; | ||
| using UnityEngine.UI; | ||
|
|
||
| [System.Serializable] | ||
| public struct WeaponTable | ||
| { | ||
| public SO_Weapon[] weapons; | ||
| } | ||
|
|
||
| public class EquipmentManager : MonoBehaviour | ||
| { | ||
| private static EquipmentManager _instance; | ||
| public static EquipmentManager Instance | ||
| { | ||
| get | ||
| { | ||
| _instance = FindAnyObjectByType<EquipmentManager>(); | ||
| if (Instance == null) | ||
| { | ||
| Debug.LogError("씬에 스크립트를 참조한 오브젝트가 없습니다"); | ||
| } | ||
| return _instance; | ||
| } | ||
| } | ||
| public static Color[] weaponLevelColor = | ||
| { | ||
| Color.green, | ||
| Color.cyan, | ||
| Color.magenta, | ||
| Color.yellow, | ||
| }; | ||
|
|
||
| [Header("합성&강화 공통 변수")] | ||
| public GameObject ItemInfoPanel; | ||
|
|
||
| private int weaponTypeValue; | ||
| private int weaponLevelValue; | ||
|
|
||
| [Header("합성")] | ||
| public Image[] WeaponBackgroundImage; | ||
| public Image[] WeaponSlotImage; | ||
| public Text[] WeaponCountText; | ||
| public Text SynthesisCountText; | ||
|
|
||
| private Color[] SynthesisColor = { Color.red, Color.cyan }; | ||
| private int synthesisCount = 1; | ||
|
|
||
| [Header("강화")] | ||
| [Header("인벤토리")] | ||
| public WeaponTable[] WeaponArray; // 2중 배열로 무기 종류와 등급에 따른 무기 분류 | ||
| public Slot[] Invens; | ||
|
|
||
| private void Awake() | ||
| { | ||
| if (_instance == null) | ||
| { | ||
| _instance = this; | ||
| DontDestroyOnLoad(gameObject); | ||
| } | ||
| else | ||
| Destroy(gameObject); | ||
| } | ||
|
|
||
| public void OpenItemInfoPage(Slot inven) | ||
| { | ||
| weaponTypeValue = (int)inven._WeaponType; | ||
| weaponLevelValue = (int)inven._WeaponLevel; | ||
| ItemInfoPanel.SetActive(true); | ||
| RefreshSynthesis(); | ||
| } | ||
|
|
||
| public void RefreshSlot() | ||
| { | ||
| for (int i = 0; i < Invens.Length; i++) | ||
| { | ||
| Invens[i].RefreshIcon(); | ||
| } | ||
| } | ||
|
|
||
| private void RefreshSynthesis() | ||
| { | ||
| if (WeaponArray[weaponTypeValue].weapons.Length < weaponLevelValue + 1) | ||
| return; | ||
| for (int i = 0; i < 2; i++) | ||
| { | ||
| WeaponBackgroundImage[i].color = weaponLevelColor[weaponLevelValue + i]; | ||
| WeaponSlotImage[i].sprite = WeaponArray[weaponTypeValue] | ||
| .weapons[weaponLevelValue + i] | ||
| .WeaponIcon; | ||
| string hexColor = "#" + ColorUtility.ToHtmlStringRGB(SynthesisColor[i]); | ||
| int weaponValue = synthesisCount * (i == 0 ? 5 : 1); | ||
| WeaponCountText[i].text = | ||
| $"{WeaponArray[weaponTypeValue].weapons[weaponLevelValue + i].weaponCount}(<color={hexColor}>{(weaponValue >= 0 ? "+" : "-")}{weaponValue}</color>)"; | ||
| SynthesisCountText.text = synthesisCount.ToString("0"); | ||
| } | ||
| } | ||
|
|
||
| public SO_Weapon GetWeapon(WeaponType type, WeaponLevel level) => | ||
| WeaponArray[(int)type].weapons[(int)level]; | ||
|
|
||
| public void UpCount() | ||
| { | ||
| if ( | ||
| (synthesisCount + 1) * 5 | ||
| <= WeaponArray[weaponTypeValue].weapons[weaponLevelValue].weaponCount | ||
| ) | ||
| { | ||
| synthesisCount++; | ||
| RefreshSynthesis(); | ||
| } | ||
| } | ||
|
|
||
| public void DownCount() | ||
| { | ||
| if (synthesisCount - 1 > 0) | ||
| { | ||
| synthesisCount--; | ||
| RefreshSynthesis(); | ||
| } | ||
| } | ||
|
|
||
| public void Synthesis() | ||
| { | ||
| if (WeaponArray[weaponTypeValue].weapons.Length < weaponLevelValue + 1) | ||
| return; | ||
| if ( | ||
| synthesisCount * 5 | ||
| <= WeaponArray[weaponTypeValue].weapons[weaponLevelValue].weaponCount | ||
| ) | ||
| { | ||
| WeaponArray[weaponTypeValue].weapons[weaponLevelValue].weaponCount -= | ||
| (uint)synthesisCount * 5; | ||
| GetItem(weaponTypeValue, weaponLevelValue + 1, (uint)synthesisCount); | ||
| synthesisCount = 1; | ||
| RefreshSynthesis(); | ||
| } | ||
| } | ||
|
|
||
| public void GetItem(int weaponType, int weaponLevel, uint amount) | ||
| { | ||
| WeaponArray[weaponType].weapons[weaponLevel].weaponCount += amount; | ||
| RefreshSlot(); | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WeaponLevel enum에서 C가 D보다 높게 쓰여있는 이유가 있을까요?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋은 지적입니다 수정하도록 하겠습니다 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,13 +24,15 @@ public enum WeaponType | |
| public class SO_Weapon : ScriptableObject | ||
| { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SO_Weapon클래스에서 WeaponId라는 속성을 추가로 넣는 것을 권장 드립니다
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WeaponID 부분과 같은 것들은 장비 탭을 만들 때 넣을 예정입니다 |
||
| //필요한 기능에 따라 변수 및 함수가 추가될 수 있음 | ||
| [Header("필요 변수"), SerializeField] | ||
| public Sprite WeaponImage { get; private set; } | ||
| [Header("필요 변수")] | ||
| [SerializeField] | ||
| private Sprite _weaponIcon; | ||
| public Sprite WeaponIcon => WeaponIcon; | ||
|
|
||
| [Header("무기 정보")] | ||
| public string weaponName; | ||
| public string weaponInfo; | ||
| public uint weaponCount; | ||
| public int Damage; | ||
| public WeaponType Type; | ||
| public WeaponLevel currentLevel; | ||
| public bool isUnlock; | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| using UnityEngine; | ||
| using UnityEngine.UI; | ||
|
|
||
| public enum SlotType | ||
| { | ||
| Inventory, | ||
| Synthesis, | ||
| Enchent, | ||
| } | ||
|
|
||
| public class Slot : MonoBehaviour | ||
| { | ||
| [Header("아이템 속성")] | ||
| public WeaponType _WeaponType; | ||
| public WeaponLevel _WeaponLevel; | ||
|
|
||
| [Header("UI속성")] | ||
| public SlotType _SlotType; | ||
| public GameObject WeaponIconWall; | ||
| public Image WeaponIcon; | ||
| public Text WeaponCountText; | ||
|
|
||
| protected void Start() | ||
| { | ||
| RefreshIcon(); | ||
| if (TryGetComponent<Button>(out Button button)) | ||
| { | ||
| button.onClick.AddListener(OnButtonClick); | ||
| } | ||
| } | ||
|
|
||
| protected void OnButtonClick() | ||
| { | ||
| EquipmentManager.Instance.OpenItemInfoPage(this); | ||
| } | ||
|
|
||
| public void GetItem() => | ||
| EquipmentManager.Instance.GetWeapon(_WeaponType, _WeaponLevel).weaponCount++; | ||
|
|
||
| public void RefreshIcon() | ||
| { | ||
| GetComponent<Image>().color = EquipmentManager.weaponLevelColor[(int)_WeaponLevel]; | ||
| WeaponIcon.sprite = EquipmentManager | ||
| .Instance.GetWeapon(_WeaponType, _WeaponLevel) | ||
| .WeaponIcon; | ||
| if (EquipmentManager.Instance.GetWeapon(_WeaponType, _WeaponLevel).isUnlock) | ||
| { | ||
| WeaponIconWall.SetActive(false); | ||
| WeaponIcon.color = Color.white; | ||
| // 무기 개수 text 필요 | ||
| } | ||
| else | ||
| { | ||
| WeaponIconWall.SetActive(true); | ||
| } | ||
| } | ||
| } |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
무기가 이미 최고 등급인 상태에서
Synthesis가 호출되면weaponLevelValue + 1인덱스 접근 시 에러가 발생합니다. 합성이 가능한 최대 등급인지 확인하는 방어 코드가 필요합니다.