コード例 #1
0
    void Shooting()
    {
        timer.GetDeltaTime(Time.deltaTime);
        timer.TimeMultiplication(shootingSpeed.Value);

        if (Input.GetMouseButton(0) && timer.time > 1f && ammo.HasAmmoInMag())
        {
            Debug.Log(name + " is shooting");
            selector.Check(rayProvider.CreateRay());
            ammo.Shot();


            if (selector.GetSelection() != null)
            {
                selector.GetSelection().GetComponent <Idamageable>().GetDamaged(damage.Value);
            }

            timer.ResetTime(0);
        }
        else if (Input.GetKeyDown(KeyCode.R))
        {
            Debug.Log(name + " Reloaded");
            ammo.Reload();
        }
        else if (!ammo.HasAmmoInMag())
        {
            return;
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        //deselection  response
        if (_currentSelection != null)
        {
            _selectionResponse.OnDeselect(_currentSelection);
        }


        _selector.Check(_rayProvider.CreateRay());

        _currentSelection = _selector.GetSelection();;

        //selection response
        if (_currentSelection != null)
        {
            //if object has prerequisite and is not complete, do nothing
            if (_currentSelection.GetComponent <Prerequisite>() && !_currentSelection.GetComponent <Prerequisite>().Complete)
            {
                return;
            }


            _selectionResponse.OnSelect(_currentSelection);
        }
    }
コード例 #3
0
    private void Update()
    {
        // Create the ray
        Ray ray = rayProvider.CreateRay();

        // Check if the ray hits a selectable object
        selector.check(ray);

        // Get the selection
        selection = selector.GetSelection();

        // Display the UI Element at the selection position if the selection is not null
        if (selection != null && !isInstantiated)
        {
            // Set the position of the transform on the screen
            itemDescription = Instantiate(itemDescriptionPrefab, this.transform);
            itemDescription.transform.position = Camera.main.WorldToScreenPoint(selection.position);

            isInstantiated = true;
        }

        if (!selection)
        {
            Destroy(itemDescription);
            isInstantiated = false;
        }
    }
コード例 #4
0
    // Update is called once per frame
    void Update()
    {
        // Set ray variable to camera center, in FPS controller the mouse is always at the screen center
        // Cast a ray into the distance, if an object is hit, the hit variable will return true
        // Get the location of the object that was hit and then get the object
        // Ensure the object is selectable

        if (Input.touchCount > 0)
        {
            if (Input.touches[0].phase == TouchPhase.Began)
            {
                Debug.Log("Touch Pressed");
                TouchTime = Time.time;
                //print(TouchTime);
                _selector.Check(_rayProvider.CreateRay());
                _initialSelection = _selector.GetSelection();
            }

            if (Input.touches[0].phase == TouchPhase.Ended)
            {
                //print(TouchTime);
                _selector.Check(_rayProvider.CreateRay());
                _currentSelection = _selector.GetSelection();

                Debug.Log("Touch Lifted/Released");
                if (_currentSelection != null && _initialSelection == _currentSelection)
                {
                    var ObjTags = _currentSelection.GetComponent <Tags>();
                    if (ObjTags.hasTag("Combinable"))
                    {
                        updateSelections(_currentSelection);
                    }

                    if (Time.time - TouchTime > 1.0)
                    {
                        //print("QUACK");
                        print(_selector.GetSelection().name);
                        _currentLongSelection = _selector.GetSelection();
                    }
                }
            }
        }
    }
    private void Update()
    {
        if (_currentselection != null)
            _selectionResponse.OnDeselect(_currentselection);

        _selector.Check(_rayProvider.CreateRay());
        _currentselection = _selector.GetSelection();

        if (_currentselection != null)
            _selectionResponse.OnSelect(_currentselection);
    }
コード例 #6
0
ファイル: Select.cs プロジェクト: trident4896/VR-Escape-Room
    private void Update()
    {
        //Deselect
        Deselection();

        //Generate and Check Ray
        _selector.Check_Ray(_RayProvider.Create_Ray());
        Current_Selection = _selector.GetSelection();

        //Select
        Selection();
    }
 private void ClickDestination()
 {
     selector.Check(rayProvider.CreateRay());
     if (selector.GetSelection() != null)
     {
         hitInfo = selector.GetHitInfo();
         SetDestination(hitInfo.point);
         SetWaypoint();
         SetSelected(false);
         animator.SetBool("IsWalking", true);
     }
 }
コード例 #8
0
    void LateUpdate()
    {
        if (_currentSelection != null)
        {
            _selectionResponse.OnDeselect(_currentSelection);
        }

        _selector.Check(_rayProvider.CreateRay());
        _currentSelection = _selector.GetSelection();

        if (_currentSelection != null)
        {
            _selectionResponse.OnHover(_currentSelection);
        }
    }
コード例 #9
0
        // Update is called once per frame
        private void Update()
        {
            if (currectSelection != null)
            {
                selectionResponse.OnDeselect(currectSelection);
            }

            selector.Check(rayProvider.CreateRay());
            currectSelection = selector.GetSelection();

            if (currectSelection != null)
            {
                selectionResponse.OnSelect(currectSelection);
            }
        }
コード例 #10
0
    void Update()
    {
        if (_currentSelection != null)
        {
            _selectionResponse.OnDeselect(_currentSelection);
        }

        var        ray = _rayProvider.CreateRay();
        RaycastHit hit;

        _selector.Check(ray);

        _currentSelection = _selector.GetSelection();
        if (_currentSelection != null)
        {
            _selectionResponse.OnSelect(_currentSelection);
        }
    }
コード例 #11
0
    private void Update()
    {
        //selection
        if (_currentSelection != null)
        {
            _selectionResponse.OnDeselect(_currentSelection);
        }

        //determineSeelection
        _selector.Check(_rayProvider.CreateRay());
        _currentSelection = _selector.GetSelection();

        //selection
        if (_currentSelection != null)
        {
            _selectionResponse.OnSelect(_currentSelection);
        }
    }
コード例 #12
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(KeyCode.E))
     {
         var selection = _selector.GetSelection();
         if (selection != null)
         {
             if (selection.gameObject.layer == LayerMask.NameToLayer("Collectable"))
             {
                 var droppedItem = selection.gameObject.GetComponent <DroppedItem>();
                 if (droppedItem != null)
                 {
                     _inventoryScript.AddItem(droppedItem.Item, droppedItem.Amount);
                     Destroy(selection.gameObject);
                 }
             }
         }
     }
 }
コード例 #13
0
    private void OnMouseEnter()
    {
        // Create the ray
        Ray ray = rayProvider.CreateRay();

        // Check if the ray hits a selectable object
        selector.check(ray);

        // Get the selection
        selection = selector.GetSelection();

        // Display the UI Element at the selection position if the selection is not null
        if (selection != null)
        {
            // Set the position of the transform on the screen
            itemDescription = Instantiate(itemDescriptionPrefab, parentUI);
            itemDescription.transform.position = Camera.main.WorldToScreenPoint(selection.position);
        }
    }
コード例 #14
0
    private void Update()
    {
        #region Raycast & Select
        _selector.Check(_rayProvider.CreateRay());
        var selection = _selector.GetSelection();
        #endregion
        if (IsNewSelection(selection))
        {
            if (_currentSelection != null)
            {
                _selectionResponse.OnDeselect(_currentSelection);
            }
            if (selection != null)
            {
                _selectionResponse.OnSelect(selection);
            }
        }

        _currentSelection = selection;
    }
コード例 #15
0
    private void Update()
    {
        if (_currentSelection != null)
        {
            _selectionResponse.OnDeselect(_currentSelection);
            _hoverResponse.OnDeselect(_currentSelection);
        }

        _selector.Check(_rayProvider.CreateRay());
        _currentSelection = _selector.GetSelection();

        if (_currentSelection != null)
        {
            _selectionResponse.OnSelect(_currentSelection);
            if (_currentSelection.CompareTag("Selectable"))
            {
                if (pointer != null)
                {
                    pointer.GetComponent <Image>().enabled = true;

                    //When click, execute the action on IClickResponse
                    if (Input.GetKeyDown(action))
                    {
                        _clickResponse.OnClick(_currentSelection);
                    }
                }
            }
            else if (_currentSelection.CompareTag("Hoverable"))
            {
                _hoverResponse.OnSelect(_currentSelection);
            }
        }
        else
        {
            if (pointer != null)
            {
                pointer.GetComponent <Image>().enabled = false;
            }
        }
    }
コード例 #16
0
    // Update is called once per frame
    void Update()
    {
        if (!dragging && Input.GetMouseButtonDown(0))
        {
            start    = cam.ScreenToViewportPoint(Input.mousePosition);
            dragging = true;
        }

        if (dragging)
        {
            end = cam.ScreenToViewportPoint(Input.mousePosition);

            //* WE FIND THE OBJECT THAT INTERSECT WITH THE CUT *****************
            // Create the ray
            Ray ray = rayProvider.CreateRay();
            // Debug.Log(ray);

            // Check if the ray hits a selectable object
            selector.check(ray);
            // Get the selection
            if (selector.GetSelection() != null)
            {
                selection = selector.GetSelection();
            }
        }

        if (dragging && Input.GetMouseButtonUp(0))
        {
            // Finished dragging. We compute the direction of the vector formed by start and end
            end          = cam.ScreenToViewportPoint(Input.mousePosition);
            dragging     = false;
            cutDirection = end - start;

            // Debug.Log("Direction: " + cutDirection);
            if (selection != null)
            {
                // Debug.Log("Selection: " + selection.gameObject.transform + ", " + selection.name);
                // var coeffs = ParallelismCoefficient(selection, cutDirection, 0.0f);

                /*
                 * GameObject plane = GameObject.Find("PlaneCutter");
                 * plane.transform.position = selection.position;
                 * plane.transform.rotation = Quaternion.LookRotation(cutDirection);
                 */
                if (isCutting)
                {
                    Debug.Log("Selection: " + selection);
                    if (selection.parent != null)
                    {
                        Cutter.SplitOBJ(selection.parent.gameObject, selection, cutDirection);
                    }
                    else
                    {
                        Cutter.SplitOBJ(selection.gameObject, selection, cutDirection);
                    }
                }
            }
        }

        // Separate the object if we do not drag anymore and the
    }
コード例 #17
0
ファイル: Board.cs プロジェクト: sommen01/Seega
    public void OnMouseClick()
    {
        //CREATING THE RAY
        var ray = _rayProvider.CreateRay();

        //SHOTING THE RAY
        //shooting a raycast to get the tile that the player clicked
        if (_selector.Check(ray))
        {
            TileField tile;
            _physicsCache.TryGetTileField(_selector.GetSelection(), out tile);
            if (_phaseManager.GetCurrentPhase() == Phase.MOVEMENT)
            {
                //Two possibilities: the field can or not have a piece
                if (tile.Piece != null)
                {
                    // One possibility: If its a piece from the current turn, we try to highlight
                    if (ValidateHighlight(tile.Piece))
                    {
                        // Three possibilities:
                        // If the clicked tile is the current highlighted, we only dehighlight
                        // If the highlighted tile is null, we only highlight
                        // If the clicked tile isn't the current highlighted, we dehighlight and highlight the clicked one
                        if (tile == m_HighlightedTile)
                        {
                            Deselect();
                        }
                        else if (m_HighlightedTile == null)
                        {
                            TrySelectEmptyAdjacents(tile);
                        }
                        else if (tile != m_HighlightedTile)
                        {
                            Deselect();
                            TrySelectEmptyAdjacents(tile);
                        }
                    }
                }
                else
                {
                    //One possibilities: if there is not a piece on the field we clicked, and we already have a highlighted field, we try to move
                    if (m_HighlightedTile != null)
                    {
                        //MOVE PIECE
                        if (tile.IsHighlighting)
                        {
                            //If this tile is highlighted, we can move to this tile.
                            m_HighlightedTile.MovePieceTo(tile);
                            UpdateBoard(tile, m_HighlightedTile);
                            Deselect();
                            _turnManager.NextTurn();
                        }
                    }
                }
            }
            else if (_phaseManager.GetCurrentPhase() == Phase.POSITIONING)
            {
                //One Possibility: There's no piece on the field, we can only move to an empty space
                if (tile.Piece == null)
                {
                    //No piece can be put in the middle on the positioning phase
                    if (tile.Coordinates.x == 2 && tile.Coordinates.y == 2)
                    {
                        return;
                    }

                    if (_turnManager.IsWhiteTurn())
                    {
                        tile.SetPiece(_pieceProvider.GetNonPlacedWhitePiece());
                    }
                    else
                    {
                        tile.SetPiece(_pieceProvider.GetNonPlacedBlackPiece());
                    }

                    _turnIndex++;

                    // Each player places 2 pieces before the next turn
                    if (_turnIndex % 2 == 0)
                    {
                        _turnManager.NextTurn();
                    }

                    //when all pieces are placed
                    if (_turnIndex == 24)
                    {
                        _phaseManager.StartMovementPhase();
                    }
                }
            }
        }
    }
コード例 #18
0
    // Update is called once per frame
    void Update()
    {
        if (!isCutting && isBoxSelectionEnabled)
        {
            Transform selection;

            if (Input.GetMouseButtonDown(0))
            {
                startPos = Input.mousePosition;
            }

            if (Input.GetMouseButtonUp(0))
            {
                DeselectAll();
                ReleaseSelectionBox();

                if (isBoxSelection)
                {
                    isBoxSelection = false;
                }
                else
                {
                    // Create the ray
                    Ray ray = rayProvider.CreateRay();

                    // Check if the ray hits a selectable object
                    selector.check(ray);

                    // Get the selection
                    selection = selector.GetSelection();

                    // We add the selection into the selection list if it is not already present
                    if (selection != null && !selection.tag.Equals("NOT_SELECTABLE"))
                    {
                        string select = selection.gameObject.name;
                        // Debug.Log("selection: " + select);
                        if (select != null)
                        {
                            if (!selected.Contains(select))
                            {
                                /*
                                 * selected.Add(select);
                                 * SessionEvents.current.SelectionAny();
                                 * SessionEvents.current.ModelSelected(select);
                                 * UpdateMeshShader(selection.gameObject, selectionShader);
                                 */
                                Debug.Log("Selection name: " + select);

                                if (selection.tag.Equals("Selectable"))
                                {
                                    SelectModelFromParent(selection.gameObject);
                                }
                                else
                                {
                                    SelectModel(selection.gameObject);
                                }
                            }
                            else // Deselect to delete from the list of selected item
                            {
                                /*
                                 * selected.Remove(select);
                                 * SessionEvents.current.DeselectionAny();
                                 * SessionEvents.current.ModelDeselected(select);
                                 * UpdateMeshShader(selection.gameObject, standardShader);
                                 */
                                DeselectModel(selection.gameObject);
                            }
                        }
                    }
                    else
                    {
                        DeselectAll();
                    }
                }
            }

            // Mouse held down
            if (Input.GetMouseButton(0))
            {
                UpdateSelectionBox(Input.mousePosition);
            }
        } // isCutting
    }