예제 #1
0
        public void OnBuildHoverEnter(int id)
        {
            var elem = ModularRoomFactory.BuildModularRoom((RoomType)id, null);

            _explanationPanelScript.gameObject.SetActive(true);
            _explanationPanelScript.Name.text        = elem.GetName();
            _explanationPanelScript.Description.text = elem.GetDescription();
        }
예제 #2
0
        private void Update()
        {
            // We want the user to click and release his mouse on the same element
            if (Input.GetMouseButtonDown(0))
            {
                currInfoD = null;
                var mousePos = Input.mousePosition;
                mousePos.z = -Camera.main.transform.position.z;
                var pos   = Camera.main.ScreenToWorldPoint(mousePos);
                var pos2d = (Vector2)pos;
                var room  = MapManager.S.MapRooms.FirstOrDefault((x) =>
                {
                    var xSize = x.Size.x / 2f;
                    return(pos2d.x > x.GameObject.transform.position.x - xSize && pos2d.x < x.GameObject.transform.position.x + xSize &&
                           pos2d.y > x.GameObject.transform.position.y && pos2d.y < x.GameObject.transform.position.y + x.Size.y);
                });
                if (room != null)
                {
                    if (_currentSelection != null && room.IsBuilt) // We want to change the type of a room
                    {
                        clicked = room as GenericRoom;
                        if (clicked != null && !clicked.RoomType.IsEmpty())
                        {
                            clicked = null;
                        }
                    }
                    else // Display info about a room
                    {
                        _roomInfo.Name.text        = room.GetName();
                        _roomInfo.Description.text = room.GetDescription();
                        if (_roomInfo.DetailPanel.transform.childCount > 0)
                        {
                            Destroy(_roomInfo.DetailPanel.transform.GetChild(0).gameObject);
                        }
                        var gRoom = room as GenericRoom;
                        if (gRoom != null || room.IsBuilt)
                        {
                            var p = room.IsBuilt
                                ? gRoom.RoomType.GetDescriptionPanel()
                                : room.GetDescriptionPanel();
                            if (p != null)
                            {
                                var go = Instantiate(p, _roomInfo.DetailPanel.transform);
                                var t  = (RectTransform)go.transform;
                                var pT = (RectTransform)_roomInfo.DetailPanel.transform;
                                t.sizeDelta = Vector2.zero;
                                t.position  = pT.position;
                                if (room.IsBuilt)
                                {
                                    gRoom.RoomType.SetupConfigPanel(go);
                                }
                                else
                                {
                                    room.SetupConfigPanel(go);
                                }
                            }
                        }
                        _roomInfo.gameObject.SetActive(true);
                        currInfoD = gRoom;
                    }
                }
                else if (Input.mousePosition.x < Screen.width - 200 ||
                         Input.mousePosition.y < Screen.height - 300)
                {
                    _roomInfo.gameObject.SetActive(false);
                }
            }
            if (Input.GetMouseButtonUp(0) && clicked != null && clicked.IsBuilt)
            {
                clicked.RoomType = ModularRoomFactory.BuildModularRoom(_currentSelection.Value, clicked);
                int index;
                if (clicked.Size.x == 2)
                {
                    if (clicked.Size.y == 1)
                    {
                        index = 0;
                    }
                    else
                    {
                        index = 1;
                    }
                }
                else
                {
                    if (clicked.Size.y == 1)
                    {
                        index = 2;
                    }
                    else
                    {
                        index = 3;
                    }
                }
                GameObject go;
                if (_currentSelection.Value == RoomType.AIRLOCK)
                {
                    go = PAirlock[index];
                }
                else if (_currentSelection.Value == RoomType.DEFENSE)
                {
                    go = PDefense[index];
                }
                else if (_currentSelection.Value == RoomType.FACTORY)
                {
                    go = PFactory[index];
                }
                else if (_currentSelection.Value == RoomType.MINING)
                {
                    go = PMining[index];
                }
                else if (_currentSelection.Value == RoomType.STORAGE)
                {
                    go = PStorage[index];
                }
                else
                {
                    go = null;
                }

                if (go != null)
                {
                    var n = Instantiate(go, clicked.GameObject.transform.position, Quaternion.Euler(0f, 180f, 0f));
                    Destroy(clicked.GameObject);
                    clicked.GameObject = n;
                }
                EventManager.S.NotifyManager(Events.Event.RoomSetType, clicked);
                clicked = null;
                SetCurrentBuild(-1);
            }
            if (Input.GetMouseButtonDown(1)) // Reset selection
            {
                currInfoD = null;
                if (_currentSelection != null)
                {
                    SetCurrentBuild(-1);
                }
                SubmarineManager.S.RemoveSubmarinePlacementMode();
            }
        }