61 lines
2.2 KiB
C#
61 lines
2.2 KiB
C#
|
|
using MiniJSON;
|
||
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Linq;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
public class BookTableData : TableDataBase
|
||
|
|
{
|
||
|
|
public int ChapterMin, ChapterMax, TotalPage, Gamble;
|
||
|
|
public string Name, Desc, IconBook;
|
||
|
|
public eStat Stat;
|
||
|
|
public float StatPerPage, Complete;
|
||
|
|
}
|
||
|
|
|
||
|
|
public class table_book : MonoBehaviour
|
||
|
|
{
|
||
|
|
public static table_book Ins;
|
||
|
|
|
||
|
|
public TextAsset m_json;
|
||
|
|
|
||
|
|
private List<TableDataBase> list_Data = new List<TableDataBase>();
|
||
|
|
|
||
|
|
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 BookTableData();
|
||
|
|
Dictionary<string, object> json = objt as Dictionary<string, object>;
|
||
|
|
|
||
|
|
temp.ID = int.Parse(json["ID"].ToString());
|
||
|
|
temp.ChapterMin = int.Parse(json["ChapterMin"].ToString());
|
||
|
|
temp.ChapterMax = int.Parse(json["ChapterMax"].ToString());
|
||
|
|
temp.TotalPage = int.Parse(json["TotalPage"].ToString());
|
||
|
|
temp.Name = json["Name"].ToString();
|
||
|
|
temp.Desc = json["Desc"].ToString();
|
||
|
|
temp.IconBook = json["IconBook"].ToString();
|
||
|
|
temp.Stat = DSUtil.StringToEnum<eStat>(json["Stat"].ToString());
|
||
|
|
temp.StatPerPage = float.Parse(json["StatPerPage"].ToString());
|
||
|
|
temp.Complete = float.Parse(json["Complete"].ToString());
|
||
|
|
|
||
|
|
list_Data.Add(temp);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public List<TableDataBase> Get_DataList() { return list_Data; }
|
||
|
|
public BookTableData Get_Data(int _id) { return list_Data.Find(f => f.ID == _id) as BookTableData; }
|
||
|
|
public float Get_BookValue(int _id, ServerData sdata)
|
||
|
|
{
|
||
|
|
var bookTdata = Get_Data(_id);
|
||
|
|
var booksdata = sdata.Book.Find(f => f.ID == _id);
|
||
|
|
var sum = booksdata.Page.Sum(s => s);
|
||
|
|
return bookTdata.StatPerPage * sum + (booksdata.Complete > 0 ? bookTdata.Complete : 0f);
|
||
|
|
}
|
||
|
|
}
|