public void SetSelet(GameObject item) { if (isSelect) { SetGridItem(item, selectOffset); selectItem = item.GetComponent <ShipItem> (); MyTools.SetObjActive(selectEffect, false); MessageCenter.SendMessage("MainPanelCount", "1", 1); } }
public void SetGridItem(GameObject item, Vector2 offset, bool isPutIn = true) { Vector3 pos = playGrid.GetGridPos(offset); item.transform.SetParent(traContainer); item.transform.position = traContainer.position + pos; if (isPutIn) { playGrid.SetGridItem(item, offset); ShipItem shipItem = item.GetComponent <ShipItem> (); if (shipItem != null) { shipItem.bulletPool = bulletPool; } } }
// Update is called once per frame void Update() { if (GameController.Instance.gameMode == Mode.edit) { if (Input.GetMouseButtonDown(0)) { #if IPHONE || ANDROID if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) { #else if (EventSystem.current.IsPointerOverGameObject()) { #endif Debuger.Log("当前触摸在UI上"); } else { Debuger.Log("当前没有触摸在UI上"); Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpaceZ)); Vector3 offset = pos - transform.position; if (playGrid.Container(offset)) { isSelect = true; GameObject obj = playGrid.GetGridItem(offset); if (obj == null) { SetGridItem(selectEffect, offset, false); MyTools.SetObjActive(selectEffect, true); selectOffset = offset; MessageCenter.SendMessage("MainPanelCount", "0", 0); } else { selectItem = obj.GetComponent <ShipItem> (); MyTools.SetObjActive(selectEffect, false); MessageCenter.SendMessage("MainPanelCount", "1", 1); } } else { MyTools.SetObjActive(selectEffect, false); selectItem = null; isSelect = false; Debug.Log("在飞船外面"); } } } } else if (GameController.Instance.gameMode == Mode.fight) { if (Input.GetMouseButtonUp(0)) { isHold = false; } if (Input.GetMouseButtonDown(0)) { Vector3 pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpaceZ)); Vector3 offset = pos - transform.position; if (playGrid.Container(offset)) { GameObject obj = playGrid.GetGridItem(offset); if (obj != null) { selectItem = obj.GetComponent <ShipItem> (); if (selectItem.type == ItemType.playerCore) { isHold = true; mouseOffset = offset; } } } } if (isHold) { transform.position = -mouseOffset + Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpaceZ)); } } }