Пример #1
0
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            baseManager.TogglePauseMenu(isPaused);
            isPaused = !isPaused;
        }

        if (!isPaused)
        {
            if (Input.GetKeyDown(KeyCode.Mouse1))
            {
                CloseAllMenus();
                selectedObject    = null;
                villagerReference = null;
                buildingReference = null;
                resourceReference = null;
            }

            if (!EventSystem.current.IsPointerOverGameObject())
            {
                if (Input.GetKeyDown(KeyCode.Mouse0))
                {
                    //Debug.Log ("Mouse Click");
                    selectedObject = FindObjectUnderMouse();

                    if (selectedObject != null)
                    {
                        //Debug.Log ("Object Selected");

                        if (selectedObject.GetComponent <BaseVillager>())
                        {
                            //Debug.Log ("Villager Found");

                            if (villagerReference == null)
                            {
                                villagerReference = selectedObject.GetComponent <BaseVillager>();

                                villagerReference.SetSelected(true);
                                OpenCharacterInfoPanel();
                            }
                            else
                            {
                                CloseCharacterInfoPanel();
                            }

                            if (buildingReference != null)
                            {
                                CloseBuildingInfoPanel();
                            }
                        }
                        else if (selectedObject.GetComponent <ResourceTile>())
                        {
                            //Debug.Log ("Resources Found");
                            resourceReference = selectedObject.GetComponent <ResourceTile>();

                            if (villagerReference != null)
                            {
                                //Debug.Log ("Setting Work Area (Controller)");
                                villagerReference.SelectWorkArea(resourceReference.gameObject);

                                CloseCharacterInfoPanel();
                            }

                            if (buildingReference != null)
                            {
                                CloseBuildingInfoPanel();
                            }

                            resourceReference = null;
                        }
                        else if (selectedObject.GetComponent <BaseBuilding>())
                        {
                            //Debug.Log ("Building Found");

                            if (buildingReference != null)
                            {
                                //Close panel and remove reference
                                CloseBuildingInfoPanel();
                            }
                            else
                            {
                                //Set building reference and open info panel
                                buildingReference = selectedObject.GetComponent <BaseBuilding>();
                                if (buildingReference.IsBuilt() == true)
                                {
                                    OpenBuildingInfoPanel();
                                }
                                else
                                {
                                    buildingReference = null;
                                }
                            }

                            if (villagerReference != null)
                            {
                                //buildingReference.OnClicked(villagerReference);

                                CloseCharacterInfoPanel();
                            }
                        }
                        else if (villagerReference != null)
                        {
                            Ray hitPosition = Camera.main.ScreenPointToRay(Input.mousePosition);

                            if (Physics.Raycast(hitPosition, out hit, Mathf.Infinity))
                            {
                                villagerReference.SetTargetPosition(new Vector3(hit.point.x, 0, hit.point.z));
                            }

                            CloseCharacterInfoPanel();
                        }
                    }
                    else
                    {
                        //Debug.Log ("Object is null");
                    }
                }
            }
        }
    }