public SimulatorDeviceSpecificationsUI(Foldout rootElement, DeviceInfo deviceInfo, SystemInfoSimulation systemInfoSimulation)
        {
            m_RootElement = rootElement;

            m_OS         = m_RootElement.Q <Label>("device_os");
            m_CPU        = m_RootElement.Q <Label>("device_cpu");
            m_GPU        = m_RootElement.Q <Label>("device_gpu");
            m_Resolution = m_RootElement.Q <Label>("device_resolution");

            Update(deviceInfo, systemInfoSimulation);
        }
        protected void InjectComponentIcon(string iconName)
        {
            var iconContent       = EditorGUIUtility.IconContent(iconName);
            var iconVisualElement = new VisualElement();

            iconVisualElement.style.backgroundImage = new StyleBackground((Texture2D)iconContent.image);
            iconVisualElement.AddToClassList("component-icon");

            // We want to inject the icon after the toggle icon and before the text.
            var foldoutToggle = ComponentFoldout.Q <VisualElement>(className: "unity-toggle__input");

            foldoutToggle.Insert(1, iconVisualElement);
        }
Ejemplo n.º 3
0
        private VisualElement CreateFoldout(SerializedProperty property)
        {
            property = property.Copy();
            var  foldout        = new Foldout();
            bool hasCustomLabel = !string.IsNullOrEmpty(label);

            foldout.text        = hasCustomLabel ? label : property.localizedDisplayName;
            foldout.value       = property.isExpanded;
            foldout.bindingPath = property.propertyPath;
            foldout.name        = "unity-foldout-" + property.propertyPath;

            // Get Foldout label.
            var foldoutToggle = foldout.Q <Toggle>(className: Foldout.toggleUssClassName);
            var foldoutLabel  = foldoutToggle.Q <Label>(className: Toggle.textUssClassName);

            if (hasCustomLabel)
            {
                foldoutLabel.text = foldout.text;
            }
            else
            {
                foldoutLabel.bindingPath = property.propertyPath;
                foldoutLabel.SetProperty(foldoutTitleBoundLabelProperty, true);
            }

            m_ChildrenContainer = foldout;

            RefreshChildrenProperties(property, false);

            return(foldout);
        }
Ejemplo n.º 4
0
        private VisualElement CreateFoldout(SerializedProperty property)
        {
            property = property.Copy();
            Foldout e = new Foldout();

            e.text        = "TEST FOLDOUT";
            e.value       = property.isExpanded;
            e.bindingPath = property.propertyPath;
            e.name        = "unity-foldout-" + property.propertyPath;
            Label label = e.Q <Toggle>((string)null, Foldout.toggleUssClassName).Q <Label>((string)null, Toggle.textUssClassName);

            label.bindingPath = property.propertyPath;
            SerializedProperty endProperty = property.GetEndProperty();

            property.NextVisible(true);
            while (!SerializedProperty.EqualContents(property, endProperty))
            {
                PropertyField propertyField = new PropertyField(property);
                propertyField.name = "unity-property-field-" + property.propertyPath;
                if (propertyField != null)
                {
                    e.Add((VisualElement)propertyField);
                }
                if (!property.NextVisible(false))
                {
                    break;
                }
            }
            return((VisualElement)e);
        }
Ejemplo n.º 5
0
        private void RebuildDetails()
        {
            CustomDetailRoot.Clear();
            DefaultLabel.Clear();

            var bifurcationsProp = CommandItem.CommandProperty.GetChildProperty("bifurcations");

            var count = bifurcationsProp.GetProperty().arraySize;

            for (int i = 0; i < count; i++)
            {
                var bifurcationBox = new VisualElement();

                var item      = bifurcationsProp.GetArrayElementAt(i);
                var labelProp = item.GetChildProperty("label").GetProperty();

                var a = new Foldout();
                a.text = $"「{labelProp.stringValue}」"; // new Label($"「{labelProp.stringValue}」");
                var toggle = a.Q <Toggle>();
                toggle.style.marginBottom    = 0f;
                a.style.marginTop            = 10f;
                toggle.style.backgroundColor = new Color(0, 0, 0, 0.5f);
                bifurcationBox.Add(a);
                DefaultLabel.Add(a);

                var l = new CommandListView(CommandItem.ParentList, item.GetChildProperty("commandList.commands"));
                a.Add(l);

                CustomDetailRoot.Add(bifurcationBox);
            }
        }
        private void InitUI()
        {
            var systemLanguageEnumField = m_RootElement.Q <EnumField>("application-system-language");

            systemLanguageEnumField.Init(SystemLanguage.Unknown);
            systemLanguageEnumField.SetValueWithoutNotify(m_ApplicationSimulation.ShimmedSystemLanguage);
            systemLanguageEnumField.RegisterValueChangedCallback((evt) => { m_ApplicationSimulation.ShimmedSystemLanguage = (SystemLanguage)evt.newValue; });

            var internetReachabilityEnumField = m_RootElement.Q <EnumField>("application-internet-reachability");

            internetReachabilityEnumField.Init(NetworkReachability.NotReachable);
            internetReachabilityEnumField.SetValueWithoutNotify(m_ApplicationSimulation.ShimmedInternetReachability);
            internetReachabilityEnumField.RegisterValueChangedCallback((evt) => { m_ApplicationSimulation.ShimmedInternetReachability = (NetworkReachability)evt.newValue; });

            var onLowMemoryButton = m_RootElement.Q <Button>("application-low-memory");

            onLowMemoryButton.clickable = new Clickable(() => m_ApplicationSimulation.OnLowMemory());
        }
Ejemplo n.º 7
0
        internal static void RegisterRightClickMenu(Foldout field, SerializedProperty property)
        {
            var toggle = field.Q <Toggle>(className: Foldout.toggleUssClassName);

            if (toggle != null)
            {
                toggle.userData = property.Copy();
                toggle.RegisterCallback <MouseUpEvent>(RightClickFieldMenuEvent, InvokePolicy.IncludeDisabled);
            }
        }
Ejemplo n.º 8
0
        public SimulatorApplicationSettingsUI(Foldout rootElement, ApplicationSimulation applicationSimulation, SimulatorSerializationStates states)
        {
            m_RootElement           = rootElement;
            m_ApplicationSimulation = applicationSimulation;

            m_SystemLanguageEnumField = m_RootElement.Q <EnumField>("application-system-language");
            m_SystemLanguageEnumField.Init(states?.systemLanguage ?? SystemLanguage.English);
            m_ApplicationSimulation.ShimmedSystemLanguage = (SystemLanguage)m_SystemLanguageEnumField.value;
            m_SystemLanguageEnumField.RegisterValueChangedCallback((evt) => { m_ApplicationSimulation.ShimmedSystemLanguage = (SystemLanguage)evt.newValue; });

            m_InternetReachabilityEnumField = m_RootElement.Q <EnumField>("application-internet-reachability");
            m_InternetReachabilityEnumField.Init(states?.networkReachability ?? NetworkReachability.NotReachable);
            m_ApplicationSimulation.ShimmedInternetReachability = (NetworkReachability)m_InternetReachabilityEnumField.value;
            m_InternetReachabilityEnumField.RegisterValueChangedCallback((evt) => { m_ApplicationSimulation.ShimmedInternetReachability = (NetworkReachability)evt.newValue; });

            var onLowMemoryButton = m_RootElement.Q <Button>("application-low-memory");

            onLowMemoryButton.clickable = new Clickable(() => m_ApplicationSimulation.OnLowMemory());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Used for nested SyncTargetContainers, such as Components with
        /// RemoteConfigSyncBehaviour on the same GameObject, or Serializable data objects tagged with
        /// [RemoteConfigSync] (or where RemoteConfigSyncBehaviour.SyncAllFields == true).
        ///
        /// Also, the SyncToggle for a SyncGroupElement is given its own row with the label "Sync All",
        /// and custom behaviour below in <see cref="UpdateSyncChoice"/>
        /// </summary>
        /// <returns>
        /// A Foldout element which will contain child UI elements created. The Foldout is useful for
        /// minimizing groups of fields in the Editor view.
        /// </returns>
        private VisualElement CreateNestedGroupElement()
        {
            var foldout = new Foldout {
                text = syncItem.Key
            };
            var foldoutToggle = foldout.Q <Toggle>();

            foldoutToggle.AddToClassList("indent-" + indentLevel);
            foldoutToggle.tooltip = container.FullKeyString;
            Add(foldout);
            return(foldout);
        }
        void SyncScalerSettingsToEditor()
        {
            // Now go through all the scaler sliders and set the actual values. We can only do this properly
            // once the system has been initialized.
            Type ti = typeof(AdaptivePerformanceScaler);

            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (Type t in asm.GetTypes())
                {
                    if (ti.IsAssignableFrom(t) && !t.IsAbstract)
                    {
                        var scaler = FindScalerObject(t);
                        if (scaler == null)
                        {
                            return;
                        }

                        var valueField = m_ScalersFoldout.Q <IntegerField>($"{t.Name}-scaler-value");
                        valueField.value = scaler.CurrentLevel;
                        valueField.SetEnabled(scaler.Enabled);

                        var toggle = m_ScalersFoldout.Q <Toggle>($"{t.Name}-scaler-toggle");
                        toggle.value = scaler.Enabled;

                        var maxLevelField = m_ScalersFoldout.Q <IntegerField>($"{t.Name}-scaler-max-level-value");
                        maxLevelField.value = scaler.MaxLevel;
                        maxLevelField.SetEnabled(scaler.Enabled);

                        var maxValueField = m_ScalersFoldout.Q <FloatField>($"{t.Name}-scaler-max-value");
                        maxValueField.value = scaler.MaxBound;
                        maxValueField.SetEnabled(scaler.Enabled);

                        var minValueField = m_ScalersFoldout.Q <FloatField>($"{t.Name}-scaler-min-value");
                        minValueField.value = scaler.MinBound;
                        minValueField.SetEnabled(scaler.Enabled);
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public HierarchicalComponentContainerElement(HierarchicalComponentContainer <TContainer, TComponent> container, T component, bool optional)
        {
            this.AddStyleSheetAndVariant(ClassNames.BaseClassName);

            m_Container  = container;
            m_IsOptional = optional;

            AddToClassList(ClassNames.BaseClassName);

            var componentContainerName = component.GetType().Name;
            var foldout = new Foldout {
                text = ObjectNames.NicifyVariableName(componentContainerName)
            };

            foldout.AddToClassList(ClassNames.Component);
            foldout.AddToClassList(componentContainerName);
            Add(foldout);

            var toggle = foldout.Q <Toggle>();

            toggle.AddToClassList(ClassNames.Header);

            m_AddButton = new Button(AddComponent);
            m_AddButton.AddToClassList(ClassNames.AddComponent);
            toggle.Add(m_AddButton);

            m_RemoveButton = new Button(RemoveComponent);
            m_RemoveButton.AddToClassList(ClassNames.RemoveComponent);
            toggle.Add(m_RemoveButton);

            m_Element            = new PropertyElement();
            m_Element.OnChanged += ElementOnOnChanged;
            m_Element.SetTarget(component);

            foldout.contentContainer.Add(m_Element);
            foldout.contentContainer.AddToClassList(ClassNames.Fields);

            m_MissingComponentLabel = new Label($"Component of type {typeof(T).Name} is missing");
            m_MissingComponentLabel.style.display = DisplayStyle.None;
            foldout.contentContainer.Add(m_MissingComponentLabel);

            SetStyle();
        }
Ejemplo n.º 12
0
        private void AddBifurcation(int index)
        {
            //データの更新
            var bifurcationsProp = CommandItem.CommandProperty.GetChildProperty("bifurcations");

            bifurcationsProp.InsertArrayElementAt(index);
            bifurcationsProp.SerializedObject.ApplyModifiedProperties();

            //UIの更新
            //リストの追加
            var bifurcationBox = new VisualElement();

            var item      = bifurcationsProp.GetArrayElementAt(index);
            var labelProp = item.GetChildProperty("label").GetProperty();

            var a = new Foldout();

            a.text = $"「{labelProp.stringValue}」";
            var toggle = a.Q <Toggle>();

            toggle.style.marginBottom    = 0f;
            a.style.marginTop            = 10f;
            toggle.style.backgroundColor = new Color(0, 0, 0, 0.5f);
            bifurcationBox.Add(a);
            DefaultLabel.Insert(index, a);

            item.GetProperty().FindPropertyRelative("commandList.commands").arraySize = 0;
            bifurcationsProp.SerializedObject.ApplyModifiedProperties();
            var commandArrayProp = item.GetChildProperty("commandList.commands");

            var l = new CommandListView(CommandItem.ParentList, commandArrayProp);

            a.Add(l);

            CustomDetailRoot.Insert(index, bifurcationBox);

            bifurcationsProp.SerializedObject.ApplyModifiedProperties();

            //CommandEditorの更新
            RebuildCommandEditor();
        }
        private static Foldout CreateFoldoutInspector(VisualElement element, string title, string foldoutEditorPref)
        {
            var foldout = new Foldout();

            foldout.value = EditorPrefs.GetBool(foldoutEditorPref, true);
            var toggle = foldout.Q <Toggle>();

            toggle.AddToClassList(Styles.classInspectorFoldoutHeader);
            var titleElement = new Label(title);

            titleElement.AddToClassList(Styles.classInspectorFoldoutHeaderText);
            toggle.Children().First().Add(titleElement);
            foldout.Add(element);

            foldout.RegisterValueChangedCallback(e =>
            {
                EditorPrefs.SetBool(foldoutEditorPref, e.newValue);
            });

            return(foldout);
        }
Ejemplo n.º 14
0
        private VisualElement CreateFoldout(SerializedProperty property)
        {
            property = property.Copy();
            var foldout = new Foldout();

            foldout.text        = property.localizedDisplayName;
            foldout.value       = property.isExpanded;
            foldout.bindingPath = property.propertyPath;
            foldout.name        = "unity-foldout-" + property.propertyPath;

            // Get Foldout label.
            var foldoutToggle = foldout.Q <Toggle>(className: Foldout.toggleUssClassName);
            var foldoutLabel  = foldoutToggle.Q <Label>(className: Toggle.textUssClassName);

            foldoutLabel.bindingPath = property.propertyPath;
            foldoutLabel.SetProperty(foldoutTitleBoundLabelProperty, true);

            var endProperty = property.GetEndProperty();

            property.NextVisible(true); // Expand the first child.
            do
            {
                if (SerializedProperty.EqualContents(property, endProperty))
                {
                    break;
                }

                var field = new PropertyField(property);
                field.m_ParentPropertyField = this;
                field.name = "unity-property-field-" + property.propertyPath;
                if (field == null)
                {
                    continue;
                }

                foldout.Add(field);
            }while (property.NextVisible(false)); // Never expand children.

            return(foldout);
        }
Ejemplo n.º 15
0
        public KeyCodeNode()
        {
            Initialize("KeyCode", DefaultNodePosition);

            var foldout = new Foldout();

            foldout.text = "KeyCode (click to select)";
            var baseComponents = Enum.GetNames(typeof(KeyCode)).ToList();
            var components     = new List <string>();

            components.AddRange(baseComponents);
            var listView = new ListView(components, 20, () => new Label(), (visualElement, index) => {
                var element  = (Label)visualElement;
                element.text = components[index];
            });

            listView.onSelectionChanged += selection => {
                CodeGraph.Instance.InvalidateSaveButton();
                var text = (string)selection[0];
                KeyCode      = text;
                foldout.text = $"KeyCode ({text})";
                foldout.SetValueWithoutNotify(false);
            };
            listView.style.height = 100;
            var searchBar = new TextField();

            searchBar.RegisterValueChangedCallback(evt => {
                var value = evt.newValue.Trim();
                if (!string.IsNullOrEmpty(value) && !string.IsNullOrWhiteSpace(value))
                {
                    components           = baseComponents.Where(s => s.ToLower(CultureInfo.InvariantCulture).Contains(value.ToLower())).ToList();
                    listView.itemsSource = components;
                    listView.Refresh();
                }
                else
                {
                    components           = baseComponents.Where(s => true).ToList();
                    listView.itemsSource = components;
                    listView.Refresh();
                }
            });

            foldout.Q("unity-checkmark").style.width = 0;
            foldout.contentContainer.Add(searchBar);
            foldout.contentContainer.Add(listView);
            foldout.RegisterValueChangedCallback(evt => {
                if (evt.newValue)
                {
                    searchBar[0].Focus();
                    searchBar.value = "";
                }
            });
            foldout.SetValueWithoutNotify(false);
            inputContainer.Add(foldout);

            var valuePort = base.InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(float));

            valuePort.portName = "keyCode";
            AddOutputPort(valuePort, () => $"KeyCode.{KeyCode}");
            Refresh();
        }
        public VisualElement GetDefaultInspector()
        {
            VisualElement inspector = new VisualElement()
            {
                name = "Inspector"
            };
            Foldout skyFoldout = new Foldout()
            {
                text = "Sky"
            };

            skyCubemapField = new ObjectField("Sky with Sun");
            skyCubemapField.allowSceneObjects = false;
            skyCubemapField.objectType        = typeof(Cubemap);
            skyCubemapField.RegisterValueChangedCallback(evt
                                                         => RegisterChange(ref environment.sky.cubemap, evt.newValue as Cubemap, updatePreview: true));
            skyFoldout.Add(skyCubemapField);

            skyRotationOffset = new FloatSliderField("Rotation", 0f, 360f, 5);
            skyRotationOffset.RegisterValueChangedCallback(evt
                                                           => RegisterChange(ref environment.sky.rotation, evt.newValue, updatePreview: true));
            skyFoldout.Add(skyRotationOffset);

            skyExposureField = new FloatField("Exposure");
            skyExposureField.RegisterValueChangedCallback(evt
                                                          => RegisterChange(ref environment.sky.exposure, evt.newValue));
            skyFoldout.Add(skyExposureField);
            var style = skyFoldout.Q <Toggle>().style;

            style.marginLeft = 3;
            style.unityFontStyleAndWeight = FontStyle.Bold;
            inspector.Add(skyFoldout);

            //[TODO: reenable when shadow composition will be finished]
            //Foldout shadowFoldout = new Foldout()
            //{
            //    text = "Shadow"
            //};
            //shadowCubemapField = new ObjectField("Sky w/o Sun");
            //shadowCubemapField.allowSceneObjects = false;
            //shadowCubemapField.objectType = typeof(Cubemap);
            //shadowCubemapField.RegisterValueChangedCallback(evt
            //    => RegisterChange(ref environment.shadow.cubemap, evt.newValue as Cubemap, updatePreview: true));
            //shadowFoldout.Add(shadowCubemapField);

            //shadowColor = new ColorField("Color");
            //shadowColor.RegisterValueChangedCallback(evt
            //    => RegisterChange(ref environment.shadow.color, evt.newValue));
            //shadowFoldout.Add(shadowColor);

            //shadowSunLatitudeField = new FloatSliderField("Sun Latitude", -90f, 90f, 5);
            //shadowSunLatitudeField.RegisterValueChangedCallback(evt
            //    => RegisterChange(ref environment.shadow.m_Latitude, Environment.Shadow.ClampLatitude(evt.newValue), shadowSunLatitudeField));
            //shadowFoldout.Add(shadowSunLatitudeField);

            //shadowSunLongitudeField = new FloatSliderField("Sun Longitude", 0f, 359.999f, 5);
            //shadowSunLongitudeField.RegisterValueChangedCallback(evt
            //    => RegisterChange(ref environment.shadow.m_Longitude, Environment.Shadow.ClampLongitude(evt.newValue), shadowSunLongitudeField));
            //shadowFoldout.Add(shadowSunLongitudeField);

            //Button sunToBrightess = new Button(()
            //    => { /* [TODO] */ })
            //{
            //    text = "Sun position to brightest"
            //};
            //shadowFoldout.Add(sunToBrightess);

            //style = shadowFoldout.Q<Toggle>().style;
            //style.marginLeft = 3;
            //style.unityFontStyleAndWeight = FontStyle.Bold;
            //inspector.Add(shadowFoldout);

            return(inspector);
        }
Ejemplo n.º 17
0
        protected override void DoDisplay()
        {
            m_StatusFoldOut = new Foldout {
                text = L10n.Tr("Status"), name = k_StatusFoldOutName, classList = { k_FoldoutClass }
            };
            foreach (var status in k_Statuses)
            {
                var toggle = new Toggle(status)
                {
                    name = status.ToLower(), classList = { k_ToggleClass }
                };
                toggle.RegisterValueChangedCallback(evt =>
                {
                    if (evt.newValue)
                    {
                        foreach (var t in m_StatusFoldOut.Children().OfType <Toggle>())
                        {
                            if (t == toggle)
                            {
                                continue;
                            }

                            t.SetValueWithoutNotify(false);
                        }

                        if (status == k_Statuses[0] && m_LabelsFoldOut != null)
                        {
                            // Uncheck labels if checked
                            foreach (var t in m_LabelsFoldOut.Children().OfType <Toggle>())
                            {
                                t.value = false;
                            }
                        }
                    }

                    UpdateFiltersIfNeeded();
                });

                m_StatusFoldOut.Add(toggle);
            }
            m_Container.Add(m_StatusFoldOut);

            if (m_Categories.Any())
            {
                m_CategoriesFoldOut = new Foldout {
                    text = L10n.Tr("Categories"), name = k_CategoriesFoldOutName, classList = { k_FoldoutClass }
                };
                foreach (var category in m_Categories)
                {
                    var toggle = new Toggle(L10n.Tr(category))
                    {
                        name = category.ToLower(), classList = { k_ToggleClass }
                    };
                    toggle.RegisterValueChangedCallback(evt => UpdateFiltersIfNeeded());
                    m_CategoriesFoldOut.Add(toggle);
                }

                m_CategoriesFoldOut.Query <Label>().ForEach(UIUtils.TextTooltipOnSizeChange);
                m_Container.Add(m_CategoriesFoldOut);
            }

            if (m_Labels.Any())
            {
                m_LabelsFoldOut = new Foldout {
                    text = L10n.Tr("Labels"), name = k_LabelsFoldOutName, classList = { k_FoldoutClass }
                };
                var i = 0;
                foreach (var label in m_Labels)
                {
                    var toggle = new Toggle(L10n.Tr(label))
                    {
                        name = label, classList = { k_ToggleClass }
                    };
                    toggle.RegisterValueChangedCallback(evt =>
                    {
                        if (evt.newValue)
                        {
                            // Uncheck Unlabeled if checked
                            m_StatusFoldOut.Q <Toggle>(k_Statuses[0].ToLower()).value = false;
                        }
                        UpdateFiltersIfNeeded();
                    });
                    m_LabelsFoldOut.Add(toggle);

                    if (++i > k_MaxDisplayLabels)
                    {
                        UIUtils.SetElementDisplay(toggle, false);
                    }
                }

                m_LabelsFoldOut.Query <Label>().ForEach(UIUtils.TextTooltipOnSizeChange);
                m_Container.Add(m_LabelsFoldOut);
            }
        }
        internal static void UnregisterRightClickMenu(Foldout field)
        {
            var toggle = field.Q <Toggle>(className: Foldout.toggleUssClassName);

            toggle?.UnregisterCallback <MouseUpEvent>(RightClickFieldMenuEvent);
        }
        private void Init(DeviceInfo deviceInfo, ScreenSimulation screenSimulation, SimulationPlayerSettings playerSettings)
        {
            m_ScreenWidthField  = m_RootElement.Q <IntegerField>("screen-width");
            m_ScreenHeightField = m_RootElement.Q <IntegerField>("screen-height");

            m_ScreenSetResolution           = m_RootElement.Q <Button>("screen-set-resolution-button");
            m_ScreenSetResolution.clickable = new Clickable(SetResolution);

            m_FullScreenToggle = m_RootElement.Q <Toggle>("full-screen");
            m_FullScreenToggle.RegisterValueChangedCallback(SetFullScreen);

            m_AutoRotationToggle = m_RootElement.Q <Toggle>("auto-rotation");
            m_AutoRotationToggle.RegisterValueChangedCallback(SetAutoRotation);

            m_ScreenOrientationEnumField = m_RootElement.Q <EnumField>("screen-orientations");
            m_ScreenOrientationEnumField.Init(RenderedScreenOrientation.Portrait);
            m_ScreenOrientationEnumField.RegisterValueChangedCallback(SetScreenOrientation);

            m_RenderedOrientationContainer = m_RootElement.Q <VisualElement>("rendered-orientation-container");
            m_RendererOrientation          = m_RootElement.Q <Label>("rendered-orientation");

            m_AllowedOrientationsSection = m_RootElement.Q <VisualElement>("allowed-orientations");

            m_AllowedPortrait = m_RootElement.Q <Toggle>("orientation-allow-portrait");
            m_AllowedPortrait.RegisterValueChangedCallback((evt) => { Screen.autorotateToPortrait = evt.newValue; });

            m_AllowedPortraitUpsideDown = m_RootElement.Q <Toggle>("orientation-allow-portrait-upside-down");
            m_AllowedPortraitUpsideDown.RegisterValueChangedCallback((evt) => { Screen.autorotateToPortraitUpsideDown = evt.newValue; });

            m_AllowedLandscapeLeft = m_RootElement.Q <Toggle>("orientation-allow-landscape-left");
            m_AllowedLandscapeLeft.RegisterValueChangedCallback((evt) => { Screen.autorotateToLandscapeLeft = evt.newValue; });

            m_AllowedLandscapeRight = m_RootElement.Q <Toggle>("orientation-allow-landscape-right");
            m_AllowedLandscapeRight.RegisterValueChangedCallback((evt) => { Screen.autorotateToLandscapeRight = evt.newValue; });

            // Initialized the control states.
            UpdateOrientationVisualElements(screenSimulation.AutoRotation);
            UpdateAllowedOrientationVisualElements();

            Update(deviceInfo, screenSimulation, playerSettings);
        }
Ejemplo n.º 20
0
        public VisualElement GetDefaultInspector()
        {
            VisualElement inspector = new VisualElement()
            {
                name = "inspector"
            };

            VisualElement header = new VisualElement()
            {
                name = "inspector-header"
            };

            header.Add(new Image()
            {
                image = CoreEditorUtils.LoadIcon(@"Packages/com.unity.render-pipelines.core/Editor/LookDev/Icons/", "Environment", forceLowRes: true)
            });
            environmentName           = new TextField();
            environmentName.isDelayed = true;
            environmentName.RegisterValueChangedCallback(evt =>
            {
                string path      = AssetDatabase.GetAssetPath(environment);
                environment.name = evt.newValue;
                AssetDatabase.SetLabels(environment, new string[] { evt.newValue });
                EditorUtility.SetDirty(environment);
                AssetDatabase.ImportAsset(path);
                environmentName.name = environment.name;
            });
            header.Add(environmentName);
            inspector.Add(header);

            Foldout foldout = new Foldout()
            {
                text = "Environment Settings"
            };

            skyCubemapField = new ObjectField("Sky with Sun")
            {
                tooltip = "A cubemap that will be used as the sky."
            };
            skyCubemapField.allowSceneObjects = false;
            skyCubemapField.objectType        = typeof(Cubemap);
            skyCubemapField.RegisterValueChangedCallback(evt =>
            {
                var tmp = environment.sky.cubemap;
                RegisterChange(ref tmp, evt.newValue as Cubemap);
                environment.sky.cubemap = tmp;
                latlong.image           = GetLatLongThumbnailTexture(environment, k_SkyThumbnailWidth);
            });
            foldout.Add(skyCubemapField);

            shadowCubemapField = new ObjectField("Sky without Sun")
            {
                tooltip = "[Optional] A cubemap that will be used to compute self shadowing.\nIt should be the same sky without the sun.\nIf nothing is provided, the sky with sun will be used with lower intensity."
            };
            shadowCubemapField.allowSceneObjects = false;
            shadowCubemapField.objectType        = typeof(Cubemap);
            shadowCubemapField.RegisterValueChangedCallback(evt =>
            {
                var tmp = environment.shadow.cubemap;
                RegisterChange(ref tmp, evt.newValue as Cubemap);
                environment.shadow.cubemap = tmp;
                latlong.image = GetLatLongThumbnailTexture(environment, k_SkyThumbnailWidth);
            });
            foldout.Add(shadowCubemapField);

            skyRotationOffset = new FloatField("Rotation")
            {
                tooltip = "Rotation offset on the longitude of the sky."
            };
            skyRotationOffset.RegisterValueChangedCallback(evt
                                                           => RegisterChange(ref environment.sky.rotation, Environment.Shadow.ClampLongitude(evt.newValue), skyRotationOffset, updatePreview: true));
            foldout.Add(skyRotationOffset);

            skyExposureField = new FloatField("Exposure")
            {
                tooltip = "The exposure to apply with this sky."
            };
            skyExposureField.RegisterValueChangedCallback(evt
                                                          => RegisterChange(ref environment.sky.exposure, evt.newValue));
            foldout.Add(skyExposureField);
            var style = foldout.Q <Toggle>().style;

            style.marginLeft = 3;
            style.unityFontStyleAndWeight = FontStyle.Bold;
            inspector.Add(foldout);

            sunPosition = new Vector2Field("Sun Position")
            {
                tooltip = "The sun position as (Longitude, Latitude)\nThe button compute brightest position in the sky with sun."
            };
            sunPosition.Q("unity-x-input").Q <FloatField>().formatString = "n1";
            sunPosition.Q("unity-y-input").Q <FloatField>().formatString = "n1";
            sunPosition.RegisterValueChangedCallback(evt =>
            {
                var tmpContainer = new Vector2(
                    environment.shadow.sunLongitude,
                    environment.shadow.sunLatitude);
                var tmpNewValue = new Vector2(
                    Environment.Shadow.ClampLongitude(evt.newValue.x),
                    Environment.Shadow.ClampLatitude(evt.newValue.y));
                RegisterChange(ref tmpContainer, tmpNewValue, sunPosition);
                environment.shadow.sunLongitude = tmpContainer.x;
                environment.shadow.sunLatitude  = tmpContainer.y;
            });
            foldout.Add(sunPosition);

            Button sunToBrightess = new Button(() =>
            {
                ResetToBrightestSpot(environment);
                sunPosition.SetValueWithoutNotify(new Vector2(
                                                      Environment.Shadow.ClampLongitude(environment.shadow.sunLongitude),
                                                      Environment.Shadow.ClampLatitude(environment.shadow.sunLatitude)));
            })
            {
                name = "sunToBrightestButton"
            };

            sunToBrightess.Add(new Image()
            {
                image = CoreEditorUtils.LoadIcon(@"Packages/com.unity.render-pipelines.core/Editor/LookDev/Icons/", "SunPosition", forceLowRes: true)
            });
            sunToBrightess.AddToClassList("sun-to-brightest-button");
            var vector2Input = sunPosition.Q(className: "unity-vector2-field__input");

            vector2Input.Remove(sunPosition.Q(className: "unity-composite-field__field-spacer"));
            vector2Input.Add(sunToBrightess);

            shadowColor = new ColorField("Shadow Tint")
            {
                tooltip = "The wanted shadow tint to be used when computing shadow."
            };
            shadowColor.RegisterValueChangedCallback(evt
                                                     => RegisterChange(ref environment.shadow.color, evt.newValue));
            foldout.Add(shadowColor);

            style            = foldout.Q <Toggle>().style;
            style.marginLeft = 3;
            style.unityFontStyleAndWeight = FontStyle.Bold;
            inspector.Add(foldout);

            return(inspector);
        }
Ejemplo n.º 21
0
        private void Init(SimulatorJsonSerialization states)
        {
            InitPlayerSettings(states);

            bool overrideDefaultPlayerSettings = (states != null) ? states.overrideDefaultPlayerSettings : false;

            m_OverrideDefaultPlayerSettings = m_RootElement.Q <Toggle>("override-default-player-settings");
            m_OverrideDefaultPlayerSettings.RegisterValueChangedCallback(SetOverridePlayerSettings);
            m_OverrideDefaultPlayerSettings.SetValueWithoutNotify(overrideDefaultPlayerSettings);
            UpdateOverridePlayerSettingsStatus();

            m_CustomizedPlayerSettingsElement = m_RootElement.Q <VisualElement>("customized-player-settings");

            m_StartInFullscreen = m_RootElement.Q <Toggle>("android-start-in-fullscreen");
            m_StartInFullscreen.SetValueWithoutNotify(m_CustomizedPlayerSettings.androidStartInFullscreen);
            m_StartInFullscreen.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.androidStartInFullscreen = evt.newValue; });

            m_ResolutionScalingMode = m_RootElement.Q <EnumField>("resolution-scaling-mode");
            m_ResolutionScalingMode.Init(ResolutionScalingMode.Disabled);
            m_ResolutionScalingMode.RegisterValueChangedCallback(SetResolutionScalingMode);
            m_ResolutionScalingMode.SetValueWithoutNotify(m_CustomizedPlayerSettings.resolutionScalingMode);

            #region DPI
            m_DpiContainer = m_RootElement.Q <VisualElement>("dpi-container");

            m_DpiSlider = m_DpiContainer.Q <SliderInt>("dpi-slider");
            m_DpiSlider.RegisterValueChangedCallback(SyncDpiField);
            m_DpiSlider.SetValueWithoutNotify(m_CustomizedPlayerSettings.targetDpi);

            m_DpiField = m_DpiContainer.Q <IntegerField>("dpi-field");
            m_DpiField.RegisterValueChangedCallback(SyncDpiSlider);
            m_DpiField.RegisterCallback <KeyDownEvent>(OnDpiFieldKeyDown);
            m_DpiField.SetValueWithoutNotify(m_CustomizedPlayerSettings.targetDpi);
            #endregion

            #region Orientation
            m_DefaultOrientation = m_RootElement.Q <EnumField>("default-screen-orientation");
            m_DefaultOrientation.Init(UIOrientation.AutoRotation);
            m_DefaultOrientation.RegisterValueChangedCallback(SetDefaultOrientation);
            m_DefaultOrientation.SetValueWithoutNotify(m_CustomizedPlayerSettings.defaultOrientation);

            m_AllowedOrienations = m_RootElement.Q <Foldout>("allowed-orientations");

            m_AllowedPortrait = m_AllowedOrienations.Q <Toggle>("orientation-allow-portrait");
            m_AllowedPortrait.SetValueWithoutNotify(m_CustomizedPlayerSettings.allowedPortrait);
            m_AllowedPortrait.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.allowedPortrait = evt.newValue; });

            m_AllowedPortraitUpsideDown = m_AllowedOrienations.Q <Toggle>("orientation-allow-portrait-upside-down");
            m_AllowedPortraitUpsideDown.SetValueWithoutNotify(m_CustomizedPlayerSettings.allowedPortraitUpsideDown);
            m_AllowedPortraitUpsideDown.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.allowedPortraitUpsideDown = evt.newValue; });

            m_AllowedLandscapeLeft = m_AllowedOrienations.Q <Toggle>("orientation-allow-landscape-left");
            m_AllowedLandscapeLeft.SetValueWithoutNotify(m_CustomizedPlayerSettings.allowedLandscapeLeft);
            m_AllowedLandscapeLeft.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.allowedLandscapeLeft = evt.newValue; });

            m_AllowedLandscapeRight = m_AllowedOrienations.Q <Toggle>("orientation-allow-landscape-right");
            m_AllowedLandscapeRight.SetValueWithoutNotify(m_CustomizedPlayerSettings.allowedLandscapeRight);
            m_AllowedLandscapeRight.RegisterValueChangedCallback((evt) => { m_CustomizedPlayerSettings.allowedLandscapeRight = evt.newValue; });
            #endregion

            #region Graphics API
            m_AutoGraphicsAPI = m_RootElement.Q <Toggle>("auto-graphics-api");
            m_AutoGraphicsAPI.SetValueWithoutNotify(m_CustomizedPlayerSettings.autoGraphicsAPI);
            m_AutoGraphicsAPI.RegisterValueChangedCallback(SetAutoGraphicsAPI);

            m_GraphicsAPIPlaceholder = m_RootElement.Q <VisualElement>("graphics-api-placeholder");
            m_GraphicsAPIPlaceholder.SetEnabled(!m_CustomizedPlayerSettings.autoGraphicsAPI);
            #endregion

            UpdateCustomizedPlayerSettings(m_OverrideDefaultPlayerSettings.value);
            UpdateStartInFullScreen();
            UpdateResolutionScalingMode(m_CustomizedPlayerSettings.resolutionScalingMode);
            UpdateAllowedOrientations(m_CustomizedPlayerSettings.defaultOrientation);
            UpdateGraphicsAPI();
        }
Ejemplo n.º 22
0
        public GetComponentNode()
        {
            Initialize("Get Component", DefaultNodePosition);

            var foldout = new Foldout();

            foldout.text = "Type (click to select)";
            var baseComponents = (from assembly in AppDomain.CurrentDomain.GetAssemblies() from type in assembly.GetTypes() where type.IsSubclassOf(typeof(Component)) select type.Name).ToList();
            var components     = new List <string>();

            components.AddRange(baseComponents);
            var listView = new ListView(components, 20, () => new Label(), (visualElement, index) => {
                var element  = (Label)visualElement;
                element.text = components[index];
            });

            listView.onSelectionChanged += selection => {
                var text = (string)selection[0];
                ComponentType = text;
                foldout.text  = $"Type ({text})";
                foldout.SetValueWithoutNotify(false);
            };
            listView.style.height = 100;
            var searchBar = new TextField();

            searchBar.RegisterValueChangedCallback(evt => {
                var value = evt.newValue.Trim();
                if (!string.IsNullOrEmpty(value) && !string.IsNullOrWhiteSpace(value))
                {
                    components           = baseComponents.Where(s => s.ToLower(CultureInfo.InvariantCulture).Contains(value.ToLower())).ToList();
                    listView.itemsSource = components;
                    listView.Refresh();
                }
                else
                {
                    components           = baseComponents.ToList();
                    listView.itemsSource = components;
                    listView.Refresh();
                }
            });

            foldout.Q("unity-checkmark").style.width = 0;
            foldout.contentContainer.Add(searchBar);
            foldout.contentContainer.Add(listView);
            foldout.RegisterValueChangedCallback(evt => {
                if (evt.newValue)
                {
                    searchBar[0].Focus();
                    searchBar.value = "";
                }
            });
            foldout.SetValueWithoutNotify(false);
            inputContainer.Add(foldout);

            var inputPort = base.InstantiatePort(Orientation.Horizontal, Direction.Input, Port.Capacity.Single, typeof(float));

            inputPort.portName = "gameobject";
            AddInputPort(inputPort, () => {
                var connections = inputPort.connections.ToList();
                if (connections.Count == 0)
                {
                    return($"new GameObject() /* WARNING: You probably want connect this node to something. */");
                }
                var output = connections[0].output;
                var node   = output.node as AbstractNode;
                if (node == null)
                {
                    return($"new GameObject() /* ERROR: Something went wrong and the connected node ended up as null. */");
                }
                return(node.OutputPortDictionary[output].GetCode());
            });

            var valuePort = base.InstantiatePort(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(float));

            valuePort.portName = "component";
            AddOutputPort(valuePort, () => $"{InputPortDictionary[inputPort].RequestCode()}.GetComponent<{ComponentType}>()");
            Refresh();
        }