115 lines
3.5 KiB
C#
115 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using Newtonsoft.Json;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEditor;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace BlueWaterProject
|
|
{
|
|
public class DataManager : Singleton<DataManager>
|
|
{
|
|
[field: Title("Inventory")]
|
|
[field: SerializeField] public PlayerInventory OceanInventory { get; private set; } = new();
|
|
[field: SerializeField] public PlayerInventory CombatInventory { get; private set; } = new();
|
|
public PlayerInventory CurrentInventory { get; set; }
|
|
public int Gold { get; set; } = 0;
|
|
|
|
[Title("DataBase", "GameObject")]
|
|
public GameObject mouseSpot;
|
|
public GameObject boat;
|
|
public GameObject assaultCard;
|
|
public GameObject radarTargetUi;
|
|
public GameObject vomit;
|
|
|
|
[Title("DataBase", "Particle")]
|
|
public GameObject nukeFire;
|
|
public GameObject grenadeFire;
|
|
public GameObject emojiHeart;
|
|
public GameObject emojiPuke;
|
|
public GameObject emojiAnger;
|
|
|
|
[Title("DataBase", "Sprites")]
|
|
public Sprite[] cardType;
|
|
public Texture2D cursorTexture;
|
|
public Sprite enemyMarker;
|
|
public Sprite scallion;
|
|
public Sprite tomato;
|
|
public Sprite onion;
|
|
public Sprite kingCrabMeat;
|
|
public Sprite beer;
|
|
|
|
[Title("DataBase", "UI")]
|
|
public UiDataBase UiDataBaseSo { get; private set; }
|
|
|
|
[field: Space(5)]
|
|
[field: SerializeField] public NpcDataSO NpcDataSo { get; private set; }
|
|
|
|
private void Init()
|
|
{
|
|
if (SceneManager.GetActiveScene().name == "02.Ocean")
|
|
{
|
|
CurrentInventory = OceanInventory;
|
|
}
|
|
else if (SceneManager.GetActiveScene().name == "02.Combat_2D")
|
|
{
|
|
CurrentInventory = CombatInventory;
|
|
}
|
|
}
|
|
|
|
protected override void OnAwake()
|
|
{
|
|
Init();
|
|
if (gameObject.GetComponent<Upd>() == null)
|
|
{
|
|
gameObject.AddComponent<Upd>();
|
|
}
|
|
}
|
|
|
|
public NpcData GetNpcData(int idx)
|
|
{
|
|
var data = NpcDataSo.npcDataList.FirstOrDefault(d => d.idx == idx);
|
|
if(data == null)
|
|
{
|
|
Debug.LogWarning($"NPC Data for index {idx} not found.");
|
|
}
|
|
return data;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Dictionary 초기화 함수
|
|
/// </summary>
|
|
private Dictionary<string, T> CreateDictionaryFromList<T>(List<T> list, int capacity) where T : IIdx
|
|
{
|
|
var newDictionary = new Dictionary<string, T>(capacity);
|
|
|
|
foreach (var item in list)
|
|
{
|
|
newDictionary.Add(item.Idx, item);
|
|
}
|
|
|
|
return newDictionary;
|
|
}
|
|
|
|
[ContextMenu("Json To So")]
|
|
public void MakeDataSoFromJson()
|
|
{
|
|
NpcDataSo.npcDataList = GetJsonData<List<NpcData>>("JSON/customer_table.json");
|
|
|
|
#if UNITY_EDITOR_OSX || UNITY_EDITOR_WIN
|
|
EditorUtility.SetDirty(NpcDataSo);
|
|
#endif
|
|
}
|
|
|
|
private static T GetJsonData<T>(string path)
|
|
{
|
|
var jsonString = File.ReadAllText(SystemPath.GetPath(path));
|
|
var data = JsonConvert.DeserializeObject<T>(jsonString);
|
|
return data;
|
|
}
|
|
}
|
|
} |