Exemplo n.º 1
0
        public virtual void Awake()
        {
            // get ship component
            shipManager = GetComponentInParent <Ship>();
            // get collider
            boxCollider2d = GetComponent <BoxCollider2D>();
            r_collider2d  = GetComponent <Collider2D>();
            // get the camera components
            cam    = Camera.main.GetComponent <Camera>();
            camMgr = Camera.main.GetComponent <CameraManager>();

            // get room's tiles
            GetTiles();
            // get room's icon
            if (this.gameObject.name != "Corridor")
            {
                iconPrefab = Resources.Load <GameObject>("Prefabs/UI/RoomIcon");
            }
            // get room's fog sprite
            fogSprite = Resources.Load <Sprite>("Sprites/fog");

            // generate room's fog
            GenerateFog();

            if (system != null)
            {
                this.gameObject.name       = system.name;
                iconPrefab.gameObject.name = shipManager.gameObject.name + " " + this.gameObject.name + " Icon";

                // instantiate system prefab
                systemGO   = Instantiate(system.roomSystemPrefab, Vector3.zero, Quaternion.identity);
                roomSystem = systemGO.GetComponent <ShipSystem>();
                // attach it to the ship's systems parent go
                systemGO.transform.parent = shipManager.systems.transform;
                // set system position to ship's position
                systemGO.transform.position = shipManager.transform.position;
                // set room system on prefab clone
                roomSystem.system = system;
                // set room on system
                roomSystem.Room = this;

                //Instantiate RoomIcon
                roomIcon = Instantiate(iconPrefab, GameManager.BattleUiManager.roomIconCanvas.transform).GetComponent <Image>();
                roomIcon.transform.SetParent(shipManager.roomIconsParent.transform);
                roomIcon.sprite = system.icon;

                SetRoomIcon();

                //TODO: organise this shit below

                onTakeDamageCallback += SetRoomIconColor;
                onRepairCallback     += SetRoomIconColor;
                roomIconScale         = 1f;
            }

            extinguishTime   = timeToExtinguish;
            breachFixingTime = timeToFixBreach;
            repairTime       = timeToRepair;
        }
Exemplo n.º 2
0
        public virtual void CheckCurrentRoom()
        {
            Vector2      currentPos = this.transform.position;
            RaycastHit2D hit        = Physics2D.Raycast(this.transform.position, -Vector2.up, 0.5f, roomLayerMask);

            isOnRoom = false;

            if (hit.collider != null)
            {
                if (hit.collider.gameObject.CompareTag("Room"))
                {
                    isOnRoom = true;

                    //currentRoomGO = hit[i].collider.gameObject;

                    currentRoom = hit.transform.GetComponent <Room>();

                    bool alreadyIn = false;

                    // check if already in the room
                    if (currentRoom.crewmembers.Contains(this.gameObject))
                    {
                        alreadyIn = true;
                    }

                    if (!alreadyIn)
                    {
                        currentRoom.AddCrewmember(this.gameObject);
                        onEnterRoomCallback?.Invoke();
                    }

                    if (currentRoom.SystemGO != null)
                    {
                        roomSystem = currentRoom.SystemGO.GetComponent <ShipSystem>();
                    }
                    else
                    {
                        roomSystem = null;
                    }
                }
            }

            if (!isOnRoom && currentRoom != null)
            {
                // remove crewmember from room
                StopAllActivities();
                onLeftRoomCallback?.Invoke();
                currentRoom.RemoveCrewmember(this.gameObject);

                // not in room anymore
                previousRoom = currentRoom;
                currentRoom  = null;
                roomSystem   = null;
            }
        }
Exemplo n.º 3
0
        // public void SetupCrew() {

        //     // clear previous crewattpanels
        //     foreach(Transform child in crewAttributePanels)
        //         Destroy(child.gameObject);

        //     int currentButtonIndex = 0;

        //     for (int i = 0; i < playerShip.crew.transform.childCount; i++) {

        //         GameObject crewmemberGO;
        //         crewmemberGO = playerShip.crew.transform.GetChild(i).gameObject;

        //         // if the crewmember's gameobject is inactive for some reason, skip to next
        //         if(crewmemberGO.activeSelf == false) {
        //             continue;
        //         }

        //         Crewmember crewmember = crewmemberGO.GetComponent<Crewmember>();

        //         print(crewmember.name);

        //         GameObject crewmemberButtonGO = crewPanel.transform.GetChild(currentButtonIndex).gameObject;
        //         // add to crew button index
        //         currentButtonIndex++;

        //         Image crewmemberIcon = crewmemberButtonGO.transform.GetChild(0).GetComponentInChildren<Image>(true);
        //         // enable crew icon
        //         crewmemberIcon.enabled = true;
        //         // set crew icon
        //         crewmemberIcon.sprite = crewmember.icon;
        //         print(crewmember.icon + " vs " + crewmemberIcon.sprite);
        //         crewmemberIcon.color = crewmember.GetComponent<SpriteRenderer>().color;

        //         RectTransform crewAttPanelRectT = crewmemberButtonGO.transform.Find("CrewAttributesPanel").GetComponent<RectTransform>();
        //         AttributesUIPanel attUI = crewAttPanelRectT.GetComponent<AttributesUIPanel>();
        //         attUI.SetCrewmember(crewmember);

        //         //crewAttPanelRectT.SetParent(crewAttributePanels.transform, true);

        //         // set double click
        //         CustomButton crewmemberButton = crewmemberButtonGO.GetComponent<CustomButton>();
        //         crewmemberButton.onDoubleTap.AddListener(
        //             () =>  crewAttPanelRectT.gameObject.SetActive(!crewAttPanelRectT.gameObject.activeSelf)
        //         );

        //         crewmemberButton.onDoubleTap?.Invoke();

        //     }

        //     AddListenerToShipCrew();

        // }

        public void SetupSystems()
        {
            for (int i = 0; i < playerShip.systems.transform.childCount; i++)
            {
                ShipSystem shipSystem = GameManager.shipSystems[i].GetComponent <ShipSystem>();
                // set system power usage to UI
                GameObject systemButton     = systemPanel.transform.GetChild(i).gameObject;
                PowerUsage systemPowerUsage = systemButton.GetComponent <PowerUsage>();
                systemPowerUsage.maxUsage = shipSystem.powerCap;
                systemPowerUsage.RefreshMaxPowerUsageUI();
                Image systemIcon = systemButton.transform.GetChild(0).GetComponentInChildren <Image>();
                // enable system icon
                systemIcon.enabled = true;
                // set system icon
                systemIcon.sprite = shipSystem.system.icon;
            }

            AddListenerToShipSystems();
            RefreshSystemsPowerUsage();
        }
Exemplo n.º 4
0
        public void RefreshSystemsPowerUsage()
        {
            for (int i = 0; i < GameManager.shipSystems.Count; i++)
            {
                int childCount = systemPanel.transform.childCount;

                ShipSystem shipSystem = GameManager.shipSystems[i].GetComponent <ShipSystem>();

                GameObject systemButton = systemPanel.transform.GetChild(i).gameObject;

                PowerUsage systemPowerUsage = systemButton.GetComponent <PowerUsage>();

                //if system is damaged, turn icon red
                if (shipSystem.IsDamaged)
                {
                    systemPowerUsage.iconGO.GetComponent <Image>().color = systemButton.GetComponent <Image>().color = damagedColor;
                }
                else
                {
                    systemPowerUsage.iconGO.GetComponent <Image>().color = systemButton.GetComponent <Image>().color = NORMAL_COLOR;
                }

                if (systemPowerUsage != null)
                {
                    systemPowerUsage.usage     = shipSystem.powerConsumption;
                    systemPowerUsage.IsPowered = shipSystem.IsPowered;
                    systemPowerUsage.RefreshPowerUsageUI(shipSystem);
                }
                else
                {
                    Debug.LogError(shipSystem.name + " is missing the power usage component");
                }
            }

            // refresh power value
            powerValueTxt      = powerValue.GetComponent <TMPro.TextMeshProUGUI>();
            powerValueTxt.text = playerShip.reactor.ToString();
        }
Exemplo n.º 5
0
        public void RefreshPowerUsageUI(ShipSystem shipSystem)
        {
            RefreshMaxPowerUsageUI();

            if (IsPowered)
            {
                for (int i = 0; i < powerBars.Count; i++)
                {
                    Image powerBarImg = powerBars[i].GetComponent <Image>();
                    if (i < usage)
                    {
                        powerBarImg.sprite = powerBarOn;
                        powerBarImg.color  = NORMAL_COLOR;
                    }
                    else
                    {
                        powerBarImg.sprite = powerBarOff;

                        // had to use this due to a unity bug (in order to refresh the changed color)
                        powerBarImg.DisableSpriteOptimizations();

                        int systemHP;

                        if (shipSystem.Room == null)
                        {
                            systemHP = shipSystem.GetComponent <Weaponry>().hp;
                        }
                        else
                        {
                            systemHP = shipSystem.Room.CurrentHP;
                        }

                        if (i >= systemHP)
                        {
                            powerBarImg.color = DAMAGED_COLOR;
                        }
                        else
                        {
                            powerBarImg.color = NORMAL_COLOR;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < powerBars.Count; i++)
                {
                    Image powerBarImg = powerBars[i].GetComponent <Image>();

                    powerBarImg.sprite = powerBarOff;

                    // had to use this due to a unity bug (in order to refresh the changed color)
                    powerBarImg.DisableSpriteOptimizations();

                    int systemHP;

                    if (shipSystem.Room == null)
                    {
                        systemHP = shipSystem.GetComponent <Weaponry>().hp;
                    }
                    else
                    {
                        systemHP = shipSystem.Room.CurrentHP;
                    }

                    if (i >= systemHP)
                    {
                        powerBarImg.color = DAMAGED_COLOR;
                    }
                    else
                    {
                        powerBarImg.color = NORMAL_COLOR;
                    }
                }
            }
        }