コード例 #1
0
    private void PlacingMode()
    {
        levelManager.GetLevelCamera().SetRotationLock(true);

        if (OverUI())
        {
            return;
        }

        interactionRay = Camera.main.ScreenPointToRay(Input.mousePosition);
        if (Physics.Raycast(interactionRay, out hitInfo))
        {
            if (string.CompareOrdinal(hitInfo.collider.gameObject.tag, "Tile") == 0)
            {
                placedOnTile = hitInfo.collider.gameObject.GetComponent <Tile>();

                if (!objectGhost.activeSelf)
                {
                    objectGhost.SetActive(true);
                }
                objectGhost.transform.position = hitInfo.collider.transform.position;

                if (Input.GetMouseButtonDown(0))
                {
                    if (objectGhost.GetComponentInChildren <ObjectGhost>().IsPlaceable())
                    {
                        NullSelectedObject();
                        placingObject.GetComponent <Animator>().SetBool("Placing", false);
                        if (economyManager.CheckCanAfford(ObjectToPlace.BuyCost))
                        {
                            GameObject temp = InstantiateNewObject(ObjectToPlace, hitInfo.collider.gameObject.transform.position, objectGhost.transform.rotation, placedOnTile);
                            objectGhost.GetComponentInChildren <ObjectGhost>().OnPlaced(temp);
                            ObjectToPlace = null;
                        }
                    }
                    else
                    {
                        print("Something is blocking this tile!");
                    }
                }
            }
            else if (string.CompareOrdinal(hitInfo.collider.gameObject.tag, "Object") == 0)
            {
                if (hitInfo.collider.gameObject.name != "Top")
                {
                    placedOnTile = GetNearestTile(hitInfo.collider);
                }
                if (!objectGhost.activeSelf)
                {
                    objectGhost.SetActive(true);
                }
                objectGhost.transform.position = placedOnTile.transform.position;

                if (Input.GetMouseButtonDown(0))
                {
                    if (objectGhost.GetComponentInChildren <ObjectGhost>().IsPlaceable())
                    {
                        NullSelectedObject();
                        if (economyManager.CheckCanAfford(ObjectToPlace.BuyCost))
                        {
                            GameObject temp = InstantiateNewObject(ObjectToPlace, objectGhost.transform.position, objectGhost.transform.rotation, placedOnTile);
                            objectGhost.GetComponentInChildren <ObjectGhost>().OnPlaced(temp);
                            ObjectToPlace = null;
                        }
                    }
                }
            }
            else if (string.CompareOrdinal(hitInfo.collider.gameObject.tag, "Wall") == 0)
            {
                if (hitInfo.collider.gameObject.name != "Top")
                {
                    placedOnTile = GetNearestTileWallVersion(hitInfo.collider);
                }
                if (!objectGhost.activeSelf)
                {
                    objectGhost.SetActive(true);
                }
                objectGhost.transform.position = placedOnTile.transform.position;
                if (Input.GetMouseButtonDown(0))
                {
                    if (objectGhost.GetComponentInChildren <ObjectGhost>().IsPlaceable())
                    {
                        NullSelectedObject();
                        if (economyManager.CheckCanAfford(ObjectToPlace.BuyCost))
                        {
                            GameObject temp = InstantiateNewObject(ObjectToPlace, objectGhost.transform.position, objectGhost.transform.rotation, placedOnTile);
                            objectGhost.GetComponentInChildren <ObjectGhost>().OnPlaced(temp);
                            ObjectToPlace = null;
                        }
                    }
                }
            }
            else if (string.CompareOrdinal(hitInfo.collider.gameObject.tag, "Ghost") == 0)
            {
                print("Touching ghost! This shouldn't happen!");
            }
            else
            {
                objectGhost.SetActive(false);
                objectGhost.gameObject.GetComponentInChildren <ObjectGhost>().ClearAll();
            }
        }
        ObjectInteraction();
    }