Example #1
0
 public SerzReader(string inputFile, MODES serzMode = MODES.wholeFile)
 {
     InputStream = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
     DebugFname  = inputFile;
     SERZ_MODE   = serzMode;
     Deserialize();
 }
Example #2
0
 public SerzReader(Stream fileStream, string debugFname, MODES serzMode = MODES.wholeFile)
 {
     InputStream = fileStream;
     DebugFname  = debugFname;
     SERZ_MODE   = serzMode;
     Deserialize();
 }
Example #3
0
    public Part getPartBeingBought()
    {
        Part tempPartBeingEquipt = partBeingBought;

        partBeingBought = null;
        mode            = MODES.VIEW_PART_STATS;
        return(tempPartBeingEquipt);
    }
Example #4
0
        /// <summary>
        /// Raises the load button event.
        /// </summary>
        public void OnLoadButton()
        {
            Debug.Log("User clicked [Load] button.");

            // Restart everything!
            dispose();

            if (facerecAlgorithm == "FaceRecognizer.Fisherfaces")
            {
                model = Face.createFisherFaceRecognizer();
            }
            else if (facerecAlgorithm == "FaceRecognizer.Eigenfaces")
            {
                model = Face.createEigenFaceRecognizer();
            }

            if (model == null)
            {
                Debug.LogError("ERROR: The FaceRecognizer algorithm [" + facerecAlgorithm + "] is not available in your version of OpenCV. Please update to OpenCV v2.4.1 or newer.");
                m_mode = MODES.MODE_DETECTION;
                return;
            }

            // load the train data.
            model.load(Application.temporaryCachePath + "/traindata.yml");

            int maxLabel = (int)Core.minMaxLoc(model.getLabels()).maxVal;

            if (maxLabel <= 0)
            {
                Debug.Log("load failure.");
                model.Dispose();
                model  = null;
                m_mode = MODES.MODE_DETECTION;
                return;
            }

            // Restore the save data.
            m_numPersons = maxLabel + 1;
            for (int i = 0; i < m_numPersons; ++i)
            {
                m_latestFaces.Add(i);
                preprocessedFaces.Add(Imgcodecs.imread(Application.temporaryCachePath + "/preprocessedface" + i + ".jpg", 0));
                if (preprocessedFaces [i].empty())
                {
                    preprocessedFaces [i] = new Mat(faceHeight, faceWidth, CvType.CV_8UC1, new Scalar(128));
                }
                faceLabels.Add(i);
            }

            // go to the recognition mode!
            m_mode = MODES.MODE_RECOGNITION;
        }
Example #5
0
    private void SetMode(MODES mode)
    {
        _mode = mode;

        switch (mode)
        {
        case MODES.STATIC:
            _label.Hide();
            break;

        case MODES.LIMITED:
            _curCycle   = _maxCycle;
            _label.Text = $"{_curCycle}";
            _label.Show();
            break;
        }
    }
Example #6
0
        /// <summary>
        /// Raises the add person button event.
        /// </summary>
        public void OnAddPersonButton()
        {
            Debug.Log("User clicked [Add Person] button when numPersons was " + m_numPersons + ".");

            // Check if there is already a person without any collected faces, then use that person instead.
            // This can be checked by seeing if an image exists in their "latest collected face".
            if ((m_numPersons == 0) || (m_latestFaces [m_numPersons - 1] >= 0))
            {
                // Add a new person.
                m_numPersons++;
                m_latestFaces.Add(-1);  // Allocate space for an extra person.
                Debug.Log("Num Persons: " + m_numPersons + ".");
            }
            // Use the newly added person. Also use the newest person even if that person was empty.
            m_selectedPerson = m_numPersons - 1;
            m_mode           = MODES.MODE_COLLECT_FACES;
        }
Example #7
0
 static Constants()
 {
     FORCED_TRANSPORTS.Add("HTTP");
     FORCED_TRANSPORTS.Add("HTTP-POLLING");
     FORCED_TRANSPORTS.Add("HTTP-STREAMING");
     FORCED_TRANSPORTS.Add("WS");
     FORCED_TRANSPORTS.Add("WS-POLLING");
     FORCED_TRANSPORTS.Add("WS-STREAMING");
     FORCED_TRANSPORTS.Add(null);
     PROXY_TYPES.Add("HTTP");
     // At the moment only HTTP proxy are supported.
     // PROXY_TYPES.Add("SOCKS4");
     // PROXY_TYPES.Add("SOCKS5");
     MODES.Add(MERGE);
     MODES.Add(COMMAND);
     MODES.Add(DISTINCT);
     MODES.Add(RAW);
 }
    public InventoryCard(long credits, Part[] humanParts, Part[] robotParts)
    {
        this.credits                 = credits;
        this.humanParts              = humanParts;
        this.robotParts              = robotParts;
        mode                         = MODES.VIEW_PART_STATS;
        partBeingPreviewed           = null;
        partBeingEquipt              = null;
        currentPartFilter            = DEFAULT_PART_FILTER;
        MASKED_INVENTORY_PART_BUTTON = GameObject.Find("Workshop").transform.Find("MaskedInventoryPartButton").gameObject;
        MASKED_INVENTORY_PART_BUTTON.SetActive(false);
        INVENTORY_SORT = GameObject.Find("InventorySort");
        currentSort    = DEFAULT_SORT;
        PERFORMANCE_METRIC_CALCULATOR = new PerformanceMetricCalculator();
        SCROLL_VIEW = GameObject.Find(INVENTORY_CARD_NAME);
        GameObject partsContainerGameObject = GameObject.Find(PARTS_CONTAINER_NAME);

        PARTS_CONTAINER  = partsContainerGameObject.GetComponent <RectTransform>();
        SCROLL_RECT      = SCROLL_VIEW.GetComponent <ScrollRect>();
        PARTS_PANEL      = GameObject.Find(PARTS_PANEL_NAME).GetComponent <RectTransform>();
        SCROLLBAR_OBJECT = GameObject.Find(INVENTORY_CARD_NAME).transform.Find(INVENTORY_SCROLLBAR_NAME).gameObject;
        SCROLLBAR        = SCROLLBAR_OBJECT.GetComponent <Scrollbar>();
        SCROLLBAR_OBJECT.SetActive(false);
        SCROLL_RECT.vertical = false;
        partButtons          = new List <GameObject>();
        partInfo             = GameObject.Find("Workshop").transform.Find(PART_INFO_NAME).gameObject;
        partType             = partInfo.transform.Find(PART_TYPE_NAME).gameObject;
        durabilityBar        = partInfo.transform.Find(DURABILITY_BAR_NAME).gameObject;
        durabilityBarLabel   = partInfo.transform.Find(DURABILITY_BAR_LABEL_NAME).gameObject;
        partStats            = partInfo.transform.Find(PART_STATS_NAME).gameObject;
        partInfo.SetActive(false);
        partStatsList = new List <GameObject>();
        initialize();
        PART_TABS = new List <GameObject>();
        foreach (Transform childTransform in GameObject.Find("InventoryTabs").transform.Find("InventoryTabMask"))
        {
            if (childTransform.gameObject.name.Contains(PART_TAB_SUFFIX))
            {
                PART_TABS.Add(childTransform.gameObject);
            }
        }
        updateSorting();
    }
Example #9
0
        // Mouse event handler. Called automatically by OpenCV when the user clicks in the GUI window.
        private void _onMouseUP(int x, int y)
        {
            Debug.Log("_onMouseUP() x:" + x + " y:" + y);

            Point pt = new Point(x, y);

            Debug.Log("User clicked on the image");
            // Check if the user clicked on one of the faces in the list.
            int clickedPerson = -1;

            for (int i = 0; i < m_numPersons; i++)
            {
                if (m_gui_faces_top >= 0)
                {
                    Rect rcFace = new Rect(m_gui_faces_left, m_gui_faces_top + i * faceHeight, faceWidth, faceHeight);
                    if (isPointInRect(pt, rcFace))
                    {
                        clickedPerson = i;
                        break;
                    }
                }
            }
            // Change the selected person, if the user clicked on a face in the GUI.
            if (clickedPerson >= 0)
            {
                // Change the current person, and collect more photos for them.
                m_selectedPerson = clickedPerson; // Use the newly added person.
                m_mode           = MODES.MODE_COLLECT_FACES;
            }
            // Otherwise they clicked in the center.
            else
            {
                // Change to training mode if it was collecting faces.
                if (m_mode == MODES.MODE_COLLECT_FACES)
                {
                    Debug.Log("User wants to begin training.");
                    m_mode = MODES.MODE_TRAINING;
                }
            }

            //Debug.Log("m_mode:" + m_mode + " clickedPerson:" + clickedPerson);
        }
Example #10
0
        // Use this for initialization
        void Start()
        {
            if (facerecAlgorithmType == facerecAlgorithmEnumType.Fisherfaces)
            {
                facerecAlgorithm = "FaceRecognizer.Fisherfaces";
            }
            else if (facerecAlgorithmType == facerecAlgorithmEnumType.Eigenfaces)
            {
                facerecAlgorithm = "FaceRecognizer.Eigenfaces";
            }

            // Load the face and 1 or 2 eye detection XML classifiers.
            initDetectors(ref faceCascade, ref eyeCascade1, ref eyeCascade2);

            // Since we have already initialized everything, lets start in Detection mode.
            m_mode = MODES.MODE_DETECTION;

            webCamTextureToMatHelper = gameObject.GetComponent <WebCamTextureToMatHelper> ();

            coroutineToWaitWebCameraInit = StartCoroutine(waitWebCameraInit(false, 0, 0.5f));
        }
Example #11
0
        private void Activate(MODES mode)
        {
            switch (mode)
            {
            case MODES.CHANGE:
                SC2_1.Visible      = true;
                SC2_1label.Visible = true;

                Firstlabel.Text = "Введите число:";
                SC1_1label.Text = "Из";

                Secondlabel.Visible = false;
                SecondBox.Visible   = false;
                SC1_2label.Visible  = false;
                SC1_2.Visible       = false;
                SCRlabel.Visible    = false;
                SCR.Visible         = false;
                break;

            case MODES.ADDITION:
            case MODES.DIVISION:
            case MODES.MULTIPLICATION:
            case MODES.SUBTRACTION:

                SC2_1.Visible      = false;
                SC2_1label.Visible = false;

                Firstlabel.Text = "Введите первое число:";
                SC1_1label.Text = "В";

                Secondlabel.Visible = true;
                SecondBox.Visible   = true;
                SC1_2label.Visible  = true;
                SC1_2.Visible       = true;
                SCRlabel.Visible    = true;
                SCR.Visible         = true;

                break;
            }
        }
Example #12
0
    public void Init(Vector2 position, float radius = 100, MODES modes = MODES.LIMITED)
    {
        Position = position;
        _radius  = radius;

        _pivot            = GetNode <Node2D>("Pivot");
        _orbitPosition    = GetNode <Position2D>("Pivot/OrbitPosition");
        _collisionShape2D = GetNode <CollisionShape2D>("CollisionShape2D");
        _sprite           = GetNode <Sprite>("Sprite");
        _animationPlayer  = GetNode <AnimationPlayer>("AnimationPlayer");
        _label            = GetNode <Label>("Label");
        SetMode(modes);

        _circleShape2D        = (CircleShape2D)_collisionShape2D.Shape;
        _circleShape2D.Radius = _radius;
        imgSize = _sprite.Texture.GetSize().x / 2;

        _sprite.Scale = Vector2.One * _radius / imgSize;

        _orbitPosition.Position = new Vector2(_radius + 25, 0);

        _rotationSpeed *= Mathf.Pow(-1, GD.Randi() % 2);
    }
Example #13
0
    IEnumerator introTextSequence()
    {
        mode = MODES.TEXTBOX;

        textbox.SetActive(true);
        textboxText.text = textEntries[0];
        int count = 0;

        while (count < textEntries.Length)
        {
            if (Input.GetKeyDown(KeyCode.Space))
            {
                count++;
                if (count < textEntries.Length)
                {
                    textboxText.text = textEntries[count];
                }
            }
            yield return(null);
        }
        textbox.SetActive(false);

        mode = MODES.GAMEPLAY;
    }
Example #14
0
 public BuildHub(List <Setting> settingList, List <ObstacleData> obstaclesData, List <Robot> myRobots, List <Part> humanRobotParts, Part[] storeParts, long credits, MODES mode) : base(settingList)
 {
     myRobotsList = new List <Robot>();
     if (myRobots != null && myRobots.Count > 0)
     {
         myRobotsList.AddRange(myRobots);
     }
     this.humanRobotParts = humanRobotParts;
     currentRobot         = (this.myRobotsList.Count > 0 ? this.myRobotsList[0] : null);
     OBSTACLES_DATA       = obstaclesData;
     STORE_PARTS          = storeParts;
     this.credits         = credits;
     this.mode            = mode;
     goToField            = false;
     trainingMode         = false;
     MESHES = new List <Mesh>();
     MESHES.Add(PrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Cube));
     MESHES.Add(PrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Sphere));
     MESHES.Add(PrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Cylinder));
     MESHES.Add(PrimitiveHelper.GetPrimitiveMesh(PrimitiveType.Cube));
     foreach (Part part in this.humanRobotParts)
     {
         if (!(part is Attachment) && part.GAME_OBJECT != null)
         {
             part.toggleGameObject(false);
         }
     }
     foreach (Part part in STORE_PARTS)
     {
         if (part.GAME_OBJECT != null)
         {
             part.toggleGameObject(false);
         }
     }
     if (currentRobot != null)
     {
         createPreviewRobot();
     }
     this.myRobots = new MyRobots(myRobotsList.ToArray(), this.humanRobotParts.ToArray(), this.credits, base.colorScheme);
     workshop      = new Workshop(MESHES, previewRobot, (currentRobot != null ? currentRobot.getName() : ""), this.humanRobotParts, (currentRobot != null ? currentRobot.getParts() : null), this.credits, base.colorScheme, enableCreditsSpentAnimation);
     store         = new Store(MESHES, previewRobot, this.STORE_PARTS, this.humanRobotParts, (currentRobot != null ? currentRobot.getParts() : null), this.credits, workshop.getConfigurationCard(), base.colorScheme, enableCreditsSpentAnimation);
     obstacleList  = new ObstacleList(OBSTACLES_DATA);
     TABS          = new List <GameObject>();
     foreach (Transform child in GameObject.Find("BuildHubTabs").transform)
     {
         TABS.Add(child.gameObject);
     }
     MY_ROBOTS_BACK_BUTTON = GameObject.Find("MyRobotsBackButton");
     OBSTACLES_INFO_BUTTON = GameObject.Find("ObstaclesInfoButton");
     SETTINGS_BUTTON       = GameObject.Find("SettingsButton");
     TRAINING_BUTTON       = GameObject.Find("TrainingButton");
     CREDITS_BUTTON        = GameObject.Find("CreditsButton");
     CREDITS_WIDGET        = GameObject.Find("CreditsWidget");
     CREDITS_WIDGET.SetActive(false);
     base.colorScheme            = ImageTools.getColorFromString(base.settingPairs.color_scheme);
     enableCreditsSpentAnimation = base.settingPairs.credits_spent_animation;
     SETTINGS_BUTTON.GetComponent <UnityEngine.UI.Image>().color = base.colorScheme;
     TRAINING_BUTTON.GetComponent <UnityEngine.UI.Image>().color = base.colorScheme;
     colorScheme             = SETTINGS_BUTTON.GetComponent <UnityEngine.UI.Image>().color;
     BACKGROUND              = GameObject.Find("Background");
     backgroundGraphicString = settingPairs.build_hub_background_graphic;
     BACKGROUND.GetComponent <UnityEngine.UI.Image>().sprite = ImageTools.getSpriteFromString(backgroundGraphicString);
     PLATFORM = GameObject.Find("Platform");
     platformGraphicString = settingPairs.build_hub_platform_graphic;
     PLATFORM.GetComponent <Renderer>().material.mainTexture = new Image(platformGraphicString).getTexture();
     enablePreviewRobotAnimation = settingPairs.preview_robot_animation;
     updateTabs();
     if (this.mode == MODES.MY_ROBOTS)
     {
         MY_ROBOTS_BACK_BUTTON.SetActive(false);
         foreach (GameObject tab in TABS)
         {
             tab.SetActive(false);
         }
     }
 }
Example #15
0
 // Start is called before the first frame update
 void Start()
 {
     mode = MODES.FADING;
     StartCoroutine(introTextSequence());
 }
Example #16
0
 // Start is called before the first frame update
 void Start()
 {
     mode          = MODES.FADING;
     fadeCoroutine = StartCoroutine(fadeIn());
 }
Example #17
0
    public MyRobotsCard(Robot[] myRobots, Part[] humanRobotParts, long credits, Color colorScheme)
    {
        this.myRobots = new List <Robot>();
        this.myRobots.AddRange(myRobots);
        this.humanRobotParts = new List <Part>();
        this.humanRobotParts.AddRange(humanRobotParts);
        this.credits                 = credits;
        this.colorScheme             = colorScheme;
        robotBeingPreviewed          = null;
        robotBeingPicked             = null;
        robotsToRemove               = new List <Robot>();
        selectedRobotIndicesToRemove = new List <int>();
        newRobot       = null;
        mode           = MODES.VIEW_MY_ROBOTS_STATS;
        MY_ROBOTS_SORT = GameObject.Find("MyRobotsSort");
        currentSort    = DEFAULT_SORT;
        SCROLL_VIEW    = GameObject.Find(MY_ROBOTS_CARD_NAME);
        GameObject storeContainerGameObject = GameObject.Find(MY_ROBOTS_CONTAINER_NAME);

        MY_ROBOTS_CONTAINER = storeContainerGameObject.GetComponent <RectTransform>();
        SCROLL_RECT         = SCROLL_VIEW.GetComponent <ScrollRect>();
        MY_ROBOTS_PANEL     = GameObject.Find(MY_ROBOTS_PANEL_NAME).GetComponent <RectTransform>();
        SCROLLBAR_OBJECT    = GameObject.Find(MY_ROBOTS_CARD_NAME).transform.Find(MY_ROBOTS_SCROLLBAR_NAME).gameObject;
        SCROLLBAR           = SCROLLBAR_OBJECT.GetComponent <Scrollbar>();
        SCROLLBAR_OBJECT.SetActive(false);
        SCROLL_RECT.vertical          = false;
        myRobotsButtons               = new List <GameObject>();
        myRobotsInfo                  = GameObject.Find("MyRobots").transform.Find(MY_ROBOTS_INFO_NAME).gameObject;
        myRobotsName                  = myRobotsInfo.transform.Find(MY_ROBOTS_NAME).gameObject;
        myRobotsStats                 = myRobotsInfo.transform.Find(MY_ROBOTS_STATS_NAME).gameObject;
        robotWidgetDurabilityBar      = myRobotsInfo.transform.transform.Find("DurabilityBar").gameObject;
        robotWidgetDurabilityBarLabel = myRobotsInfo.transform.transform.Find("DurabilityBarLabel").gameObject;
        myRobotsInfo.SetActive(false);
        NEW_ROBOT_BUTTON = GameObject.Find("NewRobot");
        NEW_ROBOT_BUTTON.GetComponent <UnityEngine.UI.Image>().color = this.colorScheme;
        REMOVE_ROBOTS_BUTTON        = GameObject.Find("MyRobots").transform.Find("RemoveRobots").gameObject;
        CANCEL_REMOVE_ROBOTS_BUTTON = GameObject.Find("MyRobots").transform.Find("CancelRemoveRobots").gameObject;
        if (myRobots.Length == 0)
        {
            REMOVE_ROBOTS_BUTTON.SetActive(false);
        }
        CANCEL_REMOVE_ROBOTS_BUTTON.SetActive(false);
        MY_ROBOTS_CREDIT = GameObject.Find("MyRobotsCredit");
        MY_ROBOTS_CREDIT.GetComponent <TextMeshProUGUI>().color = this.colorScheme;
        updateCredits();
        myRobotsStatsList = new List <GameObject>();
        foreach (Robot robot in this.myRobots)
        {
            GameObject robotButton = GameObject.Instantiate(Resources.Load("Prefabs/RobotButton") as GameObject);
            Texture2D  robotIcon   = robot.getHead().getIcon();
            if (robotIcon != null)
            {
                robotButton.transform.Find("Icon").GetComponent <UnityEngine.UI.Image>().sprite = Sprite.Create(robotIcon, new Rect(0, 0, robotIcon.width, robotIcon.height), new Vector2(0.5f, 0.5f), 100);
            }
            robotButton.GetComponent <RectTransform>().localScale = Vector3.one;
            robotButton.transform.localPosition = new Vector3(robotButton.transform.localPosition.x, robotButton.transform.localPosition.y, 0);
            robotButton.transform.Find("NameLabel").GetComponent <TextMeshProUGUI>().text = robot.getName();
            robotButton.transform.SetParent(MY_ROBOTS_PANEL);
            robotButton.transform.localPosition = new Vector3(robotButton.transform.localPosition.x, robotButton.transform.localPosition.y, 0);
            robotButton.transform.Find("SelectionIndicator").gameObject.SetActive(false);
            myRobotsButtons.Add(robotButton);
        }
        if (this.myRobots.Count > 0)
        {
            updateSorting();
        }
    }
Example #18
0
    public void update(Robot[] myRobots, Part[] humanRobotParts, long credits, Color colorScheme)
    {
        this.credits = credits;
        if (this.colorScheme != colorScheme)
        {
            this.colorScheme = colorScheme;
            NEW_ROBOT_BUTTON.GetComponent <UnityEngine.UI.Image>().color = this.colorScheme;
            MY_ROBOTS_CREDIT.GetComponent <TextMeshProUGUI>().color      = this.colorScheme;
        }
        if (this.myRobots.Count != myRobots.Length)
        {
            this.myRobots.Clear();
            this.myRobots.AddRange(myRobots);
        }
        if (this.humanRobotParts.Count != humanRobotParts.Length)
        {
            this.humanRobotParts.Clear();
            this.humanRobotParts.AddRange(humanRobotParts);
        }
        if (base.enabled)
        {
            if ((mode != MODES.NEW_ROBOT && (myRobots == null || myRobots.Length == 0)) || (NEW_ROBOT_BUTTON.activeSelf && NEW_ROBOT_BUTTON.GetComponent <ButtonListener>().isClicked()))
            {
                NEW_ROBOT_BUTTON.GetComponent <ButtonListener>().resetClick();
                mode = MODES.NEW_ROBOT;
                Part[] parts = null;
                if (myRobots != null && myRobots.Length > 0)
                {
                    parts = myRobots[0].getParts();
                }
                else
                {
                    List <Part> defaultParts = new List <Part>();
                    defaultParts.Add(findFirstPartOfType(this.humanRobotParts, typeof(Head)));
                    defaultParts.Add(findFirstPartOfType(this.humanRobotParts, typeof(Body)));
                    defaultParts.Add(findFirstPartOfType(this.humanRobotParts, typeof(Mobility)));
                    defaultParts.Add(findFirstPartOfType(this.humanRobotParts, typeof(Blaster)));
                    parts = defaultParts.ToArray();
                }
                List <Part> newParts = new List <Part>();
                foreach (Part part in parts)
                {
                    newParts.Add(part.clone(true));
                }
                newRobot            = new Robot("", true, true, newParts.ToArray());
                robotBeingPreviewed = null;
            }
            else if (CANCEL_REMOVE_ROBOTS_BUTTON.GetComponent <ButtonListener>().isClicked())
            {
                mode = MODES.VIEW_MY_ROBOTS_STATS;
                CANCEL_REMOVE_ROBOTS_BUTTON.GetComponent <ButtonListener>().resetClick();
                REMOVE_ROBOTS_BUTTON.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text = REMOVE_ROBOTS_TEXT;
                CANCEL_REMOVE_ROBOTS_BUTTON.SetActive(false);
                robotsToRemove = new List <Robot>();
                selectedRobotIndicesToRemove = new List <int>();
                foreach (GameObject robotButton in myRobotsButtons)
                {
                    robotButton.transform.Find("SelectionIndicator").gameObject.SetActive(false);
                }
            }
            else if (REMOVE_ROBOTS_BUTTON.GetComponent <ButtonListener>().isClicked())
            {
                REMOVE_ROBOTS_BUTTON.GetComponent <ButtonListener>().resetClick();
                switch (mode)
                {
                case MODES.REMOVE_ROBOTS:
                    if (selectedRobotIndicesToRemove.Count > 0)
                    {
                        mode = MODES.VIEW_MY_ROBOTS_STATS;
                        REMOVE_ROBOTS_BUTTON.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text = REMOVE_ROBOTS_TEXT;
                        CANCEL_REMOVE_ROBOTS_BUTTON.SetActive(false);
                        robotsToRemove = new List <Robot>();
                        foreach (int robotIndex in selectedRobotIndicesToRemove)
                        {
                            robotsToRemove.Add(this.myRobots[robotIndex]);
                            this.myRobots.RemoveAt(robotIndex);
                            GameObject.Destroy(myRobotsButtons[robotIndex]);
                            myRobotsButtons.RemoveAt(robotIndex);
                        }
                        selectedRobotIndicesToRemove = new List <int>();
                    }
                    break;

                default:
                    mode = MODES.REMOVE_ROBOTS;
                    REMOVE_ROBOTS_BUTTON.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text = REMOVE_SELECTED_ROBOTS_TEXT;
                    REMOVE_ROBOTS_BUTTON.GetComponent <UnityEngine.UI.Image>().color = CANCEL_REMOVE_ROBOTS_BUTTON.GetComponent <UnityEngine.UI.Image>().color;
                    CANCEL_REMOVE_ROBOTS_BUTTON.SetActive(true);
                    robotsToRemove = new List <Robot>();
                    selectedRobotIndicesToRemove = new List <int>();
                    break;
                }
            }
            if ((MY_ROBOTS_PANEL.offsetMax.y - MY_ROBOTS_PANEL.offsetMin.y) > (MY_ROBOTS_CONTAINER.offsetMax.y - MY_ROBOTS_CONTAINER.offsetMin.y))
            {
                SCROLLBAR_OBJECT.SetActive(true);
                SCROLL_RECT.vertical = true;
            }
            else
            {
                SCROLLBAR_OBJECT.SetActive(false);
                SCROLL_RECT.vertical = false;
            }
            for (int myRobotsButtonIndex = 0; myRobotsButtonIndex < myRobotsButtons.Count; ++myRobotsButtonIndex)
            {
                ButtonListener buttonListener = myRobotsButtons[myRobotsButtonIndex].GetComponent <ButtonListener>();
                if (buttonListener.isClicked())
                {
                    buttonListener.resetClick();
                    switch (mode)
                    {
                    case MODES.VIEW_MY_ROBOTS_STATS:
                        mode = MODES.PICK_ROBOT;
                        myRobotsInfo.SetActive(false);
                        robotBeingPicked = myRobots[myRobotsButtonIndex];
                        break;

                    case MODES.REMOVE_ROBOTS:
                        if (!selectedRobotIndicesToRemove.Contains(myRobotsButtonIndex))
                        {
                            selectedRobotIndicesToRemove.Add(myRobotsButtonIndex);
                            myRobotsButtons[myRobotsButtonIndex].transform.Find("SelectionIndicator").gameObject.SetActive(true);
                            REMOVE_ROBOTS_BUTTON.GetComponent <UnityEngine.UI.Image>().color = REMOVE_ROBOTS_BUTTON_COLOR;
                        }
                        else
                        {
                            selectedRobotIndicesToRemove.Remove(myRobotsButtonIndex);
                            myRobotsButtons[myRobotsButtonIndex].transform.Find("SelectionIndicator").gameObject.SetActive(false);
                            if (selectedRobotIndicesToRemove.Count == 0)
                            {
                                REMOVE_ROBOTS_BUTTON.GetComponent <UnityEngine.UI.Image>().color = CANCEL_REMOVE_ROBOTS_BUTTON.GetComponent <UnityEngine.UI.Image>().color;
                            }
                        }
                        break;

                    default:
                        break;
                    }
                    break;
                }
                if (buttonListener.isMouseOver() && mode == MODES.VIEW_MY_ROBOTS_STATS)
                {
                    robotBeingPreviewed = myRobots[myRobotsButtonIndex];
                    Vector2 position;
                    RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("BuildHubCanvas").GetComponent <RectTransform>(), Input.mousePosition, Camera.main, out position);
                    position.x += myRobotsInfo.GetComponent <RectTransform>().sizeDelta.x / 2;
                    myRobotsInfo.transform.localPosition = position;
                    myRobotsName.GetComponent <TextMeshProUGUI>().text = myRobots[myRobotsButtonIndex].getName();
                    foreach (GameObject partStat in myRobotsStatsList)
                    {
                        GameObject.Destroy(partStat);
                    }
                    myRobotsStatsList.Clear();
                    robotWidgetDurabilityBar.GetComponent <RectTransform>().localScale  = new Vector3((float)(myRobots[myRobotsButtonIndex].getRemainingDurability() / myRobots[myRobotsButtonIndex].getDurability()), robotWidgetDurabilityBar.GetComponent <RectTransform>().localScale.y, 0);
                    robotWidgetDurabilityBarLabel.GetComponent <TextMeshProUGUI>().text = DURABILITY_BAR_LABEL_PREFIX + StringTools.formatString(myRobots[myRobotsButtonIndex].getRemainingDurability()) + " / " + StringTools.formatString(myRobots[myRobotsButtonIndex].getDurability());
                    string[] myRobotsStatStrings = myRobots[myRobotsButtonIndex].getRobotStatStrings();
                    for (int myRobotsStatIndex = 0; myRobotsStatIndex < myRobotsStatStrings.Length; ++myRobotsStatIndex)
                    {
                        GameObject myRobotsStat = GameObject.Instantiate(Resources.Load("Prefabs/PartStat") as GameObject);
                        myRobotsStat.GetComponent <TextMeshProUGUI>().text = myRobotsStatStrings[myRobotsStatIndex];
                        myRobotsStat.transform.SetParent(myRobotsStats.GetComponent <RectTransform>());
                        myRobotsStat.transform.localPosition = new Vector3(myRobotsStat.transform.localPosition.x, myRobotsStat.transform.localPosition.y, 0);
                        myRobotsStatsList.Add(myRobotsStat);
                    }
                    myRobotsInfo.SetActive(true);
                    break;
                }
                else
                {
                    myRobotsInfo.SetActive(false);
                }
            }
            if (currentSort != MY_ROBOTS_SORT.GetComponent <TMP_Dropdown>().value)
            {
                currentSort = MY_ROBOTS_SORT.GetComponent <TMP_Dropdown>().value;
                applySorting();
            }
        }
    }
Example #19
0
        private void Receiver()
        {
            bool restart = true;

            for (; restart;) // restart on error
            {
                client = new TcpClient();
                stream = null;

                try
                {
                    client.Connect(address, port);
                    stream = client.GetStream();

                    if (stream != null)
                    {
                        WriteLine("Connected", true);


                        for (; ;)   // main loop
                        {
                            if (stream != null)
                            {
                                if (stream.DataAvailable)
                                {
                                    Received.Clear();
                                    while (stream.DataAvailable)
                                    {
                                        Received.Add((byte)stream.ReadByte());
                                    }
                                    ReceivedArray = Received.ToArray();
                                    string asciiString = Encoding.ASCII.GetString(ReceivedArray);

                                    if (asciiString == "Other connected") // byte_dec
                                    {
                                        WriteLine("Other connected");
                                    }
                                    else
                                    {
                                        MODES mode = (MODES)cbMode.SelectedIndex;
                                        if (mode == MODES.STR_HEX)
                                        {
                                            WriteLine(BitConverter.ToString(ReceivedArray).Replace("-", " "));
                                        }
                                        if (mode == MODES.ADV_HEX)
                                        {
                                            string byteStr = BitConverter.ToString(ReceivedArray).Replace("-", " ");
                                            for (int q = 0; q < byteStr.Length; q += 48) //16x3
                                            {
                                                int w = Math.Min(48, byteStr.Length - q);
                                                WriteLine(byteStr.Substring(q, w));
                                            }
                                        }
                                        if (mode == MODES.ASCII)
                                        {
                                            WriteLine(asciiString);
                                        }
                                        if (mode == MODES.UTF8)
                                        {
                                            WriteLine(Encoding.UTF8.GetString(ReceivedArray));
                                        }
                                    }
                                }
                                if (Send.Count > 0)
                                {
                                    byte[] arr = Send.ToArray();
                                    stream.Write(arr, 0, arr.Length);
                                    Send.Clear();
                                }
                            }
                            Thread.Sleep(1);
                        }
                    }
                    Thread.Sleep(100);
                }
                catch (ThreadAbortException)
                {
                    WriteLine("Stopped", true);
                    if (stream != null)
                    {
                        stream.Close();
                    }

                    if (client != null)
                    {
                        client.Close();
                    }
                    restart = false;
                }
                catch (Exception ex)
                {
                    WriteLine("Error: " + ex.Message, true);
                    if (stream != null)
                    {
                        stream.Close();
                    }

                    if (client != null)
                    {
                        client.Close();
                    }

                    Thread.Sleep(100);
                }
            }
        }
Example #20
0
 public void update(long credits, Part[] humanParts, Part[] robotParts)
 {
     this.credits = credits;
     if (this.humanParts.Length != humanParts.Length || this.robotParts.Length != robotParts.Length)
     {
         this.humanParts = humanParts;
         this.robotParts = robotParts;
         initialize();
     }
     if (base.enabled)
     {
         if (Input.GetMouseButton(0) && mode == MODES.PREVIEW_PART)
         {
             mode = MODES.VIEW_PART_STATS;
             partBeingPreviewed = null;
             partBeingEquipt    = null;
             MASKED_INVENTORY_PART_BUTTON.SetActive(false);
         }
         if ((PARTS_PANEL.offsetMax.y - PARTS_PANEL.offsetMin.y) > (PARTS_CONTAINER.offsetMax.y - PARTS_CONTAINER.offsetMin.y))
         {
             SCROLLBAR_OBJECT.SetActive(true);
             SCROLL_RECT.vertical = true;
         }
         else
         {
             SCROLLBAR_OBJECT.SetActive(false);
             SCROLL_RECT.vertical = false;
         }
         for (int partButtonIndex = 0; partButtonIndex < partButtons.Count; ++partButtonIndex)
         {
             ButtonListener buttonListener = partButtons[partButtonIndex].GetComponent <ButtonListener>();
             if ((buttonListener.isClicked() || buttonListener.isControlClicked()) && mode != MODES.PREVIEW_PART)
             {
                 bool ignoreClick = false;
                 foreach (Part part in robotParts)
                 {
                     if (humanParts[partButtonIndex].getID() == part.getID())
                     {
                         ignoreClick = true;
                         break;
                     }
                 }
                 if (!ignoreClick)
                 {
                     if (buttonListener.isClicked())
                     {
                         mode = MODES.PREVIEW_PART;
                         partInfo.SetActive(false);
                         partBeingPreviewed = humanParts[partButtonIndex];
                         Texture2D partIcon = humanParts[partButtonIndex].getIcon();
                         MASKED_INVENTORY_PART_BUTTON.transform.Find("Icon").gameObject.GetComponent <UnityEngine.UI.Image>().sprite = Sprite.Create(partIcon, new Rect(0, 0, partIcon.width, partIcon.height), new Vector2(0.5f, 0.5f), 100);
                         MASKED_INVENTORY_PART_BUTTON.GetComponent <RectTransform>().localScale = Vector3.one;
                         MASKED_INVENTORY_PART_BUTTON.transform.position = partButtons[partButtonIndex].transform.position;
                         MASKED_INVENTORY_PART_BUTTON.SetActive(true);
                     }
                     else if (buttonListener.isControlClicked())
                     {
                         mode            = MODES.EQUIPT_PART;
                         partBeingEquipt = humanParts[partButtonIndex];
                     }
                     buttonListener.resetClick();
                     break;
                 }
                 buttonListener.resetClick();
             }
             if (buttonListener.isMouseOver() && mode != MODES.PREVIEW_PART)
             {
                 Part robotPart = null;
                 foreach (Part part in robotParts)
                 {
                     if (part.GetType() == humanParts[partButtonIndex].GetType())
                     {
                         robotPart = part;
                         break;
                     }
                 }
                 float positionY = Input.mousePosition.y / (UnityEngine.Screen.height) * GameObject.Find("BuildHubCanvas").GetComponent <RectTransform>().sizeDelta.y - partInfo.GetComponent <RectTransform>().sizeDelta.y * 2;
                 positionY = Mathf.Clamp(positionY, -partInfo.GetComponent <RectTransform>().sizeDelta.y * 2, GameObject.Find("BuildHubCanvas").GetComponent <RectTransform>().sizeDelta.y - partInfo.GetComponent <RectTransform>().sizeDelta.y * 2);
                 partInfo.transform.localPosition = new Vector3(partInfo.transform.localPosition.x, positionY, partInfo.transform.localPosition.z);
                 partType.GetComponent <TextMeshProUGUI>().text = humanParts[partButtonIndex].GetType().ToString();
                 double[] differenceInStats = (robotPart != null ? robotPart.compareTo(humanParts[partButtonIndex]) : new double[0]);
                 durabilityBar.GetComponent <RectTransform>().localScale  = new Vector3((humanParts[partButtonIndex].getDurability() > 0 ? (float)(humanParts[partButtonIndex].getRemainingDurability() / humanParts[partButtonIndex].getDurability()) : 0), durabilityBar.GetComponent <RectTransform>().localScale.y, 0);
                 durabilityBarLabel.GetComponent <TextMeshProUGUI>().text = ConfigurationCard.DURABILITY_BAR_LABEL_PREFIX + StringTools.formatString(humanParts[partButtonIndex].getRemainingDurability()) + " / " + StringTools.formatString(humanParts[partButtonIndex].getDurability()) + (differenceInStats != null && differenceInStats.Length > 0 ? " (" + applyStatDifferenceFormatting(differenceInStats[0], false) + " / " + applyStatDifferenceFormatting(differenceInStats[1], false) + ")" : "");
                 foreach (GameObject partStat in partStatsList)
                 {
                     GameObject.Destroy(partStat);
                 }
                 partStatsList.Clear();
                 string[] partStatStrings = humanParts[partButtonIndex].getStatStrings();
                 for (int partStatIndex = 0; partStatIndex < partStatStrings.Length; ++partStatIndex)
                 {
                     GameObject partStat = GameObject.Instantiate(Resources.Load("Prefabs/PartStat") as GameObject);
                     string     differenceInStatString = "";
                     int        differenceInStatsIndex = partStatIndex + 2;
                     if (!(humanParts[partButtonIndex] is Attachment))
                     {
                         differenceInStatString = applyStatDifferenceFormatting(differenceInStats[differenceInStatsIndex], differenceInStatsIndex == 2);
                     }
                     else if (differenceInStats != null && differenceInStats.Length > 0)
                     {
                         if (differenceInStatsIndex == 3 || (differenceInStatsIndex >= 8 && differenceInStatsIndex < 11))
                         {
                             differenceInStatsIndex = -1;
                         }
                         else if (differenceInStatsIndex > 3 && differenceInStatsIndex < 8)
                         {
                             differenceInStatsIndex -= 1;
                         }
                         else if (differenceInStatsIndex == 11)
                         {
                             differenceInStatsIndex -= 4;
                         }
                         if (differenceInStatsIndex != -1)
                         {
                             if (differenceInStatsIndex >= 3 && differenceInStatsIndex <= 6)
                             {
                                 differenceInStats[differenceInStatsIndex] /= 1000;
                             }
                             differenceInStatString = applyStatDifferenceFormatting(differenceInStats[differenceInStatsIndex], differenceInStatsIndex == 2 || differenceInStatsIndex == 3 || differenceInStatsIndex == 4 || differenceInStatsIndex == 6);
                         }
                     }
                     partStat.GetComponent <TextMeshProUGUI>().text = partStatStrings[partStatIndex] + (differenceInStatString != "" ? " (" + differenceInStatString + ")" : "");
                     partStat.transform.SetParent(partStats.GetComponent <RectTransform>());
                     partStat.transform.localPosition = new Vector3(partStat.transform.localPosition.x, partStat.transform.localPosition.y, 0);
                     partStatsList.Add(partStat);
                 }
                 partInfo.SetActive(true);
                 break;
             }
             else
             {
                 partInfo.SetActive(false);
             }
         }
         bool switchTabs = false;
         foreach (GameObject tab in PART_TABS)
         {
             if (tab.GetComponent <ButtonListener>().isClicked() && currentPartFilter != tab.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text)
             {
                 switchTabs = true;
                 filterParts(tab.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text);
                 updateSorting();
                 break;
             }
             else
             {
                 tab.GetComponent <ButtonListener>().resetClick();
             }
         }
         if (switchTabs)
         {
             foreach (GameObject tab in PART_TABS)
             {
                 if (tab.GetComponent <ButtonListener>().isClicked())
                 {
                     tab.GetComponent <ButtonListener>().resetClick();
                     tab.GetComponent <UnityEngine.UI.Image>().color = ACTIVE_TAB_COLOR;
                 }
                 else
                 {
                     tab.GetComponent <UnityEngine.UI.Image>().color = INACTIVE_TAB_COLOR;
                 }
             }
         }
         if (currentSort != INVENTORY_SORT.GetComponent <TMP_Dropdown>().value)
         {
             currentSort = INVENTORY_SORT.GetComponent <TMP_Dropdown>().value;
             applySorting();
         }
     }
 }
Example #21
0
 /// <summary>
 /// Raises the delete all button event.
 /// </summary>
 public void OnDeleteAllButton()
 {
     Debug.Log("User clicked [Delete All] button.");
     m_mode = MODES.MODE_DELETE_ALL;
 }
Example #22
0
 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     curr_mode = (MODES)comboBox1.SelectedIndex;
     Activate(curr_mode);
 }
Example #23
0
 public void exitPartPreview()
 {
     mode = MODES.VIEW_PART_STATS;
     partBeingPreviewed = null;
     MASKED_INVENTORY_PART_BUTTON.SetActive(false);
 }
Example #24
0
    public override void show()
    {
        if (!base.isDisposed())
        {
            if (base.areSettingsOpen())
            {
                if (backgroundGraphicString != base.settingPairs.build_hub_background_graphic)
                {
                    backgroundGraphicString = base.settingPairs.build_hub_background_graphic;
                    BACKGROUND.GetComponent <UnityEngine.UI.Image>().sprite = ImageTools.getSpriteFromString(backgroundGraphicString);
                }
                if (platformGraphicString != base.settingPairs.build_hub_platform_graphic)
                {
                    platformGraphicString = base.settingPairs.build_hub_platform_graphic;
                    PLATFORM.GetComponent <Renderer>().material.mainTexture = new Image(platformGraphicString).getTexture();
                }
                if (colorScheme != base.colorScheme)
                {
                    colorScheme = ImageTools.getColorFromString(base.settingPairs.color_scheme);
                    SETTINGS_BUTTON.GetComponent <UnityEngine.UI.Image>().color = base.colorScheme;
                    TRAINING_BUTTON.GetComponent <UnityEngine.UI.Image>().color = base.colorScheme;
                }
                enableCreditsSpentAnimation = base.settingPairs.credits_spent_animation;
                enablePreviewRobotAnimation = base.settingPairs.preview_robot_animation;
            }
            if (obstacleList.isEnabled())
            {
                obstacleList.update();
            }
            MODES oldMode = mode;
            updateTabs();
            switch (mode)
            {
            case MODES.MY_ROBOTS:
                myRobots.update(base.colorScheme);
                break;

            case MODES.WORKSHOP:
                workshop.updateSettings(base.colorScheme, enableCreditsSpentAnimation);
                workshop.update();
                break;

            case MODES.STORE:
                if (oldMode != mode)
                {
                    store.goToDefaultTab();
                }
                store.updateSettings(base.colorScheme, enableCreditsSpentAnimation);
                store.update();
                break;

            default:
                break;
            }
            if (currentRobot != null)
            {
                if (mode == MODES.WORKSHOP && (Input.GetMouseButton(0) || Input.GetMouseButton(1) || Input.GetMouseButton(2) || Input.GetKey(KeyCode.Tab) || Input.GetKey(KeyCode.Escape) || Input.GetKey(KeyCode.Return) || Input.GetKey(KeyCode.KeypadEnter)))
                {
                    updateCurrentRobotInList();
                }
                Part[] robotParts        = workshop.getRobotParts().ToArray();
                Part[] currentRobotParts = currentRobot.getParts();
                bool   partsChanged      = false;
                if (robotParts.Length != currentRobotParts.Length)
                {
                    partsChanged = true;
                }
                else
                {
                    for (int partIndex = 0; partIndex < robotParts.Length; ++partIndex)
                    {
                        if (robotParts[partIndex] != currentRobotParts[partIndex])
                        {
                            partsChanged = true;
                            break;
                        }
                    }
                }
                if (partsChanged)
                {
                    humanRobotParts = workshop.getHumanParts();
                    myRobots.updateHumanParts(humanRobotParts);
                    workshop.updateHumanParts(humanRobotParts);
                    store.updateHumanParts(humanRobotParts);
                    for (int robotIndex = 0; robotIndex < myRobotsList.Count; ++robotIndex)
                    {
                        if (currentRobot == myRobotsList[robotIndex])
                        {
                            currentRobot             = workshop.getRobot();
                            myRobotsList[robotIndex] = currentRobot;
                            myRobots.updateMyRobots(myRobotsList);
                            List <Part> robotPartList = new List <Part>();
                            robotPartList.AddRange(robotParts);
                            workshop.updateRobotParts(robotPartList);
                            store.updateRobotParts(robotPartList);
                            break;
                        }
                    }
                }
                Part partBought = store.getPartBought();
                humanRobotParts = workshop.getHumanParts();
                if (partBought != null)
                {
                    humanRobotParts.Add(partBought);
                    workshop.updateHumanParts(humanRobotParts);
                    store.updateHumanParts(humanRobotParts);
                }
                credits = (workshop.getUpdatedCredits() < store.getUpdatedCredits()) ? workshop.getUpdatedCredits() : store.getUpdatedCredits();
                myRobots.updateCredits(credits);
                workshop.updateCredits(credits);
                store.updateCredits(credits);
            }
            if (mode == MODES.MY_ROBOTS)
            {
                Robot robotBeingPreviewed = myRobots.getRobotBeingPreviewed();
                if (robotBeingPreviewed != null)
                {
                    if (robotBeingPreviewed.getHead().getShape() == Shape.SHAPES.HEMISPHERE && !previewRobot.getHead().GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                    {
                        previewRobot.getHead().GAME_OBJECT.transform.localPosition = new Vector3(previewRobot.getHead().GAME_OBJECT.transform.localPosition.x, previewRobot.getHead().GAME_OBJECT.transform.localPosition.y - .5f, previewRobot.getHead().GAME_OBJECT.transform.localPosition.z);
                    }
                    else if (robotBeingPreviewed.getHead().getShape() != Shape.SHAPES.HEMISPHERE && previewRobot.getHead().GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                    {
                        previewRobot.getHead().GAME_OBJECT.transform.localPosition = new Vector3(previewRobot.getHead().GAME_OBJECT.transform.localPosition.x, previewRobot.getHead().GAME_OBJECT.transform.localPosition.y + .5f, previewRobot.getHead().GAME_OBJECT.transform.localPosition.z);
                    }
                    previewRobot.getHead().changeTextureAndShape(robotBeingPreviewed.getHead().getImage().getTexture(), MESHES[(int)robotBeingPreviewed.getHead().getShape()], robotBeingPreviewed.getHead().getShape());
                    if (robotBeingPreviewed.getBody().getShape() == Shape.SHAPES.HEMISPHERE && !previewRobot.getBody().GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                    {
                        previewRobot.getBody().GAME_OBJECT.transform.localPosition = new Vector3(previewRobot.getBody().GAME_OBJECT.transform.localPosition.x, previewRobot.getBody().GAME_OBJECT.transform.localPosition.y - .5f, previewRobot.getBody().GAME_OBJECT.transform.localPosition.z);
                    }
                    else if (robotBeingPreviewed.getBody().getShape() != Shape.SHAPES.HEMISPHERE && previewRobot.getBody().GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                    {
                        previewRobot.getBody().GAME_OBJECT.transform.localPosition = new Vector3(previewRobot.getBody().GAME_OBJECT.transform.localPosition.x, previewRobot.getBody().GAME_OBJECT.transform.localPosition.y + .5f, previewRobot.getBody().GAME_OBJECT.transform.localPosition.z);
                    }
                    previewRobot.getBody().changeTextureAndShape(robotBeingPreviewed.getBody().getImage().getTexture(), MESHES[(int)robotBeingPreviewed.getBody().getShape()], robotBeingPreviewed.getBody().getShape());
                    if (robotBeingPreviewed.getMobility().getShape() == Shape.SHAPES.HEMISPHERE && !previewRobot.getMobility().GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                    {
                        previewRobot.getMobility().GAME_OBJECT.transform.localPosition = new Vector3(previewRobot.getMobility().GAME_OBJECT.transform.localPosition.x, previewRobot.getMobility().GAME_OBJECT.transform.localPosition.y - .5f, previewRobot.getMobility().GAME_OBJECT.transform.localPosition.z);
                    }
                    else if (robotBeingPreviewed.getMobility().getShape() != Shape.SHAPES.HEMISPHERE && previewRobot.getMobility().GAME_OBJECT.GetComponent <MeshFilter>().mesh.name.Contains("Sphere"))
                    {
                        previewRobot.getMobility().GAME_OBJECT.transform.localPosition = new Vector3(previewRobot.getMobility().GAME_OBJECT.transform.localPosition.x, previewRobot.getMobility().GAME_OBJECT.transform.localPosition.y + .5f, previewRobot.getMobility().GAME_OBJECT.transform.localPosition.z);
                    }
                    previewRobot.getMobility().changeTextureAndShape(robotBeingPreviewed.getMobility().getImage().getTexture(), MESHES[(int)robotBeingPreviewed.getMobility().getShape()], robotBeingPreviewed.getMobility().getShape());
                }
            }
            goToField = workshop.getGoToField();
            if (previewRobot != null)
            {
                animatePreviewRobot();
            }
            base.show();
        }
    }
Example #25
0
    public StoreCard(long credits, Part[] storeParts, Part[] humanParts, Part[] robotParts, Color colorScheme, bool enableCreditsSpentAnimation)
    {
        this.credits     = credits;
        this.storeParts  = storeParts;
        this.humanParts  = humanParts;
        this.robotParts  = robotParts;
        this.colorScheme = colorScheme;
        this.enableCreditsSpentAnimation = enableCreditsSpentAnimation;
        mode = MODES.VIEW_PART_STATS;
        partBeingPreviewed            = null;
        partBeingBought               = null;
        currentPartFilter             = DEFAULT_STORE_FILTER;
        STORE_SORT                    = GameObject.Find("StoreSort");
        currentSort                   = DEFAULT_SORT;
        PERFORMANCE_METRIC_CALCULATOR = new PerformanceMetricCalculator();
        SCROLL_VIEW                   = GameObject.Find(STORE_CARD_NAME);
        GameObject storeContainerGameObject = GameObject.Find(STORE_CONTAINER_NAME);

        STORE_CONTAINER = storeContainerGameObject.GetComponent <RectTransform>();
        SCROLL_RECT     = SCROLL_VIEW.GetComponent <ScrollRect>();
        STORE_PANEL     = GameObject.Find(STORE_PANEL_NAME).GetComponent <RectTransform>();
        SCROLLBAR       = GameObject.Find(STORE_CARD_NAME).transform.Find(STORE_SCROLLBAR_NAME).gameObject;
        SCROLLBAR.SetActive(false);
        SCROLL_RECT.vertical = false;
        storeButtons         = new List <GameObject>();
        partInfo             = GameObject.Find("Store").transform.Find(PART_INFO_NAME).gameObject;
        partType             = partInfo.transform.Find(PART_TYPE_NAME).gameObject;
        partStats            = partInfo.transform.Find(PART_STATS_NAME).gameObject;
        partInfo.SetActive(false);
        BUY_PART_BUTTON = GameObject.Find("Store").transform.Find("BuyPart").gameObject;
        BUY_PART_BUTTON.SetActive(false);
        STORE_CREDIT = GameObject.Find("StoreCredit");
        STORE_CREDIT.GetComponent <TextMeshProUGUI>().color = colorScheme;
        updateCredits();
        STORE_CREDITS_SPENT = GameObject.Find("Store").transform.Find("StoreCreditsSpent").gameObject;
        STORE_CREDITS_SPENT_HOME_POSITION = STORE_CREDITS_SPENT.transform.localPosition;
        STORE_CREDITS_SPENT.SetActive(false);
        partStatsList = new List <GameObject>();
        ATTACHMENT_PARTS_ROWS_LABELS = new List <string>();
        foreach (Part part in this.storeParts)
        {
            if (part is Attachment && !ATTACHMENT_PARTS_ROWS_LABELS.Contains(part.GetType().ToString()))
            {
                ATTACHMENT_PARTS_ROWS_LABELS.Add(part.GetType().ToString());
            }
            GameObject storeButton = GameObject.Instantiate(Resources.Load("Prefabs/FeaturedPartButton") as GameObject);
            Texture2D  partIcon    = part.getIcon();
            if (partIcon != null)
            {
                storeButton.transform.Find("Icon").GetComponent <UnityEngine.UI.Image>().sprite = Sprite.Create(partIcon, new Rect(0, 0, partIcon.width, partIcon.height), new Vector2(0.5f, 0.5f), 100);
            }
            storeButton.GetComponent <RectTransform>().localScale = Vector3.one;
            storeButton.transform.localPosition = new Vector3(storeButton.transform.localPosition.x, storeButton.transform.localPosition.y, 0);
            storeButton.transform.Find("CostLabel").GetComponent <TextMeshProUGUI>().text += PERFORMANCE_METRIC_CALCULATOR.calculateCost(part);
            storeButton.transform.Find("CostLabel").GetComponent <TextMeshProUGUI>().color = (PERFORMANCE_METRIC_CALCULATOR.calculateCost(part) <= this.credits ? AFFORDABLE_TEXT_COLOR : UNAFFORDABLE_TEXT_COLOR);
            storeButton.SetActive(false);
            storeButtons.Add(storeButton);
        }
        STORE_TABS = new List <GameObject>();
        foreach (Transform childTransform in GameObject.Find("StoreTabs").transform.Find("StoreTabMask"))
        {
            if (childTransform.gameObject.name.Contains(STORE_TAB_SUFFIX))
            {
                STORE_TABS.Add(childTransform.gameObject);
            }
        }
        FEATURED_PARTS_ROWS = new List <GameObject>();
        foreach (string featuredPartsRowLabel in FEATURED_PARTS_ROWS_LABELS)
        {
            GameObject featuredPartsRow          = GameObject.Instantiate(Resources.Load("Prefabs/FeaturedPartsRow") as GameObject);
            string     featuredPartsRowLabelText = featuredPartsRow.transform.Find("AllParts").Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text;
            featuredPartsRow.transform.Find("AllParts").Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text = featuredPartsRowLabelText.Substring(0, featuredPartsRowLabelText.IndexOf(" ") + 1) + featuredPartsRowLabel + featuredPartsRowLabelText.Substring(featuredPartsRowLabelText.IndexOf(" "));
            featuredPartsRow.transform.localPosition = new Vector3(featuredPartsRow.transform.localPosition.x, featuredPartsRow.transform.localPosition.y, 0);
            featuredPartsRow.SetActive(false);
            FEATURED_PARTS_ROWS.Add(featuredPartsRow);
        }
        ATTACHMENT_PARTS_ROWS = new List <GameObject>();
        foreach (string attachmentPartsRowLabel in ATTACHMENT_PARTS_ROWS_LABELS)
        {
            GameObject attachmentPartsRow          = GameObject.Instantiate(Resources.Load("Prefabs/AttachmentPartsRow") as GameObject);
            string     attachmentPartsRowLabelText = attachmentPartsRow.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text;
            attachmentPartsRow.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text = attachmentPartsRowLabel;
            attachmentPartsRow.transform.localPosition = new Vector3(attachmentPartsRow.transform.localPosition.x, attachmentPartsRow.transform.localPosition.y, 0);
            attachmentPartsRow.SetActive(false);
            ATTACHMENT_PARTS_ROWS.Add(attachmentPartsRow);
        }
        filterFeaturedParts();
        updateSorting();
    }
Example #26
0
        // Main loop that runs forever, until the user hits Escape to quit.
        private void recognizeAndTrainUsingWebcam(Mat cameraFrame, CascadeClassifier faceCascade, CascadeClassifier eyeCascade1, CascadeClassifier eyeCascade2)
        {
            if (cameraFrame != null && cameraFrame.empty())
            {
                Debug.LogError("ERROR: Couldn't grab the next camera frame.");
            }

            // Get a copy of the camera frame that we can draw onto.
            Mat displayedFrame = cameraFrame;

            int   cx;
            float current_processingTime     = Time.realtimeSinceStartup;
            float processingTimeDiff_seconds = (current_processingTime - old_processingTime);

            if (processingTimeDiff_seconds > CHANGE_IN_SECONDS_FOR_PROCESSING)
            {
                // Run the face recognition system on the camera image. It will draw some things onto the given image, so make sure it is not read-only memory!
                int identity = -1;

                // Find a face and preprocess it to have a standard size and contrast & brightness.
                Rect  faceRect = new Rect();                                       // Position of detected face.
                Rect  searchedLeftEye = new Rect(), searchedRightEye = new Rect(); // top-left and top-right regions of the face, where eyes were searched.
                Point leftEye = new Point(), rightEye = new Point();               // Position of the detected eyes.

                Mat preprocessedFace = PreprocessFace.GetPreprocessedFace(displayedFrame, faceWidth, faceCascade, eyeCascade1, eyeCascade2, preprocessLeftAndRightSeparately, ref faceRect, ref leftEye, ref rightEye, ref searchedLeftEye, ref searchedRightEye);

                bool gotFaceAndEyes = false;

                if (preprocessedFace != null && !preprocessedFace.empty())
                {
                    gotFaceAndEyes = true;
                }

                // Draw an anti-aliased rectangle around the detected face.
                if (faceRect.width > 0)
                {
                    Imgproc.rectangle(displayedFrame, faceRect.tl(), faceRect.br(), YELLOW, 2, Imgproc.LINE_AA, 0);

                    // Draw light-blue anti-aliased circles for the 2 eyes.
                    Scalar eyeColor = LIGHT_BLUE;
                    if (leftEye.x >= 0)     // Check if the eye was detected
                    {
                        Imgproc.circle(displayedFrame, new Point(faceRect.x + leftEye.x, faceRect.y + leftEye.y), 6, eyeColor, 1, Imgproc.LINE_AA, 0);
                    }
                    if (rightEye.x >= 0)     // Check if the eye was detected
                    {
                        Imgproc.circle(displayedFrame, new Point(faceRect.x + rightEye.x, faceRect.y + rightEye.y), 6, eyeColor, 1, Imgproc.LINE_AA, 0);
                    }
                }

                prev_prepreprocessedFace = preprocessedFace;

                if (m_mode == MODES.MODE_DETECTION)
                {
                    // Don't do anything special.
                }
                else if (m_mode == MODES.MODE_COLLECT_FACES)
                {
                    // Check if we have detected a face.
                    if (gotFaceAndEyes)
                    {
                        // Check if this face looks somewhat different from the previously collected face.
                        double imageDiff = 10000000000.0d;
                        if (old_prepreprocessedFace != null && !old_prepreprocessedFace.empty())
                        {
                            imageDiff = Recognition.GetSimilarity(preprocessedFace, old_prepreprocessedFace);
                        }

                        // Also record when it happened.
                        double current_time     = Time.realtimeSinceStartup;
                        double timeDiff_seconds = (current_time - old_time);

                        // Only process the face if it is noticeably different from the previous frame and there has been noticeable time gap.
                        if ((imageDiff > CHANGE_IN_IMAGE_FOR_COLLECTION) && (timeDiff_seconds > CHANGE_IN_SECONDS_FOR_COLLECTION))
                        {
                            // Also add the mirror image to the training set, so we have more training data, as well as to deal with faces looking to the left or right.
                            Mat mirroredFace = new Mat();
                            Core.flip(preprocessedFace, mirroredFace, 1);

                            // Add the face images to the list of detected faces.
                            preprocessedFaces.Add(preprocessedFace);
                            preprocessedFaces.Add(mirroredFace);
                            faceLabels.Add(m_selectedPerson);
                            faceLabels.Add(m_selectedPerson);

                            // Keep a reference to the latest face of each person.
                            m_latestFaces [m_selectedPerson] = preprocessedFaces.Count - 2;  // Point to the non-mirrored face.
                            // Show the number of collected faces. But since we also store mirrored faces, just show how many the user thinks they stored.
                            Debug.Log("Saved face " + (preprocessedFaces.Count / 2) + " for person " + m_selectedPerson);

                            // Make a white flash on the face, so the user knows a photo has been taken.
                            using (Mat displayedFaceRegion = new Mat(displayedFrame, faceRect)) {
                                Core.add(displayedFaceRegion, DARK_GRAY, displayedFaceRegion);
                            }

                            // Keep a copy of the processed face, to compare on next iteration.
                            old_prepreprocessedFace = preprocessedFace;
                            old_time = current_time;
                        }
                    }
                }
                else if (m_mode == MODES.MODE_TRAINING)
                {
                    // Check if there is enough data to train from. For Eigenfaces, we can learn just one person if we want, but for Fisherfaces,
                    // we need atleast 2 people otherwise it will crash!
                    bool haveEnoughData = true;
                    if (facerecAlgorithm == "FaceRecognizer.Fisherfaces")
                    {
                        if ((m_numPersons < 2) || (m_numPersons == 2 && m_latestFaces [1] < 0))
                        {
                            Debug.Log("Warning: Fisherfaces needs atleast 2 people, otherwise there is nothing to differentiate! Collect more data ...");
                            haveEnoughData = false;
                        }
                    }
                    if (m_numPersons < 1 || preprocessedFaces.Count <= 0 || preprocessedFaces.Count != faceLabels.Count)
                    {
                        Debug.Log("Warning: Need some training data before it can be learnt! Collect more data ...");
                        haveEnoughData = false;
                    }

                    if (haveEnoughData)
                    {
                        // Start training from the collected faces using Eigenfaces or a similar algorithm.
                        model = Recognition.LearnCollectedFaces(preprocessedFaces, faceLabels, facerecAlgorithm);

                        // Show the internal face recognition data, to help debugging.
                        //if (m_debug)
                        //Recognition.ShowTrainingDebugData(model, faceWidth, faceHeight);

                        // Now that training is over, we can start recognizing!
                        m_mode = MODES.MODE_RECOGNITION;
                    }
                    else
                    {
                        // Since there isn't enough training data, go back to the face collection mode!
                        m_mode = MODES.MODE_COLLECT_FACES;
                    }
                }
                else if (m_mode == MODES.MODE_RECOGNITION)
                {
                    prev_identity   = -1;
                    prev_similarity = 100000000.0d;
                    if (reconstructedFace != null && !reconstructedFace.IsDisposed)
                    {
                        reconstructedFace.Dispose();
                    }
                    reconstructedFace = null;

                    if (gotFaceAndEyes && (preprocessedFaces.Count > 0) && (preprocessedFaces.Count == faceLabels.Count))
                    {
                        // Generate a face approximation by back-projecting the eigenvectors & eigenvalues.
                        reconstructedFace = Recognition.ReconstructFace(model, preprocessedFace);

                        // Verify whether the reconstructed face looks like the preprocessed face, otherwise it is probably an unknown person.
                        double similarity = Recognition.GetSimilarity(preprocessedFace, reconstructedFace);
                        double confidence = 0.0d;

                        string outputStr;
                        if (similarity < UNKNOWN_PERSON_THRESHOLD)
                        {
                            int[]    predictedLabel      = new int [1];
                            double[] predictedConfidence = new double [1];
                            // Identify who the person is in the preprocessed face image.
                            model.predict(preprocessedFace, predictedLabel, predictedConfidence);
                            identity   = predictedLabel [0];
                            confidence = predictedConfidence [0];

                            outputStr     = identity.ToString();
                            prev_identity = identity;
                        }
                        else
                        {
                            // Since the confidence is low, assume it is an unknown person.
                            outputStr = "Unknown";
                        }
                        prev_similarity = similarity;
                        Debug.Log("Identity: " + outputStr + ". Similarity: " + similarity + ". Confidence: " + confidence);
                    }
                }
                else if (m_mode == MODES.MODE_DELETE_ALL)
                {
                    // Restart everything!
                    dispose();

                    // Restart in Detection mode.
                    m_mode = MODES.MODE_DETECTION;
                }
                else
                {
                    Debug.LogError("ERROR: Invalid run mode " + m_mode);
                    //exit(1);
                }

                old_processingTime = current_processingTime;
            }

            // Show the help, while also showing the number of collected faces. Since we also collect mirrored faces, we should just
            // tell the user how many faces they think we saved (ignoring the mirrored faces), hence divide by 2.
            strBuilder.Length = 0;
            Rect rcHelp = new Rect();

            if (m_mode == MODES.MODE_DETECTION)
            {
                strBuilder.Append("Click [Add Person] when ready to collect faces.");
            }
            else if (m_mode == MODES.MODE_COLLECT_FACES)
            {
                strBuilder.Append("Click anywhere to train from your ");
                strBuilder.Append(preprocessedFaces.Count / 2);
                strBuilder.Append(" faces of ");
                strBuilder.Append(m_numPersons);
                strBuilder.Append(" people.");
            }
            else if (m_mode == MODES.MODE_TRAINING)
            {
                strBuilder.Append("Please wait while your ");
                strBuilder.Append(preprocessedFaces.Count / 2);
                strBuilder.Append(" faces of ");
                strBuilder.Append(m_numPersons);
                strBuilder.Append(" people builds.");
            }
            else if (m_mode == MODES.MODE_RECOGNITION)
            {
                strBuilder.Append("Click people on the right to add more faces to them, or [Add Person] for someone new.");
            }

            if (strBuilder.Length > 0)
            {
                // Draw it with a black background and then again with a white foreground.
                // Since BORDER may be 0 and we need a negative position, subtract 2 from the border so it is always negative.
                float txtSize = 0.4f;
                drawString(displayedFrame, strBuilder.ToString(), new Point(BORDER, -BORDER - 2), BLACK, txtSize);              // Black shadow.
                rcHelp = drawString(displayedFrame, strBuilder.ToString(), new Point(BORDER + 1, -BORDER - 1), WHITE, txtSize); // White text.
            }

            // Show the current mode.
            strBuilder.Length = 0;
            if (m_mode >= 0 && m_mode < MODES.MODE_END)
            {
                strBuilder.Append(" people builds.");
                strBuilder.Append(MODE_NAMES [(int)m_mode]);
                drawString(displayedFrame, strBuilder.ToString(), new Point(BORDER, -BORDER - 2 - rcHelp.height), BLACK);     // Black shadow
                drawString(displayedFrame, strBuilder.ToString(), new Point(BORDER + 1, -BORDER - 1 - rcHelp.height), GREEN); // Green text
            }

            // Show the current preprocessed face in the top-center of the display.
            cx = (displayedFrame.cols() - faceWidth) / 2;
            if (prev_prepreprocessedFace != null && !prev_prepreprocessedFace.empty())
            {
                // Get a RGBA version of the face, since the output is RGBA color.
                using (Mat srcRGBA = new Mat(prev_prepreprocessedFace.size(), CvType.CV_8UC4)) {
                    Imgproc.cvtColor(prev_prepreprocessedFace, srcRGBA, Imgproc.COLOR_GRAY2RGBA);
                    // Get the destination ROI (and make sure it is within the image!).
                    Rect dstRC = new Rect(cx, BORDER, faceWidth, faceHeight);
                    using (Mat dstROI = new Mat(displayedFrame, dstRC)) {
                        // Copy the pixels from src to dst.
                        srcRGBA.copyTo(dstROI);
                    }
                }
            }

            // Draw an anti-aliased border around the face, even if it is not shown.
            Imgproc.rectangle(displayedFrame, new Point(cx - 1, BORDER - 1), new Point(cx - 1 + faceWidth + 2, BORDER - 1 + faceHeight + 2), LIGHT_GRAY, 1, Imgproc.LINE_AA, 0);

            // Show the most recent face for each of the collected people, on the right side of the display.
            m_gui_faces_left = displayedFrame.cols() - BORDER - faceWidth;
            m_gui_faces_top  = BORDER;
            for (int i = 0; i < m_numPersons; i++)
            {
                int index = m_latestFaces [i];
                if (index >= 0 && index < preprocessedFaces.Count)
                {
                    Mat srcGray = preprocessedFaces [index];
                    if (srcGray != null && !srcGray.empty())
                    {
                        // Get a RGBA version of the face, since the output is RGBA color.
                        using (Mat srcRGBA = new Mat(srcGray.size(), CvType.CV_8UC4)) {
                            Imgproc.cvtColor(srcGray, srcRGBA, Imgproc.COLOR_GRAY2RGBA);
                            // Get the destination ROI (and make sure it is within the image!).
                            int  y     = Mathf.Min(m_gui_faces_top + i * faceHeight, displayedFrame.rows() - faceHeight);
                            Rect dstRC = new Rect(m_gui_faces_left, y, faceWidth, faceHeight);
                            using (Mat dstROI = new Mat(displayedFrame, dstRC)) {
                                // Copy the pixels from src to dst.
                                srcRGBA.copyTo(dstROI);
                            }
                        }
                    }
                }
            }

            // Highlight the person being collected, using a red rectangle around their face.
            if (m_mode == MODES.MODE_COLLECT_FACES)
            {
                if (m_selectedPerson >= 0 && m_selectedPerson < m_numPersons)
                {
                    int  y  = Mathf.Min(m_gui_faces_top + m_selectedPerson * faceHeight, displayedFrame.rows() - faceHeight);
                    Rect rc = new Rect(m_gui_faces_left, y, faceWidth, faceHeight);
                    Imgproc.rectangle(displayedFrame, rc.tl(), rc.br(), RED, 3, Imgproc.LINE_AA, 0);
                }
            }

            // Highlight the person that has been recognized, using a green rectangle around their face.
            if (m_mode == MODES.MODE_RECOGNITION && prev_identity >= 0 && prev_identity < 1000)
            {
                int  y  = Mathf.Min(m_gui_faces_top + prev_identity * faceHeight, displayedFrame.rows() - faceHeight);
                Rect rc = new Rect(m_gui_faces_left, y, faceWidth, faceHeight);
                Imgproc.rectangle(displayedFrame, rc.tl(), rc.br(), GREEN, 3, Imgproc.LINE_AA, 0);
            }

            if (m_mode == MODES.MODE_RECOGNITION)
            {
                if (m_debug)
                {
                    if (reconstructedFace != null && !reconstructedFace.empty())
                    {
                        cx = (displayedFrame.cols() - faceWidth) / 2;
                        Point rfDebugBottomRight = new Point(cx + faceWidth * 2 + 5, BORDER + faceHeight);
                        Point rfDebugTopLeft     = new Point(cx + faceWidth + 5, BORDER);
                        Rect  rfDebugRC          = new Rect(rfDebugTopLeft, rfDebugBottomRight);
                        using (Mat srcRGBA = new Mat(reconstructedFace.size(), CvType.CV_8UC4)) {
                            Imgproc.cvtColor(reconstructedFace, srcRGBA, Imgproc.COLOR_GRAY2RGBA);
                            using (Mat dstROI = new Mat(displayedFrame, rfDebugRC)) {
                                srcRGBA.copyTo(dstROI);
                            }
                        }
                        Imgproc.rectangle(displayedFrame, rfDebugTopLeft, rfDebugBottomRight, LIGHT_GRAY, 1, Imgproc.LINE_AA, 0);
                    }
                }

                // Show the confidence rating for the recognition in the mid-top of the display.
                cx = (displayedFrame.cols() - faceWidth) / 2;
                Point ptBottomRight = new Point(cx - 5, BORDER + faceHeight);
                Point ptTopLeft     = new Point(cx - 15, BORDER);
                // Draw a gray line showing the threshold for an "unknown" person.
                Point ptThreshold = new Point(ptTopLeft.x, ptBottomRight.y - (1.0 - UNKNOWN_PERSON_THRESHOLD) * faceHeight);
                Imgproc.rectangle(displayedFrame, ptThreshold, new Point(ptBottomRight.x, ptThreshold.y), LIGHT_GRAY, 1, Imgproc.LINE_AA, 0);
                // Crop the confidence rating between 0.0 to 1.0, to show in the bar.
                double confidenceRatio = 1.0d - Math.Min(Math.Max(prev_similarity, 0.0d), 1.0d);
                Point  ptConfidence    = new Point(ptTopLeft.x, ptBottomRight.y - confidenceRatio * faceHeight);
                // Show the light-blue confidence bar.
                Imgproc.rectangle(displayedFrame, ptConfidence, ptBottomRight, LIGHT_BLUE, Core.FILLED, Imgproc.LINE_AA, 0);
                // Show the gray border of the bar.
                Imgproc.rectangle(displayedFrame, ptTopLeft, ptBottomRight, LIGHT_GRAY, 1, Imgproc.LINE_AA, 0);
            }

            /*
             * // If the user wants all the debug data, show it to them!
             * if (m_debug)
             * {
             *  Mat face = new Mat();
             *  if (faceRect.width > 0)
             *  {
             *      face = new Mat(cameraFrame, faceRect);
             *      if (searchedLeftEye.width > 0 && searchedRightEye.width > 0)
             *      {
             *          Mat topLeftOfFace = new Mat(face, searchedLeftEye);
             *          Mat topRightOfFace = new Mat(face, searchedRightEye);
             *          //imshow("topLeftOfFace", topLeftOfFace);
             *          //imshow("topRightOfFace", topRightOfFace);
             *      }
             *  }
             *
             *  //if (model != null)
             *      //showTrainingDebugData(model, faceWidth, faceHeight);
             * }
             */
        }
Example #27
0
        /// <summary>
        /// Private helper workhorse function for <see cref="Execute"/>.
        /// </summary>
        ///
        /// <param name="moduleUnit">The moduleUnit to process.</param>
        /// <returns>True if successful; false otherwise.</returns>
        private bool ExecuteHelper(Phx.ModuleUnit moduleUnit)
        {
            Console.Out.WriteLine();

            Phx.Graphs.CallGraph callGraph = moduleUnit.CallGraph;
            if (callGraph == null)
            {
                Console.Out.WriteLine("PHOENIX: Call graph is null.");
                Console.Out.WriteLine("Exiting GameTime.");
                Environment.Exit(1);
                return(false);
            }

            /* Load GameTime configuration. */
            string configFile = Console.ReadLine();

            Console.Out.WriteLine("PHOENIX: Configuring this GameTime session with " +
                                  configFile + "...");
            Utilities.Configuration config = Utilities.Configuration.ReadConfigFile(configFile);
            Console.Out.WriteLine("PHOENIX: Successfully configured this session.");

            /* Load the project configuration. */
            string projectConfigFile = Console.ReadLine();

            Console.Out.WriteLine("PHOENIX: Loading project configuration from " +
                                  projectConfigFile + "...");
            ProjectConfiguration projectConfig =
                ProjectConfiguration.ReadProjectConfigFile(projectConfigFile, config);

            Console.Out.WriteLine("PHOENIX: Successfully loaded the project for this session.");

            /* Determine the current GameTime operation mode. */
            string currentMode = Console.ReadLine();

            mode = (currentMode.Equals(config.TEMP_PHX_CREATE_DAG)) ?
                   MODES.CREATE_DAG : MODES.FIND_CONDITIONS;
            Console.Out.WriteLine("PHOENIX: GameTime operation mode is: " +
                                  ((mode == MODES.CREATE_DAG) ? "Create DAG." : "Find path conditions."));

            /* Find the function to analyze. */
            string funcToProcess = projectConfig.func;

            Console.Out.WriteLine("PHOENIX: Preprocessing " + funcToProcess + "...");
            Console.Out.WriteLine();

            Console.Out.WriteLine("PHOENIX: Finding the corresponding function unit...");

            /* Find the function unit corresponding to the function to be analyzed. */
            FunctionUnit functionUnitToProcess = null;

            /* Traverse the graph in post-order (top-down order). */
            Phx.Graphs.NodeFlowOrder nodeOrder = Phx.Graphs.NodeFlowOrder.New(callGraph.Lifetime);
            nodeOrder.Build(callGraph, Phx.Graphs.Order.PostOrder);
            Phx.Targets.Runtimes.Runtime runtime = moduleUnit.Runtime;
            uint functionCount = 0;

            for (uint i = 1; i <= nodeOrder.NodeCount; ++i)
            {
                Phx.Graphs.CallNode node = nodeOrder.Node(i).AsCallNode;
                if ((node == callGraph.UnknownCallerNode) ||
                    (node == callGraph.UnknownCalleeNode))
                {
                    continue;
                }
                if (node.FunctionSymbol != null)
                {
                    /* Is this LTCG mode? */
                    bool isLTCG = false;
                    try
                    {
                        IDictionary env = Environment.GetEnvironmentVariables();
                        if (env.Contains("LINK_TIME_CODE_GENERATION"))
                        {
                            isLTCG = true;
                        }
                    }
                    catch (ArgumentNullException) { }

                    /* Only perform the check when the LTCG mode is off. */
                    if (isLTCG || moduleUnit.IsPEModuleUnit)
                    {
                        moduleUnit = node.FunctionSymbol.CompilationUnitParentSymbol.Unit.AsModuleUnit;
                    }

                    /* Create the corresponding function unit. */
                    Phx.Lifetime     lifetime     = Phx.Lifetime.New(Phx.LifetimeKind.Function, null);
                    Phx.FunctionUnit functionUnit = Phx.FunctionUnit.New(lifetime,
                                                                         node.FunctionSymbol, Phx.CodeGenerationMode.Native,
                                                                         moduleUnit.TypeTable, runtime.Architecture, runtime,
                                                                         moduleUnit, functionCount++);

                    /* Attach debugging info. */
                    Phx.Debug.Info.New(functionUnit.Lifetime, functionUnit);

                    node.FunctionSymbol.FunctionUnit = functionUnit;
                    this.PhaseConfiguration.PhaseList.DoPhaseList(functionUnit);
                    functionUnit.Context.PopUnit();

                    string funcName = FunctionUnitHelper.GetFunctionName(functionUnit);
                    if (funcName == funcToProcess)
                    {
                        functionUnitToProcess = functionUnit;
                        break;
                    }
                }
            }

            if (functionUnitToProcess == null)
            {
                Console.Out.WriteLine("PHOENIX: Cannot find function named " + funcToProcess + ".");
                Console.Out.WriteLine("PHOENIX: Exiting GameTime...");
                Environment.Exit(1);
                return(false);
            }
            else
            {
                Console.Out.WriteLine("PHOENIX: Function unit found.");
            }

            Console.Out.WriteLine("PHOENIX: Preprocessing the function unit...");
            FunctionUnitHelper.Preprocess(functionUnitToProcess);
            Console.Out.WriteLine("PHOENIX: Function unit preprocessing complete.");
            Console.Out.WriteLine();

            Console.Out.WriteLine("PHOENIX: Building the flow graph...");
            functionUnitToProcess.BuildFlowGraphWithoutEH();
            Phx.Graphs.FlowGraph graph = functionUnitToProcess.FlowGraph;
            Console.Out.WriteLine("PHOENIX: Flow graph built.");

            Console.Out.WriteLine("PHOENIX: Snipping the relevant portion of the flow graph...");

            uint sourceBlockId = 1;
            uint sinkBlockId   = graph.NodeCount;

            if (projectConfig.startLabel != "")
            {
                Phx.Graphs.BasicBlock sourceBlock =
                    FunctionUnitHelper.SplitAtUserLabel(functionUnitToProcess,
                                                        projectConfig.startLabel);
                sourceBlockId = sourceBlock.Id;
            }
            if (projectConfig.endLabel != "")
            {
                Phx.Graphs.BasicBlock sinkBlock =
                    FunctionUnitHelper.SplitAtUserLabel(functionUnitToProcess,
                                                        projectConfig.endLabel);

                /* Correct the sink block: we want the block just before the block
                 * we receive from SplitAtUserLabel. */
                Phx.Graphs.FlowEdge edgeToSink = sinkBlock.PredecessorEdgeList;
                sinkBlock   = edgeToSink.PredecessorNode;
                sinkBlockId = sinkBlock.Id;
            }

            Console.Out.WriteLine("PHOENIX: Relevant portion snipped.");
            Console.Out.WriteLine();

            Console.Out.WriteLine("PHOENIX: Starting analysis...");

            switch (mode)
            {
            case MODES.CREATE_DAG:
                FunctionUnitHelper.DumpCfgToFile(functionUnitToProcess,
                                                 sourceBlockId, sinkBlockId, config, projectConfig);
                break;

            case MODES.FIND_CONDITIONS:
                FunctionUnitHelper.FindPathConditions(functionUnitToProcess,
                                                      config, projectConfig);
                break;
            }

            Console.Out.WriteLine("PHOENIX: Analysis successful.");
            Console.Out.WriteLine();

            Environment.Exit(0);
            return(true);
        }
Example #28
0
    public void update(long credits, Part[] humanParts, Part[] robotParts, Color colorScheme, bool enableCreditsSpentAnimation)
    {
        this.credits     = credits;
        this.humanParts  = humanParts;
        this.robotParts  = robotParts;
        this.colorScheme = colorScheme;
        this.enableCreditsSpentAnimation = enableCreditsSpentAnimation;
        if (STORE_CREDIT.GetComponent <TextMeshProUGUI>().color != this.colorScheme)
        {
            STORE_CREDIT.GetComponent <TextMeshProUGUI>().color = this.colorScheme;
        }
        if (base.enabled)
        {
            if (BUY_PART_BUTTON.activeSelf && BUY_PART_BUTTON.GetComponent <ButtonListener>().isClicked() && PERFORMANCE_METRIC_CALCULATOR.calculateCost(partBeingPreviewed) <= credits)
            {
                BUY_PART_BUTTON.GetComponent <ButtonListener>().resetClick();
                mode               = MODES.BUY_PART;
                partBeingBought    = partBeingPreviewed;
                partBeingPreviewed = null;
                BUY_PART_BUTTON.SetActive(false);
                credits -= PERFORMANCE_METRIC_CALCULATOR.calculateCost(partBeingBought);
                updateCredits();
                if (enableCreditsSpentAnimation)
                {
                    STORE_CREDITS_SPENT.SetActive(true);
                    STORE_CREDITS_SPENT.transform.localPosition = STORE_CREDITS_SPENT_HOME_POSITION;
                    Color storeCreditsSpentColor = STORE_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color;
                    STORE_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color = new Color(storeCreditsSpentColor.r, storeCreditsSpentColor.g, storeCreditsSpentColor.b, 1);
                    STORE_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().text  = "-" + PERFORMANCE_METRIC_CALCULATOR.calculateCost(partBeingBought).ToString();
                }
            }
            if (Input.GetMouseButton(0) && mode == MODES.PREVIEW_PART && !BUY_PART_BUTTON.GetComponent <ButtonListener>().isMouseOver())
            {
                mode = MODES.VIEW_PART_STATS;
                partBeingPreviewed = null;
                partBeingBought    = null;
                BUY_PART_BUTTON.SetActive(false);
            }
            if ((STORE_PANEL.offsetMax.y - STORE_PANEL.offsetMin.y) > (STORE_CONTAINER.offsetMax.y - STORE_CONTAINER.offsetMin.y))
            {
                SCROLLBAR.SetActive(true);
                SCROLL_RECT.vertical = true;
            }
            else
            {
                SCROLLBAR.SetActive(false);
                SCROLL_RECT.vertical = false;
            }
            for (int storeButtonIndex = 0; storeButtonIndex < storeButtons.Count; ++storeButtonIndex)
            {
                ButtonListener buttonListener = storeButtons[storeButtonIndex].GetComponent <ButtonListener>();
                if ((buttonListener.isClicked()) && mode != MODES.PREVIEW_PART)
                {
                    bool ignoreClick = false;
                    foreach (Part part in humanParts)
                    {
                        if (storeParts[storeButtonIndex].getID() == part.getID())
                        {
                            ignoreClick = true;
                            break;
                        }
                    }
                    if (!ignoreClick)
                    {
                        if (buttonListener.isClicked())
                        {
                            mode = MODES.PREVIEW_PART;
                            partInfo.SetActive(false);
                            partBeingPreviewed = storeParts[storeButtonIndex];
                            BUY_PART_BUTTON.SetActive(true);
                            BUY_PART_BUTTON.GetComponent <UnityEngine.UI.Image>().color = (PERFORMANCE_METRIC_CALCULATOR.calculateCost(partBeingPreviewed) <= credits ? colorScheme : UNAFFORDABLE_COLOR);
                        }
                        buttonListener.resetClick();
                        break;
                    }
                    buttonListener.resetClick();
                }
                if (buttonListener.isMouseOver() && mode != MODES.PREVIEW_PART)
                {
                    Part robotPart = null;
                    foreach (Part part in robotParts)
                    {
                        if (part.GetType() == storeParts[storeButtonIndex].GetType())
                        {
                            robotPart = part;
                            break;
                        }
                    }
                    Vector2 position;
                    RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("BuildHubCanvas").GetComponent <RectTransform>(), Input.mousePosition, Camera.main, out position);
                    position.x += partInfo.GetComponent <RectTransform>().sizeDelta.x / 2;
                    partInfo.transform.localPosition = position;
                    partType.GetComponent <TextMeshProUGUI>().text = storeParts[storeButtonIndex].GetType().ToString();
                    double[] differenceInStats = robotPart != null?robotPart.compareTo(storeParts[storeButtonIndex]) : (new Blaster("", null, 0, null, Shape.SHAPES.CYLINDER, 0, 0, 0, 0, 0, 0)).compareTo(storeParts[storeButtonIndex]);

                    foreach (GameObject partStat in partStatsList)
                    {
                        GameObject.Destroy(partStat);
                    }
                    partStatsList.Clear();
                    GameObject durabilityPartStat = GameObject.Instantiate(Resources.Load("Prefabs/PartStat") as GameObject);
                    durabilityPartStat.GetComponent <TextMeshProUGUI>().text = "Durability: " + StringTools.formatString(storeParts[storeButtonIndex].getDurability()) + (differenceInStats.Length > 0 ? " (" + applyStatDifferenceFormatting(differenceInStats[1], false) + ")": "");
                    durabilityPartStat.transform.SetParent(partStats.GetComponent <RectTransform>());
                    durabilityPartStat.transform.localPosition = new Vector3(durabilityPartStat.transform.localPosition.x, durabilityPartStat.transform.localPosition.y, 0);
                    partStatsList.Add(durabilityPartStat);
                    string[] partStatStrings = storeParts[storeButtonIndex].getStatStrings();
                    for (int partStatIndex = 0; partStatIndex < partStatStrings.Length; ++partStatIndex)
                    {
                        GameObject partStat = GameObject.Instantiate(Resources.Load("Prefabs/PartStat") as GameObject);
                        string     differenceInStatString = "";
                        int        differenceInStatsIndex = partStatIndex + 2;
                        if (!(storeParts[storeButtonIndex] is Attachment))
                        {
                            differenceInStatString = applyStatDifferenceFormatting(differenceInStats[differenceInStatsIndex], differenceInStatsIndex == 2);
                        }
                        else if (differenceInStats != null && differenceInStats.Length > 0)
                        {
                            if (differenceInStatsIndex == 3 || (differenceInStatsIndex >= 8 && differenceInStatsIndex < 11))
                            {
                                differenceInStatsIndex = -1;
                            }
                            else if (differenceInStatsIndex > 3 && differenceInStatsIndex < 8)
                            {
                                differenceInStatsIndex -= 1;
                            }
                            else if (differenceInStatsIndex == 11)
                            {
                                differenceInStatsIndex -= 4;
                            }
                            if (differenceInStatsIndex != -1)
                            {
                                if (differenceInStatsIndex >= 3 && differenceInStatsIndex <= 6)
                                {
                                    differenceInStats[differenceInStatsIndex] /= 1000;
                                }
                                differenceInStatString = applyStatDifferenceFormatting(differenceInStats[differenceInStatsIndex], differenceInStatsIndex == 2 || differenceInStatsIndex == 3 || differenceInStatsIndex == 4 || differenceInStatsIndex == 6);
                            }
                        }
                        partStat.GetComponent <TextMeshProUGUI>().text = partStatStrings[partStatIndex] + (differenceInStatString != "" ? " (" + differenceInStatString + ")" : "");
                        partStat.transform.SetParent(partStats.GetComponent <RectTransform>());
                        partStat.transform.localPosition = new Vector3(partStat.transform.localPosition.x, partStat.transform.localPosition.y, 0);
                        partStatsList.Add(partStat);
                    }
                    partInfo.SetActive(true);
                    break;
                }
                else
                {
                    partInfo.SetActive(false);
                }
            }
            bool switchTabs = false;
            foreach (GameObject tab in STORE_TABS)
            {
                if (tab.GetComponent <ButtonListener>().isClicked() && currentPartFilter != tab.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text)
                {
                    switchTabs = true;
                    filterParts(tab.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text);
                    updateSorting();
                    break;
                }
                else
                {
                    tab.GetComponent <ButtonListener>().resetClick();
                }
            }
            foreach (GameObject featuredPartsRow in FEATURED_PARTS_ROWS)
            {
                if (featuredPartsRow.GetComponent <ButtonListener>().isClicked())
                {
                    switchTabs = true;
                    string allPartsButtonLabelText = featuredPartsRow.transform.Find("AllParts").Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text;
                    foreach (GameObject tab in STORE_TABS)
                    {
                        if (allPartsButtonLabelText.Contains(tab.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text))
                        {
                            tab.GetComponent <ButtonListener>().click();
                            break;
                        }
                    }
                    featuredPartsRow.GetComponent <ButtonListener>().resetClick();
                    filterParts(allPartsButtonLabelText.Substring(allPartsButtonLabelText.IndexOf(" ") + 1, allPartsButtonLabelText.LastIndexOf(" ") - (allPartsButtonLabelText.IndexOf(" ") + 1) - 1));
                    updateSorting();
                    break;
                }
                else
                {
                    featuredPartsRow.GetComponent <ButtonListener>().resetClick();
                }
            }
            if (switchTabs)
            {
                foreach (GameObject tab in STORE_TABS)
                {
                    if (tab.GetComponent <ButtonListener>().isClicked())
                    {
                        tab.GetComponent <ButtonListener>().resetClick();
                        tab.GetComponent <UnityEngine.UI.Image>().color = ACTIVE_TAB_COLOR;
                    }
                    else
                    {
                        tab.GetComponent <UnityEngine.UI.Image>().color = INACTIVE_TAB_COLOR;
                    }
                }
            }
            if (currentSort != STORE_SORT.GetComponent <TMP_Dropdown>().value)
            {
                currentSort = STORE_SORT.GetComponent <TMP_Dropdown>().value;
                applySorting();
            }
            if (enableCreditsSpentAnimation && STORE_CREDITS_SPENT.activeSelf)
            {
                Vector3 position = STORE_CREDITS_SPENT.transform.localPosition;
                STORE_CREDITS_SPENT.transform.localPosition = new Vector3(position.x, position.y + STORE_CREDITS_SPENT_ANIMATION_POSITION_SPEED, position.z);
                Color storeCreditsSpentColor = STORE_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color;
                STORE_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color = new Color(storeCreditsSpentColor.r, storeCreditsSpentColor.g, storeCreditsSpentColor.b, storeCreditsSpentColor.a - STORE_CREDITS_SPENT_ANIMATION_COLOR_SPEED);
                if (STORE_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color.a <= 0)
                {
                    STORE_CREDITS_SPENT.SetActive(false);
                }
            }
            else
            {
                if (STORE_CREDITS_SPENT.transform.localPosition != STORE_CREDITS_SPENT_HOME_POSITION)
                {
                    STORE_CREDITS_SPENT.transform.localPosition = STORE_CREDITS_SPENT_HOME_POSITION;
                }
                Color storeCreditsSpentColor = STORE_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color;
                if (STORE_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color.a != 1)
                {
                    STORE_CREDITS_SPENT.GetComponent <TextMeshProUGUI>().color = new Color(storeCreditsSpentColor.r, storeCreditsSpentColor.g, storeCreditsSpentColor.b, 1);
                }
                if (STORE_CREDITS_SPENT.activeInHierarchy)
                {
                    STORE_CREDITS_SPENT.SetActive(false);
                }
            }
        }
    }
Example #29
0
 private void updateTabs()
 {
     if (!obstacleList.isEnabled() && !base.areSettingsOpen())
     {
         if (!OBSTACLES_INFO_BUTTON.activeInHierarchy && !SETTINGS_BUTTON.activeInHierarchy)
         {
             if (mode != MODES.MY_ROBOTS)
             {
                 MY_ROBOTS_BACK_BUTTON.SetActive(true);
                 foreach (GameObject tab in TABS)
                 {
                     tab.SetActive(true);
                 }
             }
             previewRobot.GAME_OBJECT.SetActive(true);
             OBSTACLES_INFO_BUTTON.SetActive(true);
             SETTINGS_BUTTON.SetActive(true);
             TRAINING_BUTTON.SetActive(true);
         }
         if (mode == MODES.MY_ROBOTS && (myRobots.getRobotBeingPicked() != null || myRobots.getNewRobot() != null || myRobots.getRobotsToRemove().Count > 0))
         {
             if (myRobots.getRobotsToRemove().Count > 0)
             {
                 List <Robot> robotsToRemove = myRobots.getRobotsToRemove();
                 foreach (Robot robot in robotsToRemove)
                 {
                     myRobotsList.Remove(robot);
                 }
                 if (myRobotsList.Count == 0)
                 {
                     myRobots = new MyRobots(myRobotsList.ToArray(), humanRobotParts.ToArray(), credits, base.colorScheme);
                 }
                 myRobots.clearPickedAndNewRobotAndRobotsToRemove();
             }
             else
             {
                 currentRobot = (myRobots.getRobotBeingPicked() != null ? myRobots.getRobotBeingPicked() : myRobots.getNewRobot());
                 if (myRobots.getNewRobot() != null)
                 {
                     myRobotsList.Add(currentRobot);
                 }
                 if (previewRobot == null)
                 {
                     createPreviewRobot();
                 }
                 myRobots.clearPickedAndNewRobotAndRobotsToRemove();
                 workshop.destroyAllGeneratedObjects();
                 store.destroyAllGeneratedObjects();
                 GameObject.Find("BuildHubCanvas").transform.Find("Workshop").gameObject.SetActive(true);
                 GameObject.Find("BuildHubCanvas").transform.Find("Store").gameObject.SetActive(true);
                 workshop = new Workshop(MESHES, previewRobot, currentRobot.getName(), this.humanRobotParts, currentRobot.getParts(), this.credits, base.colorScheme, enableCreditsSpentAnimation);
                 store    = new Store(MESHES, previewRobot, this.STORE_PARTS, this.humanRobotParts, currentRobot.getParts(), this.credits, workshop.getConfigurationCard(), base.colorScheme, enableCreditsSpentAnimation);
                 mode     = MODES.WORKSHOP;
                 MY_ROBOTS_BACK_BUTTON.SetActive(true);
                 foreach (GameObject tab in TABS)
                 {
                     tab.SetActive(true);
                 }
             }
         }
         if (MY_ROBOTS_BACK_BUTTON.GetComponent <ButtonListener>().isClicked())
         {
             MY_ROBOTS_BACK_BUTTON.GetComponent <ButtonListener>().resetClick();
             updateCurrentRobotInList();
             mode = MODES.MY_ROBOTS;
             MY_ROBOTS_BACK_BUTTON.SetActive(false);
             foreach (GameObject tab in TABS)
             {
                 tab.SetActive(false);
             }
             myRobots.destroyAllGeneratedObjects();
             GameObject.Find("BuildHubCanvas").transform.Find("MyRobots").gameObject.SetActive(true);
             myRobots = new MyRobots(myRobotsList.ToArray(), humanRobotParts.ToArray(), credits, base.colorScheme);
         }
         foreach (GameObject tab in TABS)
         {
             if (tab.GetComponent <UnityEngine.UI.Image>().color == INACTIVE_TAB_COLOR && (tab.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text.ToLower().Contains(mode.ToString().ToLower()) || tab.GetComponent <ButtonListener>().isClicked()))
             {
                 tab.GetComponent <UnityEngine.UI.Image>().color = ACTIVE_TAB_COLOR;
                 mode = (MODES)Enum.Parse(typeof(MODES), tab.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text.ToUpper(), true);
                 tab.GetComponent <ButtonListener>().resetClick();
             }
             else if (!tab.transform.Find("Label").gameObject.GetComponent <TextMeshProUGUI>().text.ToLower().Contains(mode.ToString().ToLower()))
             {
                 tab.GetComponent <UnityEngine.UI.Image>().color = INACTIVE_TAB_COLOR;
             }
             tab.GetComponent <ButtonListener>().resetClick();
         }
         GameObject.Find("BuildHubCanvas").transform.Find("MyRobots").gameObject.SetActive(mode == MODES.MY_ROBOTS);
         GameObject.Find("BuildHubCanvas").transform.Find("Workshop").gameObject.SetActive(mode == MODES.WORKSHOP);
         GameObject.Find("BuildHubCanvas").transform.Find("Store").gameObject.SetActive(mode == MODES.STORE);
         if (OBSTACLES_INFO_BUTTON.GetComponent <ButtonListener>().isClicked())
         {
             OBSTACLES_INFO_BUTTON.GetComponent <ButtonListener>().resetClick();
             MY_ROBOTS_BACK_BUTTON.SetActive(false);
             foreach (GameObject tab in TABS)
             {
                 tab.SetActive(false);
             }
             previewRobot.GAME_OBJECT.SetActive(false);
             GameObject.Find("BuildHubCanvas").transform.Find("Workshop").gameObject.SetActive(false);
             GameObject.Find("BuildHubCanvas").transform.Find("Store").gameObject.SetActive(false);
             OBSTACLES_INFO_BUTTON.SetActive(false);
             SETTINGS_BUTTON.SetActive(false);
             TRAINING_BUTTON.SetActive(false);
             obstacleList.enable();
         }
         if (SETTINGS_BUTTON.GetComponent <ButtonListener>().isClicked())
         {
             SETTINGS_BUTTON.GetComponent <ButtonListener>().resetClick();
             MY_ROBOTS_BACK_BUTTON.SetActive(false);
             foreach (GameObject tab in TABS)
             {
                 tab.SetActive(false);
             }
             previewRobot.GAME_OBJECT.SetActive(false);
             GameObject.Find("BuildHubCanvas").transform.Find("Workshop").gameObject.SetActive(false);
             GameObject.Find("BuildHubCanvas").transform.Find("Store").gameObject.SetActive(false);
             OBSTACLES_INFO_BUTTON.SetActive(false);
             SETTINGS_BUTTON.SetActive(false);
             base.openSettings();
         }
         if (TRAINING_BUTTON.GetComponent <ButtonListener>().isClicked())
         {
             TRAINING_BUTTON.GetComponent <ButtonListener>().resetClick();
             workshop.setGoToField(true);
             goToField    = true;
             trainingMode = true;
         }
         if (CREDITS_BUTTON.GetComponent <ButtonListener>().isClicked())
         {
             CREDITS_BUTTON.GetComponent <ButtonListener>().resetClick();
             CREDITS_WIDGET.SetActive(!CREDITS_WIDGET.activeInHierarchy);
         }
     }
 }