/// <summary>Creates a draggable label with current unit (mph or km/h).</summary> /// <param name="builder">The UI builder to use.</param> private void SetupControls_TitleBar(UBuilder builder) { string unitTitle = string.Format( format: "{0} - {1}", Translation.SpeedLimits.Get("Window.Title:Speed Limits"), GlobalConfig.Instance.Main.DisplaySpeedLimitsMph ? Translation.SpeedLimits.Get("Miles per hour") : Translation.SpeedLimits.Get("Kilometers per hour")); // The label will be repositioned to the top of the parent this.windowTitleLabel_ = builder.Label_( parent: this, t: unitTitle, stack: UStackMode.Below); this.dragHandle_ = this.CreateDragHandle(); // On window drag - clamp to screen and then save in the config this.eventPositionChanged += (_, value) => { GlobalConfig.Instance.Main.SpeedLimitsWindowX = (int)value.x; GlobalConfig.Instance.Main.SpeedLimitsWindowY = (int)value.y; if (!queuedClampToScreen) { // Prevent multiple invocations by setting a flag queuedClampToScreen = true; Invoke(eventName: "OnPeriodicClampToScreen", 2.0f); } }; }
/// <summary> /// Sets up two stacked labels: for mode description (what the user sees) and for hint. /// The text is empty but is updated after every mode or view change. /// </summary> public void SetupControls(SpeedLimitsToolWindow window, UBuilder builder, SpeedLimitsTool parentTool) { this.position = Vector3.zero; this.backgroundSprite = "GenericPanel"; this.color = new Color32(64, 64, 64, 255); this.SetPadding(UPadding.Default); this.ResizeFunction( resizeFn: (UResizer r) => { r.Stack( UStackMode.ToTheRight, spacing: UConst.UIPADDING, stackRef: window.modeButtonsPanel_); r.FitToChildren(); }); this.ModeDescriptionLabel = builder.Label_( parent: this, t: string.Empty, stack: UStackMode.Below, processMarkup: true); this.ModeDescriptionLabel.SetPadding( new UPadding(top: 12f, right: 0f, bottom: 0f, left: 0f)); }
public override void Build(UIComponent parent, U.UBuilder builder) { ULabel l = builder.Label <U.ULabel>( parent, this.localizedText_, stack: UStackMode.NewRowBelow, processMarkup: true); l.opacity = 0.8f; }
IEnumerator MissionShow() { Main_Camera.SetActive(false); UI_Camera.AddComponent <AudioListener>(); UIAudioSrc.Play(); yield return(new WaitForSeconds(UIAudioSrc.clip.length)); Debug.LogWarning("10012_C02_wav.aax播放完毕,进入关卡"); BackGroundPic.SetActive(false); ULabel.SetActive(false); Main_Camera.SetActive(true); Spotlight.SetActive(false); Scene_BGM.Play(); JoyStickPanel_Left.SetActive(true); DragButton.SetActive(true); playerManager.loadJoyStick(); }
private void CreatePaletteButtonHintLabel(UBuilder builder, bool showMph, SpeedValue speedValue, SpeedLimitPaletteButton button, UPanel buttonPanel) { // Other speed unit info label string otherUnit = showMph ? ToKmphPreciseString(speedValue) : ToMphPreciseString(speedValue); // Choose label text under the button string GetSpeedButtonHintText() { if (FloatUtil.NearlyEqual(speedValue.GameUnits, 0.0f)) { return(Translation.SpeedLimits.Get("Palette.Text:Default")); } if (speedValue.GameUnits >= SpeedValue.UNLIMITED) { return(Translation.SpeedLimits.Get("Palette.Text:Unlimited")); } return(otherUnit); } ULabel label = button.AltUnitsLabel = builder.Label_( parent: buttonPanel, t: GetSpeedButtonHintText(), stack: UStackMode.Below); label.width = SpeedLimitPaletteButton.SELECTED_WIDTH; label.textAlignment = UIHorizontalAlignment.Center; label.ContributeToBoundingBox(false); // parent ignore our width }
/// <summary> /// Generate and return a list of counterexamples by iterating over the training set /// </summary> /// <param name="datasetname"></param> /// <param name="options"></param> /// <param name="nn"></param> /// <param name="ds"></param> /// <returns></returns> public static List<LabelWithConfidence> SynthesizeCounterexamples( NeuralNet nn, ImageDataset ds, Action<LabelWithConfidence> snapshot) { /* Initialization stuff */ List<LabelWithConfidence> counterexamples = new List<LabelWithConfidence>(); SynthRegistry reg = new SynthRegistry(RobustnessOptions.Registry + ".csv", RobustnessOptions.Registry); /* How many training points to do */ int trainingPointsToDo = (int)Math.Round(ds.Dataset.Count() * RobustnessOptions.DataSetPercentage); int completed = 0; /* The symbolic variables: NB we use the dimension PostCrop to avoid generating lots of useless variables */ Tuple<LPSTerm[],LPSTerm> inputs = GenSymbolicInputs(nn.InputDimensionPostCrop); // Alternatively (the code is thread-safe already): // Parallel.For(0, ds.Dataset.Count(), RobustnessOptions.ParallelOptions, i => for (int i = 0; i < ds.Dataset.Count(); i++) { if (completed < trainingPointsToDo) { Console.WriteLine("Image count = {0}", i); NNInstrumentation instr = new NNInstrumentation(); LabelWithConfidence imageLab = ULabel.LabelWithConfidence(nn, instr, ds.Dataset.GetDatum(i), true); Nullable<LabelWithConfidence> synthLab = null; try { var stopwatch = new Stopwatch(); stopwatch.Start(); synthLab = SynthesizeCounterexample( nn, inputs.Item1, inputs.Item2, imageLab, instr, ds.Dataset.GetLabel(i), ds.RowCount, ds.ColumnCount, ds.IsColor); stopwatch.Stop(); Console.WriteLine("Processed image in {0} milliseconds", stopwatch.ElapsedMilliseconds); GC.Collect(); } catch { lock(lockObj) { completed++; } continue; } lock (lockObj) { completed++; if (synthLab.HasValue) { // VERY IMPORTANTLY: Change the label of the counterexample // to be the label of the original point! This was a horrible bug. var forRetraining = synthLab.Value; forRetraining.actualLabel = imageLab.actualLabel; counterexamples.Add(forRetraining); snapshot(forRetraining); Console.WriteLine("forRetraining.label = {0}", forRetraining.actualLabel); Console.WriteLine("synthLab.Value.label = {0}", synthLab.Value.actualLabel); reg.RecordAtomically( RobustnessOptions.Registry, i, imageLab, synthLab.Value, RobustnessOptions.ScalePreProcessed, RobustnessOptions.OffsetPreProcessed, ds.RowCount, ds.ColumnCount, ds.IsColor); } Console.WriteLine("Counterexamples/Processed-so-far: " + counterexamples.Count() + "/" + completed); } } } return counterexamples; }
public InspectorDemo() { // label { UDrawer labelDrawer = new UDrawer("Label Drawer"); AddWidget(labelDrawer); ULabel label = new ULabel("This is a label"); labelDrawer.AddWidget(label); UFixedSpace space = new UFixedSpace(3); AddWidget(space); } // helpbox { UDrawer helpboxDrawer = new UDrawer("HelpBox Drawer"); AddWidget(helpboxDrawer); UHelpBox helpBox = new UHelpBox("none...", MessageType.None); helpboxDrawer.AddWidget(helpBox); UHelpBox infoHelpBox = new UHelpBox("information...", MessageType.Info); helpboxDrawer.AddWidget(infoHelpBox); UHelpBox warningHelpBox = new UHelpBox("warning...", MessageType.Warning); helpboxDrawer.AddWidget(warningHelpBox); UHelpBox errorHelpBox = new UHelpBox("error...", MessageType.Error); helpboxDrawer.AddWidget(errorHelpBox); UFixedSpace space = new UFixedSpace(3); AddWidget(space); } // field { UDrawer fieldDrawer = new UDrawer("Field Drawer"); AddWidget(fieldDrawer); UTextField textField = new UTextField("Text Filed"); fieldDrawer.AddWidget(textField); UIntField intField = new UIntField("Int Field"); fieldDrawer.AddWidget(intField); UFloatField floatField = new UFloatField("Float Field"); fieldDrawer.AddWidget(floatField); UObjectField objectField = new UObjectField("Object Field", typeof(GameObject)); fieldDrawer.AddWidget(objectField); UAnimationCurveField curveField = new UAnimationCurveField("AnimationCurve Filed"); fieldDrawer.AddWidget(curveField); UColorField colorField = new UColorField("Color Field"); fieldDrawer.AddWidget(colorField); UBoundsField boundsField = new UBoundsField("Bounds Field"); fieldDrawer.AddWidget(boundsField); URectField rectField = new URectField("Rect Field"); fieldDrawer.AddWidget(rectField); UVector2Filed vector2Field = new UVector2Filed("Vector2 Field"); fieldDrawer.AddWidget(vector2Field); UVector3Filed vector3Field = new UVector3Filed("Vector3 Field"); fieldDrawer.AddWidget(vector3Field); UVector4Filed vector4Field = new UVector4Filed("Vector4 Field"); fieldDrawer.AddWidget(vector4Field); USearchField searchField = new USearchField("Search Field"); fieldDrawer.AddWidget(searchField); //UPropertyField propertyField = new UPropertyField("Property Field", null); //fieldDrawer.AddWidget(propertyField); UPasswordField passwordFiled = new UPasswordField("Password Field", "123"); fieldDrawer.AddWidget(passwordFiled); UFixedSpace space = new UFixedSpace(3); AddWidget(space); } // slider { UDrawer sliderDrawer = new UDrawer("Slider Drawer"); AddWidget(sliderDrawer); UIntSlider intSlider = new UIntSlider("Int Slider", 5, 0, 10); sliderDrawer.AddWidget(intSlider); UFixedSpace space = new UFixedSpace(3); AddWidget(space); } // popup { UDrawer popupDrawer = new UDrawer("Popup Drawer"); AddWidget(popupDrawer); UEnumPopup enumPopup = new UEnumPopup("Enum Popup", EnumType.B); popupDrawer.AddWidget(enumPopup); int[] popupValues = new int[] { 1, 3, 5, 7, 9 }; string[] popupTexts = new string[] { "1", "3", "5", "7", "9" }; UIntPopup intPopup = new UIntPopup("Int Popup", popupValues[2], popupValues, popupTexts); popupDrawer.AddWidget(intPopup); ULayerPopup layerPopup = new ULayerPopup("Layer Popup", 0); popupDrawer.AddWidget(layerPopup); UTagPopup tagPopup = new UTagPopup("Tag Popup", "Untagged"); popupDrawer.AddWidget(tagPopup); UEnumMaskPopup enumMaskPopup = new UEnumMaskPopup("Enum Mask Popup", EnumMaskType.BM); popupDrawer.AddWidget(enumMaskPopup); UFixedSpace space = new UFixedSpace(3); AddWidget(space); } // button { UDrawer buttonDrawer = new UDrawer("Button Drawer"); AddWidget(buttonDrawer); UButton button = new UButton("Button"); button.color = Color.green; buttonDrawer.AddWidget(button); UHLayout buttonLayout = new UHLayout(); buttonDrawer.AddLayout(buttonLayout); UButton leftButton = new UButton("LeftButton", UButton.Style.Left); buttonLayout.AddWidget(leftButton); UButton midButton = new UButton("MidButton", UButton.Style.Middle); buttonLayout.AddWidget(midButton); UButton rightButton = new UButton("RightButton", UButton.Style.Right); buttonLayout.AddWidget(rightButton); UButton miniButton = new UButton("Mini Button", UButton.Style.Mini); miniButton.color = Color.red; buttonDrawer.AddWidget(miniButton); UHLayout miniButtonLayout = new UHLayout(); buttonDrawer.AddLayout(miniButtonLayout); UButton leftMiniButton = new UButton("Left Mini Button", UButton.Style.MiniLeft); miniButtonLayout.AddWidget(leftMiniButton); UButton midMiniButton = new UButton("Mid Mini Button", UButton.Style.MiniMiddle); miniButtonLayout.AddWidget(midMiniButton); UButton rightMiniButton = new UButton("Right Mini Button", UButton.Style.MiniRight); miniButtonLayout.AddWidget(rightMiniButton); UToggleButton toggleButton = new UToggleButton("Toggle Button"); toggleButton.color = Color.blue; buttonDrawer.AddWidget(toggleButton); UHLayout toggleLayout = new UHLayout(); buttonDrawer.AddLayout(toggleLayout); UToggleButton leftToggleButton = new UToggleButton("Left Toggle Button", UToggleButton.Style.Left); toggleLayout.AddWidget(leftToggleButton); UToggleButton midToggleButton = new UToggleButton("Mid Toggle Button", UToggleButton.Style.Middle); toggleLayout.AddWidget(midToggleButton); UToggleButton rightToggleButton = new UToggleButton("Right Toggle Button", UToggleButton.Style.Right); toggleLayout.AddWidget(rightToggleButton); UToggleButton miniToggleButton = new UToggleButton("Mini Toggle Button", UButton.Style.Mini); miniToggleButton.color = Color.yellow; buttonDrawer.AddWidget(miniToggleButton); UHLayout miniToggleLayout = new UHLayout(); buttonDrawer.AddLayout(miniToggleLayout); UToggleButton leftMiniToggleButton = new UToggleButton("Left Mini Toggle Button", UToggleButton.Style.MiniLeft); miniToggleLayout.AddWidget(leftMiniToggleButton); UToggleButton midMiniToggleButton = new UToggleButton("Mid Mini Toggle Button", UToggleButton.Style.MiniMiddle); miniToggleLayout.AddWidget(midMiniToggleButton); UToggleButton rightMiniToggleButton = new UToggleButton("Right Mini Toggle Button", UToggleButton.Style.MiniRight); miniToggleLayout.AddWidget(rightMiniToggleButton); UCheckbox checkbox = new UCheckbox("Right Checkbox"); buttonDrawer.AddWidget(checkbox); UCheckbox leftCheckbox = new UCheckbox("Left Checkbox", UCheckbox.Style.Left); buttonDrawer.AddWidget(leftCheckbox); URadiobox radiobox = new URadiobox(); buttonDrawer.AddWidget(radiobox); } }
/// <summary> /// Create button triples for number of lanes. /// Buttons are linked to lanes later by LaneArrowTool class. /// </summary> /// <param name="builder">The UI Builder.</param> /// <param name="numLanes">How many lane groups.</param> public void SetupControls(UBuilder builder, int numLanes) { Buttons = new List <LaneArrowButton>(); var buttonRowPanel = builder.Panel_(parent: this, stack: UStackMode.NewRowBelow); buttonRowPanel.name = "TMPE_ButtonRow"; buttonRowPanel.SetPadding(UPadding.Default); buttonRowPanel.ResizeFunction((UResizer r) => { r.FitToChildren(); }); // ----------------------------------- // Create a row of button groups // [ Lane 1 ] [ Lane 2 ] [ Lane 3 ] ... // [ [←] [↑] [→] ] [... ] [ ... ] // ----------------------------------- for (var i = 0; i < numLanes; i++) { string buttonName = $"TMPE_LaneArrow_ButtonGroup{i + 1}"; UPanel buttonGroupPanel = builder.Panel_( parent: buttonRowPanel, stack: i == 0 ? UStackMode.Below : UStackMode.ToTheRight); buttonGroupPanel.name = buttonName; buttonGroupPanel.atlas = TextureUtil.Ingame; buttonGroupPanel.backgroundSprite = "GenericPanel"; int i1 = i; // copy of the loop variable, for the resizeFunction below buttonGroupPanel.ResizeFunction((UResizer r) => { r.FitToChildren(); }); buttonGroupPanel.SetPadding(UPadding.Default); // Create a label with "Lane #" title string labelText = Translation.LaneRouting.Get("Format.Label:Lane") + " " + (i + 1); ULabel laneLabel = builder.Label_( parent: buttonGroupPanel, t: labelText); // The label will be repositioned to the top of the parent laneLabel.ResizeFunction(r => { r.Stack(UStackMode.Below); }); // Create and populate the panel with buttons // 3 buttons are created [←] [↑] [→], // The click event is assigned outside in LaneArrowTool.cs foreach (string prefix in new[] { "LaneArrowLeft", "LaneArrowForward", "LaneArrowRight", }) { LaneArrowButton arrowButton = builder.Button <LaneArrowButton>( parent: buttonGroupPanel, text: string.Empty, tooltip: null, size: new Vector2(40f, 40f), stack: prefix == "LaneArrowLeft" ? UStackMode.Below : UStackMode.ToTheRight); arrowButton.atlas = GetAtlas(); arrowButton.Skin = CreateDefaultButtonSkin(); arrowButton.Skin.ForegroundPrefix = prefix; Buttons.Add(arrowButton); } // for each button } // end button loop, for each lane }