Exemple #1
0
 private void Awake()
 {
     Debug.Log("Created a player");
     IP = new InputHandler();
     IP.EnableControls();
     PlayerState   = StateOfPlayer.TopDown;
     FPSController = this.GetComponent <FirstPersonController>();
     TDController  = this.GetComponent <TopDownController>();
     TDController.SetRotationSpeed(RotationSpeedOfTopDownCamera);
 }
Exemple #2
0
 public void SwitchCameras()
 {
     if (PlayerState == StateOfPlayer.TopDown)
     {
         TopDownCamera.gameObject.SetActive(false);
         FirstPersonCamera.gameObject.SetActive(true);
         PlayerState = StateOfPlayer.FirstPerson;
     }
     else
     {
         TopDownCamera.gameObject.SetActive(true);
         FirstPersonCamera.gameObject.SetActive(false);
         PlayerState = StateOfPlayer.TopDown;
     }
 }
Exemple #3
0
    public void ClickOnObjects()
    {
        if (Input.GetKeyDown(KeyCode.Space))
        {
            CreateAndPassCommand(new MoveCommand(new List <int> {
                1, 2, 3, 4, 5
            }, new Vector3(3, 8, 2)));
            CreateAndPassCommand(new MoveCommand(new List <int> {
                1, 9
            }, new Vector3(5, 8, 10)));
            CreateAndPassCommand(new BuildCommand(5, new List <int> {
                10
            }, new Vector3(4, 3, 1)));

            print(JsonConvert.SerializeObject(ServiceLocator.GetService <CommandManager>().CreateTurnData(3, 0)));
        }
        if (!_enabled)
        {
            return;
        }

        if (Input.GetMouseButtonDown(0))
        {
            _mousePos = Input.mousePosition;
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 1000f))
            {
                GameObject obj = hit.transform.gameObject;
                if (obj.GetComponent(typeof(ISelectable)) != null)
                {
                    foreach (Unit u in _units)
                    {
                        u.Deselect();
                    }
                    _units.Clear();
                    var unit = obj.transform.gameObject.GetComponent <Unit>();
                    _units.Add(unit);

                    foreach (Unit u in _units)
                    {
                        u.Select();
                    }
                    playerState = StateOfPlayer.UnitsSelected;
                }
                else
                {
                    _units.Clear();
                    playerState = StateOfPlayer.Idle;
                    _dragging   = true;
                }
            }
        }

        if (Input.GetMouseButtonUp(0))
        {
            foreach (var unit in _gm.Units)
            {
                if (IsInSelection(unit.Value.transform))
                {
                    _units.Add(unit.Value);
                    unit.Value.Select();
                }
                if (!_units.Contains(unit.Value))
                {
                    unit.Value.Deselect();
                }
            }
            if (_units.Count > 0)
            {
                playerState = StateOfPlayer.UnitsSelected;
            }
            else
            {
                playerState = StateOfPlayer.Idle;
            }
            _dragging = false;
        }

        if (Input.GetMouseButtonUp(1))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out hit, 1000f))
            {
                if (playerState == StateOfPlayer.UnitsSelected)
                {
                    _clickPoint = hit.point;
                    CreateAndPassCommand(_units, _clickPoint);
                    //CalculateLocationInFormation(_clickPoint, _units);
                    //playerState = StateOfPlayer.Idle;
                }
            }
        }
    }
Exemple #4
0
 private void Start()
 {
     playerState = StateOfPlayer.Idle;
     ServiceLocator.GetService <CommandManager>().SubsribeToEvent();
     _gm = ServiceLocator.GetService <GameManager>();
 }