コード例 #1
0
    public ConfigurationCard(string robotName, long credits, double durability, double remainingDurability, string[] robotStatStrings, bool maxForceExceeded, Part[] parts, Color colorScheme, bool enableCreditsSpentAnimation)
    {
        this.robotName           = robotName;
        this.credits             = credits;
        this.durability          = durability;
        this.remainingDurability = remainingDurability;
        this.robotStatStrings    = robotStatStrings;
        this.maxForceExceeded    = maxForceExceeded;
        this.parts       = new List <Part>();
        attachments      = new List <Attachment>();
        this.colorScheme = colorScheme;
        this.enableCreditsSpentAnimation = enableCreditsSpentAnimation;
        foreach (Part part in parts)
        {
            if (!(part is Attachment))
            {
                this.parts.Add(part);
            }
            else
            {
                this.attachments.Add((Attachment)part);
            }
        }
        mode = InventoryCard.MODES.VIEW_PART_STATS;
        MASKED_ROBOT_WIDGET = GameObject.Find("Workshop").transform.Find("MaskedRobotWidget").gameObject;
        MASKED_ROBOT_WIDGET.SetActive(false);
        partBeingPreviewed            = null;
        partToEquipt                  = null;
        PERFORMANCE_METRIC_CALCULATOR = new PerformanceMetricCalculator();
        SCROLL_VIEW = GameObject.Find(CONFIGURATION_CARD_NAME);
        GameObject partsContainerGameObject = GameObject.Find(WIDGETS_CONTAINER_NAME);

        WIDGETS_CONTAINER = partsContainerGameObject.GetComponent <RectTransform>();
        SCROLL_RECT       = SCROLL_VIEW.GetComponent <ScrollRect>();
        WIDGETS_PANEL     = GameObject.Find(WIDGETS_PANEL_NAME).GetComponent <RectTransform>();
        SCROLLBAR_OBJECT  = GameObject.Find(WIDGETS_CARD_NAME).transform.Find(CONFIGURATION_SCROLLBAR_NAME).gameObject;
        SCROLLBAR         = SCROLLBAR_OBJECT.GetComponent <Scrollbar>();
        SCROLLBAR_OBJECT.SetActive(false);
        SCROLL_RECT.vertical        = false;
        robotWidget                 = GameObject.Find(CONFIGURATION_CARD_NAME).transform.Find(ROBOT_WIDGET_NAME).gameObject;
        robotWidgetLabel            = robotWidget.transform.Find(ROBOT_WIDGET_LABEL_NAME).gameObject;
        robotWidgetLabelPlaceholder = robotWidgetLabel.transform.Find("Text Area").Find(ROBOT_WIDGET_LABEL_PLACEHOLDER_NAME).gameObject;
        robotWidgetLabelPlaceholder.GetComponent <TextMeshProUGUI>().enabled = false;
        robotWidgetLabelText          = robotWidgetLabel.transform.Find("Text Area").Find(ROBOT_WIDGET_LABEL_TEXT_NAME).gameObject;
        robotWidgetDurabilityBar      = robotWidget.transform.Find(ROBOT_WIDGET_DURABILITY_BAR_NAME).gameObject;
        robotWidgetDurabilityBarLabel = robotWidget.transform.Find(ROBOT_WIDGET_DURABILITY_BAR_LABEL_NAME).gameObject;
        robotWidgetStats = robotWidget.transform.Find(ROBOT_WIDGET_STATS_NAME).gameObject;
        WORKSHOP_CREDIT  = GameObject.Find("WorkshopCredit");
        updateCredits();
        WORKSHOP_CREDITS_SPENT = GameObject.Find("Workshop").transform.Find("WorkshopCreditsSpent").gameObject;
        WORKSHOP_CREDITS_SPENT_HOME_POSITION = WORKSHOP_CREDITS_SPENT.transform.localPosition;
        WORKSHOP_CREDITS_SPENT.SetActive(false);
        WORKSHOP_CREDIT.GetComponent <TextMeshProUGUI>().color = colorScheme;
        initialize();
    }
コード例 #2
0
    public void setMode(InventoryCard.MODES mode, Part partBeingPreviewed, Part partToEquipt, string[] previewRobotStats)
    {
        this.partBeingPreviewed = partBeingPreviewed;
        this.partToEquipt       = partToEquipt;
        if (mode != this.mode)
        {
            switch (mode)
            {
            case InventoryCard.MODES.VIEW_PART_STATS:
                MASKED_ROBOT_WIDGET.SetActive(false);
                break;

            case InventoryCard.MODES.PREVIEW_PART:
                MASKED_ROBOT_WIDGET.transform.Find("MaskedRobotWidgetLabel").gameObject.GetComponent <TextMeshProUGUI>().text              = robotWidgetLabel.GetComponent <TMP_InputField>().text;
                MASKED_ROBOT_WIDGET.transform.Find("MaskedRobotWidgetDurabilityBar").gameObject.GetComponent <RectTransform>().localScale  = robotWidgetDurabilityBar.GetComponent <RectTransform>().localScale;
                MASKED_ROBOT_WIDGET.transform.Find("MaskedRobotWidgetDurabilityBarLabel").gameObject.GetComponent <TextMeshProUGUI>().text = robotWidgetDurabilityBarLabel.GetComponent <TextMeshProUGUI>().text;
                MASKED_ROBOT_WIDGET.GetComponent <RectTransform>().localScale = Vector3.one;
                MASKED_ROBOT_WIDGET.transform.position = robotWidget.transform.position;
                MASKED_ROBOT_WIDGET.SetActive(true);
                Part   robotPart = null;
                double robotPartRemainingDurability = 0, robotPartDurability = 0;
                for (int partIndex = 0; partIndex < numberOfWidgets; ++partIndex)
                {
                    Part part = (partIndex < parts.Count ? parts[partIndex] : attachments[partIndex - parts.Count]);
                    if (part.GetType() == this.partBeingPreviewed.GetType())
                    {
                        robotPart = part;
                        robotPartRemainingDurability = robotPart.getRemainingDurability();
                        robotPartDurability          = robotPart.getDurability();
                        break;
                    }
                }
                double[] differenceInStats = robotPart != null?robotPart.compareTo(this.partBeingPreviewed) : (new Blaster("", null, 0, null, Shape.SHAPES.CYLINDER, 0, 0, 0, 0, 0, 0)).compareTo(this.partBeingPreviewed);

                double tempRemainingDurability = this.remainingDurability - robotPartRemainingDurability + this.partBeingPreviewed.getRemainingDurability();
                double tempDurability          = this.durability - robotPartDurability + this.partBeingPreviewed.getDurability();
                MASKED_ROBOT_WIDGET.transform.Find("MaskedRobotWidgetDurabilityBar").gameObject.GetComponent <RectTransform>().localScale  = new Vector3((float)(tempRemainingDurability / tempDurability), robotWidgetDurabilityBar.GetComponent <RectTransform>().localScale.y, 0);
                MASKED_ROBOT_WIDGET.transform.Find("MaskedRobotWidgetDurabilityBarLabel").gameObject.GetComponent <TextMeshProUGUI>().text = ConfigurationCard.DURABILITY_BAR_LABEL_PREFIX + StringTools.formatString(tempRemainingDurability) + " / " + StringTools.formatString(tempDurability) + (differenceInStats != null && differenceInStats.Length > 0 ? " (" + applyStatDifferenceFormatting(differenceInStats[0], false) + " / " + applyStatDifferenceFormatting(differenceInStats[1], false) + ")" : "");
                GameObject maskedRobotWidgetStats = MASKED_ROBOT_WIDGET.transform.Find("MaskedRobotWidgetStats").gameObject;
                foreach (Transform child in maskedRobotWidgetStats.GetComponent <RectTransform>())
                {
                    GameObject.Destroy(child.gameObject);
                }
                for (int robotStatStringIndex = 0; robotStatStringIndex < robotStatStringLabels.Count; ++robotStatStringIndex)
                {
                    robotStatStringLabels[robotStatStringIndex].GetComponent <TextMeshProUGUI>().text = previewRobotStats[robotStatStringIndex];
                    GameObject partStat = GameObject.Instantiate(Resources.Load("Prefabs/PartStat") as GameObject);
                    partStat.GetComponent <TextMeshProUGUI>().text = previewRobotStats[robotStatStringIndex];
                    if (previewRobotStats[robotStatStringIndex].Contains(WEIGHT_STRING) && maxForceExceeded)
                    {
                        partStat.GetComponent <TextMeshProUGUI>().color = BAD_COLOR;
                    }
                    partStat.transform.SetParent(maskedRobotWidgetStats.GetComponent <RectTransform>());
                    partStat.transform.localPosition = new Vector3(partStat.transform.localPosition.x, partStat.transform.localPosition.y, 0);
                }
                break;

            case InventoryCard.MODES.EQUIPT_PART:
                MASKED_ROBOT_WIDGET.SetActive(false);
                for (int robotPartIndex = 0; robotPartIndex < parts.Count + attachments.Count; ++robotPartIndex)
                {
                    if (robotPartIndex < parts.Count && parts[robotPartIndex].GetType() == partToEquipt.GetType())
                    {
                        parts[robotPartIndex] = partToEquipt;
                        break;
                    }
                    else if (robotPartIndex >= parts.Count && attachments[robotPartIndex - parts.Count].GetType() == partToEquipt.GetType())
                    {
                        attachments[robotPartIndex - parts.Count] = (Attachment)partToEquipt;
                        break;
                    }
                    else if (robotPartIndex - parts.Count == attachments.Count - 1)
                    {
                        attachments.Add((Attachment)partToEquipt);
                    }
                }
                initialize();
                break;

            default:
                break;
            }
            this.mode = mode;
        }
    }
コード例 #3
0
ファイル: Workshop.cs プロジェクト: ebgolden/The-Robot-Games
    private void checkInventoryCardMode()
    {
        InventoryCard.MODES mode = INVENTORY_CARD.getMode();
        Part partBeingPreviewed = null, partBeingEquipt = null;

        Part[]   previewRobotParts = previewRobot.getParts();
        string[] robotStats        = null;
        if (CONFIGURATION_CARD.getMode() != mode)
        {
            switch (mode)
            {
            case InventoryCard.MODES.VIEW_PART_STATS:
                MASK.SetActive(false);
                previewRobot.GAME_OBJECT.transform.localPosition = new Vector3(previewRobot.GAME_OBJECT.transform.localPosition.x, previewRobot.GAME_OBJECT.transform.localPosition.y, 500);
                previewRobot.GAME_OBJECT.transform.localScale    = new Vector3(100, 100, 100);
                CONFIGURATION_CARD.initialize();
                if (partWithPreviewedTexture != null)
                {
                    if (partWithPreviewedTexture.getShape() == Shape.SHAPES.HEMISPHERE && !partWithPreviewedTexture.GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                    {
                        partWithPreviewedTexture.GAME_OBJECT.transform.localPosition = new Vector3(partWithPreviewedTexture.GAME_OBJECT.transform.localPosition.x, partWithPreviewedTexture.GAME_OBJECT.transform.localPosition.y - .5f, partWithPreviewedTexture.GAME_OBJECT.transform.localPosition.z);
                    }
                    else if (partWithPreviewedTexture.getShape() != Shape.SHAPES.HEMISPHERE && partWithPreviewedTexture.GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                    {
                        partWithPreviewedTexture.GAME_OBJECT.transform.localPosition = new Vector3(partWithPreviewedTexture.GAME_OBJECT.transform.localPosition.x, partWithPreviewedTexture.GAME_OBJECT.transform.localPosition.y + .5f, partWithPreviewedTexture.GAME_OBJECT.transform.localPosition.z);
                    }
                    partWithPreviewedTexture.changeTextureAndShape(partWithPreviewedTexture.getImage().getTexture(), MESHES[(int)partWithPreviewedTexture.getShape()], partWithPreviewedTexture.getShape());
                    partWithPreviewedTexture = null;
                }
                break;

            case InventoryCard.MODES.PREVIEW_PART:
                partBeingPreviewed = INVENTORY_CARD.getPartBeingPreviewed();
                previewRobot.GAME_OBJECT.transform.localPosition = new Vector3(previewRobot.GAME_OBJECT.transform.localPosition.x, previewRobot.GAME_OBJECT.transform.localPosition.y, 125);
                previewRobot.GAME_OBJECT.transform.localScale    = new Vector3(25, 25, 25);
                MASK.SetActive(true);
                List <Part>       parts       = new List <Part>();
                List <Attachment> attachments = new List <Attachment>();
                if (partBeingPreviewed is Attachment)
                {
                    attachments.Add((Attachment)partBeingPreviewed);
                }
                for (int robotPartIndex = 0; robotPartIndex < robotParts.Count; ++robotPartIndex)
                {
                    if (!(robotParts[robotPartIndex] is Attachment))
                    {
                        if (partBeingPreviewed.GetType() == robotParts[robotPartIndex].GetType())
                        {
                            partWithPreviewedTexture = previewRobotParts[robotPartIndex];
                            if (partBeingPreviewed.getShape() == Shape.SHAPES.HEMISPHERE && !previewRobotParts[robotPartIndex].GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                            {
                                previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition = new Vector3(previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition.x, previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition.y - .5f, previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition.z);
                            }
                            else if (partBeingPreviewed.getShape() != Shape.SHAPES.HEMISPHERE && previewRobotParts[robotPartIndex].GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                            {
                                previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition = new Vector3(previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition.x, previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition.y + .5f, previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition.z);
                            }
                            previewRobotParts[robotPartIndex].changeTextureAndShape(partBeingPreviewed.getImage().getTexture(), MESHES[(int)partBeingPreviewed.getShape()], partBeingPreviewed.getShape());
                        }
                        parts.Add(partBeingPreviewed.GetType() == robotParts[robotPartIndex].GetType() ? partBeingPreviewed : robotParts[robotPartIndex]);
                    }
                    else if (robotParts[robotPartIndex].GetType() != partBeingPreviewed.GetType())
                    {
                        attachments.Add((Attachment)robotParts[robotPartIndex]);
                    }
                }
                Robot tempRobot = new Robot("", true, robot.isHuman(), (Head)parts[(int)PART_INDICES.HEAD], (Body)parts[(int)PART_INDICES.BODY], (Mobility)parts[(int)PART_INDICES.MOBILITY], attachments.ToArray());
                robotStats = tempRobot.getRobotStatStrings();
                double[] differenceInStats = robot.compareTo(tempRobot);
                for (int differenceInStatsIndex = FIRST_STAT_INDEX; differenceInStatsIndex < differenceInStats.Length; ++differenceInStatsIndex)
                {
                    robotStats[differenceInStatsIndex - FIRST_STAT_INDEX] += (differenceInStats[differenceInStatsIndex] != 0 ? " (" + applyStatDifferenceFormatting(differenceInStats[differenceInStatsIndex], robotStats[differenceInStatsIndex - FIRST_STAT_INDEX].Contains("Weight")) + ")" : "");
                }
                break;

            case InventoryCard.MODES.EQUIPT_PART:
                MASK.SetActive(false);
                partBeingEquipt = INVENTORY_CARD.getPartBeingEquipt();
                if (partWithPreviewedTexture != null)
                {
                    if (partWithPreviewedTexture.getShape() == Shape.SHAPES.HEMISPHERE && !partWithPreviewedTexture.GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                    {
                        partWithPreviewedTexture.GAME_OBJECT.transform.localPosition = new Vector3(partWithPreviewedTexture.GAME_OBJECT.transform.localPosition.x, partWithPreviewedTexture.GAME_OBJECT.transform.localPosition.y - .5f, partWithPreviewedTexture.GAME_OBJECT.transform.localPosition.z);
                    }
                    else if (partWithPreviewedTexture.getShape() != Shape.SHAPES.HEMISPHERE && partWithPreviewedTexture.GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                    {
                        partWithPreviewedTexture.GAME_OBJECT.transform.localPosition = new Vector3(partWithPreviewedTexture.GAME_OBJECT.transform.localPosition.x, partWithPreviewedTexture.GAME_OBJECT.transform.localPosition.y + .5f, partWithPreviewedTexture.GAME_OBJECT.transform.localPosition.z);
                    }
                    partWithPreviewedTexture.changeTextureAndShape(partWithPreviewedTexture.getImage().getTexture(), MESHES[(int)partWithPreviewedTexture.getShape()], partWithPreviewedTexture.getShape());
                    partWithPreviewedTexture = null;
                }
                for (int robotPartIndex = 0; robotPartIndex < robotParts.Count; ++robotPartIndex)
                {
                    if (robotParts[robotPartIndex].GetType() == partBeingEquipt.GetType())
                    {
                        robotParts[robotPartIndex] = partBeingEquipt;
                        if (!(partBeingEquipt is Attachment))
                        {
                            if (partBeingEquipt.getShape() == Shape.SHAPES.HEMISPHERE && !previewRobotParts[robotPartIndex].GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                            {
                                previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition = new Vector3(previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition.x, previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition.y - .5f, previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition.z);
                            }
                            else if (partBeingEquipt.getShape() != Shape.SHAPES.HEMISPHERE && previewRobotParts[robotPartIndex].GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                            {
                                previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition = new Vector3(previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition.x, previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition.y + .5f, previewRobotParts[robotPartIndex].GAME_OBJECT.transform.localPosition.z);
                            }
                            previewRobotParts[robotPartIndex].changeTextureAndShape(partBeingPreviewed.getImage().getTexture(), MESHES[(int)partBeingPreviewed.getShape()], partBeingPreviewed.getShape());
                        }
                        break;
                    }
                    if (robotPartIndex == robotParts.Count - 1)
                    {
                        robotParts.Add(partBeingEquipt);
                    }
                }
                robot = new Robot("", true, robot.isHuman(), robotParts.ToArray());
                break;

            default:
                break;
            }
            CONFIGURATION_CARD.setMode(mode, partBeingPreviewed, partBeingEquipt, robotStats);
        }
    }