using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Random = UnityEngine.Random; public class GameManager : MonoBehaviour { public static GameManager ins; public bool start; public Camera mainCamera; public List itemDatas; public List itemDatas1; public List itemDatas2; public ItemObj seletObj; public Grid stopGrid; private Vector3 oldvec; public int index = 2; [SerializeField] private float scale=0.2f; private void Awake() { ins = this; } 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; } MapManager.ins.PlayBoxOpen(); } 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 (seletObj==null) { return; } if (MapManager.ins.openSave(stopGrid,seletObj)) { foreach (var grid in seletObj._grids) { grid.item = null; } seletObj.startGrid = stopGrid; ItemSystem.ins.GetGridsRest(seletObj.startGrid, seletObj); } ItemSystem.ins.SetPosition(seletObj, seletObj.startGrid); 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); Debug.LogError(grid.X+" "+grid.Y); if (stopGrid!=grid) { stopGrid = grid; MapManager.ins.RegionGridBack(stopGrid, seletObj.itemSize.x+stopGrid.X, seletObj.itemSize.y+stopGrid.Y); } } } } 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; } } }