Example #1
0
            public void Initialize(VisualElement rootVisualElement)
            {
                m_Root = UIElementHelpers.LoadTemplate(kBasePath, "StartLiveLinkWindow");
                m_Root.style.flexGrow = 1;

                m_SearchField = m_Root.Q <ToolbarSearchField>(kNamePrefix + "body__search");
                m_SearchField.RegisterValueChangedCallback(evt => FilterConfigurations());

                m_EmptyMessage = m_Root.Q <VisualElement>(kNamePrefix + "body__empty-message");

                m_ConfigurationsListView               = m_Root.Q <ListView>(kNamePrefix + "body__configurations-list");
                m_ConfigurationsListView.makeItem      = CreateBuildConfigurationItemVisualElement;
                m_ConfigurationsListView.bindItem      = BindBuildConfigurationItem;
                m_ConfigurationsListView.itemsSource   = m_FilteredBuildConfigurationViewModels;
                m_ConfigurationsListView.selectionType = SelectionType.Single;


#if UNITY_2020_1_OR_NEWER
                m_ConfigurationsListView.onSelectionChange += OnConfigurationListViewSelectionChange;
                m_ConfigurationsListView.onItemsChosen     += chosenConfigurations => EditBuildConfiguration((BuildConfigurationViewModel)chosenConfigurations.First());
#else
                m_ConfigurationsListView.onSelectionChanged += OnConfigurationListViewSelectionChanged;
                m_ConfigurationsListView.onItemChosen       += chosenConfiguration => EditBuildConfiguration((BuildConfigurationViewModel)chosenConfiguration);
#endif

                m_AddNewButton          = m_Root.Q <Button>(kNamePrefix + "body__new-build-button");
                m_AddNewButton.clicked += ShowNewBuildNameInput;

                m_NewBuildName          = m_Root.Q <VisualElement>(kNamePrefix + "new-build-name");
                m_NewBuildNameTextField = m_NewBuildName.Q <TextField>();
                m_NewBuildNameSubmit    = m_NewBuildName.Q <Button>(kNamePrefix + "new-build-name__submit");
                m_NewBuildNameTextField.RegisterCallback <KeyDownEvent>(OnNewBuildKeyDown);
                m_NewBuildNameTextField.RegisterCallback <BlurEvent>(OnNewBuildFocusChanged);
                m_NewBuildName.Hide();

                m_BuildMessage = m_Root.Q <VisualElement>(kNamePrefix + "build-message");
                m_BuildMessage.Hide();
                m_ActionButtons     = m_Root.Q <VisualElement>(kNamePrefix + "footer");
                m_StartModeDropdown = new PopupField <StartMode>(sStartModes, StartMode.RunLatestBuild, FormatStartMode, FormatStartMode)
                {
                    style = { flexGrow = 1 }
                };
                m_StartModeDropdown.RegisterValueChangedCallback(OnSelectedStartModeChanged);
                m_ActionButtons.Q <VisualElement>(kNamePrefix + "footer__build-mode-container").Add(m_StartModeDropdown);

                m_StartButton          = m_ActionButtons.Q <Button>(kNamePrefix + "footer__start-button");
                m_StartButton.clicked += () =>
                {
                    m_FooterMessage.Hide();
                    Start(m_StartModeDropdown.value, m_SelectedConfiguration);
                };

                m_FooterMessage = m_Root.Q <VisualElement>(kNamePrefix + "message");
                m_FooterMessage.Hide();

                rootVisualElement.Add(m_Root);
            }
        public override void OnOpen()
        {
            const string basePath = "Packages/com.unity.entities/Editor/Resources/LiveLink";
            var          template = m_LinkConnections.Count == 0
                ? UIElementHelpers.LoadTemplate(basePath, "LiveLinkConnectionsDropdown.Empty", "LiveLinkConnectionsDropdown")
                : UIElementHelpers.LoadTemplate(basePath, "LiveLinkConnectionsDropdown");

            if (m_LinkConnections.Count > 0)
            {
                var placeholder = template.Q <VisualElement>("devices");
                var tpl         = UIElementHelpers.LoadClonableTemplate(basePath, "LiveLinkConnectionsDropdown.ItemTemplate");
                foreach (var connection in m_LinkConnections)
                {
                    var item = tpl.GetNewInstance();
                    item.Q <Image>().AddToClassList(GetStatusClass(connection.Status));
                    var label = item.Q <Label>();
                    label.text = connection.Name.Length <= SizeHelper.MaxCharCount ? connection.Name : connection.Name.Substring(0, SizeHelper.MaxCharCount) + "...";
                    if (connection.Name.Length > SizeHelper.MaxCharCount)
                    {
                        label.tooltip = connection.Name;
                    }
                    placeholder.Add(item);
                }
            }

            var footer      = UIElementHelpers.LoadTemplate(basePath, "LiveLinkConnectionsDropdown.Footer", "LiveLinkConnectionsDropdown");
            var buildButton = footer.Q <Button>("live-link-connections-dropdown__footer__build");
            var resetButton = footer.Q <Button>("live-link-connections-dropdown__footer__reset");
            var clearButton = footer.Q <Button>("live-link-connections-dropdown__footer__clear");

            if (LiveLinkBuildSettings.CurrentLiveLinkBuildSettings != null)
            {
                buildButton.clickable.clicked += LiveLinkCommands.BuildAndRunLiveLinkPlayer;
            }
            else
            {
                buildButton.SetEnabled(false);
                buildButton.tooltip = "Please first select a build setting.";
            }

            if (m_LinkConnections.Count > 0)
            {
                resetButton.clickable.clicked += LiveLinkCommands.ResetPlayer;
                clearButton.clickable.clicked += LiveLinkCommands.ClearLiveLinkCache;
            }
            else
            {
                resetButton.SetEnabled(false);
                clearButton.SetEnabled(false);
            }

            template.Add(footer);
            editorWindow.rootVisualElement.Add(template);
        }
        void GenerateUiFromState()
        {
            const string basePath = "Packages/com.unity.entities/Editor/LiveLink";
            var          template = m_LinkConnections.Count == 0
                ? UIElementHelpers.LoadTemplate(basePath, "LiveLinkConnectionsDropdown.Empty", "LiveLinkConnectionsDropdown")
                : UIElementHelpers.LoadTemplate(basePath, "LiveLinkConnectionsDropdown");

            if (m_LinkConnections.Count > 0)
            {
                var placeholder = template.Q <VisualElement>("devices");
                var tpl         = UIElementHelpers.LoadClonableTemplate(basePath, "LiveLinkConnectionsDropdown.ItemTemplate");
                foreach (var connection in m_LinkConnections)
                {
                    var item = tpl.GetNewInstance();
                    var icon = item.Q <Image>();
                    icon.AddToClassList(GetStatusClass(connection.Status));
                    icon.RegisterCallback <PointerDownEvent>(i => ToggleConnectionStatus(i, connection));
                    var label = item.Q <Label>();
                    label.text    = connection.Name.Length <= SizeHelper.MaxCharCount ? connection.Name : connection.Name.Substring(0, SizeHelper.MaxCharCount) + "...";
                    label.tooltip = $"{connection.Name} - build setting: {connection.BuildSettingsName}";
                    placeholder.Add(item);
                }
            }

            var footer = UIElementHelpers.LoadTemplate(basePath, "LiveLinkConnectionsDropdown.Footer", "LiveLinkConnectionsDropdown");

            footer.Q <Button>("live-link-connections-dropdown__footer__build").SetEnabled(false);
            var resetButton = footer.Q <Button>("live-link-connections-dropdown__footer__reset");
            var clearButton = footer.Q <Button>("live-link-connections-dropdown__footer__clear");

            if (m_LinkConnections.Count > 0)
            {
                resetButton.clickable.clicked += LiveLinkCommands.ResetPlayer;
                clearButton.clickable.clicked += LiveLinkCommands.ClearLiveLinkCache;
            }
            else
            {
                resetButton.SetEnabled(false);
                clearButton.SetEnabled(false);
            }

            template.Add(footer);
            editorWindow.rootVisualElement.Clear();
            editorWindow.rootVisualElement.Add(template);
        }
Example #4
0
        public override void OnOpen()
        {
            const string basePath = "Packages/com.unity.entities/Editor/Resources/LiveLink";

            if (LiveLinkBuildSettingsCache.Count == 0)
            {
                editorWindow.rootVisualElement.Add(UIElementHelpers.LoadTemplate(basePath, "LiveLinkBuildSettingsDropdown.Empty", "LiveLinkBuildSettingsDropdown"));
                return;
            }

            var visualElement = UIElementHelpers.LoadTemplate(basePath, "LiveLinkBuildSettingsDropdown");
            var tpl           = UIElementHelpers.LoadClonableTemplate(basePath, "LiveLinkBuildSettingsDropdown.ItemTemplate");

            var radioButtonGroup = visualElement.Q <RadioButtonGroup>();

            radioButtonGroup.RegisterValueChangedCallback(evt => LiveLinkBuildSettings.CurrentLiveLinkBuildSettings = (BuildSettings)evt.newValue.userData);

            foreach (var buildSettingsCache in LiveLinkBuildSettingsCache.BuildSettings)
            {
                var item   = tpl.GetNewInstance();
                var toggle = item.Q <Toggle>();
                var label  = item.Q <Label>();
                var image  = item.Q <Image>();

                label.RegisterCallback <PointerDownEvent>(e => OnClick(e, toggle));
                image.RegisterCallback <PointerDownEvent>(e => OnClick(e, toggle));

                toggle.userData = buildSettingsCache.Asset;
                toggle.SetValueWithoutNotify(LiveLinkBuildSettings.CurrentLiveLinkBuildSettings == buildSettingsCache.Asset);
                var fileName = Path.GetFileNameWithoutExtension(buildSettingsCache.Path);

                label.text    = fileName.Length > SizeHelper.MaxCharCount ? fileName.Substring(0, SizeHelper.MaxCharCount) + "..." : fileName;
                label.tooltip = buildSettingsCache.Path;

                var target = buildSettingsCache.Asset.GetComponent <ClassicBuildProfile>().Target;
                image.AddToClassList(UIElementHelpers.Style.GetUssClass(target));

                radioButtonGroup.Add(item);
            }

            editorWindow.rootVisualElement.Add(visualElement);
        }