示例#1
0
    void Awake()
    {
        const int numWidgets = 10;

        widgets = new Widget[numWidgets];
        for (int a = 0; a < numWidgets; a++)
        {
            int r = Random.Range(0, 3);
            if (r == 0)
            {
                widgets[a] = new PortWidget();
            }
            else if (r == 1)
            {
                widgets[a] = new IndicatorWidget();
            }
            else
            {
                widgets[a] = new BatteryWidget();
            }
        }

        char[] possibleCharArray = new char[35]
        {
            'A', 'B', 'C', 'D', 'E',
            'F', 'G', 'H', 'I', 'J',
            'K', 'L', 'M', 'N', 'E',
            'P', 'Q', 'R', 'S', 'T',
            'U', 'V', 'W', 'X', 'Z',
            '0', '1', '2', '3', '4',
            '5', '6', '7', '8', '9'
        };
        string str1 = string.Empty;

        for (int index = 0; index < 2; ++index)
        {
            str1 = str1 + possibleCharArray[Random.Range(0, possibleCharArray.Length)];
        }
        string str2 = str1 + (object)Random.Range(0, 10);

        for (int index = 3; index < 5; ++index)
        {
            str2 = str2 + possibleCharArray[Random.Range(0, possibleCharArray.Length - 10)];
        }
        serial = str2 + Random.Range(0, 10);

        Debug.Log("Serial: " + serial);
    }
示例#2
0
    /// <summary>
    /// Sets up the edgework of the FakeBombInfo according to the provided edgework configuration.
    /// </summary>
    /// <param name="config"></param>
    public void SetupEdgework(EdgeworkConfiguration config)
    {
        if (config == null)
        {
            const int numWidgets = 5;
            widgets = new Widget[numWidgets];
            for (int a = 0; a < numWidgets; a++)
            {
                int r = Random.Range(0, 3);
                if (r == 0)
                {
                    widgets[a] = new PortWidget();
                }
                else if (r == 1)
                {
                    widgets[a] = new IndicatorWidget();
                }
                else
                {
                    widgets[a] = new BatteryWidget();
                }
            }
            string str1 = string.Empty;
            for (int index = 0; index < 2; ++index)
            {
                str1 = str1 + SerialNumberPossibleCharArray[Random.Range(0, SerialNumberPossibleCharArray.Length)];
            }
            string str2 = str1 + Random.Range(0, 10);
            for (int index = 3; index < 5; ++index)
            {
                str2 = str2 + SerialNumberPossibleCharArray[Random.Range(0, SerialNumberPossibleCharArray.Length - 10)];
            }
            serial = str2 + Random.Range(0, 10);

            Debug.Log("Serial: " + serial);
        }
        else
        {
            if (config.SerialNumberType == SerialNumberType.RANDOM_NORMAL)
            {
                string str1 = string.Empty;
                for (int index = 0; index < 2; ++index)
                {
                    str1 = str1 + SerialNumberPossibleCharArray[Random.Range(0, SerialNumberPossibleCharArray.Length)];
                }
                string str2 = str1 + Random.Range(0, 10);
                for (int index = 3; index < 5; ++index)
                {
                    str2 = str2 + SerialNumberPossibleCharArray[Random.Range(0, SerialNumberPossibleCharArray.Length - 10)];
                }
                serial = str2 + Random.Range(0, 10);
            }
            else if (config.SerialNumberType == SerialNumberType.RANDOM_ANY)
            {
                string res = string.Empty;
                for (int index = 0; index < 6; ++index)
                {
                    res = res + SerialNumberPossibleCharArray[Random.Range(0, SerialNumberPossibleCharArray.Length)];
                }
                serial = res;
            }
            else
            {
                serial = config.CustomSerialNumber;
            }
            Debug.Log("Serial: " + serial);

            List <Widget>   widgetsResult    = new List <Widget>();
            List <THWidget> RandomIndicators = new List <THWidget>();
            List <THWidget> RandomWidgets    = new List <THWidget>();
            foreach (THWidget widgetConfig in config.Widgets)
            {
                if (widgetConfig.Type == WidgetType.RANDOM)
                {
                    RandomWidgets.Add(widgetConfig);
                }
                else if (widgetConfig.Type == WidgetType.INDICATOR && widgetConfig.IndicatorLabel == IndicatorLabel.RANDOM)
                {
                    RandomIndicators.Add(widgetConfig);
                }
                else
                {
                    switch (widgetConfig.Type)
                    {
                    case WidgetType.BATTERY:
                        for (int i = 0; i < widgetConfig.Count; i++)
                        {
                            if (widgetConfig.BatteryType == BatteryType.CUSTOM)
                            {
                                widgetsResult.Add(new BatteryWidget(widgetConfig.BatteryCount));
                            }
                            else if (widgetConfig.BatteryType == BatteryType.RANDOM)
                            {
                                widgetsResult.Add(new BatteryWidget(Random.Range(widgetConfig.MinBatteries, widgetConfig.MaxBatteries + 1)));
                            }
                            else
                            {
                                widgetsResult.Add(new BatteryWidget((int)widgetConfig.BatteryType));
                            }
                        }
                        break;

                    case WidgetType.INDICATOR:
                        if (widgetConfig.IndicatorLabel == IndicatorLabel.CUSTOM)
                        {
                            widgetsResult.Add(new IndicatorWidget(widgetConfig.CustomLabel, widgetConfig.IndicatorState));
                        }
                        else
                        {
                            widgetsResult.Add(new IndicatorWidget(widgetConfig.IndicatorLabel.ToString(), widgetConfig.IndicatorState));
                        }
                        break;

                    case WidgetType.PORT_PLATE:
                        for (int i = 0; i < widgetConfig.Count; i++)
                        {
                            List <string> ports = new List <string>();
                            if (widgetConfig.PortPlateType == PortPlateType.CUSTOM)
                            {
                                if (widgetConfig.DVIPort)
                                {
                                    ports.Add("DVI");
                                }
                                if (widgetConfig.PS2Port)
                                {
                                    ports.Add("PS2");
                                }
                                if (widgetConfig.RJ45Port)
                                {
                                    ports.Add("RJ45");
                                }
                                if (widgetConfig.StereoRCAPort)
                                {
                                    ports.Add("StereoRCA");
                                }
                                if (widgetConfig.ParallelPort)
                                {
                                    ports.Add("Parallel");
                                }
                                if (widgetConfig.SerialPort)
                                {
                                    ports.Add("Serial");
                                }
                                ports.AddRange(widgetConfig.CustomPorts);
                            }
                            else if (widgetConfig.PortPlateType == PortPlateType.RANDOM_ANY)
                            {
                                if (Random.value > 0.5f)
                                {
                                    ports.Add("DVI");
                                }
                                if (Random.value > 0.5f)
                                {
                                    ports.Add("PS2");
                                }
                                if (Random.value > 0.5f)
                                {
                                    ports.Add("RJ45");
                                }
                                if (Random.value > 0.5f)
                                {
                                    ports.Add("StereoRCA");
                                }
                                if (Random.value > 0.5f)
                                {
                                    ports.Add("Parallel");
                                }
                                if (Random.value > 0.5f)
                                {
                                    ports.Add("Serial");
                                }
                                foreach (string port in widgetConfig.CustomPorts)
                                {
                                    if (Random.value > 0.5f)
                                    {
                                        ports.Add(port);
                                    }
                                }
                            }
                            else
                            {
                                if (Random.value > 0.5)
                                {
                                    if (Random.value > 0.5)
                                    {
                                        ports.Add("Parallel");
                                    }
                                    if (Random.value > 0.5)
                                    {
                                        ports.Add("Serial");
                                    }
                                }
                                else
                                {
                                    if (Random.value > 0.5)
                                    {
                                        ports.Add("DVI");
                                    }
                                    if (Random.value > 0.5)
                                    {
                                        ports.Add("PS2");
                                    }
                                    if (Random.value > 0.5)
                                    {
                                        ports.Add("RJ45");
                                    }
                                    if (Random.value > 0.5)
                                    {
                                        ports.Add("StereoRCA");
                                    }
                                }
                                foreach (string port in widgetConfig.CustomPorts)
                                {
                                    if (Random.value > 0.5f)
                                    {
                                        ports.Add(port);
                                    }
                                }
                            }
                            widgetsResult.Add(new PortWidget(ports));
                        }
                        break;

                    case WidgetType.CUSTOM:
                        for (int i = 0; i < widgetConfig.Count; i++)
                        {
                            widgetsResult.Add(new CustomWidget(widgetConfig.CustomQueryKey, widgetConfig.CustomData));
                        }
                        break;
                    }
                }
            }
            foreach (THWidget randIndWidget in RandomIndicators)
            {
                widgetsResult.Add(new IndicatorWidget());
            }
            foreach (THWidget randIndWidget in RandomWidgets)
            {
                for (int i = 0; i < randIndWidget.Count; i++)
                {
                    int r = Random.Range(0, 3);
                    if (r == 0)
                    {
                        widgetsResult.Add(new BatteryWidget());
                    }
                    else if (r == 1)
                    {
                        widgetsResult.Add(new IndicatorWidget());
                    }
                    else
                    {
                        widgetsResult.Add(new PortWidget());
                    }
                }
            }
            widgets = widgetsResult.ToArray();
        }
    }
示例#3
0
    public static PortWidget CreateComponent(PortWidget where, List <string> portNames = null)
    {
        PortWidget widget = Instantiate(where);

        widget.ports = new List <string>();
        string portList = "";

        if (portNames == null)
        {
            if (Random.value > 0.5)
            {
                if (Random.value > 0.5)
                {
                    widget.ports.Add("Parallel");
                    portList += "Parallel";
                }
                if (Random.value > 0.5)
                {
                    widget.ports.Add("Serial");
                    if (portList.Length > 0)
                    {
                        portList += ", ";
                    }
                    portList += "Serial";
                }
            }
            else
            {
                if (Random.value > 0.5)
                {
                    widget.ports.Add("DVI");
                    portList += "DVI";
                }
                if (Random.value > 0.5)
                {
                    widget.ports.Add("PS2");
                    if (portList.Length > 0)
                    {
                        portList += ", ";
                    }
                    portList += "PS2";
                }
                if (Random.value > 0.5)
                {
                    widget.ports.Add("RJ45");
                    if (portList.Length > 0)
                    {
                        portList += ", ";
                    }
                    portList += "RJ45";
                }
                if (Random.value > 0.5)
                {
                    widget.ports.Add("StereoRCA");
                    if (portList.Length > 0)
                    {
                        portList += ", ";
                    }
                    portList += "StereoRCA";
                }
            }
        }
        else
        {
            widget.ports = portNames;
            portList     = string.Join(", ", portNames.ToArray());
        }
        if (portList.Length == 0)
        {
            portList = "Empty plate";
        }


        foreach (Transform t in widget.TextPortsTransform.GetComponentsInChildren <Transform>(true))
        {
            if (t.parent != widget.TextPortsTransform)
            {
                continue;
            }
            t.gameObject.SetActive(false);
        }

        foreach (Transform t in widget.GraphicPortsTransform.GetComponentsInChildren <Transform>(true))
        {
            if (t.parent != widget.GraphicPortsTransform)
            {
                continue;
            }
            t.gameObject.SetActive(false);
        }

        foreach (Transform t in widget.GraphicPortsFillerTransform.GetComponentsInChildren <Transform>(true))
        {
            if (t.parent != widget.GraphicPortsFillerTransform)
            {
                continue;
            }
            t.gameObject.SetActive(true);
        }


        List <string> otherPorts = new List <string>();

        foreach (string port in widget.ports)
        {
            Transform p = widget.TextPortsTransform.Find(port);
            if (p != null)
            {
                p.gameObject.SetActive(true);
            }
            else
            {
                otherPorts.Add(port);
            }

            p = widget.GraphicPortsTransform.Find(port);
            if (p != null)
            {
                p.gameObject.SetActive(true);
            }

            p = widget.GraphicPortsFillerTransform.Find(port);
            if (p != null)
            {
                p.gameObject.SetActive(false);
            }
        }

        widget.TextPortsTransform.parent.gameObject.SetActive(otherPorts.Count != 0);
        widget.GraphicPortsTransform.parent.gameObject.SetActive(otherPorts.Count == 0);

        widget.OtherPortsTextMesh.text = string.Join(", ", otherPorts.ToArray());

        Debug.Log("Added port widget: " + portList);
        return(widget);
    }