예제 #1
0
 private void CameraAim()
 {
     aimCam.gameObject.SetActive(_input.aim);
     CamSensitivity             = _input.aim ? aimCamSensitivity : 1f;
     aimPos                     = Mouse3D.GetPos(new Vector3(Screen.width / 2f, Screen.height / 2f), aimLayer);
     aimDir                     = aimPos - transform.position;
     aimDir.y                   = 0f;
     aimDir                     = aimDir.normalized;
     debugAimTransform.position = aimPos;
 }
예제 #2
0
    private void PlayerBase_OnShoot(object sender, CharacterAim_Base.OnShootEventArgs e)
    {
        Vector3 shootDir = (e.shootPosition - e.gunEndPointPosition).normalized;

        BulletRaycast3D.Shoot(e.gunEndPointPosition, shootDir);

        Shoot_Flash.AddFlash(e.gunEndPointPosition, new Vector3(3, 2.7f));
        Vector3 mouseWorldPosition = Mouse3D.GetMouseWorldPosition();

        mouseWorldPosition.y = e.gunEndPointPosition.y;
        WeaponTracer.Create3D(e.gunEndPointPosition, mouseWorldPosition);
    }
예제 #3
0
    private void HandleAimShooting()
    {
        Vector3 targetPosition = Mouse3D.GetMouseWorldPosition();

        targetPosition.y = offsetY;
        playerBase.SetAimTarget(targetPosition);

        if (Input.GetMouseButton(0) && Time.time >= nextShootTime)
        {
            nextShootTime = Time.time + FIRE_RATE;
            playerBase.ShootTarget(targetPosition);
        }
    }
예제 #4
0
        void Update()
        {
            if (bindedSpells == null || bindedSpells.Length == 0)
            {
                return;
            }
            var pos = Mouse3D.GetPos();
            var obj = Mouse3D.GetObject();

            playerAimTarget.transform.position =
                new Vector3(pos.x, Player.Local.currPawn.spellOrigin.position.y, pos.z);
            foreach (var binding in bindedSpells)
            {
                UpdateBinding(binding, pos, obj);
            }
        }
예제 #5
0
    public Vector3 GetMouseWorldSnappedPosition()
    {
        Vector3 mousePosition = Mouse3D.GetMouseWorldPosition();

        grid.GetXZ(mousePosition, out int x, out int z);

        if (placedObjectTypeSO != null)
        {
            Vector2Int rotationOffset            = placedObjectTypeSO.GetRotationOffset(dir);
            Vector3    placedObjectWorldPosition = grid.GetWorldPosition(x, z) + new Vector3(rotationOffset.x, 0, rotationOffset.y) * grid.GetCellSize();
            return(placedObjectWorldPosition);
        }
        else
        {
            return(mousePosition);
        }
    }
예제 #6
0
 void Awake()
 {
     instance = this;
 }
예제 #7
0
    private void Update()
    {
        // 当点击的地板有建筑时,应该抬起重放
        if (Input.GetMouseButtonDown(0) && placedObjectTypeSO == null)
        {
            Vector3 mousePosition = Mouse3D.GetMouseWorldPosition();
            if (grid.GetGridObject(mousePosition) != null)
            {
                // Valid Grid Position
                PlacedObject_Done placedObject = grid.GetGridObject(mousePosition).GetPlacedObject();
                if (placedObject != null)
                {
                    // Demolish
                    placedObject.DestroySelf();

                    List <Vector2Int> gridPositionList = placedObject.GetGridPositionList();
                    foreach (Vector2Int gridPosition in gridPositionList)
                    {
                        grid.GetGridObject(gridPosition.x, gridPosition.y).ClearPlacedObject();
                    }

                    placedObjectTypeSO = placedObject.PlacedObjectTypeSO;
                    RefreshSelectedObjectType();
                    return;
                }
            }
        }

        if (Input.GetMouseButtonDown(0) && placedObjectTypeSO != null)
        {
            Vector3 mousePosition = Mouse3D.GetMouseWorldPosition();
            grid.GetXZ(mousePosition, out int x, out int z);

            Vector2Int placedObjectOrigin = new Vector2Int(x, z);
            placedObjectOrigin = grid.ValidateGridPosition(placedObjectOrigin);

            // Test Can Build
            List <Vector2Int> gridPositionList = placedObjectTypeSO.GetGridPositionList(placedObjectOrigin, dir);
            bool canBuild = true;
            foreach (Vector2Int gridPosition in gridPositionList)
            {
                if (!grid.GetGridObject(gridPosition.x, gridPosition.y).CanBuild())
                {
                    canBuild = false;
                    break;
                }
            }

            if (canBuild)
            {
                Vector2Int rotationOffset            = placedObjectTypeSO.GetRotationOffset(dir);
                Vector3    placedObjectWorldPosition = grid.GetWorldPosition(placedObjectOrigin.x, placedObjectOrigin.y) + new Vector3(rotationOffset.x, 0, rotationOffset.y) * grid.GetCellSize();

                PlacedObject_Done placedObject = PlacedObject_Done.Create(placedObjectWorldPosition, placedObjectOrigin, dir, placedObjectTypeSO);

                foreach (Vector2Int gridPosition in gridPositionList)
                {
                    grid.GetGridObject(gridPosition.x, gridPosition.y).SetPlacedObject(placedObject);
                }

                OnObjectPlaced?.Invoke(this, EventArgs.Empty);

                //DeselectObjectType();
            }
            else
            {
                // Cannot build here
                UtilsClass.CreateWorldTextPopup("Cannot Build Here!", mousePosition);
            }
        }

        if (Input.GetKeyDown(KeyCode.R))
        {
            dir = PlacedObjectTypeSO.GetNextDir(dir);
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            placedObjectTypeSO = placedObjectTypeSOList[0]; RefreshSelectedObjectType();
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            placedObjectTypeSO = placedObjectTypeSOList[1]; RefreshSelectedObjectType();
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            placedObjectTypeSO = placedObjectTypeSOList[2]; RefreshSelectedObjectType();
        }
        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            placedObjectTypeSO = placedObjectTypeSOList[3]; RefreshSelectedObjectType();
        }
        if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            placedObjectTypeSO = placedObjectTypeSOList[4]; RefreshSelectedObjectType();
        }
        if (Input.GetKeyDown(KeyCode.Alpha6))
        {
            placedObjectTypeSO = placedObjectTypeSOList[5]; RefreshSelectedObjectType();
        }

        if (Input.GetKeyDown(KeyCode.Alpha0))
        {
            DeselectObjectType();
        }


        if (Input.GetMouseButtonDown(1))
        {
            Vector3 mousePosition = Mouse3D.GetMouseWorldPosition();
            if (grid.GetGridObject(mousePosition) != null)
            {
                // Valid Grid Position
                PlacedObject_Done placedObject = grid.GetGridObject(mousePosition).GetPlacedObject();
                if (placedObject != null)
                {
                    // Demolish
                    placedObject.DestroySelf();

                    List <Vector2Int> gridPositionList = placedObject.GetGridPositionList();
                    foreach (Vector2Int gridPosition in gridPositionList)
                    {
                        grid.GetGridObject(gridPosition.x, gridPosition.y).ClearPlacedObject();
                    }
                }
            }
        }
    }
예제 #8
0
 private void Awake()
 {
     Instance = this;
 }