public void PlaceGridPiece(GameObject goToPlace) { if (myGridObject == null) { GameObject newObj = (GameObject)(Instantiate(goToPlace, this.transform.position, Quaternion.identity, this.transform)); myGridObject = newObj.GetComponent <GridGameObject>(); myGridObject.SetMyPiece = this; myGridObject.Create(); myGridObject.Init(); } }
public void DeleteGridObj() { if (myGridObject != null) { GameObject DeleteMe = myGridObject.gameObject; ResourceManager.rManager.curResource += myGridObject.buildCost; myGridObject.StopNeighbors(); Destroy(DeleteMe); myGridObject = null; } }
void ManageTouch() { if (RunFactory.run) { return; } for (int touchi = 0; touchi < Input.touchCount; touchi++) // if(Input.touchCount > 0) { if ((Input.GetTouch(touchi).phase == TouchPhase.Began)) // if(true) { Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(touchi).position); RaycastHit hit; if (es.IsPointerOverGameObject(touchi)) { return; } if (Physics.Raycast(ray, out hit)) { // if (!(hit.transform is RectTransform)) // { //Debug.Log(hit.transform.name); if (hit.transform.parent.transform.GetComponent <GridPiece>() != null) { if ((hit.transform.parent.transform.GetComponent <GridPiece>().GridObj != null) && hit.transform.parent.transform.GetComponent <GridPiece>().GridObj.gameObject.GetComponent <Description>() != null) { ToolTip.getTT.setTT(hit.transform.parent.transform.GetComponent <GridPiece>().GridObj.gameObject.GetComponent <Description>().myDescription); } if (editObj != null) { editPanel.gameObject.SetActive(false); editObj = null; } if (ObjToSpawn != null && !hit.transform.parent.transform.GetComponent <GridPiece>().hasGridObject&& (ObjToSpawn.GetComponent <GridGameObject>().buildCost <= ResourceManager.rManager.curResource)) { ResourceManager.rManager.curResource -= ObjToSpawn.GetComponent <GridGameObject>().buildCost; hit.transform.parent.transform.GetComponent <GridPiece>().PlaceGridPiece(ObjToSpawn); // ObjToSpawn = null; } else { if (hit.transform.parent.transform.GetComponent <GridPiece>().hasGridObject&& hit.transform.parent.GetComponent <GridPiece>().isEditable) { editObj = hit.transform.parent.transform.GetComponent <GridPiece>().GridObj; EditObj(); } } } } } } // } }
void ManageInput() { if (RunFactory.run) { return; } if ((Input.GetMouseButtonDown(0))) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (es.IsPointerOverGameObject()) { return; } if (Physics.Raycast(ray, out hit)) { // if (!(hit.transform is RectTransform)) // { // Debug.Log(hit.transform.name); if (hit.transform.parent.transform.GetComponent <GridPiece>() != null) { if ((hit.transform.parent.transform.GetComponent <GridPiece>().GridObj != null) && hit.transform.parent.transform.GetComponent <GridPiece>().GridObj.gameObject.GetComponent <Description>() != null) { ToolTip.getTT.setTT(hit.transform.parent.transform.GetComponent <GridPiece>().GridObj.gameObject.GetComponent <Description>().myDescription); } // if (editObj == null) if (editObj != null) { editPanel.gameObject.SetActive(false); editObj = null; } if (ObjToSpawn != null && !hit.transform.parent.transform.GetComponent <GridPiece>().hasGridObject&& (ObjToSpawn.GetComponent <GridGameObject>().buildCost <= ResourceManager.rManager.curResource)) { ResourceManager.rManager.curResource -= ObjToSpawn.GetComponent <GridGameObject>().buildCost; hit.transform.parent.transform.GetComponent <GridPiece>().PlaceGridPiece(ObjToSpawn); // ObjToSpawn = null; } else { if (hit.transform.parent.transform.GetComponent <GridPiece>().hasGridObject&& hit.transform.parent.GetComponent <GridPiece>().isEditable) { editObj = hit.transform.parent.transform.GetComponent <GridPiece>().GridObj; EditObj(); } } // } // else // { // editPanel.gameObject.SetActive(false); // editObj = null; // } // } } } } }
// Use this for initialization void Start() { AnimStateCont = GetComponent <GridGameObject>(); myAnimator = gameObject.GetComponentInChildren <Animator>(); }
public GridGameObject GetNeighbor(IOStreamDir dirToCheck) { GridGameObject returnObj = null; switch (dirToCheck) { case IOStreamDir.Top: // bool hasNeighbor = myGrid.hasNeighbor(wPos, hPos + 1); if (myGrid.getGridPiece(wPos, hPos - 1) != null) { if (myGrid.getGridPiece(wPos, hPos - 1).hasGridObject) { returnObj = myGrid.getGridPiece(wPos, hPos - 1).GridObj; if (returnObj.StreamInputs.Contains(IOStreamDir.Bottom)) { } else { returnObj = null; } } } break; case IOStreamDir.Right: if (myGrid.getGridPiece(wPos + 1, hPos) != null) { if (myGrid.getGridPiece(wPos + 1, hPos).hasGridObject) { returnObj = myGrid.getGridPiece(wPos + 1, hPos).GridObj; if (returnObj.StreamInputs.Contains(IOStreamDir.Left)) { } else { returnObj = null; } } } break; case IOStreamDir.Bottom: if (myGrid.getGridPiece(wPos, hPos + 1) != null) { if (myGrid.getGridPiece(wPos, hPos + 1).hasGridObject) { returnObj = myGrid.getGridPiece(wPos, hPos + 1).GridObj; if (returnObj.StreamInputs.Contains(IOStreamDir.Top)) { } else { returnObj = null; } } } break; case IOStreamDir.Left: if (myGrid.getGridPiece(wPos - 1, hPos) != null) { if (myGrid.getGridPiece(wPos - 1, hPos).hasGridObject) { returnObj = myGrid.getGridPiece(wPos - 1, hPos).GridObj; if (returnObj.StreamInputs.Contains(IOStreamDir.Right)) { } else { returnObj = null; } } } break; default: Debug.LogError("Cannot currently support passing :" + dirToCheck); break; } return(returnObj); }