public static BatteryWidget CreateComponent(BatteryWidget where, int battCount = -1)
    {
        BatteryWidget widget = Instantiate(where);

        if (battCount == -1)
        {
            widget.batt = Random.Range(1, 3);
        }
        else
        {
            widget.batt = battCount;
        }

        widget.BatteryTextMesh.transform.parent.gameObject.SetActive(false);
        foreach (Transform t in widget.BatteryHolders)
        {
            t.gameObject.SetActive(false);
        }
        foreach (Transform t in widget.BatterySets)
        {
            t.gameObject.SetActive(false);
        }
        foreach (Transform t in widget.BatterySets.SelectMany(x => x.GetComponentsInChildren <MeshRenderer>()).Select(x => x.transform))
        {
            t.localEulerAngles = new Vector3(t.localEulerAngles.x, t.localEulerAngles.y, Random.Range(0, 360f));
        }

        switch (widget.batt)
        {
        case 0:
            widget.BatteryHolders[Random.Range(0, widget.BatteryHolders.Length)].gameObject.SetActive(true);
            break;

        case 1:
        case 2:
        case 3:
        case 4:
            widget.BatteryHolders[widget.batt - 1].gameObject.SetActive(true);
            widget.BatterySets[widget.batt - 1].gameObject.SetActive(true);
            break;

        default:
            widget.BatteryTextMesh.transform.parent.gameObject.SetActive(true);
            widget.BatteryTextMesh.text = widget.batt + " Cells";
            break;
        }

        Debug.Log("Added battery widget: " + widget.batt);

        return(widget);
    }
示例#2
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);
    }
示例#3
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();
        }
    }