Esempio n. 1
0
 public Screen(List <Setting> settingList)
 {
     CURRENT_SETTINGS = settingList;
     SETTINGS_MANAGER = new SettingsManager();
     settingPairs     = SETTINGS_MANAGER.getSettingPairs(settingList);
     colorScheme      = ImageTools.getColorFromString(settingPairs.color_scheme);
     getMenuToggleKeyCode();
     resetSettings = settingPairs.reset_settings;
     SETTINGS_MENU = new SettingsMenu(settingList, colorScheme, menuToggle, resetSettings);
     GAME_OBJECT   = GameObject.Find(getName().ToLower());
     CANVAS        = UnityEngine.Object.FindObjectOfType <Canvas>();
     findSound();
     currentMasterVolume     = settingPairs.master_volume;
     currentMusicVolume      = settingPairs.music_volume;
     currentButtonVolume     = settingPairs.action_performed_volume;
     currentAttachmentVolume = settingPairs.attachment_sound_volume;
     currentWeaponVolume     = settingPairs.weapon_used_volume;
     currentRobotVolume      = settingPairs.robot_sound_volume;
     musicSound.GetComponent <AudioSource>().volume  = (float)(currentMasterVolume / 100 * currentMusicVolume / 100);
     buttonSound.GetComponent <AudioSource>().volume = (float)(currentMasterVolume / 100 * currentButtonVolume / 100);
     GAME_OBJECTS      = new List <GameObject>();
     disposed          = false;
     triedFindingSound = false;
     GAME_OBJECTS.Add(GAME_OBJECT);
 }
Esempio n. 2
0
 public void update(SettingPairs settingPairs)
 {
     if (MENU != null)
     {
         this.settingPairs = settingPairs;
         Color gameMenuColor = default;
         if (gameMenuColorString != this.settingPairs.game_menu_color)
         {
             gameMenuColorString = this.settingPairs.game_menu_color;
             gameMenuColor       = ImageTools.getColorFromString(gameMenuColorString);
         }
         MENU.SetActive(base.enabled);
         if (base.enabled)
         {
             MENU.transform.SetAsLastSibling();
             for (int buttonIndex = 0; buttonIndex < NUMBER_OF_BUTTONS; ++buttonIndex)
             {
                 BUTTON_STATES[buttonIndex] = MENU_BUTTONS[buttonIndex].GetComponent <ButtonListener>().isClicked();
                 if (gameMenuColor != default)
                 {
                     MENU_BUTTONS[buttonIndex].GetComponent <UnityEngine.UI.Image>().color = gameMenuColor;
                 }
             }
         }
     }
 }
Esempio n. 3
0
 public GamePlayMenu(SettingPairs settingPairs)
 {
     this.settingPairs   = settingPairs;
     gameMenuColorString = this.settingPairs.game_menu_color;
     CANVAS = GameObject.Find(DYNAMIC_CANVAS_NAME);
     MENU   = GameObject.Instantiate(Resources.Load("Prefabs/Menu") as GameObject);
     MENU.transform.SetParent(CANVAS.transform);
     MENU.transform.localPosition = Vector3.zero;
     BUTTON_STATES      = new bool[NUMBER_OF_BUTTONS];
     MENU_BUTTONS       = new GameObject[NUMBER_OF_BUTTONS];
     MENU_BUTTON_LABELS = new GameObject[NUMBER_OF_BUTTONS];
     for (int buttonIndex = 0; buttonIndex < NUMBER_OF_BUTTONS; ++buttonIndex)
     {
         GameObject button      = GameObject.Instantiate(Resources.Load("Prefabs/MenuButton") as GameObject);
         GameObject buttonLabel = button.transform.Find(MENU_BUTTON_LABEL_NAME).gameObject;
         buttonLabel.GetComponent <TextMeshProUGUI>().text = processButtonLabel(buttonIndex);
         button.transform.SetParent(MENU.transform);
         button.transform.localScale     = Vector3.one;
         MENU_BUTTONS[buttonIndex]       = button;
         MENU_BUTTON_LABELS[buttonIndex] = buttonLabel;
         MENU_BUTTONS[buttonIndex].GetComponent <UnityEngine.UI.Image>().color = ImageTools.getColorFromString(gameMenuColorString);
     }
     MENU.SetActive(false);
     calculatePoints();
 }
Esempio n. 4
0
 void Start()
 {
     loadingSplashScreen         = GameObject.Find(LOADING_SPLASH_SCREEN_NAME);
     loadingIcon                 = GameObject.Find(LOADING_ICON_NAME);
     splashMessage               = GameObject.Find(SPLASH_MESSAGE_NAME);
     splashMessageHomePosition   = splashMessage.transform.localPosition;
     splashMessageStartYPosition = splashMessageHomePosition.y - (Math.Abs(splashMessageHomePosition.y) - (loadingIcon.GetComponent <RectTransform>().sizeDelta.y / 2 - loadingIcon.transform.localPosition.y) - splashMessage.GetComponent <RectTransform>().sizeDelta.y / 2);
     splashMessage.GetComponent <TextMeshProUGUI>().color = new Color(splashMessage.GetComponent <TextMeshProUGUI>().color.r, splashMessage.GetComponent <TextMeshProUGUI>().color.g, splashMessage.GetComponent <TextMeshProUGUI>().color.b, 0);
     musicSound                  = GameObject.Find(MUSIC_SOUND_NAME);
     battleButtonSound           = GameObject.Find(BATTLE_BUTTON_SOUND);
     splashMessageHomeStartTime  = 0;
     splashMessageColorDirection = true;
     splashMessageGenerator      = new SplashMessageGenerator();
     screenType                  = typeof(Field);
     splashScreenStartTime       = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
     for (int sceneIndex = 0; sceneIndex < SceneManager.sceneCount; ++sceneIndex)
     {
         Scene scene = SceneManager.GetSceneAt(sceneIndex);
         if (GetType().ToString() != scene.name)
         {
             foreach (GameObject gameObject in scene.GetRootGameObjects())
             {
                 RobotGame robotGame = gameObject.GetComponent <RobotGame>();
                 if (robotGame != null)
                 {
                     screenType = robotGame.getScreenTypeToChangeTo();
                     if (screenType == default)
                     {
                         screenType = GameObject.Find("BuildHubCanvas") != null ? typeof(BuildHub) : typeof(Field);
                     }
                     SettingsManager settingsManager = new SettingsManager();
                     SettingPairs    settingPairs    = settingsManager.getSettingPairs(robotGame.getCurrentSettings());
                     enableSplashScreenAnimation = settingPairs.splash_screen_animation;
                     splashMessage.SetActive(enableSplashScreenAnimation);
                     colorScheme = ImageTools.getColorFromString(settingPairs.color_scheme);
                     musicVolume = (float)(settingPairs.music_volume / 100 * settingPairs.master_volume / 100);
                     musicSound.GetComponent <AudioSource>().volume = musicVolume;
                     battleButtionVolume = (float)(settingPairs.action_performed_volume / 100 * settingPairs.master_volume / 100);
                     battleButtonSound.GetComponent <AudioSource>().volume = battleButtionVolume;
                     if (screenType.ToString() == "Field")
                     {
                         battleButtonSound.GetComponent <AudioSource>().Play();
                     }
                     loadingIcon.GetComponent <UnityEngine.UI.Image>().color = colorScheme;
                     splashMessage.GetComponent <TextMeshProUGUI>().color    = colorScheme;
                     splashMessage.GetComponent <TextMeshProUGUI>().color    = new Color(splashMessage.GetComponent <TextMeshProUGUI>().color.r, splashMessage.GetComponent <TextMeshProUGUI>().color.g, splashMessage.GetComponent <TextMeshProUGUI>().color.b, 0);
                 }
                 if (SceneManager.GetActiveScene().name == "SplashScreen")
                 {
                     gameObject.SetActive(false);
                 }
             }
         }
     }
     if (GetComponent <RobotGame>() == null)
     {
         switchScene();
     }
 }
Esempio n. 5
0
    public void update(SettingPairs settingPairs)
    {
        this.settingPairs = settingPairs;
        if (chargeBarColorString != this.settingPairs.charge_bar_color)
        {
            chargeBarColorString = this.settingPairs.charge_bar_color;
            ELAPSED_TIME_BAR.GetComponent <UnityEngine.UI.Image>().color = ImageTools.getColorFromString(chargeBarColorString);
        }
        if (crosshairGraphicString != this.settingPairs.crosshair_graphic)
        {
            crosshairGraphicString = this.settingPairs.crosshair_graphic;
            CROSSHAIR.GetComponent <UnityEngine.UI.Image>().sprite = ImageTools.getSpriteFromString(crosshairGraphicString);
        }
        if (attachmentWheelGraphicString != this.settingPairs.attachment_wheel_graphic)
        {
            attachmentWheelGraphicString = this.settingPairs.attachment_wheel_graphic;
            WHEEL.GetComponent <UnityEngine.UI.Image>().sprite = ImageTools.getSpriteFromString(attachmentWheelGraphicString);
        }
        if (HUMAN != null && HUMAN_DURABILITY_BAR != null)
        {
            HUMAN_DURABILITY_BAR.GetComponent <RectTransform>().localScale = new Vector3((float)(HUMAN.getRemainingDurability() / HUMAN.getDurability()), HUMAN_DURABILITY_BAR.GetComponent <RectTransform>().localScale.y, 0);
        }
        int robotIndex = 0;

        foreach (GameObject durabilityBar in ROBOT_DURABILITY_BARS)
        {
            durabilityBar.GetComponent <RectTransform>().localScale = new Vector3((float)(ROBOTS[robotIndex].getRemainingDurability() / ROBOTS[robotIndex++].getDurability()), durabilityBar.GetComponent <RectTransform>().localScale.y, 0);
        }
        Robot robot = (HUMAN != null) ? HUMAN : ROBOTS[0];

        if (robot.getAttachments().Selected().isWeapon() && robot.getAttachments().Selected().isCooled())
        {
            ELAPSED_TIME_BAR.GetComponent <RectTransform>().localScale = new Vector3((float)robot.getAttachments().Selected().getElapsedChargeTime() / (float)robot.getAttachments().Selected().getMaxChargeTime(), ELAPSED_TIME_BAR.GetComponent <RectTransform>().localScale.y, 0);
        }
        int attachmentIndex = 0;

        Attachment[] attachments = robot.getAttachments().ToArray();
        foreach (Attachment attachment in attachments)
        {
            if (!attachment.isPassive())
            {
                if (attachment.canUse())
                {
                    ATTACHMENT_WHEEL.enableAttachment(attachmentIndex++);
                }
                else
                {
                    ATTACHMENT_WHEEL.disableAttachment(attachmentIndex++);
                }
            }
        }
        CHARGE_BAR.transform.localScale = Vector3.one;
        CROSSHAIR.transform.localScale  = Vector3.one;
    }
Esempio n. 6
0
 public virtual void show()
 {
     if (areSettingsOpen())
     {
         settingPairs = SETTINGS_MANAGER.getSettingPairs(getSettings());
         colorScheme  = ImageTools.getColorFromString(settingPairs.color_scheme);
         if (!triedFindingSound && (musicSound == null || buttonSound == null || attachmentSound == null || weaponSound == null || robotSound == null))
         {
             triedFindingSound = true;
             findSound();
         }
         if (musicSound != null && (currentMasterVolume != settingPairs.master_volume || currentMusicVolume != settingPairs.music_volume))
         {
             musicSound.GetComponent <AudioSource>().volume = (float)(settingPairs.master_volume / 100 * settingPairs.music_volume / 100);
         }
         if (buttonSound != null && (currentMasterVolume != settingPairs.master_volume || currentButtonVolume != settingPairs.action_performed_volume))
         {
             buttonSound.GetComponent <AudioSource>().volume = (float)(settingPairs.master_volume / 100 * settingPairs.action_performed_volume / 100);
         }
         if (attachmentSound != null && (currentMasterVolume != settingPairs.master_volume || currentAttachmentVolume != settingPairs.attachment_sound_volume))
         {
             attachmentSound.GetComponent <AudioSource>().volume = (float)(settingPairs.master_volume / 100 * settingPairs.attachment_sound_volume / 100);
         }
         if (weaponSound != null && (currentMasterVolume != settingPairs.master_volume || currentWeaponVolume != settingPairs.weapon_used_volume))
         {
             weaponSound.GetComponent <AudioSource>().volume = (float)(settingPairs.master_volume / 100 * settingPairs.weapon_used_volume / 100);
         }
         if (robotSound != null && (currentMasterVolume != settingPairs.master_volume || currentRobotVolume != settingPairs.robot_sound_volume))
         {
             robotSound.GetComponent <AudioSource>().volume = (float)(settingPairs.master_volume / 100 * settingPairs.robot_sound_volume / 100);
         }
         currentMasterVolume     = settingPairs.master_volume;
         currentMusicVolume      = settingPairs.music_volume;
         currentButtonVolume     = settingPairs.action_performed_volume;
         currentAttachmentVolume = settingPairs.attachment_sound_volume;
         currentWeaponVolume     = settingPairs.weapon_used_volume;
         currentRobotVolume      = settingPairs.robot_sound_volume;
         getMenuToggleKeyCode();
         resetSettings = settingPairs.reset_settings;
         SETTINGS_MENU.updateSettings(colorScheme, menuToggle, resetSettings);
         SETTINGS_MENU.update();
     }
 }
Esempio n. 7
0
    private async void initializeScene(string sceneName) //test stuff inside! will need to be rewritten for actual game
    {
        running        = true;
        saveDataThread = new Thread(saveData);
        saveDataThread.Start();
        if (currentSettings == "")
        {
            currentSettings = SettingsManager.DEFAULT_SETTINGS;
        }
        SettingPairs settingPairs = settingsManager.getSettingPairs(currentSettings);

        settingList = settingsManager.getSettingList(currentSettings);
        fieldSize   = Field.getFieldSize(settingPairs.field_size);
        foreach (PartData partData in partsData)
        {
            Part part = partManager.partDataToPart(partData);
            if (part.GAME_OBJECT != null)
            {
                part.toggleGameObject(false);
            }
            parts.Add(part);
        }
        if (currentTest == TESTS.BUILD_HUB)
        {
            IconGenerator iconGenerator = new IconGenerator();
            Camera        camera        = null;
            foreach (Camera currCam in Camera.allCameras)
            {
                if (currCam.name == "IconCamera")
                {
                    camera = currCam;
                    camera.forceIntoRenderTexture = true;
                    break;
                }
            }
            iconGenerator.camera      = camera;
            Camera.main.targetDisplay = 1;
            foreach (Part part in parts)
            {
                if (part.GAME_OBJECT == null)
                {
                    continue;
                }
                part.toggleGameObject(true);
                part.GAME_OBJECT.transform.Rotate(new Vector3(9, 120, -15));
                iconGenerator.gameObjectOfIcon = part.GAME_OBJECT;
                while (part.getIcon() == null)
                {
                    if (part.GAME_OBJECT.GetComponent <Renderer>().isVisible)
                    {
                        iconGenerator.initialize();
                        if (iconGenerator.getIcon() != null)
                        {
                            part.setIcon(iconGenerator.getIcon());
                        }
                    }
                    if (part.getIcon() == null)
                    {
                        await Task.Delay(25);
                    }
                }
                part.toggleGameObject(false);
                part.destroyGameObject();
            }
            Camera.main.targetDisplay = 0;
        }
        else
        {
            foreach (Part part in parts)
            {
                if (part.GAME_OBJECT != null)
                {
                    part.destroyGameObject();
                }
            }
        }
        experience = playerData.experience;
        credits    = playerData.credits;
        previousRoundDamageDifference    = playerData.previousRoundDamageDifference;
        previousRoundMaxDamageDifference = playerData.previousRoundMaxDamageDifference;
        previousRoundTimeElapsed         = playerData.previousRoundTimeElapsed;
        ObstacleGenerator obstacleGenerator = new ObstacleGenerator(experience, settingPairs.max_obstacles, fieldSize);

        humanRobotParts = new List <Part>();
        obstaclesData   = new List <ObstacleData>();
        List <int> badIndices = new List <int>();
        PerformanceMetricCalculator performanceMetricCalculator = new PerformanceMetricCalculator();
        Head     cheapestHead     = null;
        Body     cheapestBody     = null;
        Mobility cheapestMobility = null;
        Blaster  cheapestBlaster  = null;

        foreach (Part part in parts)
        {
            if (part is Head && (cheapestHead == null || performanceMetricCalculator.calculateCost(part) < performanceMetricCalculator.calculateCost(cheapestHead)))
            {
                cheapestHead = (Head)part;
            }
            else if (part is Body && (cheapestBody == null || performanceMetricCalculator.calculateCost(part) < performanceMetricCalculator.calculateCost(cheapestBody)))
            {
                cheapestBody = (Body)part;
            }
            else if (part is Mobility && (cheapestMobility == null || performanceMetricCalculator.calculateCost(part) < performanceMetricCalculator.calculateCost(cheapestMobility)))
            {
                cheapestMobility = (Mobility)part;
            }
            else if (part is Blaster && (cheapestBlaster == null || performanceMetricCalculator.calculateCost(part) < performanceMetricCalculator.calculateCost(cheapestBlaster)))
            {
                cheapestBlaster = (Blaster)part;
            }
        }
        if (playerData.humanRobotParts != default)
        {
            for (int partIndex = 0; partIndex < playerData.humanRobotParts.Length; ++partIndex)
            {
                PlayerPartData playerPartData = playerData.humanRobotParts[partIndex];
                if (parts.Exists(p => p.getID() == playerPartData.id))
                {
                    Part part = parts.Find(p => p.getID() == playerPartData.id);
                    part.damage(part.getDurability() - playerPartData.remainingDurability);
                    if (part is Head)
                    {
                        humanRobotParts.Add((Head)part.clone(true));
                    }
                    else if (part is Body)
                    {
                        humanRobotParts.Add((Body)part.clone(true));
                    }
                    else if (part is Mobility)
                    {
                        humanRobotParts.Add((Mobility)part.clone(true));
                    }
                    else if (part is Attachment)
                    {
                        humanRobotParts.Add((Attachment)part.clone(true));
                    }
                }
                else
                {
                    humanRobotParts.Add(null);
                    badIndices.Add(partIndex);
                }
            }
        }
        else
        {
            humanRobotParts.AddRange(new Part[] { cheapestHead, cheapestBody, cheapestMobility, cheapestBlaster });
        }
        myRobots = new List <Robot>();
        if (playerData.myRobots != default)
        {
            foreach (RobotData robotData in playerData.myRobots)
            {
                List <Part> robotPartList = new List <Part>();
                foreach (int partIndex in robotData.partIndices)
                {
                    if (!badIndices.Contains(partIndex))
                    {
                        robotPartList.Add(humanRobotParts[partIndex]);
                    }
                }
                try
                {
                    Robot robot = new Robot(robotData.name, true, robotData.human, robotPartList.ToArray());
                    myRobots.Add(robot);
                }
                catch {}
            }
        }
        foreach (int index in badIndices)
        {
            humanRobotParts.RemoveAt(index);
        }
        if (!humanRobotParts.Exists(part => part is Head))
        {
            humanRobotParts.Add(cheapestHead);
        }
        if (!humanRobotParts.Exists(part => part is Body))
        {
            humanRobotParts.Add(cheapestBody);
        }
        if (!humanRobotParts.Exists(part => part is Mobility))
        {
            humanRobotParts.Add(cheapestMobility);
        }
        if (!humanRobotParts.Exists(part => part is Attachment && ((Attachment)part).isWeapon()))
        {
            humanRobotParts.Add(cheapestBlaster);
        }
        if (humanRobotParts.Contains(null))
        {
            throw new Exception("There are missing part files. There neeeds to be at least one part file each of types Head, Body, Mobility, and a weapon Attachment.");
        }
        if (playerData.obstacles != default)
        {
            obstaclesData.AddRange(playerData.obstacles);
        }
        else
        {
            obstaclesData.AddRange(obstacleGenerator.getObstaclesData());
        }
        if (currentSettingValueList.Count == 0)
        {
            foreach (Setting setting in settingList)
            {
                currentSettingValueList.Add(setting.currentValue);
            }
        }
        Head       head1       = null;
        Head       head2       = null;
        Body       body1       = null;
        Body       body2       = null;
        Mobility   mobility    = null;
        Attachment attachment1 = null;
        Attachment attachment2 = null;
        Attachment attachment3 = null;

        foreach (Part part in parts)
        {
            if (part is Head)
            {
                if (head1 == null)
                {
                    head1 = (Head)part.clone(true);
                    head1.damage(2);
                }
                else if (head2 == null)
                {
                    head2 = (Head)part.clone(true);
                    head2.damage(3);
                }
            }
            else if (part is Body)
            {
                if (body1 == null)
                {
                    body1 = (Body)part.clone(true);
                    body1.damage(3);
                }
                else if (body2 == null)
                {
                    body2 = (Body)part.clone(true);
                    body2.damage(4);
                }
            }
            else if (part is Mobility)
            {
                if (mobility == null)
                {
                    mobility = (Mobility)part.clone(true);
                    mobility.damage(1);
                }
            }
            else if (part is Attachment)
            {
                if (attachment1 == null)
                {
                    attachment1 = (Attachment)part.clone(true);
                    attachment1.damage(1);
                }
                else if (attachment2 == null)
                {
                    attachment2 = (Attachment)part.clone(true);
                    attachment2.damage(1);
                }
                else if (attachment3 == null)
                {
                    attachment3 = (Attachment)part.clone(true);
                    attachment3.damage(3);
                }
            }
        }
        List <Robot> robots = new List <Robot>();
        int          numberOfNonHumanRobots = 0;
        int          numberOfHumanRobots    = 0;

        Obstacle[]           obstacles      = null;
        List <BuildHubState> buildHubStates = default;

        if (buildHubStatesData != default && buildHubStatesData.Count > 0)
        {
            buildHubStates = new List <BuildHubState>();
            foreach (BuildHubStateData buildHubStateData in buildHubStatesData)
            {
                buildHubStates.Add(buildHubStateDataManager.stateDataToState(buildHubStateData));
            }
        }
        List <FieldState> fieldStates = default;

        if (fieldStatesData != default && fieldStatesData.Count > 0)
        {
            fieldStates = new List <FieldState>();
            foreach (FieldStateData fieldStateData in fieldStatesData)
            {
                fieldStates.Add(fieldStateDataManager.stateDataToState(fieldStateData, parts));
            }
        }
        BuildHub.MODES mode;
        switch (currentTest)
        {
        case TESTS.FIELD:
        case TESTS.HUMAN_V_VOID_ROBOT:
            List <Part> humanParts = new List <Part>();
            foreach (Part part in humanRobot.getParts())
            {
                Part clonePart = part.clone(false);
                if (clonePart is Head)
                {
                    clonePart = (Head)clonePart;
                }
                else if (clonePart is Body)
                {
                    clonePart = (Body)clonePart;
                }
                else if (clonePart is Mobility)
                {
                    clonePart = (Mobility)clonePart;
                }
                else if (clonePart is Attachment)
                {
                    clonePart = (Attachment)clonePart;
                }
                humanParts.Add(clonePart);
            }
            humanRobot = new Robot(humanRobot.getName(), humanRobot.isHuman(), humanParts.ToArray());
            currentHumanRobotHealth = humanRobot.getRemainingDurability();
            Attachment[] nonHumanAttachments = { (Attachment)attachment1.clone(true) };
            numberOfNonHumanRobots = RANDOM.Next(1, settingPairs.max_ai_robots + 1);
            numberOfHumanRobots    = 1;
            obstacles = obstacleGenerator.obstaclesDataToObstacles(obstaclesData.ToArray());
            aiManager = new AIManager(numberOfNonHumanRobots, numberOfNonHumanRobots - 1 + numberOfHumanRobots, new Robot[] { humanRobot }, parts.ToArray(), new Part[] { cheapestHead, cheapestBody, cheapestMobility, cheapestBlaster }, obstacles, fieldSize, buildHubStates, fieldStates, experience);
            robots.Add(humanRobot);
            robots.AddRange(aiManager.getAgentRobots());
            setScreen(new Field(settingList, robots.ToArray(), obstacles, previousRoundDamageDifference, previousRoundMaxDamageDifference, previousRoundTimeElapsed));
            break;

        case TESTS.AI_AGENT_TRAINING:
            numberOfNonHumanRobots = NUMBER_OF_AGENTS;
            numberOfHumanRobots    = 0;
            obstacles = obstacleGenerator.obstaclesDataToObstacles(obstaclesData.ToArray());
            aiManager = new AIManager(numberOfNonHumanRobots, numberOfNonHumanRobots - 1 + numberOfHumanRobots, null, parts.ToArray(), new Part[] { cheapestHead, cheapestBody, cheapestMobility, cheapestBlaster }, obstacles, fieldSize, buildHubStates, fieldStates, experience);
            Robot[] agentRobots = aiManager.getAgentRobots();
            for (int agentIndex = 0; agentIndex < NUMBER_OF_AGENTS; ++agentIndex)
            {
                FIELD_AGENT_ROBOTS[agentIndex] = agentRobots[agentIndex];
            }
            robots.AddRange(FIELD_AGENT_ROBOTS);
            setScreen(new Field(settingList, robots.ToArray(), obstacles, previousRoundDamageDifference, previousRoundMaxDamageDifference, previousRoundTimeElapsed));
            break;

        case TESTS.BUILD_HUB:
            mode = BuildHub.MODES.MY_ROBOTS;
            setScreen(new BuildHub(settingList, obstaclesData, myRobots, humanRobotParts, parts.ToArray(), credits, mode));
            break;
        }
    }
Esempio n. 8
0
    public FieldPeripheral(Robot human, Robot[] robots, SettingPairs settingPairs)
    {
        HUMAN                        = human;
        ROBOTS                       = robots;
        this.settingPairs            = settingPairs;
        chargeBarColorString         = this.settingPairs.charge_bar_color;
        crosshairGraphicString       = this.settingPairs.crosshair_graphic;
        attachmentWheelGraphicString = this.settingPairs.attachment_wheel_graphic;
        STATIC_CANVAS                = GameObject.Find(STATIC_CANVAS_NAME);
        DYNAMIC_CANVAS               = GameObject.Find(DYNAMIC_CANVAS_NAME);
        DURABILITY_BAR_TO_START_FROM = 1;
        if (HUMAN != null)
        {
            DURABILITY_BAR_TO_START_FROM = 2;
            HUMAN_DURABILITY_BAR         = GameObject.Instantiate(Resources.Load("Prefabs/DurabilityBar") as GameObject);
            HUMAN_DURABILITY_BAR_LABEL   = GameObject.Instantiate(Resources.Load("Prefabs/DurabilityBarLabel") as GameObject);
            HUMAN_DURABILITY_BAR.transform.SetParent(STATIC_CANVAS.transform);
            HUMAN_DURABILITY_BAR_LABEL.transform.SetParent(STATIC_CANVAS.transform);
            HUMAN_DURABILITY_BAR.transform.localPosition       = new Vector3(STATIC_CANVAS.GetComponent <RectTransform>().sizeDelta.x / 2 - DURABILITY_BAR_LABEL_OFFSET, STATIC_CANVAS.GetComponent <RectTransform>().sizeDelta.y / 2 - DURABILITY_BAR_LABEL_OFFSET, 0);
            HUMAN_DURABILITY_BAR_LABEL.transform.localPosition = new Vector3(STATIC_CANVAS.GetComponent <RectTransform>().sizeDelta.x / 2 - DURABILITY_BAR_LABEL_OFFSET, STATIC_CANVAS.GetComponent <RectTransform>().sizeDelta.y / 2 - DURABILITY_BAR_LABEL_OFFSET, 0);
            HUMAN_DURABILITY_BAR_LABEL.GetComponent <TextMeshProUGUI>().text     = HUMAN.getName();
            HUMAN_DURABILITY_BAR.GetComponent <RectTransform>().localScale       = Vector3.one;
            HUMAN_DURABILITY_BAR_LABEL.GetComponent <RectTransform>().localScale = Vector3.one;
        }
        ROBOT_DURABILITY_BARS       = new GameObject[ROBOTS.Length];
        ROBOT_DURABILITY_BAR_LABELS = new GameObject[ROBOTS.Length];
        int robotIndex = 0;

        foreach (Robot otherRobot in ROBOTS)
        {
            ROBOT_DURABILITY_BARS[robotIndex]       = GameObject.Instantiate(Resources.Load("Prefabs/DurabilityBar") as GameObject);
            ROBOT_DURABILITY_BAR_LABELS[robotIndex] = GameObject.Instantiate(Resources.Load("Prefabs/DurabilityBarLabel") as GameObject);
            ROBOT_DURABILITY_BARS[robotIndex].transform.SetParent(STATIC_CANVAS.transform);
            ROBOT_DURABILITY_BAR_LABELS[robotIndex].transform.SetParent(STATIC_CANVAS.transform);
            ROBOT_DURABILITY_BARS[robotIndex].transform.localPosition                         = new Vector3(STATIC_CANVAS.GetComponent <RectTransform>().sizeDelta.x / 2 - DURABILITY_BAR_LABEL_OFFSET, STATIC_CANVAS.GetComponent <RectTransform>().sizeDelta.y / 2 - (robotIndex + DURABILITY_BAR_TO_START_FROM) * DURABILITY_BAR_SPACING, 0);
            ROBOT_DURABILITY_BAR_LABELS[robotIndex].transform.localPosition                   = new Vector3(STATIC_CANVAS.GetComponent <RectTransform>().sizeDelta.x / 2 - DURABILITY_BAR_LABEL_OFFSET, STATIC_CANVAS.GetComponent <RectTransform>().sizeDelta.y / 2 - (robotIndex + DURABILITY_BAR_TO_START_FROM) * DURABILITY_BAR_SPACING, 0);
            ROBOT_DURABILITY_BARS[robotIndex].GetComponent <RectTransform>().localScale       = Vector3.one;
            ROBOT_DURABILITY_BAR_LABELS[robotIndex].GetComponent <RectTransform>().localScale = Vector3.one;
            ROBOT_DURABILITY_BAR_LABELS[robotIndex++].GetComponent <TextMeshProUGUI>().text   = otherRobot.getName();
        }
        CHARGE_BAR           = GameObject.Instantiate(Resources.Load("Prefabs/ChargeBar") as GameObject);
        ELAPSED_TIME_BAR     = CHARGE_BAR.transform.Find("ElapsedTimeBar").gameObject;
        MIN_CHARGE_TIME_TICK = CHARGE_BAR.transform.Find("MinChargeTimeTick").gameObject;
        ELAPSED_TIME_BAR.GetComponent <RectTransform>().localScale   = new Vector3(0, ELAPSED_TIME_BAR.GetComponent <RectTransform>().localScale.y, 0);
        ELAPSED_TIME_BAR.GetComponent <UnityEngine.UI.Image>().color = ImageTools.getColorFromString(chargeBarColorString);;
        CHARGE_BAR.SetActive(false);
        CHARGE_BAR.transform.SetParent(DYNAMIC_CANVAS.transform);
        CHARGE_BAR.transform.localPosition = new Vector3(0, CHARGE_BAR_OFFSET, 0);
        CHARGE_BAR.transform.localScale    = Vector3.one;
        changeWeapon();
        CROSSHAIR = GameObject.Instantiate(Resources.Load("Prefabs/Crosshair") as GameObject);
        CROSSHAIR.GetComponent <UnityEngine.UI.Image>().sprite = ImageTools.getSpriteFromString(crosshairGraphicString);
        CROSSHAIR.SetActive(false);
        CROSSHAIR.transform.SetParent(DYNAMIC_CANVAS.transform);
        CROSSHAIR.transform.localPosition = Vector3.zero;
        CROSSHAIR.transform.localScale    = Vector3.one;
        Robot robot = (HUMAN != null) ? HUMAN : ROBOTS[0];

        MIN_CHARGE_TIME_TICK.transform.localPosition = new Vector3(-CHARGE_BAR.GetComponent <RectTransform>().sizeDelta.x / 2 + (float)robot.getAttachments().Selected().getMinChargeTime() / (float)robot.getAttachments().Selected().getMaxChargeTime() * CHARGE_BAR.GetComponent <RectTransform>().sizeDelta.x, MIN_CHARGE_TIME_TICK.transform.localPosition.y, 0);
        ATTACHMENT_WHEEL = new AttachmentWheel(robot.getAttachments());
        WHEEL            = ATTACHMENT_WHEEL.getWheelMenu().gameObject;
        WHEEL.GetComponent <UnityEngine.UI.Image>().sprite = ImageTools.getSpriteFromString(attachmentWheelGraphicString);
    }