private void Awake()
        {
            _unitSelection = GetComponentInParent <UnitSelection>(); // TODO: anything better?
            _camera        = Camera.main;
            _rtsControls   = new Rts();

            // Setup UI callbacks, TODO: must check if something cleaner with new input system
            var e = new EventTrigger.Entry {
                eventID = EventTriggerType.BeginDrag
            };

            e.callback.AddListener(StartDraggingAnimal);
            triggerAnimal.triggers.Add(e);
            e = new EventTrigger.Entry {
                eventID = EventTriggerType.EndDrag
            };
            e.callback.AddListener(StopDraggingAnimal);
            triggerAnimal.triggers.Add(e);

            e = new EventTrigger.Entry {
                eventID = EventTriggerType.BeginDrag
            };
            e.callback.AddListener(StartDraggingPlant);
            triggerPlant.triggers.Add(e);
            e = new EventTrigger.Entry {
                eventID = EventTriggerType.EndDrag
            };
            e.callback.AddListener(StopDraggingPlant);
            triggerPlant.triggers.Add(e);

#if UNITY_IOS || UNITY_ANDROID && !UNITY_EDITOR
            UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.Enable();
#endif
        }
Exemple #2
0
        private void Awake()
        {
            _rtsControls  = new Rts();
            _currentState = State.Wandering;

            void Im(bool b)
            {
                if (!b)
                {
                    return;
                }
                ChangeState(State.InputMenu);
                inputsMenu.VisibilityChanged -= Im;
            } // Just once

            inputsMenu.VisibilityChanged += Im;

            void Em(bool b)
            {
                if (!b)
                {
                    return;
                }
                ChangeState(State.ExperiencesMenu);
                experiencesMenu.VisibilityChanged -= Em;
            } // Just once

            experiencesMenu.VisibilityChanged += Em;

            void OnPlayStateStarted()
            {
                niwradMenu.ShowNotification(KPlayHelpTextFormat
                                            .Replace("{move}", _rtsControls.Player.Move.GetBindingDisplayString())
                                            .Replace("{movey}", _rtsControls.Player.MoveY.GetBindingDisplayString()),
                                            4);
                Gm.instance.PlayStateStarted -= OnPlayStateStarted;
            }

            Gm.instance.PlayStateStarted += OnPlayStateStarted;

            void OnExperienceStateStarted()
            {
                niwradMenu.ShowNotification("You can try to play with artificial selection or try to change time", 4);
                Gm.instance.ExperienceStateStarted -= OnExperienceStateStarted;
            }

            Gm.instance.ExperienceStateStarted += OnExperienceStateStarted;
        }
        private void Awake()
        {
            _rtsControls = new Rts();
#if UNITY_STANDALONE || UNITY_EDITOR
            _rtsControls.Player.MoveY.performed += ctx =>
            {
                var newPos = transform.position + Vector3.up * (ctx.ReadValue <Vector2>().y *zoomSpeed);
                if (disable || Bounds != default && !Bounds.Contains(newPos))
                {
                    return;
                }
                transform.position = newPos;
            };
#elif UNITY_IOS || UNITY_ANDROID
            _moveJoystick   = moveJoystick.GetComponent <FixedJoystick>();
            _rotateJoystick = rotateJoystick.GetComponent <FixedJoystick>();
            _flyJoystick    = flyJoystick.GetComponent <FixedJoystick>();
            moveJoystick.SetActive(true);
            rotateJoystick.SetActive(true);
            flyJoystick.SetActive(true);
            rotationSpeed *= 10; // Somehow slower on mobile
            _mobile        = true;
#endif
        }
Exemple #4
0
        private void Start()
        {
            Gm.instance.State      = GameState.Menu;
            _notificationText      = notification.GetComponentInChildren <TextMeshProUGUI>();
            _notificationJoinDelay = notification.GetComponentInChildren <LeanJoinDelay>();
            _serverIp   = serverIpGameObject.GetComponent <TMP_InputField>();
            _serverPort = serverPortGameObject.GetComponent <TMP_InputField>();
            playButton.OnClick.AddListener(() => Connect(new InputAction.CallbackContext()));
            _rtsControls = new Rts();
            _rtsControls.Enable();
            _rtsControls.UI.Submit.performed += Connect;
            debugToggle.onValueChanged.AddListener(Advanced);
            developmentToggle.On = bool.Parse(PlayerPrefs.GetString("development", "false"));
            developmentToggle.OnOff.AddListener(() =>
            {
                PlayerPrefs.SetString("serverPort", "30020");
            });
            developmentToggle.OnOn.AddListener(() =>
            {
                PlayerPrefs.SetString("serverPort", "30021");
            });
            username.text = PlayerPrefs.GetString("username");
            // _serverIp.text = PlayerPrefs.GetString("serverIp");
            // _serverPort.text = PlayerPrefs.GetString("serverPort");

            singlePlayerButton.OnClick.AddListener(() =>
            {
                secondMenu.Hide();
                background.Hide();
                Gm.instance.State = GameState.Play;
                settings.Show();
            });
            multiplayerButton.OnClick.AddListener(() =>
                                                  throw new NotImplementedException("Online mode in maintenance")); // TODO next

            // Pointless for mobile
#if UNITY_STANDALONE || UNITY_EDITOR
            // Lock cursor withing window in standalone
            Cursor.lockState = CursorLockMode.Confined;

            void ReLock(InputAction.CallbackContext _)
            {
                Screen.fullScreen = true;
                Cursor.lockState  = CursorLockMode.Confined;
                ShowNotification("Cursor locked again");
                _rtsControls.Player.Fire.performed -= ReLock;
            }

            // Basically copy paste of how Google Stadia handle full screen :D
            _rtsControls.Player.DoubleCancel.performed += ctx =>
            {
                ShowNotification($"Press and hold {_rtsControls.Player.LongCancel.activeControl.displayName}" +
                                 $" to unlock the cursor from the window");
            };
            // Can unlock cursor from the window in standalone by pressing escape
            _rtsControls.Player.LongCancel.performed += ctx =>
            {
                Screen.fullScreen = false;
                Cursor.lockState  = CursorLockMode.None;
                ShowNotification("Cursor unlocked from the window," +
                                 " click inside the window to re-lock the cursor");
                // Can re-lock cursor from the window in standalone by pressing escape
                _rtsControls.Player.Fire.performed += ReLock;
            };
#elif UNITY_IOS || UNITY_ANDROID
            UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.Enable();
#endif


            Sm.instance.ConnectionSucceed += OnConnectionSucceed;
        }
Exemple #5
0
 private void Awake()
 {
     m_System     = EventSystem.current;// EventSystemManager.currentSystem;
     _rtsControls = new Rts();
 }
Exemple #6
0
 private void Awake()
 {
     _rtsControls = new Rts();
     Gm.instance.PlayStateStarted += () => _rtsControls.Player.Cancel.started += _ => SubShow();
 }
Exemple #7
0
        public bool disable; // Can disable, useful for example when interacting with UI

        private void Awake()
        {
            _cam         = Camera.main;
            _rtsControls = new Rts();
        }
Exemple #8
0
 private void Awake()
 {
     _rtsControls = new Rts();
 }