165 lines
4.0 KiB
C#
165 lines
4.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
|
|
public class GameSystem : MonoBehaviour
|
|
{
|
|
public static GameSystem ins;
|
|
public DrawingManager drawingManager;
|
|
public List<ItemData> List;
|
|
public List<NPCBuyData> saveStart;
|
|
public ItemDataAsset DataAsset;
|
|
public float maxTime=100;
|
|
public float nowTime;
|
|
[SerializeField]
|
|
private ForgePanel forgePanel;
|
|
|
|
[SerializeField] private List<NPCBuyData> _npcBuyDatas;
|
|
|
|
|
|
[SerializeField] private RectTransform seleTransform;
|
|
|
|
private int id=0;
|
|
private int index = -1;
|
|
private bool getNpc=false;
|
|
private void Awake()
|
|
{
|
|
ins = this;
|
|
foreach (var data in List)
|
|
{
|
|
DataManager.AddItem(data.item,data.num);
|
|
}
|
|
drawingManager=transform.AddComponent<DrawingManager>();
|
|
forgePanel.ResetItemData();
|
|
forgePanel.ResetSlotItem();
|
|
_npcBuyDatas = new List<NPCBuyData>();
|
|
getNpc = false;
|
|
SaveFirstID();
|
|
}
|
|
|
|
public void StartNpcData()
|
|
{
|
|
foreach (var buyData in saveStart)
|
|
{
|
|
_npcBuyDatas.Add(buyData);
|
|
}
|
|
|
|
nowTime = 0;
|
|
SaveFirstID();
|
|
}
|
|
|
|
public void SaveNPCbo(bool bo)
|
|
{
|
|
getNpc = bo;
|
|
}
|
|
|
|
private void SaveFirstID()
|
|
{
|
|
if (_npcBuyDatas.Count>0)
|
|
{
|
|
drawingManager.itemID = _npcBuyDatas[0].buyID;
|
|
forgePanel.ResetCrafting(drawingManager.itemID);
|
|
forgePanel.Open();
|
|
}
|
|
else
|
|
{
|
|
forgePanel.Close();
|
|
}
|
|
}
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
public void Crafting(bool bo)
|
|
{
|
|
drawingManager.CraftItem(bo,() =>
|
|
{
|
|
forgePanel.ResetItemData();
|
|
forgePanel.ResetSlotItem();
|
|
});
|
|
}
|
|
public void SaveSeledID(int sendID)
|
|
{
|
|
id = sendID;
|
|
index = -1;
|
|
seleTransform.GetComponent<SeletItemUI>().SaveSprite(id);
|
|
}
|
|
|
|
public void SaveIndex(int slotIndex)
|
|
{
|
|
index = slotIndex;
|
|
}
|
|
|
|
private void FixedUpdate()
|
|
{
|
|
if (_npcBuyDatas.Count>0)
|
|
{
|
|
nowTime += Time.deltaTime;
|
|
if (nowTime>maxTime)
|
|
{
|
|
_npcBuyDatas = new List<NPCBuyData>();
|
|
nowTime = 0;
|
|
SaveFirstID();
|
|
}
|
|
}
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
if (Input.GetMouseButtonUp(0))
|
|
{
|
|
if (id!=0)
|
|
{
|
|
if (Input.mousePosition.x>640&&Input.mousePosition.y>900)
|
|
{
|
|
if (drawingManager.itemID==id)
|
|
{
|
|
DataManager.RemoveItem(id, (bool bo) =>
|
|
{
|
|
if (bo)
|
|
{
|
|
_npcBuyDatas.Remove(_npcBuyDatas[0]);
|
|
SaveFirstID();
|
|
if (_npcBuyDatas.Count>0)
|
|
{
|
|
forgePanel.SetData(true);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
else
|
|
{
|
|
forgePanel.SetData(false);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (index!=-1)
|
|
{
|
|
drawingManager.SaveIndexID(index,id);
|
|
}
|
|
}
|
|
}
|
|
id = 0;
|
|
seleTransform.position = new Vector3(-3000, 0, 0);
|
|
index = -1;
|
|
getNpc = false;
|
|
forgePanel.ResetSlotItem();
|
|
forgePanel.ResetItemData();
|
|
}
|
|
if (Input.GetMouseButton(0))
|
|
{
|
|
if (id!=0)
|
|
{
|
|
Vector2 mouse = Input.mousePosition;
|
|
seleTransform.position = mouse;
|
|
}
|
|
}
|
|
}
|
|
}
|