2024-11-13 16:56:37 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using Unity.VisualScripting;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
public class GameSystem : MonoBehaviour
|
|
|
|
{
|
|
|
|
public static GameSystem ins;
|
2024-12-04 17:26:27 +08:00
|
|
|
public JsonTab tab;
|
2024-11-13 16:56:37 +08:00
|
|
|
public DrawingManager drawingManager;
|
2024-11-29 21:37:01 +08:00
|
|
|
public AssetBundleManager abManager;
|
2024-11-13 16:56:37 +08:00
|
|
|
public List<ItemData> List;
|
|
|
|
public List<NPCBuyData> saveStart;
|
|
|
|
public ItemDataAsset DataAsset;
|
|
|
|
public float maxTime=100;
|
|
|
|
public float nowTime;
|
2024-11-21 10:26:47 +08:00
|
|
|
public int goldCoin=0;
|
|
|
|
public int playingGold=0;
|
2024-11-13 16:56:37 +08:00
|
|
|
[SerializeField]
|
2024-11-21 10:26:47 +08:00
|
|
|
public ForgePanel forgePanel;
|
2024-11-13 16:56:37 +08:00
|
|
|
|
2024-11-21 10:26:47 +08:00
|
|
|
[SerializeField] public List<NPCBuyData> _npcBuyDatas;
|
2024-11-13 16:56:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
[SerializeField] private RectTransform seleTransform;
|
|
|
|
|
|
|
|
private int id=0;
|
|
|
|
private int index = -1;
|
|
|
|
private bool getNpc=false;
|
2024-12-04 17:26:27 +08:00
|
|
|
#if UNITY_EDITOR
|
|
|
|
[InspectorButton]
|
|
|
|
private void ClearPlayerPrefs()
|
|
|
|
{
|
|
|
|
PlayerPrefs.DeleteAll();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2024-11-13 16:56:37 +08:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
ins = this;
|
|
|
|
foreach (var data in List)
|
|
|
|
{
|
2024-12-04 17:26:27 +08:00
|
|
|
DataManager.AddItem(data.id,data.num);
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
2024-12-04 17:26:27 +08:00
|
|
|
tab=new JsonTab();
|
|
|
|
tab.InitData();
|
2024-11-21 10:26:47 +08:00
|
|
|
|
|
|
|
goldCoin = 5;
|
2024-11-13 16:56:37 +08:00
|
|
|
drawingManager=transform.AddComponent<DrawingManager>();
|
|
|
|
forgePanel.ResetItemData();
|
|
|
|
forgePanel.ResetSlotItem();
|
2024-12-04 17:26:27 +08:00
|
|
|
_npcBuyDatas = new List<NPCBuyData>();
|
2024-11-13 16:56:37 +08:00
|
|
|
getNpc = false;
|
|
|
|
SaveFirstID();
|
2024-11-21 10:26:47 +08:00
|
|
|
forgePanel.ResetGold();
|
2024-11-29 21:37:01 +08:00
|
|
|
abManager.InitAsset(()=>
|
|
|
|
{
|
2024-12-04 17:26:27 +08:00
|
|
|
if (!DataManager.GetFirst())
|
|
|
|
{
|
|
|
|
|
|
|
|
//JsonTab.Instance.tables.Main.
|
|
|
|
var data = JsonTab.Instance.tables.Main.Get(18);
|
|
|
|
var idStr = data.ConstantValue;
|
|
|
|
var idList = idStr.Split(',');
|
|
|
|
foreach (var id in idList)
|
|
|
|
{
|
|
|
|
var intId = int.Parse(id);
|
|
|
|
DataManager.SaveItemUnLock(intId,true);
|
|
|
|
var pData = JsonTab.Instance.tables.CraftingRecipes.Get(intId);
|
|
|
|
if (pData.Levelprops1!=0)
|
|
|
|
{
|
|
|
|
DataManager.SaveItemUnLock(pData.Levelprops1,true);
|
|
|
|
}
|
|
|
|
if (pData.Levelprops2!=0)
|
|
|
|
{
|
|
|
|
DataManager.SaveItemUnLock(pData.Levelprops2,true);
|
|
|
|
}
|
|
|
|
if (pData.Levelprops3!=0)
|
|
|
|
{
|
|
|
|
DataManager.SaveItemUnLock(pData.Levelprops3,true);
|
|
|
|
}
|
|
|
|
if (pData.Levelprops4!=0)
|
|
|
|
{
|
|
|
|
DataManager.SaveItemUnLock(pData.Levelprops4,true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var dataItem=JsonTab.Instance.tables.Main.Get(19).ConstantValue;
|
|
|
|
var dataItemList = dataItem.Split(',');
|
|
|
|
DataManager.SaveItem(int.Parse(dataItemList[0]), int.Parse(dataItemList[1]));
|
|
|
|
DataManager.SaveFirst();
|
|
|
|
}
|
2024-11-29 21:37:01 +08:00
|
|
|
});
|
2024-11-21 10:26:47 +08:00
|
|
|
}
|
|
|
|
|
2024-11-29 21:37:01 +08:00
|
|
|
|
2024-11-21 10:26:47 +08:00
|
|
|
public void ResetItem()
|
|
|
|
{
|
|
|
|
forgePanel.ResetItemData();
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void StartNpcData()
|
|
|
|
{
|
|
|
|
foreach (var buyData in saveStart)
|
|
|
|
{
|
|
|
|
_npcBuyDatas.Add(buyData);
|
|
|
|
}
|
|
|
|
|
|
|
|
nowTime = 0;
|
|
|
|
SaveFirstID();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SaveNPCbo(bool bo)
|
|
|
|
{
|
|
|
|
getNpc = bo;
|
|
|
|
}
|
2024-11-21 10:26:47 +08:00
|
|
|
/// <summary>
|
|
|
|
/// 默认获得金币
|
|
|
|
/// </summary>
|
|
|
|
public void GoldRest()
|
|
|
|
{
|
|
|
|
goldCoin += playingGold;
|
|
|
|
forgePanel.ResetGold();
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// 双倍获得金币
|
|
|
|
/// </summary>
|
|
|
|
public void DoubleGoldRest()
|
|
|
|
{
|
|
|
|
goldCoin += (playingGold*2);
|
|
|
|
forgePanel.ResetGold();
|
|
|
|
|
|
|
|
}
|
|
|
|
public void StartGamePanel()
|
|
|
|
{
|
|
|
|
forgePanel.OpenStartPanel();
|
|
|
|
}
|
2024-11-13 16:56:37 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2024-11-21 10:26:47 +08:00
|
|
|
playingGold += 10;
|
2024-11-13 16:56:37 +08:00
|
|
|
DataManager.RemoveItem(id, (bool bo) =>
|
|
|
|
{
|
|
|
|
if (bo)
|
|
|
|
{
|
|
|
|
_npcBuyDatas.Remove(_npcBuyDatas[0]);
|
|
|
|
SaveFirstID();
|
2024-11-21 10:26:47 +08:00
|
|
|
|
2024-11-13 16:56:37 +08:00
|
|
|
if (_npcBuyDatas.Count>0)
|
|
|
|
{
|
|
|
|
forgePanel.SetData(true);
|
|
|
|
}
|
2024-11-21 10:26:47 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
forgePanel.OpenStartPanel();
|
|
|
|
}
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-11-21 10:26:47 +08:00
|
|
|
playingGold += 2;
|
|
|
|
DataManager.RemoveItem(id, (bool bo) =>
|
|
|
|
{
|
|
|
|
if (bo)
|
|
|
|
{
|
|
|
|
_npcBuyDatas.Remove(_npcBuyDatas[0]);
|
|
|
|
SaveFirstID();
|
|
|
|
if (_npcBuyDatas.Count>0)
|
|
|
|
{
|
|
|
|
forgePanel.SetData(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
forgePanel.OpenStartPanel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2024-11-13 16:56:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|