57 lines
2.0 KiB
C#
57 lines
2.0 KiB
C#
|
|
using MiniJSON;
|
||
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class BookPageTableData : TableDataBase
|
||
|
|
{
|
||
|
|
public int Book, Page;
|
||
|
|
}
|
||
|
|
|
||
|
|
public class table_bookpage : MonoBehaviour
|
||
|
|
{
|
||
|
|
public static table_bookpage Ins;
|
||
|
|
|
||
|
|
public TextAsset m_json;
|
||
|
|
|
||
|
|
private List<TableDataBase> list_Data = new List<TableDataBase>();
|
||
|
|
protected Dictionary<int, List<float>> dic_pageids = new Dictionary<int, List<float>>();
|
||
|
|
|
||
|
|
private void Awake()
|
||
|
|
{
|
||
|
|
Ins = this;
|
||
|
|
|
||
|
|
Dictionary<string, object> jsonData = Json.Deserialize(m_json.text) as Dictionary<string, object>;
|
||
|
|
|
||
|
|
// ["items"]은 items.txt 안의 items를 가리킨다. 툴 우측 하단 파일 종류란에서 설정 가능.
|
||
|
|
List<object> obj = jsonData[GetType().Name] as List<object>;
|
||
|
|
|
||
|
|
foreach (object objt in obj)
|
||
|
|
{
|
||
|
|
var temp = new BookPageTableData();
|
||
|
|
Dictionary<string, object> json = objt as Dictionary<string, object>;
|
||
|
|
|
||
|
|
temp.ID = int.Parse(json["ID"].ToString());
|
||
|
|
temp.Book = int.Parse(json["Book"].ToString());
|
||
|
|
temp.Page = int.Parse(json["Page"].ToString());
|
||
|
|
|
||
|
|
var Drop = float.Parse(json["Drop"].ToString());
|
||
|
|
if (dic_pageids.ContainsKey(temp.Book))
|
||
|
|
dic_pageids[temp.Book].Add(Drop);
|
||
|
|
else
|
||
|
|
dic_pageids.Add(temp.Book, new List<float> { Drop });
|
||
|
|
|
||
|
|
list_Data.Add(temp);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public List<TableDataBase> Get_DataList() { return list_Data; }
|
||
|
|
public List<TableDataBase> Get_DataList(int book) { return list_Data.FindAll(f => (f as BookPageTableData).Book == book); }
|
||
|
|
public BookPageTableData Get_Data(int _id) { return list_Data.Find(f => f.ID == _id) as BookPageTableData; }
|
||
|
|
public int Get_RandomPageID(List<int> _book)
|
||
|
|
{
|
||
|
|
var book = _book[Random.Range(0, _book.Count)];
|
||
|
|
var page = DSUtil.Get_RandomIndex(dic_pageids[book]) + 1;
|
||
|
|
return list_Data.Find(f => (f as BookPageTableData).Book == book && (f as BookPageTableData).Page == page).ID;
|
||
|
|
}
|
||
|
|
}
|