Beispiel #1
0
        private void InitViewports()
        {
            if (m_gameViewports != null)
            {
                for (int i = 0; i < m_gameViewports.Length; ++i)
                {
                    Destroy(m_gameViewports[i].gameObject);
                }
            }

            if (m_viewportPlaceholders.Length < m_viewportCount)
            {
                Debug.LogError("m_viewports.Length < m_playerCount");
            }
            else
            {
                m_gameViewports = new GameViewport[m_viewportCount];

                m_secondRow.SetActive(m_viewportCount > 2);
                m_secondCol.SetActive(m_viewportCount > 1);

                IEventSystemManager eventSystemMan = Dependencies.EventSystemManager;

                for (int i = 0; i < m_viewportCount; ++i)
                {
                    GameViewport gameViewport = Instantiate(m_gameViewportPrefab, m_viewportPlaceholders[i]);
                    gameViewport.Camera.gameObject.SetActive(m_isOn);
                    gameViewport.name             = "Viewport" + i;
                    gameViewport.LocalPlayerIndex = i;
                    m_gameViewports[i]            = gameViewport;

                    eventSystemMan.Apply(gameViewport.gameObject, i);

                    PlayerMenu playerMenu = gameViewport.GetComponent <PlayerMenu>();
                    if (playerMenu != null)
                    {
                        playerMenu.LocalPlayerIndex = i;
                    }
                }

                VoxelConsole console = GetComponentInParent <VoxelConsole>();
                console.Initialize();

                for (int i = 0; i < m_viewportCount; ++i)
                {
                    PlayerConsoleCommandHandler cmdHandler = m_viewportPlaceholders[i].GetComponentInChildren <PlayerConsoleCommandHandler>();
                    if (cmdHandler != null)
                    {
                        cmdHandler.LocalPlayerIndex = i;
                        cmdHandler.Initialize();
                    }
                }
            }
        }
        private void Awake()
        {
            m_gameState           = Dependencies.GameState;
            m_inputManager        = Dependencies.InputManager;
            m_selection           = Dependencies.UnitSelection;
            m_eventSystemMananger = Dependencies.EventSystemManager;

            for (int i = 0; i < m_buttons.Length; ++i)
            {
                int index = i;
                m_buttons[i].onClick.AddListener(() => { OnAction(index); });
            }
        }
        private void Awake()
        {
            m_gameState           = Dependencies.GameState;
            m_inputManager        = Dependencies.InputManager;
            m_selection           = Dependencies.UnitSelection;
            m_eventSystemMananger = Dependencies.EventSystemManager;

            m_gameState.ActionsMenu    += OnActionsMenu;
            m_autoCommandsPanel.Action += OnAutoCommandsPanelAction;

            m_cancelBtn.onClick.AddListener(OnCancel);
            m_attackBtn.onClick.AddListener(OnAttack);
            m_moveBtn.onClick.AddListener(OnMove);
            m_autoBtn.onClick.AddListener(OnAuto);
            m_bombBtn.onClick.AddListener(OnBomb);
            m_wallBtn.onClick.AddListener(OnWall);
            m_spawnButton.onClick.AddListener(OnSpawn);
            m_splitButton.onClick.AddListener(OnSplit);
            m_split4Button.onClick.AddListener(OnSplit4);
            m_growButton.onClick.AddListener(OnGrow);
            m_diminishButton.onClick.AddListener(OnDiminish);
        }
        private void Start()
        {
            m_gState   = Dependencies.State;
            m_progress = Dependencies.Progress;


            m_eventSystemManager = Dependencies.EventSystemManager;
            for (int i = 0; i < m_eventSystemManager.EventSystemCount; ++i)
            {
                IndependentEventSystem eventSystem = m_eventSystemManager.GetEventSystem(i);
                eventSystem.EventSystemUpdate += OnEventSystemUpdate;
            }

            if (m_eventSystemManager.CommonEventSystem != null)
            {
                m_eventSystemManager.CommonEventSystem.EventSystemUpdate += OnCommonEventSystemUpdate;
            }


            m_isPointerOverGameObject = new bool[m_eventSystemManager.EventSystemCount];
            m_isInputFieldSelected    = new bool[m_eventSystemManager.EventSystemCount];
            m_selectedGameObject      = new GameObject[m_eventSystemManager.EventSystemCount];

            InputManager.OnDeviceAttached      += OnDeviceAttached;
            InputManager.OnDeviceDetached      += OnDeviceDetached;
            InputManager.OnActiveDeviceChanged += OnActiveDeviceChanged;

            if (!m_gState.HasKey(DevicesPersistentKey))
            {
                m_devices = new List <InputDevice>(InputManager.Devices.Count);
                m_gState.SetValue(DevicesPersistentKey, m_devices);
            }
            else
            {
                m_devices = m_gState.GetValue <List <InputDevice> >(DevicesPersistentKey);
                for (int i = 0; i < m_devices.Count; ++i)
                {
                    UnityInputDevice device = m_devices[i] as UnityInputDevice;
                    if (device == null)
                    {
                        if (m_devices[i] != null)
                        {
                            m_devices[i].IsSuspended = true;
                        }
                        m_devices[i] = null;
                    }
                    else
                    {
                        InputDevice replacementDevice = InputManager.Devices.OfType <UnityInputDevice>().Where(dev => dev.JoystickId == device.JoystickId).FirstOrDefault();
                        if (replacementDevice != null)
                        {
                            replacementDevice.IsSuspended = false;
                            m_devices[i] = replacementDevice;
                        }
                        else
                        {
                            if (m_devices[i] != null)
                            {
                                m_devices[i].IsSuspended = true;
                            }
                            m_devices[i] = null;
                        }
                    }
                }
            }

            LogDevices();
        }