Exemple #1
0
    void Update()
    {
        ctrD++;
        sumD += Time.deltaTime;
        Body.transform.localPosition = Vector3.zero;
        if (Input.GetMouseButtonDown(0))
        {
            if (!inventoryOpen && !marketInventoryOpen && !OrdersMenuController.open)
            {
                if (Time.time < InitialTouch + 0.5f)
                {
                    agent.speed = SPEED * 2;
                    Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;
                    faster = true;
                    if (Physics.Raycast(ray, out hit))
                    {
                        agent.SetDestination(hit.point);
                    }
                }
                else
                {
                    agent.speed = SPEED;
                    Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    RaycastHit hit;
                    faster = false;
                    if (Physics.Raycast(ray, out hit) && !BuyingPanelController.atBuyingPanel)
                    {
                        if (hit.transform.CompareTag("station"))
                        {
                            if (Vector3.Magnitude(hit.point - transform.position) < 10)
                            {
                                inventoryOpen = true;
                                inventory.SetActive(true);
                                //inventory.transform.position = Input.mousePosition;
                                current = hit.transform.gameObject;
                                RecipeController.recipes = hit.transform.GetComponent <Station>().Outputs;
                                foreach (GameObject item in hit.transform.GetComponent <Station>().Outputs)
                                {
                                    GameObject recipe = Instantiate(Recipe, RecipeBook.transform);
                                    Image      image  = recipe.transform.GetChild(2).GetComponent <Image>();
                                    image.transform.localScale *= 0.6f;
                                    Text text = recipe.transform.GetChild(0).GetComponent <Text>();
                                    text.text = item.name.ToUpper();
                                    if (item.GetComponent <MealMaterial>())
                                    {
                                        image.sprite = item.GetComponent <MealMaterial>().image;
                                    }
                                    else if (item.GetComponent <Meal>())
                                    {
                                        image.sprite = item.GetComponent <Meal>().image;
                                    }
                                }
                                FindObjectOfType <RecipeController>().GetToggles();
                            }
                        }
                        else if (hit.transform.parent != null)
                        {
                            if (hit.transform.parent.CompareTag("station"))
                            {
                                if (Vector3.Magnitude(hit.point - transform.position) < 10)
                                {
                                    inventoryOpen = true;
                                    inventory.SetActive(true);
                                    //inventory.transform.position = Input.mousePosition;
                                    current = hit.transform.parent.gameObject;
                                    RecipeController.recipes = hit.transform.parent.GetComponent <Station>().Outputs;
                                    foreach (GameObject item in hit.transform.parent.GetComponent <Station>().Outputs)
                                    {
                                        GameObject recipe = Instantiate(Recipe, RecipeBook.transform);
                                        Image      image  = recipe.transform.GetChild(2).GetComponent <Image>();
                                        Text       text   = recipe.transform.GetChild(0).GetComponent <Text>();
                                        text.text = item.name;
                                        if (item.GetComponent <MealMaterial>())
                                        {
                                            image.sprite = item.GetComponent <MealMaterial>().image;
                                        }
                                        else if (item.GetComponent <Meal>())
                                        {
                                            image.sprite = item.GetComponent <Meal>().image;
                                        }
                                    }
                                    GameObject.FindObjectOfType <RecipeController>().GetToggles();
                                }
                            }
                            if (hit.transform.parent.CompareTag("delivery"))
                            {
                                if (Vector3.Magnitude(hit.point - transform.position) < 30)
                                {
                                    OrdersMenuController.open           = true;
                                    OrdersMenuController.atOrderStation = true;
                                }
                            }
                        }
                        else if (hit.transform.CompareTag("market"))
                        {
                            if (Vector3.Magnitude(hit.point - transform.position) < 30)
                            {
                                marketInventoryOpen = true;
                                marketInventory.SetActive(true);
                                marketInventory.transform.position =
                                    new Vector3(Screen.width / 2 - marketInventory.GetComponent <RectTransform>().rect.width
                                                , Screen.height / 2 - marketInventory.GetComponent <RectTransform>().rect.y);
                                current = hit.transform.gameObject;
                            }
                        }
                        else if (hit.transform.CompareTag("delivery"))
                        {
                            if (Vector3.Magnitude(hit.point - transform.position) < 30)
                            {
                                OrdersMenuController.open           = true;
                                OrdersMenuController.atOrderStation = true;
                                current = hit.transform.gameObject;
                            }
                        }
                        agent.SetDestination(hit.point);
                    }
                }
                InitialTouch = Time.time;
            }
            else
            {
                GraphicRaycaster gr  = inventory.GetComponent <GraphicRaycaster>();
                PointerEventData ped = new PointerEventData(null);
                ped.position = Input.mousePosition;
                List <RaycastResult> results = new List <RaycastResult>();
                gr.Raycast(ped, results);
                GraphicRaycaster gr2  = marketInventory.GetComponent <GraphicRaycaster>();
                PointerEventData ped2 = new PointerEventData(null);
                ped2.position = Input.mousePosition;
                List <RaycastResult> results2 = new List <RaycastResult>();
                gr2.Raycast(ped2, results2);
                GraphicRaycaster gr3  = charInventory.GetComponent <GraphicRaycaster>();
                PointerEventData ped3 = new PointerEventData(null);
                ped3.position = Input.mousePosition;
                List <RaycastResult> results3 = new List <RaycastResult>();
                gr3.Raycast(ped3, results3);
                // Debug.Log(results3.Count);
                foreach (var item in results)
                {
                }
                if (results.Count > 0)
                {
                }
                else if (results2.Count > 0)
                {
                }
                else if (results3.Count > 0)
                {
                }
                else
                {
                    if (kralinYarra)
                    {
                        kralinYarra = false;
                    }
                    else
                    {
                        Debug.Log("buraya girdi");
                        if (GameObject.FindGameObjectWithTag("stationAdjuster"))
                        {
                            GameObject.FindGameObjectWithTag("stationAdjuster").SetActive(false);
                        }
                        if (inventoryOpen)
                        {
                            ImageCreator.Closure();
                        }
                        RecipeBook.GetComponent <RecipeController>().clean();
                        inventoryOpen       = false;
                        marketInventoryOpen = false;
                        inventory.SetActive(false);
                        marketInventory.SetActive(false);
                        PlayerController.current = null;
                        foreach (GameObject item in PlayerSlot.adjusters)
                        {
                            if (item)
                            {
                                item.SetActive(false);
                            }
                        }
                    }


                    /*OrdersMenuController.open = false;
                     * OrdersMenuController.atStation = false;*/
                }
            }
        }

        if (agent.velocity.magnitude > 0.1f)
        {
            if (faster)
            {
                animator.SetFloat("Speed_f", 30);
            }
            else
            {
                animator.SetFloat("Speed_f", 3);
            }
        }
        else
        {
            animator.SetFloat("Speed_f", 0);
        }
    }