274 lines
8.3 KiB
C#
274 lines
8.3 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
// using Unity.VisualScripting;
|
||
using UnityEngine;
|
||
using Random = UnityEngine.Random;
|
||
|
||
public class GameManager : MonoBehaviour
|
||
{
|
||
public static GameManager ins;
|
||
private JsonTab _tab;
|
||
public bool start;
|
||
public Camera mainCamera;
|
||
public int level => levelID;
|
||
private int levelID;
|
||
public List<ItemData> itemDatas;
|
||
public List<ItemData> itemDatas1;
|
||
public List<ItemData> itemDatas2;
|
||
public List<RandomItemData> list;
|
||
|
||
public ItemObj seletObj
|
||
{
|
||
get { return seletItem; }
|
||
set
|
||
{
|
||
seletItem = value;
|
||
if (seletUnlock!=null)
|
||
{
|
||
seletUnlock.transform.position = MapManager.ins.lockParent.position;
|
||
seletUnlock = null;
|
||
}
|
||
}
|
||
}
|
||
|
||
private ItemObj seletItem;
|
||
|
||
public UnLockGrid seletUnlock
|
||
{
|
||
get { return seletLockObj; }
|
||
set
|
||
{
|
||
seletLockObj = value;
|
||
if (seletObj != null)
|
||
{
|
||
ItemSystem.ins.GetGridsRest(seletObj.startGrid, seletObj);
|
||
seletObj = null;
|
||
}
|
||
}
|
||
}
|
||
private UnLockGrid seletLockObj;
|
||
public Grid stopGrid;
|
||
private Vector3 oldvec;
|
||
public int index = 2;
|
||
[SerializeField] private float scale=0.2f;
|
||
private void Awake()
|
||
{
|
||
ins = this;
|
||
_tab = new JsonTab();
|
||
_tab.InitData();
|
||
}
|
||
|
||
private void Start()
|
||
{
|
||
|
||
}
|
||
|
||
public void ResetPack()
|
||
{
|
||
start = true;
|
||
index = 2;
|
||
// var indexID = Random.Range(0, 4);
|
||
// switch (indexID)
|
||
// {
|
||
// case 0:
|
||
// ItemSystem.ins.InitItem(itemDatas);
|
||
// break;
|
||
// case 1:
|
||
// ItemSystem.ins.InitItem(itemDatas1);
|
||
// break;
|
||
// case 2:
|
||
// ItemSystem.ins.InitItem(itemDatas2);
|
||
// break;
|
||
// default:
|
||
// ItemSystem.ins.InitItem(itemDatas);
|
||
// break;
|
||
// }
|
||
ItemSystem.ins.RandomItem(list);
|
||
MapManager.ins.PlayBoxOpen();
|
||
MapManager.ins.ResetLockGrid();
|
||
ItemSystem.ins.ResetItemOrder();
|
||
}
|
||
|
||
public void PackEvent()
|
||
{
|
||
index--;
|
||
if (index<=0)
|
||
{
|
||
bool win = true;
|
||
foreach (var item in ItemSystem.ins.itemObjs)
|
||
{
|
||
if (item.type==GridType.wait)
|
||
{
|
||
win = false;
|
||
}
|
||
}
|
||
|
||
if (win)
|
||
{
|
||
MainPanel.ins.Win();
|
||
}
|
||
else
|
||
{
|
||
MainPanel.ins.Lose();
|
||
}
|
||
|
||
start = false;
|
||
MapManager.ins.PlayBoxClose();
|
||
return;
|
||
}
|
||
else
|
||
{
|
||
MapManager.ins.PlayBoxClose(()=>
|
||
{
|
||
MapManager.ins.PlayBoxOpen();
|
||
});
|
||
}
|
||
|
||
ItemSystem.ins.PackItem();
|
||
}
|
||
private void Update()
|
||
{
|
||
if (Input.GetMouseButtonDown(0))
|
||
{
|
||
oldvec = Input.mousePosition;
|
||
}
|
||
if (Input.GetMouseButtonUp(0))
|
||
{
|
||
if (seletUnlock!=null )
|
||
{
|
||
if (stopGrid!=null&& MapManager.ins.UnLockOpen(stopGrid,seletUnlock.openData))
|
||
{
|
||
MapManager.ins.LockRayRest(stopGrid, seletUnlock.openData,out var bo);
|
||
MapManager.ins.ResetRayLockGrid();
|
||
seletUnlock.transform.position = MapManager.ins.lockParent.position;
|
||
seletUnlock = null;
|
||
}
|
||
}
|
||
if (seletObj!=null)
|
||
{
|
||
if (stopGrid.GetItemObj()!=null&& stopGrid.GetItemObj()!=seletObj)
|
||
{
|
||
ItemSystem.ins.ItemLevelUp(stopGrid.GetItemObj(), seletObj);
|
||
foreach (var item in ItemSystem.ins.itemObjs)
|
||
{
|
||
item.Reset();
|
||
}
|
||
|
||
foreach (var grid in MapManager.ins.WaitList)
|
||
{
|
||
grid.ResetWaitBack();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (MapManager.ins.openSave(stopGrid,seletObj))
|
||
{
|
||
foreach (var grid in seletObj._grids)
|
||
{
|
||
switch (grid.Type)
|
||
{
|
||
case GridType.box:
|
||
grid.item = null;
|
||
break;
|
||
case GridType.wait:
|
||
grid.Pop();
|
||
break;
|
||
default:
|
||
throw new ArgumentOutOfRangeException();
|
||
}
|
||
}
|
||
|
||
seletObj.startGrid = stopGrid;
|
||
ItemSystem.ins.GetGridsRest(seletObj.startGrid, seletObj);
|
||
foreach (var item in ItemSystem.ins.itemObjs)
|
||
{
|
||
item.Reset();
|
||
}
|
||
|
||
foreach (var grid in MapManager.ins.WaitList)
|
||
{
|
||
grid.ResetWaitBack();
|
||
}
|
||
}
|
||
}
|
||
if (seletObj!=null)
|
||
{
|
||
ItemSystem.ins.SetPosition(seletObj, seletObj.startGrid);
|
||
}
|
||
|
||
|
||
|
||
ItemSystem.ins.ResetItemOrder();
|
||
stopGrid = null;
|
||
seletObj = null;
|
||
MapManager.ins.ResetAnimation();
|
||
}
|
||
|
||
|
||
|
||
}
|
||
|
||
if (seletObj!=null)
|
||
{
|
||
Ray rays = mainCamera.ScreenPointToRay(Input.mousePosition);
|
||
RaycastHit hits;
|
||
if (Physics.Raycast(rays, out hits))
|
||
{
|
||
//射线检测,第三个参数可根据需求设置或不设置,具体看api;
|
||
Physics.Raycast(rays, out hits, 500000);
|
||
Vector3 mousePos = hits.point+seletObj.mouseDev;
|
||
if (MapManager.ins.GetRegionGridType(mousePos,out var type))
|
||
{
|
||
MapManager.ins.RegionGrid(mousePos, type, out var grid);
|
||
if (stopGrid!=grid)
|
||
{
|
||
stopGrid = grid;
|
||
MapManager.ins.RegionGridBack(stopGrid, seletObj.itemSize.x+stopGrid.X, seletObj.itemSize.y+stopGrid.Y);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
if (seletUnlock!=null)
|
||
{
|
||
Ray rays = mainCamera.ScreenPointToRay(Input.mousePosition);
|
||
RaycastHit hits;
|
||
if (Physics.Raycast(rays, out hits))
|
||
{
|
||
//射线检测,第三个参数可根据需求设置或不设置,具体看api;
|
||
Physics.Raycast(rays, out hits, 500000);
|
||
Vector3 mousePos = hits.point + seletUnlock.mouseDev;
|
||
if (MapManager.ins.GetRegionGridType(mousePos,out var type))
|
||
{
|
||
MapManager.ins.RegionGrid(mousePos, type, out var grid);
|
||
if (stopGrid!=grid)
|
||
{
|
||
stopGrid = grid;
|
||
MapManager.ins.RayToutchGrid(stopGrid, seletUnlock.openData);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if (Input.GetMouseButton(0) && seletObj!=null&& start)
|
||
{
|
||
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
|
||
RaycastHit hit;
|
||
//射线检测,第三个参数可根据需求设置或不设置,具体看api;
|
||
Physics.Raycast(ray, out hit, 500000);
|
||
Vector3 mousePos = hit.point;
|
||
seletObj.transform.position = mousePos;
|
||
}
|
||
|
||
if (Input.GetMouseButton(0) && seletUnlock!= null && start)
|
||
{
|
||
Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition);
|
||
RaycastHit hit;
|
||
//射线检测,第三个参数可根据需求设置或不设置,具体看api;
|
||
Physics.Raycast(ray, out hit, 500000);
|
||
Vector3 mousePos = hit.point;
|
||
seletUnlock.transform.position = mousePos;
|
||
}
|
||
}
|
||
}
|