コード例 #1
0
        public void Unselect(int playerIndex) ///this is player index (not owner index)
        {
            if (IsSelected(playerIndex))
            {
                m_selection &= ~(1ul << playerIndex);

                if (m_selectionOutlines != null)
                {
                    if (m_gameState == null)
                    {
                        m_gameState = Dependencies.GameState;
                    }

                    if (m_gameState.IsLocalPlayer(playerIndex))
                    {
                        int localPlayerIndex = m_gameState.PlayerToLocalIndex(playerIndex);

                        cakeslice.Outline outline = m_selectionOutlines.Where(o => o.layerMask == GameConstants.PlayerLayerMasks[localPlayerIndex]).FirstOrDefault();

                        if (outline != null)
                        {
                            Destroy(outline);
                        }
                    }

                    m_selectionOutlines = null;
                }

                if (m_ui != null)
                {
                    if (m_gameState == null)
                    {
                        m_gameState = Dependencies.GameState;
                    }

                    if (m_gameState.IsLocalPlayer(playerIndex))
                    {
                        int localPlayerIndex = m_gameState.PlayerToLocalIndex(playerIndex);

                        VoxelUI ui = m_ui.Where(o => o.gameObject.layer == GameConstants.PlayerLayers[localPlayerIndex]).FirstOrDefault();
                        if (ui != null)
                        {
                            Destroy(ui.gameObject);
                        }
                    }

                    m_ui = null;
                }

                OnUnselect(playerIndex);
            }
        }
コード例 #2
0
        public void Select(int playerIndex) //this is player index (not owner index)
        {
            if (!IsSelected(playerIndex))
            {
                m_selection |= (1ul << playerIndex);

                // Dependencies.GameView.GetViewport(m_gameState.PlayerToLocalIndex(pla))
                if (m_gameState == null)
                {
                    m_gameState = Dependencies.GameState;
                }

                if (m_gameState.IsLocalPlayer(playerIndex))
                {
                    if (m_renderer != null)
                    {
                        if (m_selectionOutlines == null)
                        {
                            m_selectionOutlines = new List <cakeslice.Outline>();
                        }

                        cakeslice.Outline outline = m_renderer.gameObject.AddComponent <cakeslice.Outline>();
                        m_selectionOutlines.Add(outline);

                        int localPlayerIndex = m_gameState.PlayerToLocalIndex(playerIndex);
                        outline.layerMask = GameConstants.PlayerLayerMasks[localPlayerIndex];

                        if (Owner == playerIndex)
                        {
                            outline.color = 0;
                        }
                        else
                        {
                            if (Owner != 0)
                            {
                                outline.color = 1;
                            }
                            else
                            {
                                outline.color = 2;
                            }
                        }
                    }

                    if (m_uiPrefab != null)
                    {
                        VoxelUI ui = Instantiate(m_uiPrefab, transform, false);
                        int     localPlayerIndex = m_gameState.PlayerToLocalIndex(playerIndex);
                        foreach (Transform t in ui.GetComponentsInChildren <Transform>(true))
                        {
                            t.gameObject.layer = GameConstants.PlayerLayers[localPlayerIndex];
                        }
                        ui.LocalPlayerIndex = localPlayerIndex;
                        if (m_ui == null)
                        {
                            m_ui = new List <VoxelUI>();
                        }
                        m_ui.Add(ui);
                        UpdateUIVisibility();
                    }
                }

                OnSelect(playerIndex);
            }
        }