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); }
public static IndicatorWidget CreateComponent(IndicatorWidget where, string label = null, IndicatorState state = IndicatorState.RANDOM) { IndicatorWidget widget = Instantiate(where); if (label == null) { if (possibleValues.Any()) { int pos = Random.Range(0, possibleValues.Count); widget.Val = possibleValues[pos]; possibleValues.RemoveAt(pos); } else { widget.Val = "NLL"; } } else { if (possibleValues.Contains(label)) { widget.Val = label; possibleValues.Remove(label); } else { widget.Val = "NLL"; } } if (state == IndicatorState.RANDOM) { widget.On = Random.value > 0.4f; } else { widget.On = state == IndicatorState.ON ? true : false; } widget.LightOnTransform.gameObject.SetActive(widget.On); widget.LightOffTransform.gameObject.SetActive(!widget.On); widget.IndicatorTextMesh.text = widget.Val; Debug.Log("Added indicator widget: " + widget.Val + " is " + (widget.On ? "ON" : "OFF")); return(widget); }
/// <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(); } }