Esempio n. 1
0
    private void Start()
    {
        if (CheckButtonsNotAssigned())
        {
            Debug.LogError("You must set buttons in the inspector");
            enabled = false;
            return;
        }

        _dotButton.onClick.AddListener(() =>
        {
            HandleButtonClick(_dotButton, ActionType.Dot);
        });

        _lineButton.onClick.AddListener(() =>
        {
            HandleButtonClick(_lineButton, ActionType.Line);
        });

        _parallelLineButton.onClick.AddListener(() =>
        {
            HandleButtonClick(_parallelLineButton, ActionType.ParallelLine);
        });

        _rotateButton.onClick.AddListener(() =>
        {
            CreateNewConstructionHelper.ResetAction();

            var shape = GameObject.Find($"{Game.CurrentLevelData.Type.ToString()}Core");

            shape.transform.localRotation = Quaternion.identity;
            shape.transform.Rotate(-8, -12, 0.5f);
        });

        _crossSectionButton.onClick.AddListener(() =>
        {
            HandleButtonClick(_crossSectionButton, ActionType.CrossSection);

            GameOkButton.Enable(CreateNewConstructionHelper.Action == ActionType.CrossSection);
        });

        _checkButton.onClick.AddListener(() =>
        {
            CreateNewConstructionHelper.ResetAction();

            CreateNewConstructionHelper.Action = ActionType.Check;
            CreateNewConstructionHelper.CreateObject();
        });

        _createButton.onClick.AddListener(CreateNewConstructionHelper.CreateObject);
    }
Esempio n. 2
0
    private void HandleButtonClick(Button button, ActionType actionType)
    {
        string currentImageName = button.gameObject.GetComponent <Image>().sprite.name;

        if (CreateNewConstructionHelper.Action == actionType)
        {
            CreateNewConstructionHelper.ResetAction();
            button.gameObject.GetComponent <Image>().sprite = GetNotFilledSprite(currentImageName);
        }
        else
        {
            ResetButtonByActionType(CreateNewConstructionHelper.Action);
            CreateNewConstructionHelper.Action = actionType;
            button.gameObject.GetComponent <Image>().sprite = GetFilledSprite(currentImageName);
        }
    }
Esempio n. 3
0
    private void ProcessSingleTouch()
    {
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, 100.0f))
        {
            if (hit.collider.transform != null)
            {
                GameObject hitObject = hit.collider.transform.gameObject;

                switch (hitObject.tag)
                {
                case Tags.Edge:
                {
                    if (CreateNewConstructionHelper.Action == ActionType.Dot ||
                        CreateNewConstructionHelper.Action == ActionType.ParallelLine)
                    {
                        if (CreateNewConstructionHelper.Action == ActionType.ParallelLine &&
                            CreateNewConstructionHelper.SelectedObjects.Count == 1 &&
                            CreateNewConstructionHelper.SelectedObjects[0].CompareTag(Tags.Edge))
                        {
                            return;
                        }

                        GameObject parentObject = hitObject.transform.parent.gameObject;

                        CreateNewConstructionHelper.SelectedObjects.Add(parentObject);
                        var renderer = parentObject.GetComponent <Renderer>();
                        renderer.material.color = Color.magenta;

                        if (CreateNewConstructionHelper.SelectedObjects.Count == 2)
                        {
                            CreateNewConstructionHelper.CreateObject();
                        }
                    }

                    break;
                }

                case Tags.Dot:
                {
                    if (CreateNewConstructionHelper.Action == ActionType.Line ||
                        CreateNewConstructionHelper.Action == ActionType.ParallelLine ||
                        CreateNewConstructionHelper.Action == ActionType.CrossSection)
                    {
                        if (CreateNewConstructionHelper.Action == ActionType.ParallelLine &&
                            CreateNewConstructionHelper.SelectedObjects.Count == 1 &&
                            CreateNewConstructionHelper.SelectedObjects[0].CompareTag(Tags.Dot))
                        {
                            return;
                        }

                        CreateNewConstructionHelper.SelectedObjects.Add(hitObject);

                        var renderer = hitObject.GetComponent <Renderer>();
                        renderer.material.color = Color.magenta;

                        if (CreateNewConstructionHelper.SelectedObjects.Count == 2 &&
                            CreateNewConstructionHelper.Action != ActionType.CrossSection)
                        {
                            CreateNewConstructionHelper.CreateObject();
                        }
                    }

                    break;
                }
                }
            }
        }
    }
Esempio n. 4
0
    private void ProcessTouchOnShapeComponents()
    {
        if (Input.touchCount == 1)
        {
            Touch touch = Input.GetTouch(0);
            _touchPosition = touch.position;

            if (touch.phase == TouchPhase.Began)
            {
                Ray ray = _arCamera.ScreenPointToRay(touch.position);
                if (Physics.Raycast(ray, out RaycastHit hitObject))
                {
                    switch (hitObject.transform.tag)
                    {
                    case Tags.Edge:
                    {
                        if (CreateNewConstructionHelper.Action == ActionType.Dot || CreateNewConstructionHelper.Action == ActionType.ParallelLine)
                        {
                            if (CreateNewConstructionHelper.Action == ActionType.ParallelLine && CreateNewConstructionHelper.SelectedObjects.Count == 1 &&
                                CreateNewConstructionHelper.SelectedObjects[0].tag == Tags.Edge)
                            {
                                return;
                            }

                            GameObject parentObject = hitObject.transform.parent.gameObject;

                            CreateNewConstructionHelper.SelectedObjects.Add(parentObject);

                            var renderer = parentObject.GetComponent <Renderer>();
                            renderer.material.color = Color.magenta;

                            if (CreateNewConstructionHelper.SelectedObjects.Count == 2)
                            {
                                CreateNewConstructionHelper.CreateObject();
                            }
                        }

                        break;
                    }

                    case Tags.Dot:
                    {
                        if (CreateNewConstructionHelper.Action == ActionType.Line || CreateNewConstructionHelper.Action == ActionType.CrossSection ||
                            CreateNewConstructionHelper.Action == ActionType.ParallelLine)
                        {
                            if (CreateNewConstructionHelper.Action == ActionType.ParallelLine && CreateNewConstructionHelper.SelectedObjects.Count == 1 &&
                                CreateNewConstructionHelper.SelectedObjects[0].tag == Tags.Dot)
                            {
                                return;
                            }

                            CreateNewConstructionHelper.SelectedObjects.Add(hitObject.transform.gameObject);

                            var hitObjectRenderer = hitObject.transform.GetComponent <Renderer>();
                            hitObjectRenderer.material.color = Color.magenta;

                            if (CreateNewConstructionHelper.SelectedObjects.Count == 2 &&
                                CreateNewConstructionHelper.Action != ActionType.CrossSection)
                            {
                                CreateNewConstructionHelper.CreateObject();
                            }
                        }

                        break;
                    }

                    default:
                    {
                        PlacementObject placementObject = hitObject.transform.GetComponent <PlacementObject>();
                        if (placementObject != null)
                        {
                            _onTouchHold = true;
                        }

                        break;
                    }
                    }
                }
            }

            if (touch.phase == TouchPhase.Ended)
            {
                _onTouchHold = false;
            }
        }
    }