コード例 #1
0
    public static SerialNumber CreateComponent(SerialNumber where, EdgeworkConfiguration config)
    {
        SerialNumberType sntype = config == null ? SerialNumberType.RANDOM_NORMAL : config.SerialNumberType;
        string           sn     = config == null ? string.Empty : config.CustomSerialNumber;

        SerialNumber widget = Instantiate(where);

        if (string.IsNullOrEmpty(sn) && sntype == SerialNumberType.CUSTOM)
        {
            sntype = SerialNumberType.RANDOM_NORMAL;
        }

        if (sntype == 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 + (object)Random.Range(0, 10);
            for (int index = 3; index < 5; ++index)
            {
                str2 = str2 + SerialNumberPossibleCharArray[Random.Range(0, SerialNumberPossibleCharArray.Length - 10)];
            }
            widget.serial = str2 + Random.Range(0, 10);
        }
        else if (sntype == SerialNumberType.RANDOM_ANY)
        {
            string res = string.Empty;
            for (int index = 0; index < 6; ++index)
            {
                res = res + SerialNumberPossibleCharArray[Random.Range(0, SerialNumberPossibleCharArray.Length)];
            }
            widget.serial = res;
        }
        else
        {
            widget.serial = sn;
        }

        widget.serialTextMesh.text = widget.serial;

        Debug.Log("Serial: " + widget.serial);
        return(widget);
    }
コード例 #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();
        }
    }