public static void Unbind(UnityEngine.UIElements.Button button) { if (actions.ContainsKey(button)) { button.clicked -= actions[button]; } }
public OverlayMenu(OverlayCanvas canvas) { m_Canvas = canvas; name = ussClassName; if (s_TreeAsset == null) { s_TreeAsset = EditorGUIUtility.Load(k_UxmlPath) as VisualTreeAsset; } if (s_TreeAsset != null) { s_TreeAsset.CloneTree(this); } AddToClassList(ussClassName); m_Toggle = this.Q <Toggle>("overlay-toggle"); m_Toggle.RegisterCallback <ChangeEvent <bool> >((evt) => { canvas.SetOverlaysEnabled(evt.newValue); }); m_ListRoot = this.Q <ListView>("OverlayList"); m_ListRoot.makeItem = CreateListItem; m_ListRoot.bindItem = BindListItem; m_ListRoot.itemsSource = m_OverlayToShow; m_ListRoot.fixedItemHeight = 20; m_ListRoot.selectionType = SelectionType.None; m_Dropdown = this.Q <Button>("preset-dropdown"); m_Dropdown.clicked += DropdownOnClicked; m_DropdownText = this.Q <TextElement>(classes: "preset-dropdown-text"); var lastSavedPreset = canvas.lastAppliedPresetName; m_DropdownText.text = string.IsNullOrEmpty(lastSavedPreset) ? L10n.Tr("Window Preset") : lastSavedPreset; canvas.afterOverlaysInitialized += () => { m_DropdownText.text = canvas.lastAppliedPresetName; }; RegisterCallback <FocusOutEvent>(evt => { if (s_KeepAlive) { var focusController = evt.relatedTarget?.focusController; s_DelayUntilCanHide += () => CheckIfShouldHide(focusController?.focusedElement as VisualElement); } else { CheckIfShouldHide(evt.relatedTarget as VisualElement); } }); canvas.overlaysEnabledChanged += OnOverlayEnabledChanged; focusable = true; Hide(); }
private void OnEnable() { var root = rootVisualElement; root.style.flexDirection = FlexDirection.Row; var menuBox = new Box(); menuBox.style.alignItems = Align.Stretch; menuBox.style.width = new StyleLength(250f); _onComponentField = new ObjectField("On component field") { objectType = typeof(OnComponentFound <TextMeshProUGUI>) }; menuBox.Add(_onComponentField); var updateScriptsButton = new UnityEngine.UIElements.Button() { text = "Add components" }; updateScriptsButton.clicked += () => LoadPrefabs(); menuBox.Add(updateScriptsButton); root.Add(menuBox); }
private void AssignButtons() { root.Q <Button>("PreviousButton").clicked += () => { favoritesCoffeesController.SwitchToPreviousFavoriteCoffee(); RefreshView(); }; root.Q <Button>("NextButton").clicked += () => { favoritesCoffeesController.SwitchToNextFavoriteCoffee(); RefreshView(); }; addCoffeeButton = root.Q <Button>("AddFavCoffee"); addCoffeeButton.clicked += () => { favoritesCoffeesController.AddFavoriteCoffee(nameField.value, waterField.value, coffeeField.value); RefreshView(); }; removeCoffeeButton = root.Q <Button>("RemoveFavCoffee"); removeCoffeeButton.clicked += () => { favoritesCoffeesController.RemoveCurrentCoffee(); RefreshView(); }; }
private void PopulateTags(bool isOpen) { Foldout tagsFoldout = rootVisualElement.Q <Foldout>("TagsFoldout"); tagsFoldout.SetValueWithoutNotify(isOpen); tagsFoldout.Clear(); ListView listView = CreateListViewForTags(); tagsFoldout.Add(listView); List <ScriptableTag> tags = ScriptableSettingsManager.Instance.Tags; for (int i = 0; i < tags.Count; i++) { Toggle toggle = new Toggle(); toggle.text = " " + tags[i].name; int index = i; toggle.RegisterValueChangedCallback(x => OnToggleTag(tags[index], x)); ContextualMenuManipulator manipulator = new ContextualMenuManipulator(x => { x.menu.AppendAction("Delete", y => DeleteTag(tags[index])); }) { target = toggle }; listView.Add(toggle); } listView.style.height = Mathf.Min(tags.Count * 20, 100); Button tagsAdd = rootVisualElement.Q <Button>("TagsAdd"); tagsAdd.clicked -= GoToCreateNewTag; tagsAdd.clicked += GoToCreateNewTag; }
public void AddChoicePort(DialogueNode nodeCache, string overriddenPortName = "") { var generatedPort = GetPortInstance(nodeCache, Direction.Output); var portLabel = generatedPort.contentContainer.Q <Label>("type"); generatedPort.contentContainer.Remove(portLabel); var outputPortCount = nodeCache.outputContainer.Query("connector").ToList().Count(); var outputPortName = string.IsNullOrEmpty(overriddenPortName) ? $"Option {outputPortCount + 1}" : overriddenPortName; var textField = new TextField() { name = string.Empty, value = outputPortName }; textField.RegisterValueChangedCallback(evt => generatedPort.portName = evt.newValue); generatedPort.contentContainer.Add(new Label(" ")); generatedPort.contentContainer.Add(textField); var deleteButton = new Button(() => RemovePort(nodeCache, generatedPort)) { text = "X" }; generatedPort.contentContainer.Add(deleteButton); generatedPort.portName = outputPortName; nodeCache.outputContainer.Add(generatedPort); nodeCache.RefreshPorts(); nodeCache.RefreshExpandedState(); }
public void UpdateCreateNewPath() { if (state != CruddyAction.BrowsingPath) { return; } TextField txtFld = root.Q <TextField>(UXMLNames.CreateNewPathField); Button createBtn = root.Q <Button>(UXMLNames.CreateNewButton); string tarPath = GetFullPath(txtFld.value); if (AssetDatabase.LoadAllAssetsAtPath(tarPath).Length > 0) { var styleColor = createBtn.style.backgroundColor; styleColor.value = new Color(0.65f, 0.20f, 0.20f); createBtn.style.backgroundColor = styleColor; createBtn.text = " Already Exists "; var styleUnityFontStyleAndWeight = txtFld.style.unityFontStyleAndWeight; styleUnityFontStyleAndWeight.value = FontStyle.Bold; txtFld.style.unityFontStyleAndWeight = styleUnityFontStyleAndWeight; } else { var styleColor = createBtn.style.backgroundColor; styleColor.value = new Color(0.35f, 0.35f, 0.35f); createBtn.style.backgroundColor = styleColor; createBtn.text = " Create New "; var styleUnityFontStyleAndWeight = txtFld.style.unityFontStyleAndWeight; styleUnityFontStyleAndWeight.value = FontStyle.Normal; txtFld.style.unityFontStyleAndWeight = styleUnityFontStyleAndWeight; } }
void SetContextMenuManipulator(Button element, ScriptableSettings scriptableSettings) { ContextualMenuManipulator m = new ContextualMenuManipulator(x => ShowButtonContextMenu(scriptableSettings, x)) { target = element }; }
public void PopulatePresetList() { ClearButtons(); if (cameraOutputControl != null && cameraOutputControl.outputTextures != null) { foreach (var tex in cameraOutputControl.outputTextures) { var button = new Button(); button.text = tex.name; button.style.height = 30; buttons.Add(button); button.clicked += (() => { cameraOutputControl.GetComponent <RawImage>().texture = tex; if (!GameViewSizeHelper.Contains(GameViewSizeGroupType.Standalone, GameViewSizeHelper.GameViewSizeType.FixedResolution, tex.width, tex.height, tex.name)) { AddGameViewSize(tex.width, tex.height, tex.name); } GameViewSizeHelper.ChangeGameViewSize(GameViewSizeGroupType.Standalone, GameViewSizeHelper.GameViewSizeType.FixedResolution, tex.width, tex.height, tex.name); }); // } } // _iEnumerator = null; }
public DialogueNode CreateDialogueNode(string dialogue, string target, Vector2 mousePosition) { var dialogueNode = new DialogueNode { title = "DialogueNode", DialogueText = dialogue, TargetPlayer = target, GUID = Guid.NewGuid().ToString() }; var inputPort = GeneratePort(dialogueNode, Direction.Input, Port.Capacity.Multi); inputPort.portName = "Input"; dialogueNode.inputContainer.Add(inputPort); dialogueNode.styleSheets.Add(Resources.Load <StyleSheet>("DialogueNode")); var button = new Button(clickEvent: () => { AddChoicePort(dialogueNode); }); button.text = "New Choice"; dialogueNode.titleContainer.Add(button); var textFieldTarget = new TextField { name = "Target", value = target, label = "Target\n" }; textFieldTarget.RegisterValueChangedCallback(evt => { dialogueNode.TargetPlayer = evt.newValue; }); dialogueNode.mainContainer.Add(textFieldTarget); var textField = new TextField { name = "Dialogue", value = dialogue, label = "Dialogue\n" }; textField.RegisterValueChangedCallback(evt => { dialogueNode.DialogueText = evt.newValue; //dialogueNode.title = evt.newValue; }); //textField.SetValueWithoutNotify(dialogueNode.title); dialogueNode.mainContainer.Add(textField); dialogueNode.RefreshExpandedState(); dialogueNode.RefreshPorts(); dialogueNode.SetPosition(new Rect(mousePosition, defaultNodeSize)); return(dialogueNode); }
private void SetupButton(Button button) { var icon = button.Query(className: "quicktool-button-icon"); var iconPath = "Icons" + button.parent.name + "-icon"; var iconAsset = Resources.Load <Texture2D>(iconPath); button.style.backgroundImage = iconAsset; button.clickable.clicked += () => { }; button.tooltip = button.parent.name; }
private void StartTrackerProfiling(Button btn, string trackerId, bool deepProfile, bool editorProfile) { if (!ProfilerHelpers.StartProfilerRecording(trackerId, editorProfile, deepProfile)) { return; } m_CurrentProfileTag = trackerId; UpdateActionButton(btn, trackerId); }
public DialogueNode CreateNode(string nodeName, string nodeText, Vector2 position) { var tempDialogueNode = new DialogueNode() { title = nodeName, DialogueId = nodeName, DialogueText = nodeText, GUID = Guid.NewGuid().ToString() }; tempDialogueNode.styleSheets.Add(Resources.Load <StyleSheet>("Node")); var inputPort = GetPortInstance(tempDialogueNode, Direction.Input, Port.Capacity.Multi); inputPort.portName = "Input"; tempDialogueNode.inputContainer.Add(inputPort); tempDialogueNode.RefreshExpandedState(); tempDialogueNode.RefreshPorts(); tempDialogueNode.SetPosition(new Rect(position, DefaultNodeSize)); //To-Do: implement screen center instantiation positioning var idLabel = new Label("Node Id:"); tempDialogueNode.mainContainer.Add(idLabel); var idField = new TextField(int.MaxValue, false, false, '*'); idField.RegisterValueChangedCallback(evt => { tempDialogueNode.DialogueId = evt.newValue; tempDialogueNode.title = evt.newValue; }); idField.SetValueWithoutNotify(tempDialogueNode.DialogueId); tempDialogueNode.mainContainer.Add(idField); var textLabel = new Label("Dialogue (multi-line):"); tempDialogueNode.mainContainer.Add(textLabel); var textField = new TextField(int.MaxValue, true, false, '*'); textField.RegisterValueChangedCallback(evt => { tempDialogueNode.DialogueText = evt.newValue; }); textField.SetValueWithoutNotify(tempDialogueNode.DialogueText); tempDialogueNode.mainContainer.Add(textField); var button = new Button(() => { AddChoicePort(tempDialogueNode); }) { text = "Add Choice" }; tempDialogueNode.titleButtonContainer.Add(button); return(tempDialogueNode); }
void SetServiceToUninstalledState(Button installButton, VisualElement serviceRoot, SingleService singleService) { installButton.style.display = DisplayStyle.Flex; serviceRoot.RemoveManipulator(m_ClickableByServiceName[singleService.name]); serviceRoot[0].RemoveFromClassList(k_EntryClassName); serviceRoot[0].AddToClassList(k_UninstalledEntryClassName); if (singleService.displayToggle) { m_StatusLabelByServiceName[singleService.name].style.display = DisplayStyle.None; } }
public ActorStateNode GenerateAINode(string nodeName, ActorState relevantState = null) { var retNode = new ActorStateNode { relevantState = relevantState, GUID = Guid.NewGuid().ToString(), }; var oldLabel = retNode.titleContainer.Q <Label>(); retNode.titleContainer.Remove(oldLabel); var inputPort = GeneratePort(retNode, Direction.Input, Port.Capacity.Multi); inputPort.portName = "Input"; retNode.inputContainer.Add(inputPort); retNode.styleSheets.Add(Resources.Load <StyleSheet>("Node")); var button = new Button(() => { AddConditionPort(retNode); }); button.text = "New State Transition Condition"; retNode.nodeName = nodeName; var titleText = new TextField(); titleText.value = nodeName; titleText.RegisterValueChangedCallback(evt => { retNode.nodeName = evt.newValue; }); retNode.titleContainer.Add(titleText); retNode.titleContainer.Add(button); /*retNode.titleContainer.Add(new TextField * { * text = nodeName * });*/ retNode.mainContainer.Add(new Label("State Behaviour")); var condField = new ObjectField { objectType = typeof(ActorState), value = relevantState }; condField.RegisterValueChangedCallback(evt => retNode.relevantState = evt.newValue as ActorState); retNode.mainContainer.Add(condField); retNode.SetPosition(new Rect(Vector2.zero, defaultNodeSize)); retNode.RefreshExpandedState(); retNode.RefreshPorts(); return(retNode); }
private void BindCreateNewDialog() { Button createFirstButton = root.Q <Button>(UXMLNames.CreateFirstButton); TextField createFirstPath = root.Q <TextField>(UXMLNames.EmptyDirectoryCreateNewPathField); createFirstButton.clickable.clicked += () => { CreateEmpty(createFirstPath.value); }; Button createNewButton = root.Q <Button>(UXMLNames.CreateNewButton); TextField createNewPath = root.Q <TextField>(UXMLNames.CreateNewPathField); createNewButton.clickable.clicked += () => { CreateEmpty(createNewPath.value); }; }
void BuildMetricFields() { m_MetricEditorContainer.Clear(); m_SO = new SerializedObject(m_Asset); SerializedProperty metrics = m_SO.FindProperty(Asset.k_MetricsPropertyPath); int metricsCount = metrics.arraySize; VisualElement buttonContainer = null; for (int metricIndex = 0; metricIndex < metricsCount; ++metricIndex) { VisualElement metricElement = new VisualElement(); SerializedProperty metricProperty = metrics.GetArrayElementAtIndex(metricIndex); metricElement.Add(new MetricField(m_Asset, metricProperty, metricIndex)); buttonContainer = new VisualElement(); buttonContainer.AddToClassList(k_ButtonContainerKey); metricElement.Add(buttonContainer); Button removeButton = new Button(); int index = metricIndex; removeButton.clickable.clicked += () => { RemoveMetric(index); }; removeButton.text = k_RemoveButtonText; removeButton.tooltip = k_RemoveTooltip; removeButton.AddToClassList(k_RemoveMetricButtonKey); removeButton.AddToClassList(k_ArrayButtonKey); buttonContainer.Add(removeButton); metricElement.AddToClassList(k_DrawerElementKey); m_MetricEditorContainer.Add(metricElement); } if (buttonContainer == null) { //If we have no metrics we should still show the Add button buttonContainer = new VisualElement(); m_MetricEditorContainer.Add(buttonContainer); } Button addButton = new Button(); addButton.name = "addMetricButton"; addButton.clickable.clicked += AddMetric; addButton.text = "+"; addButton.tooltip = k_AddTooltip; addButton.AddToClassList("metricButton"); addButton.AddToClassList(k_ArrayButtonKey); buttonContainer.Insert(0, addButton); m_MetricEditorContainer.Bind(m_SO); }
private void UpdateActionButton(Button btn, string trackerId) { if (trackerId == m_CurrentProfileTag) { btn.style.width = 100f; btn.text = "Stop profiling..."; } else { btn.text = "..."; btn.style.width = 30f; } }
public void Start() { var elementsInDOM = new List <UnityEngine.UIElements.VisualElement>(); this.getAllContainedElements(uIDocument.rootVisualElement, ref elementsInDOM); for (int i = 0; i < elementsInDOM.Count; i++) { if (BUTTON_TOWER_1 == elementsInDOM[i].name) { buttonSelectTower1 = (UnityEngine.UIElements.Button)elementsInDOM[i]; } else if (BUTTON_TOWER_2 == elementsInDOM[i].name) { buttonSelectTower2 = (UnityEngine.UIElements.Button)elementsInDOM[i]; } else if (BUTTON_TOWER_3 == elementsInDOM[i].name) { buttonSelectTower3 = (UnityEngine.UIElements.Button)elementsInDOM[i]; } else if (BUTTON_TOWER_4 == elementsInDOM[i].name) { buttonSelectTower4 = (UnityEngine.UIElements.Button)elementsInDOM[i]; } else if (BUTTON_TOWER_5 == elementsInDOM[i].name) { buttonSelectTower5 = (UnityEngine.UIElements.Button)elementsInDOM[i]; } else if (BUTTON_TOWER_6 == elementsInDOM[i].name) { buttonSelectTower6 = (UnityEngine.UIElements.Button)elementsInDOM[i]; } else if (BUTTON_TOWER_7 == elementsInDOM[i].name) { buttonSelectTower7 = (UnityEngine.UIElements.Button)elementsInDOM[i]; } else if (LABEL_MONEY == elementsInDOM[i].name) { moneyLabel = (UnityEngine.UIElements.Label)elementsInDOM[i]; } } buttonSelectTower1.clicked += ButtonSelectTower1Clicked; buttonSelectTower2.clicked += ButtonSelectTower2Clicked; buttonSelectTower3.clicked += ButtonSelectTower3Clicked; buttonSelectTower4.clicked += ButtonSelectTower4Clicked; buttonSelectTower5.clicked += ButtonSelectTower5Clicked; buttonSelectTower6.clicked += ButtonSelectTower6Clicked; buttonSelectTower7.clicked += ButtonSelectTower7Clicked; }
public GetFlagNode CreateGetFlagNode(string flagName, Vector2 mousePosition) { var getFlagNode = new GetFlagNode { title = "GetFlagNode", FlagName = flagName, GUID = Guid.NewGuid().ToString() }; var inputPort = GeneratePort(getFlagNode, Direction.Input, Port.Capacity.Multi); inputPort.portName = "Input"; getFlagNode.inputContainer.Add(inputPort); var generatedPort = GeneratePort(getFlagNode, Direction.Output); generatedPort.portName = "Other"; generatedPort.name = "Other"; getFlagNode.outputContainer.Add(generatedPort); var button = new Button(clickEvent: () => { AddChoicePort(getFlagNode); }); button.text = "New Choice"; getFlagNode.titleContainer.Add(button); getFlagNode.styleSheets.Add(Resources.Load <StyleSheet>("FlagNode")); var textFieldTarget = new TextField { name = "FlagName", value = flagName, label = "FlagName\n" }; textFieldTarget.RegisterValueChangedCallback(evt => { getFlagNode.FlagName = evt.newValue; }); getFlagNode.mainContainer.Add(textFieldTarget); getFlagNode.RefreshExpandedState(); getFlagNode.RefreshPorts(); getFlagNode.SetPosition(new Rect(mousePosition, defaultNodeSize)); return(getFlagNode); }
private void OnEnable() { ab = new ObjectField(); ab.objectType = typeof(TMP_FontAsset); bb = new ObjectField(); bb.objectType = typeof(Material); var but = new Button() { text = "Replace fonts" }; rootVisualElement.Add(ab); rootVisualElement.Add(bb); rootVisualElement.Add(but); but.RegisterCallback <MouseUpEvent>(aa); }
private void UpdateRecordingDeviceButtons() { recordingDeviceButtonContainer.Clear(); if (Microphone.devices.Length <= 1) { // No real choice return; } Microphone.devices.ForEach(device => { Button deviceButton = new Button(); deviceButton.RegisterCallbackButtonTriggered( () => clientSideMicSampleRecorder.SetRecordingDevice(device)); deviceButton.text = $"{device}"; recordingDeviceButtonContainer.Add(deviceButton); }); }
public void AddChoicePort(DialogueNode dialogueNode, string overriddenPortName = "") { var generatedPort = GeneratePort(dialogueNode, Direction.Output); //geting the target to remove the item //var oldLabel = generatedPort.contentContainer.Q<Label>("type"); // generatedPort.contentContainer.Remove(oldLabel); var outputPortCount = dialogueNode.outputContainer.Query("connector").ToList().Count; generatedPort.portName = $"Choice {outputPortCount}"; //Checking if port name is empty if is give default name Choice var choicePortName = string.IsNullOrEmpty(overriddenPortName) ? $"Choice {outputPortCount + 1}" : overriddenPortName; //Creating the text file for each port var textField = new TextField { name = string.Empty, value = choicePortName }; textField.RegisterValueChangedCallback(EnvironmentVariableTarget => generatedPort.portName = EnvironmentVariableTarget.newValue); //adding the text and label generatedPort.contentContainer.Add(new Label("")); generatedPort.contentContainer.Add(textField); //adding a delete button var deleteButton = new Button(() => RemovePort(dialogueNode, generatedPort)) { text = "X" }; generatedPort.contentContainer.Add(deleteButton); generatedPort.portName = choicePortName; dialogueNode.outputContainer.Add(generatedPort); dialogueNode.RefreshPorts(); dialogueNode.RefreshExpandedState(); }
private VisualElement CreateItemSelectionButton(BaseItem baseItem) { VisualElement visualElement = new VisualElement(); Button button = new Button(); button.style.height = 50; button.style.width = 50; button.text = string.Empty; Sprite icon = baseItem.icon; button.style.backgroundImage = new StyleBackground(icon?icon.texture:null); button.style.alignSelf = new StyleEnum <Align>(Align.Center); Label label = new Label { text = baseItem.name }; label.style.alignSelf = new StyleEnum <Align>(Align.Center); visualElement.Add(button); visualElement.Add(label); button.clicked += () => SelectItem(baseItem); Manipulator manipulator = new ContextualMenuManipulator( contextualMenuPopulateEvent => AddContextMenuOptions( contextualMenuPopulateEvent, new [] { new Tuple <string, Action>("ChangeID", () => ChangeItemName(baseItem)), new Tuple <string, Action>("Delete", () => DestroyItem(baseItem)) } )) { target = button }; button.AddManipulator(manipulator); return(visualElement); }
private void SetupPolygonChangeShapeWindowElements(VisualElement moduleView) { var sidesField = moduleView.Q <IntegerField>("labelIntegerField"); sidesField.SetValueWithoutNotify(polygonSides); sidesField.RegisterValueChangedCallback((evt) => { polygonSides = (int)evt.newValue; ShowHideWarningMessage(); }); m_ChangeButton = moduleView.Q <UIElementButton>("changeButton"); m_ChangeButton.RegisterCallback <MouseUpEvent>((e) => { if (isSidesValid) { GeneratePolygonOutline(); showChangeShapeWindow = false; } }); m_WarningMessage = moduleView.Q("warning"); ShowHideWarningMessage(); }
public DialogueNode CreateDialogueNode(string nodeName, Vector2 position) { var dialogueNode = new DialogueNode { title = nodeName, DialogueText = nodeName, GUID = Guid.NewGuid().ToString() }; var inputPort = GeneratePort(dialogueNode, Direction.Input, Port.Capacity.Multi); inputPort.portName = "Input"; dialogueNode.inputContainer.Add(inputPort); //adding style dialogueNode.styleSheets.Add(Resources.Load <StyleSheet>("Node")); var button = new Button(() => { AddChoicePort(dialogueNode); }); button.text = "New Choice"; dialogueNode.titleContainer.Add(button); //Adding the text field var textField = new TextField(string.Empty); textField.RegisterValueChangedCallback(evt => { dialogueNode.DialogueText = evt.newValue; dialogueNode.title = evt.newValue; }); textField.SetValueWithoutNotify(dialogueNode.title); dialogueNode.mainContainer.Add(textField); dialogueNode.RefreshExpandedState(); dialogueNode.RefreshPorts(); dialogueNode.SetPosition(new Rect(position, defaultNodeSize)); return(dialogueNode); }
private VisualElement CreateProductSelectionButton(BaseProduct baseProduct, Action <BaseProduct> OnProductSelected, Tuple <string, Action>[] contextualMenuOptions) { VisualElement visualElement = new VisualElement(); Button button = new Button(); button.style.height = 50; button.style.width = 50; button.text = string.Empty; button.style.alignSelf = new StyleEnum <Align>(Align.Center); Sprite icon = baseProduct.Icon; button.style.backgroundImage = new StyleBackground(icon?icon.texture:null); Label label = new Label { text = RemoveUntilFirstPoint(baseProduct.name) }; label.style.alignSelf = new StyleEnum <Align>(Align.Center); button.style.alignSelf = new StyleEnum <Align>(Align.Center); visualElement.Add(button); visualElement.Add(label); button.clicked += () => OnProductSelected.Invoke(baseProduct); if (contextualMenuOptions == null) { return(visualElement); } Manipulator manipulator = new ContextualMenuManipulator(contextualMenuPopulateEvent => AddContextMenuOptions(contextualMenuPopulateEvent.menu, contextualMenuOptions)) { target = button }; button.AddManipulator(manipulator); return(visualElement); }
private void AddNewTableEntry(Button pressedButton, SpeakEasyNode node, IntegerField indexField, TextField textField) { //Check if we by any chance already have a reference. for (int i = 0; i < localText.localizedText.Count; i++) { if (node.stringReference == "" || node.stringReference == System.String.Empty) { EditorUtility.DisplayDialog("Oops!", "Sorry, cannot add a new entry without a proper Identifier.", "OK"); return; } if (node.stringReference == localText.localizedText[i].id) { //We already have a point of reference pressedButton.SetEnabled(false); node.stringIndex = i; indexField.SetValueWithoutNotify(node.stringIndex); textField.SetValueWithoutNotify(GetStringIndex(node.stringIndex)); textField.SetEnabled(true); return; } } pressedButton.SetEnabled(false); //We no longer need a new reference point. //Give this node a new string ID node.stringIndex = localText.localizedText.Count; //the Count is always +1 which means it will place the new reference at the right index.. right? localText.localizedText.Add(new LocalizedText() { id = node.stringReference }); //we add the new address for the list. //Now we need to connect the three fields indexField.SetValueWithoutNotify(node.stringIndex); textField.SetValueWithoutNotify(GetStringIndex(node.stringIndex)); textField.SetEnabled(true); }
void AddBuildTarget(VisualElement targetsContainer, Dictionary <string, JSONValue> buildEntry) { if (buildEntry[k_JsonNodeNameEnabled].AsBool()) { ServicesConfiguration.instance.RequestCloudBuildApiUrl(cloudBuildApiUrl => { var buildTargetName = buildEntry[k_JsonNodeNameName].AsString(); var buildTargetId = buildEntry[k_JsonNodeNameBuildTargetId].AsString(); var buildTargetUrls = buildEntry[k_JsonNodeNameLinks].AsDict(); var startBuildUrl = cloudBuildApiUrl + buildTargetUrls[k_JsonNodeNameStartBuilds].AsDict()[k_JsonNodeNameHref].AsString(); var targetContainer = new VisualElement(); targetContainer.AddToClassList(k_ClassNameTargetEntry); var buildNameTextElement = new TextElement(); buildNameTextElement.AddToClassList(k_ClassNameTitle); buildNameTextElement.text = buildTargetName; targetContainer.Add(buildNameTextElement); var buildButton = new Button(); buildButton.name = k_BuildButtonNamePrefix + buildTargetId; buildButton.AddToClassList(k_ClassNameBuildButton); if (m_BillingPlanLabel.ToLower() == k_SubscriptionPersonal || k_SubscriptionTeamsBasic.ToLower() == k_SubscriptionPersonal) { buildButton.SetEnabled(false); } buildButton.text = L10n.Tr(k_LabelBuildButton); buildButton.clicked += () => { var uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(k_LaunchBuildPayload)); var launchBuildPostRequest = new UnityWebRequest(startBuildUrl, UnityWebRequest.kHttpVerbPOST) { downloadHandler = new DownloadHandlerBuffer(), uploadHandler = uploadHandler }; launchBuildPostRequest.suppressErrorsToConsole = true; launchBuildPostRequest.SetRequestHeader("AUTHORIZATION", $"Bearer {UnityConnect.instance.GetUserInfo().accessToken}"); launchBuildPostRequest.SetRequestHeader("Content-Type", "application/json;charset=utf-8"); m_Provider.m_BuildRequests.Add(launchBuildPostRequest); var launchingMessage = string.Format(L10n.Tr(k_MessageLaunchingBuild), buildTargetName); Debug.Log(launchingMessage); NotificationManager.instance.Publish( Notification.Topic.BuildService, Notification.Severity.Info, launchingMessage); EditorAnalytics.SendLaunchCloudBuildEvent(new BuildPostInfo() { targetName = buildTargetName }); var operation = launchBuildPostRequest.SendWebRequest(); operation.completed += asyncOperation => { try { if (ServicesUtils.IsUnityWebRequestReadyForJsonExtract(launchBuildPostRequest)) { try { if (launchBuildPostRequest.responseCode == k_HttpResponseCodeAccepted) { var jsonLaunchedBuildParser = new JSONParser(launchBuildPostRequest.downloadHandler.text); var launchedBuildJson = jsonLaunchedBuildParser.Parse(); var launchedBuilds = launchedBuildJson.AsList(); foreach (var rawLaunchedBuild in launchedBuilds) { var launchedBuild = rawLaunchedBuild.AsDict(); if (launchedBuild.ContainsKey(k_JsonNodeNameBuild)) { var buildNumber = launchedBuild[k_JsonNodeNameBuild].AsFloat().ToString(); var message = string.Format(L10n.Tr(k_MessageLaunchedBuildSuccess), buildNumber, buildTargetName); Debug.Log(message); NotificationManager.instance.Publish( Notification.Topic.BuildService, Notification.Severity.Info, message); } else if (launchedBuild.ContainsKey(k_JsonNodeNameError)) { var message = string.Format(L10n.Tr(k_MessageLaunchedBuildFailedWithMsg), buildTargetName, launchedBuild[k_JsonNodeNameError].ToString()); Debug.LogError(message); NotificationManager.instance.Publish( Notification.Topic.BuildService, Notification.Severity.Error, message); } } } else { var message = L10n.Tr(k_MessageLaunchedBuildFailure); Debug.LogError(message); NotificationManager.instance.Publish( Notification.Topic.BuildService, Notification.Severity.Error, message); } } catch (Exception ex) { NotificationManager.instance.Publish( Notification.Topic.BuildService, Notification.Severity.Error, L10n.Tr(k_MessageErrorForBuildLaunch)); Debug.LogException(ex); } } } finally { m_Provider.m_BuildRequests.Remove(launchBuildPostRequest); launchBuildPostRequest.Dispose(); launchBuildPostRequest = null; } }; }; targetContainer.Add(buildButton); targetsContainer.Add(targetContainer); var separator = new VisualElement(); separator.AddToClassList(k_ClassNameSeparator); targetsContainer.Add(separator); }); } }
public void OnEnable() { var root = this.rootVisualElement; #region Label m_Label = new Label() { text = "Clients" }; m_Label.style.fontSize = 20f; m_Label.style.color = new Color(1f, 0f, 0.25f); #endregion #region KillFeedLabel m_KillFeedLabel = new Label() { text = "Kill Feed" }; m_KillFeedLabel.style.fontSize = 20f; m_KillFeedLabel.style.color = new Color(0.33f, 0.5f, 0.45f); #endregion #region Client Field m_IntField = new IntegerField() { bindingPath = "ClientCount" }; m_IntField.style.unityTextAlign = new StyleEnum <TextAnchor>(TextAnchor.MiddleCenter); m_IntField.style.fontSize = 20; #endregion #region Wi-Fighters Logo m_Logo = new Image() { image = Resources.Load("Images/Wi-Fighters") as Texture }; m_Logo.style.alignSelf = new StyleEnum <Align>(Align.Center); m_Logo.style.width = 300f; m_Logo.style.height = 50f; m_Logo.style.top = 7; #endregion #region KillFeed Section m_RefreshKillFeed = new Button(); m_Killer = new TextField(); m_Killed = new TextField(); m_Killer.style.maxWidth = 70; m_Killed.style.maxWidth = 70; m_RefreshKillFeed.text = "Refresh Kill"; m_RefreshKillFeed.clicked += RefreshKillFeed; #endregion root.Add(m_Logo); root.Add(m_Label); root.Add(m_IntField); root.Add(m_KillFeedLabel); root.Add(m_Killer); root.Add(m_Killed); root.Add(m_RefreshKillFeed); Bind(); }