protected void PopulateSpriteFrameInspectorField()
        {
            m_SelectedFrameInspector.style.display = hasSelected ?  DisplayStyle.Flex : DisplayStyle.None;
            if (!hasSelected)
            {
                return;
            }
            m_NameElement.SetEnabled(containsMultipleSprites);
            m_NameField.SetValueWithoutNotify(selectedSpriteName);
            m_PositionElement.SetEnabled(containsMultipleSprites);
            var spriteRect = selectedSpriteRect;

            m_PositionFieldX.SetValueWithoutNotify(Mathf.RoundToInt(spriteRect.x));
            m_PositionFieldY.SetValueWithoutNotify(Mathf.RoundToInt(spriteRect.y));
            m_PositionFieldW.SetValueWithoutNotify(Mathf.RoundToInt(spriteRect.width));
            m_PositionFieldH.SetValueWithoutNotify(Mathf.RoundToInt(spriteRect.height));
            var spriteBorder = selectedSpriteBorder;

            m_BorderFieldL.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.x));
            m_BorderFieldT.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.w));
            m_BorderFieldR.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.z));
            m_BorderFieldB.SetValueWithoutNotify(Mathf.RoundToInt(spriteBorder.y));
            m_PivotField.SetValueWithoutNotify(selectedSpriteAlignment);
            m_PivotUnitModeField.SetValueWithoutNotify(m_PivotUnitMode);
            Vector2 pivot = selectedSpritePivotInCurUnitMode;

            m_CustomPivotFieldX.SetValueWithoutNotify(pivot.x);
            m_CustomPivotFieldY.SetValueWithoutNotify(pivot.y);

            m_CustomPivotElement.SetEnabled(hasSelected && selectedSpriteAlignment == SpriteAlignment.Custom);
        }
Beispiel #2
0
        public void Bind(AnyStateFilterItem filter)
        {
            _filter = filter;

            _stateFinder.SelectItemWithoutNotify(filter.State, true);
            _filterModeField.SetValueWithoutNotify(filter.Mode);
        }
Beispiel #3
0
        public void Bind(TransitionInfoCondition condition)
        {
            _condition = condition;

            if (_parameterFinder.Item != null)
            {
                _parameterFinder.Item.OnTypeChanged -= ParameterTypeChanged;
            }

            _parameterFinder.SelectItemWithoutNotify(_condition.Parameter, true);

            if (_parameterFinder.Item != null)
            {
                _parameterFinder.Item.OnTypeChanged += ParameterTypeChanged;
            }

            _stateFinder.SelectItemWithoutNotify(_condition.State, true);
            _stateValueProvider.SetValueWithoutNotify(_condition.StateValueProvider);

            SetProviderSourceType(_condition.ProviderSourceType);

            _boolComparisonValueField.SetValueWithoutNotify(_condition.BoolComparisonValue ? Bool.True : Bool.False);

            _intComparisonField.SetValueWithoutNotify(_condition.IntComparison);
            _intComparisonValueField.SetValueWithoutNotify(_condition.IntComparisonValue);

            _floatComparisonField.SetValueWithoutNotify(_condition.FloatComparison);
            _floatComparisonValueField.SetValueWithoutNotify(_condition.FloatComparisonValue);
        }
Beispiel #4
0
    public override void Enable()
    {
        parameterNode = nodeTarget as ParameterNode;

        EnumField accessorSelector = new EnumField(parameterNode.accessor);

        accessorSelector.SetValueWithoutNotify(parameterNode.accessor);
        accessorSelector.RegisterValueChangedCallback(evt =>
        {
            parameterNode.accessor = (ParameterAccessor)evt.newValue;
            UpdatePort();
            controlsContainer.MarkDirtyRepaint();
            ForceUpdatePorts();
        });

        UpdatePort();
        controlsContainer.Add(accessorSelector);

        //    Find and remove expand/collapse button
        titleContainer.Remove(titleContainer.Q("title-button-container"));
        //    Remove Port from the #content
        topContainer.parent.Remove(topContainer);
        //    Add Port to the #title
        titleContainer.Add(topContainer);

        parameterNode.onParameterChanged += UpdateView;
        UpdateView();
    }
Beispiel #5
0
        public static VisualElement GetElementOfEnumField(Enum startValue, string fieldName, Action <object> setValue, Action <object> getValue)
        {
            EnumField field = new EnumField(fieldName, startValue);

            field.RegisterValueChangedCallback(s => setValue.Invoke(s.newValue));
            getValue += o => field.SetValueWithoutNotify((Enum)o);
            return(field);
        }
        public static void RenderEnumProperty(VisualElement container, string name, object value, Action <object> setter)
        {
            var field = new EnumField(name);

            field.SetValueWithoutNotify((Enum)value);
            field.MarkDirtyRepaint();
            field.RegisterValueChangedCallback(evt => setter(evt.newValue));
            container.Add(field);
        }
 private void BindTransitionFields(TransitionInfo transition)
 {
     DurationTypeField.SetValueWithoutNotify(transition.DurationType);
     DurationField.SetValueWithoutNotify(transition.Duration);
     OffsetTypeField.SetValueWithoutNotify(transition.OffsetType);
     OffsetField.SetValueWithoutNotify(transition.Offset);
     InterruptionSourceField.SetValueWithoutNotify(transition.InterruptionSource);
     OrderedInterruptionToggle.SetValueWithoutNotify(transition.OrderedInterruption);
     InterruptableByAnyStateToggle.SetValueWithoutNotify(transition.InterruptableByAnyState);
     PlayAfterTransitionToggle.SetValueWithoutNotify(transition.PlayAfterTransition);
     _conditions.itemsSource   = transition.Conditions;
     _conditions.selectedIndex = -1;
     _conditions.Refresh();
 }
Beispiel #8
0
    //讀取時候放入資料
    public override void LoadValueIntoField()
    {
        //sceneField.SetValueWithoutNotify((UnityEngine.Object)(object)AssetDatabase.LoadAssetAtPath<SceneAsset>(scenePath));
        sceneField.SetValueWithoutNotify((UnityEngine.Object)(object) AssetDatabase.LoadAssetAtPath <SceneAsset>(AssetDatabase.GUIDToAssetPath(scenAssetGuid)));
        asyncTypeField.SetValueWithoutNotify(asyncType);
        loadTypeField.SetValueWithoutNotify(loadType);
        //scene = SceneManager.GetSceneByPath(scenAssetGuid);
        scene = AssetDatabase.LoadAssetAtPath <SceneAsset>(AssetDatabase.GUIDToAssetPath(scenAssetGuid));
        //title = Path.GetFileNameWithoutExtension(scenAssetGuid);
        title = Path.GetFileNameWithoutExtension(AssetDatabase.GUIDToAssetPath(scenAssetGuid));
        SetupSubPortSets();

        //RefreshExpandedState();
        //RefreshPorts();
    }
Beispiel #9
0
    public override void Update()
    {
        _isCreatedField.SetValueWithoutNotify(Target.Collider.IsCreated);

        unsafe
        {
            long address = (long)Target.Collider.GetUnsafePtr();
            _addressField.SetValueWithoutNotify(address);
        }

        if (Target.Collider.IsCreated)
        {
            _radiusField.SetValueWithoutNotify(Target.Collider.Value.Radius);
            _typeField.SetValueWithoutNotify(Target.Collider.Value.ColliderType);
        }
    }
Beispiel #10
0
    public override void Enable()
    {
        parameterNode = nodeTarget as ParameterNode;

        EnumField accessorSelector = new EnumField(parameterNode.accessor);

        accessorSelector.SetValueWithoutNotify(parameterNode.accessor);
        accessorSelector.RegisterValueChangedCallback(evt =>
        {
            parameterNode.accessor = (ParameterAccessor)evt.newValue;
            controlsContainer.MarkDirtyRepaint();
            ForceUpdatePorts();
        });
        controlsContainer.Add(accessorSelector);

        parameterNode.onParameterChanged += UpdateView;
        UpdateView();
    }
Beispiel #11
0
        public void RefreshSettingsValues()
        {
            outputSizeMode?.SetValueWithoutNotify(settings.sizeMode);
            outputDimension?.SetValueWithoutNotify(settings.dimension);
            outputChannels?.SetValueWithoutNotify(settings.outputChannels);
            outputPrecision?.SetValueWithoutNotify(settings.outputPrecision);
            wrapMode?.SetValueWithoutNotify(settings.wrapMode);
            filterMode?.SetValueWithoutNotify(settings.filterMode);
            potSize?.SetValueWithoutNotify(settings.potSize);

            outputWidth?.SetValueWithoutNotify(settings.width);
            outputWidthScale?.SetValueWithoutNotify(SizeScaleToInt(settings.widthScale));
            outputHeight?.SetValueWithoutNotify(settings.height);
            outputHeightScale?.SetValueWithoutNotify(SizeScaleToInt(settings.heightScale));
            outputDepth?.SetValueWithoutNotify(settings.depth);
            outputDepthScale?.SetValueWithoutNotify(SizeScaleToInt(settings.depthScale));

            doubleBuffered?.SetValueWithoutNotify(settings.doubleBuffered);

            refreshMode?.SetValueWithoutNotify(settings.refreshMode);
            period?.SetValueWithoutNotify(settings.period);
        }
Beispiel #12
0
    public override void Enable()
    {
        parameterNode = nodeTarget as ParameterNode;
        owner.graph.onExposedParameterRemoved += OnParamRemoved;

        EnumField accessorSelector = new EnumField(parameterNode.accessor);

        accessorSelector.SetValueWithoutNotify(parameterNode.accessor);
        accessorSelector.RegisterValueChangedCallback(evt =>
        {
            parameterNode.accessor = (ParameterAccessor)evt.newValue;
            UpdatePort();
            controlsContainer.MarkDirtyRepaint();
            ForceUpdatePorts();
        });

        UpdatePort();
        controlsContainer.Add(accessorSelector);

        //    Find and remove expand/collapse button
        titleContainer.Remove(titleContainer.Q("title-button-container"));
        //    Remove Port from the #content
        topContainer.parent.Remove(topContainer);
        //    Add Port to the #title
        titleContainer.Add(topContainer);
        //    Find parameter type and add icon
        var type = parameterNode.parameter.type.Split(new[] { ',' })[0].Split(new[] { '.' })[1];

        mainContainer.parent.AddToClassList("parameter-" + type);
        mainContainer.parent.AddToClassList("pName-" + parameterNode.parameter.name);
        titleContainer.Add(new VisualElement {
            name = "parameterIcon"
        });
        titleContainer.Q("parameterIcon").SendToBack();

        parameterNode.onParameterChanged += UpdateView;
        UpdateView();
    }
Beispiel #13
0
    public LevelNode(Vector2 _position, LevelEditorWindow _editorWindow, LevelFlowGraphView _graphView)
    {
        SetPosition(new Rect(_position, defaultNodeSize));

        CreateSubGraphView();

        //Scene Object field
        sceneField = new ObjectField
        {
            objectType        = typeof(Scene),
            allowSceneObjects = false
        };

        sceneField.RegisterValueChangedCallback(ValueTuple =>
        {
            scene         = ValueTuple.newValue;
            title         = ValueTuple.newValue.name;
            scenAssetGuid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(ValueTuple.newValue as SceneAsset));
            scenePath     = AssetDatabase.GetAssetPath(ValueTuple.newValue as SceneAsset);
            //SetScenePath();
        });
        mainContainer.Add(sceneField);


        //Async? Enum field
        asyncTypeField = new EnumField()
        {
            value = asyncType
        };
        asyncTypeField.Init(asyncType);

        asyncTypeField.RegisterValueChangedCallback((value) =>
        {
            //賦予新value
            asyncType = (AsyncLoadType)value.newValue;
        });

        asyncTypeField.SetValueWithoutNotify(asyncType);

        mainContainer.Add(asyncTypeField);

        //Load Type Enum field
        loadTypeField = new EnumField()
        {
            value = loadType
        };
        loadTypeField.Init(loadType);

        loadTypeField.RegisterValueChangedCallback((value) =>
        {
            //賦予新value
            loadType = (SceneLoadType)value.newValue;
        });

        loadTypeField.SetValueWithoutNotify(loadType);

        mainContainer.Add(loadTypeField);



        //新增節點須refresh
        RefreshExpandedState();
        RefreshPorts();
    }
Beispiel #14
0
        BuilderStyleRow CreateAttributeRow(UxmlAttributeDescription attribute)
        {
            var attributeType = attribute.GetType();

            // Generate field label.
            var             fieldLabel = BuilderNameUtilities.ConvertDashToHuman(attribute.name);
            BindableElement fieldElement;

            if (attribute is UxmlStringAttributeDescription)
            {
                // Hard-coded
                if (attribute.name.Equals("value") && currentVisualElement is EnumField enumField)
                {
                    var uiField = new EnumField("Value");
                    if (null != enumField.value)
                    {
                        uiField.Init(enumField.value, enumField.includeObsoleteValues);
                    }
                    else
                    {
                        uiField.SetValueWithoutNotify(null);
                    }
                    uiField.RegisterValueChangedCallback(evt =>
                                                         PostAttributeValueChange(uiField, uiField.value.ToString()));
                    fieldElement = uiField;
                }
                else if (attribute.name.Equals("value") && currentVisualElement is TagField tagField)
                {
                    var uiField = new TagField("Value");
                    uiField.RegisterValueChangedCallback(evt =>
                                                         PostAttributeValueChange(uiField, uiField.value.ToString()));
                    fieldElement = uiField;
                }
                else
                {
                    var uiField = new TextField(fieldLabel);
                    if (attribute.name.Equals("name") || attribute.name.Equals("view-data-key"))
                    {
                        uiField.RegisterValueChangedCallback(e =>
                        {
                            OnValidatedAttributeValueChange(e, BuilderNameUtilities.attributeRegex,
                                                            BuilderConstants.AttributeValidationSpacialCharacters);
                        });
                    }
                    else if (attribute.name.Equals("binding-path"))
                    {
                        uiField.RegisterValueChangedCallback(e =>
                        {
                            OnValidatedAttributeValueChange(e, BuilderNameUtilities.bindingPathAttributeRegex,
                                                            BuilderConstants.BindingPathAttributeValidationSpacialCharacters);
                        });
                    }
                    else
                    {
                        uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                    }

                    if (attribute.name.Equals("text") || attribute.name.Equals("label"))
                    {
                        uiField.multiline = true;
                        uiField.AddToClassList(BuilderConstants.InspectorMultiLineTextFieldClassName);
                    }

                    fieldElement = uiField;
                }
            }
            else if (attribute is UxmlFloatAttributeDescription)
            {
                var uiField = new FloatField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlDoubleAttributeDescription)
            {
                var uiField = new DoubleField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlIntAttributeDescription)
            {
                if (attribute.name.Equals("value") && currentVisualElement is LayerField)
                {
                    var uiField = new LayerField("Value");
                    uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                    fieldElement = uiField;
                }
                else if (attribute.name.Equals("value") && currentVisualElement is LayerMaskField)
                {
                    var uiField = new LayerMaskField("Value");
                    uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                    fieldElement = uiField;
                }
                else
                {
                    var uiField = new IntegerField(fieldLabel);
                    uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                    fieldElement = uiField;
                }
            }
            else if (attribute is UxmlLongAttributeDescription)
            {
                var uiField = new LongField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlBoolAttributeDescription)
            {
                var uiField = new Toggle(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attribute is UxmlColorAttributeDescription)
            {
                var uiField = new ColorField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }
            else if (attributeType.IsGenericType &&
                     !attributeType.GetGenericArguments()[0].IsEnum &&
                     attributeType.GetGenericArguments()[0] is Type)
            {
                var desiredType = attributeType.GetGenericArguments()[0];

                var uiField = new TextField(fieldLabel)
                {
                    isDelayed = true
                };

                var completer = new FieldSearchCompleter <TypeInfo>(uiField);
                uiField.RegisterCallback <AttachToPanelEvent, FieldSearchCompleter <TypeInfo> >((evt, c) =>
                {
                    // When possible, the popup should have the same width as the input field, so that the auto-complete
                    // characters will try to match said input field.
                    c.popup.anchoredControl = ((VisualElement)evt.target).Q(className: "unity-text-field__input");
                }, completer);
                completer.matcherCallback    += (str, info) => info.value.IndexOf(str, StringComparison.OrdinalIgnoreCase) >= 0;
                completer.itemHeight          = 36;
                completer.dataSourceCallback += () =>
                {
                    return(TypeCache.GetTypesDerivedFrom(desiredType)
                           .Where(t => !t.IsGenericType)
                           // Remove UIBuilder types from the list
                           .Where(t => t.Assembly != GetType().Assembly)
                           .Select(GetTypeInfo));
                };
                completer.getTextFromDataCallback += info => info.value;
                completer.makeItem    = () => s_TypeNameItemPool.Get();
                completer.destroyItem = e =>
                {
                    if (e is BuilderAttributeTypeName typeItem)
                    {
                        s_TypeNameItemPool.Release(typeItem);
                    }
                };
                completer.bindItem = (v, i) =>
                {
                    if (v is BuilderAttributeTypeName l)
                    {
                        l.SetType(completer.results[i].type, completer.textField.text);
                    }
                };

                uiField.RegisterValueChangedCallback(e => OnValidatedTypeAttributeChange(e, desiredType));

                fieldElement = uiField;
                uiField.RegisterCallback <DetachFromPanelEvent, FieldSearchCompleter <TypeInfo> >((evt, c) =>
                {
                    c.popup.RemoveFromHierarchy();
                }, completer);
                uiField.userData = completer;
            }
            else if (attributeType.IsGenericType && attributeType.GetGenericArguments()[0].IsEnum)
            {
                var propInfo         = attributeType.GetProperty("defaultValue");
                var defaultEnumValue = propInfo.GetValue(attribute, null) as Enum;

                if (defaultEnumValue.GetType().GetCustomAttribute <FlagsAttribute>() == null)
                {
                    // Create and initialize the EnumField.
                    var uiField = new EnumField(fieldLabel);
                    uiField.Init(defaultEnumValue);

                    uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                    fieldElement = uiField;
                }
                else
                {
                    // Create and initialize the EnumField.
                    var uiField = new EnumFlagsField(fieldLabel);
                    uiField.Init(defaultEnumValue);

                    uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                    fieldElement = uiField;
                }
            }
            else
            {
                var uiField = new TextField(fieldLabel);
                uiField.RegisterValueChangedCallback(OnAttributeValueChange);
                fieldElement = uiField;
            }

            // Create row.
            var styleRow = new BuilderStyleRow();

            styleRow.Add(fieldElement);

            // Link the field.
            fieldElement.SetProperty(BuilderConstants.InspectorLinkedStyleRowVEPropertyName, styleRow);
            fieldElement.SetProperty(BuilderConstants.InspectorLinkedAttributeDescriptionVEPropertyName, attribute);

            // Set initial value.
            RefreshAttributeField(fieldElement);

            // Setup field binding path.
            fieldElement.bindingPath = attribute.name;
            fieldElement.tooltip     = attribute.name;

            // Context menu.
            fieldElement.AddManipulator(new ContextualMenuManipulator(BuildAttributeFieldContextualMenu));

            return(styleRow);
        }
            public void Update()
            {
                var value = provider.GetDataAtOffset <TValue>(m_Offset);

                m_Element.SetValueWithoutNotify((Enum)Enum.ToObject(typeof(TEnumType), m_Translator.ToField(value)));
            }
        public void RefreshPropertyValue(object val, int specificity)
        {
            if (val is StyleFloat)
            {
                var        style = (StyleFloat)val;
                FloatField field = GetOrCreateField <FloatField, float>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(style.value);
                }
            }
            else if (val is StyleInt)
            {
                var          style = (StyleInt)val;
                IntegerField field = GetOrCreateField <IntegerField, int>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(style.value);
                }
            }
            else if (val is StyleLength)
            {
                var style = (StyleLength)val;
                StyleLengthField field = GetOrCreateField <StyleLengthField, StyleLength>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(style);
                }
            }
            else if (val is StyleColor)
            {
                var        style = (StyleColor)val;
                ColorField field = GetOrCreateField <ColorField, Color>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(style.value);
                }
            }
            else if (val is StyleFont)
            {
                var         style = (StyleFont)val;
                ObjectField field = GetOrCreateObjectField <Font>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(style.value);
                }
            }
            else if (val is StyleBackground)
            {
                var         background = ((StyleBackground)val).value;
                ObjectField field;
                if (background.vectorImage != null)
                {
                    field = GetOrCreateObjectField <VectorImage>();
                }
                else
                {
                    field = GetOrCreateObjectField <Texture2D>();
                }
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(background.vectorImage != null ? (UnityEngine.Object)background.vectorImage : (UnityEngine.Object)background.texture);
                }
            }
            else if (val is StyleCursor)
            {
                // Recreate the cursor fields every time since StyleCursor
                // can be made of different fields (based on the value)
                Clear();

                StyleCursor style = (StyleCursor)val;
                if (style.value.texture != null)
                {
                    var uiTextureField = new ObjectField(m_PropertyName)
                    {
                        value = style.value.texture
                    };
                    uiTextureField.RegisterValueChangedCallback(e =>
                    {
                        StyleCursor styleCursor = (StyleCursor)StyleDebug.GetComputedStyleValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        var currentCursor       = styleCursor.value;
                        currentCursor.texture   = e.newValue as Texture2D;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiTextureField);

                    var uiHotspotField = new Vector2Field("hotspot")
                    {
                        value = style.value.hotspot
                    };
                    uiHotspotField.RegisterValueChangedCallback(e =>
                    {
                        StyleCursor styleCursor = (StyleCursor)StyleDebug.GetComputedStyleValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        var currentCursor       = styleCursor.value;
                        currentCursor.hotspot   = e.newValue;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiHotspotField);
                }
                else
                {
                    int mouseId = style.value.defaultCursorId;
                    var uiField = new EnumField(m_PropertyName, (MouseCursor)mouseId);
                    uiField.RegisterValueChangedCallback(e =>
                    {
                        int cursorId = Convert.ToInt32(e.newValue);
                        var cursor   = new Cursor()
                        {
                            defaultCursorId = cursorId
                        };
                        SetPropertyValue(new StyleCursor(cursor));
                    });
                    Add(uiField);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
            }
            else
            {
                // StyleEnum<T>
                var       type      = val.GetType();
                var       propInfo  = type.GetProperty("value");
                Enum      enumValue = propInfo.GetValue(val, null) as Enum;
                EnumField field     = GetOrCreateEnumField(enumValue);
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(enumValue);
                }
            }

            SetSpecificity(specificity);
        }
        public void RefreshPropertyValue(object val, int specificity)
        {
            if (val is float floatValue)
            {
                FloatField field = GetOrCreateField <FloatField, float>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(floatValue);
                }
            }
            else if (val is int intValue)
            {
                IntegerField field = GetOrCreateField <IntegerField, int>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(intValue);
                }
            }
            else if (val is Length lengthValue)
            {
                StyleLengthField field = GetOrCreateField <StyleLengthField, StyleLength>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(new StyleLength(lengthValue));
                }
            }
            else if (val is Color colorValue)
            {
                ColorField field = GetOrCreateField <ColorField, Color>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(colorValue);
                }
            }
            // Note: val may be null in case of reference type like "Font"
            else if (m_PropertyInfo.type == typeof(StyleFont))
            {
                ObjectField field;
                field = GetOrCreateObjectField <Font>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(val as Font);
                }
            }
            else if (val is FontDefinition fontDefinition)
            {
                ObjectField field;
                if (fontDefinition.fontAsset != null)
                {
                    if (childCount == 0)
                    {
                        field = GetObjectFieldOfTypeFontAsset();
                        SetField(field);
                    }
                    else
                    {
                        field = (ObjectField)ElementAt(0);
                    }
                }
                else
                {
                    field = GetOrCreateObjectField <Font>();
                }

                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(fontDefinition.fontAsset != null ? fontDefinition.fontAsset : fontDefinition.font);
                }
            }
            else if (val is Background bgValue)
            {
                ObjectField field;
                if (bgValue.vectorImage != null)
                {
                    field = GetOrCreateObjectField <VectorImage>();
                }
                else if (bgValue.sprite != null)
                {
                    field = GetOrCreateObjectField <Sprite>();
                }
                else if (bgValue.renderTexture != null)
                {
                    field = GetOrCreateObjectField <RenderTexture>();
                }
                else
                {
                    field = GetOrCreateObjectField <Texture2D>();
                }
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(
                        bgValue.vectorImage != null ? (UnityEngine.Object)bgValue.vectorImage :
                        (bgValue.sprite != null ? (UnityEngine.Object)bgValue.sprite :
                         (bgValue.renderTexture != null ? (UnityEngine.Object)bgValue.renderTexture :
                          (UnityEngine.Object)bgValue.texture)));
                }
            }
            else if (val is Cursor cursorValue)
            {
                // Recreate the cursor fields every time since StyleCursor
                // can be made of different fields (based on the value)
                Clear();

                if (cursorValue.texture != null)
                {
                    var uiTextureField = new ObjectField(m_PropertyName)
                    {
                        value = cursorValue.texture
                    };
                    uiTextureField.RegisterValueChangedCallback(e =>
                    {
                        var currentCursor     = (Cursor)StyleDebug.GetComputedStyleActualValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        currentCursor.texture = e.newValue as Texture2D;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiTextureField);

                    var uiHotspotField = new Vector2Field("hotspot")
                    {
                        value = cursorValue.hotspot
                    };
                    uiHotspotField.RegisterValueChangedCallback(e =>
                    {
                        var currentCursor     = (Cursor)StyleDebug.GetComputedStyleActualValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        currentCursor.hotspot = e.newValue;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiHotspotField);
                }
                else
                {
                    int mouseId = cursorValue.defaultCursorId;
                    var uiField = new EnumField(m_PropertyName, (MouseCursor)mouseId);
                    uiField.RegisterValueChangedCallback(e =>
                    {
                        int cursorId = Convert.ToInt32(e.newValue);
                        var cursor   = new Cursor()
                        {
                            defaultCursorId = cursorId
                        };
                        SetPropertyValue(new StyleCursor(cursor));
                    });
                    Add(uiField);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
            }
            else if (val is TextShadow textShadow)
            {
                ColorField colorFieldfield = GetOrCreateFields <ColorField, Color>(m_PropertyName, 0);
                if (!IsFocused(colorFieldfield))
                {
                    colorFieldfield.SetValueWithoutNotify(textShadow.color);
                }

                Vector2Field vector2Field = GetOrCreateFields <Vector2Field, Vector2>("offset", 1);
                if (!IsFocused(vector2Field))
                {
                    vector2Field.SetValueWithoutNotify(textShadow.offset);
                }

                FloatField floatField = GetOrCreateFields <FloatField, float>("blur", 2);
                if (!IsFocused(floatField))
                {
                    floatField.SetValueWithoutNotify(textShadow.blurRadius);
                }

                if (childCount == 3)
                {
                    Add(m_SpecificityLabel);
                }
            }
            else
            {
                // Enum
                Debug.Assert(val is Enum, "Expected Enum value");
                Enum      enumValue = (Enum)val;
                EnumField field     = GetOrCreateEnumField(enumValue);
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(enumValue);
                }
            }

            SetSpecificity(specificity);
        }
        void InitializeView()
        {
            // Register callbacks
            settingsButton.clicked += () => {
                if (settingsButton.ClassListContains("ActiveButton"))
                {
                    settingsButton.RemoveFromClassList("ActiveButton");
                    portSettings.style.display  = DisplayStyle.None;
                    portNameField.style.display = DisplayStyle.None;
                }
                else
                {
                    settingsButton.AddToClassList("ActiveButton");
                    portSettings.style.display  = DisplayStyle.Flex;
                    portNameField.style.display = DisplayStyle.Flex;
                }
            };

            portNameField.RegisterValueChangedCallback(name => {
                graphView.RegisterCompleteObjectUndo("Change output name");
                var uniqueName      = ObjectNames.GetUniqueName(node.outputTextureSettings.Select(o => o.name).ToArray(), name.newValue);
                targetSettings.name = uniqueName;
                portName.text       = uniqueName;

#if UNITY_EDITOR
                if (graphView.graph.isRealtime)
                {
                    graphView.graph.UpdateRealtimeAssetsOnDisk();
                }
#endif
            });
            portNameField.value = targetSettings.name;
            portName.text       = targetSettings.name;

            enableCompression.RegisterValueChangedCallback(enabled => {
                graphView.RegisterCompleteObjectUndo($"Change {targetSettings.name} compression");
                var textureDim = node.rtSettings.GetTextureDimension(graphView.graph);

                if (textureDim == TextureDimension.Tex2D || textureDim == TextureDimension.Cube)
                {
                    targetSettings.enableCompression = enabled.newValue;
                    if (enabled.newValue)
                    {
                        compressionFields.style.display = DisplayStyle.Flex;
                    }
                    else
                    {
                        compressionFields.style.display = DisplayStyle.None;
                    }
                }
                else
                {
                    Debug.LogError("Compression is not yet supported for " + textureDim);
                    enableCompression.SetValueWithoutNotify(false);
                }
            });
            enableCompression.value = targetSettings.enableCompression;

            compressionFormat.RegisterValueChangedCallback(format => {
                targetSettings.compressionFormat = (TextureFormat)format.newValue;
            });
            compressionQuality.RegisterValueChangedCallback(quality => {
                targetSettings.compressionQuality = (MixtureCompressionQuality)quality.newValue;
            });

            compressionFormat.SetValueWithoutNotify(targetSettings.compressionFormat);
            compressionQuality.SetValueWithoutNotify(targetSettings.compressionQuality);

            createMipMapShaderButton.clicked += MixtureAssetCallbacks.CreateCustomMipMapShaderGraph;
            // TODO: assign the created shader when finished

            mipmapShaderField.objectType           = typeof(Shader);
            mipmapShaderField.value                = targetSettings.customMipMapShader;
            createMipMapShaderButton.style.display = targetSettings.customMipMapShader != null ? DisplayStyle.None : DisplayStyle.Flex;
            mipmapShaderField.RegisterValueChangedCallback(e => {
                graphView.RegisterCompleteObjectUndo("Changed Custom Mip Map Shader");
                targetSettings.customMipMapShader      = e.newValue as Shader;
                createMipMapShaderButton.style.display = e.newValue != null ? DisplayStyle.None : DisplayStyle.Flex;;
            });

            enableMipMap.RegisterValueChangedCallback(e => {
                targetSettings.hasMipMaps = e.newValue;
                if (supportCustomMipMaps)
                {
                    mipmapFields.style.display = targetSettings.hasMipMaps ? DisplayStyle.Flex : DisplayStyle.None;
                }

                // Processing the graph to update the previews with the new mipmaps
                graphView.ProcessGraph();
            });
            enableMipMap.value = targetSettings.hasMipMaps;

            removeOutputButton.clicked += () => {
                node.RemoveTextureOutput(targetSettings);
                nodeView.ForceUpdatePorts();
            };

            enableConversion.RegisterValueChangedCallback(e => {
                graphView.RegisterCompleteObjectUndo("Changed Conversion value");
                targetSettings.enableConversion = e.newValue;
                conversionFormat.style.display  = e.newValue ? DisplayStyle.Flex : DisplayStyle.None;
            });
            enableConversion.value = targetSettings.enableConversion;

            conversionFormat.RegisterValueChangedCallback(e => {
                graphView.RegisterCompleteObjectUndo("Changed Conversion Format");
                targetSettings.conversionFormat = (ConversionFormat)e.newValue;
            });
            conversionFormat.value = targetSettings.conversionFormat;

            sRGB.RegisterValueChangedCallback(e => {
                graphView.RegisterCompleteObjectUndo("Changed sRGB");
                targetSettings.sRGB = e.newValue;

                // when updating sRGB flag, we need to process the graph to update the final copy material
                graphView.ProcessGraph();
            });
            sRGB.value = targetSettings.sRGB;

            // Initial view state
            portSettings.style.display      = DisplayStyle.None;
            compressionFields.style.display = targetSettings.enableCompression ? DisplayStyle.Flex : DisplayStyle.None;
            mipmapFields.style.display      = targetSettings.hasMipMaps ? DisplayStyle.Flex : DisplayStyle.None;
            portNameField.style.display     = DisplayStyle.None;
            conversionFormat.style.display  = targetSettings.enableConversion ? DisplayStyle.Flex : DisplayStyle.None;
        }
Beispiel #19
0
        public void RefreshPropertyValue(object val, int specificity)
        {
            if (val is float floatValue)
            {
                FloatField field = GetOrCreateField <FloatField, float>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(floatValue);
                }
            }
            else if (val is int intValue)
            {
                IntegerField field = GetOrCreateField <IntegerField, int>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(intValue);
                }
            }
            else if (val is Length lengthValue)
            {
                StyleLengthField field = GetOrCreateField <StyleLengthField, StyleLength>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(new StyleLength(lengthValue));
                }
            }
            else if (val is Color colorValue)
            {
                ColorField field = GetOrCreateField <ColorField, Color>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(colorValue);
                }
            }
            // Note: val may be null in case of reference type like "Font"
            else if (m_PropertyInfo.type == typeof(StyleFont))
            {
                ObjectField field;
                field = GetOrCreateObjectField <Font>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(val as Font);
                }
            }
            else if (val is FontDefinition fontDefinition)
            {
                ObjectField field;
                if (fontDefinition.fontAsset != null)
                {
                    if (childCount == 0)
                    {
                        var o = new ObjectField();
                        o.objectType = typeof(FontAsset);
                        field        = o;

                        SetField(field);
                    }
                    else
                    {
                        field = (ObjectField)ElementAt(0);
                    }
                }
                else
                {
                    field = GetOrCreateObjectField <Font>();
                }

                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(fontDefinition.fontAsset != null ? (UnityEngine.Object)fontDefinition.fontAsset : (UnityEngine.Object)fontDefinition.font);
                }
            }
            else if (val is Background bgValue)
            {
                ObjectField field;
                if (bgValue.vectorImage != null)
                {
                    field = GetOrCreateObjectField <VectorImage>();
                }
                else if (bgValue.sprite != null)
                {
                    field = GetOrCreateObjectField <Sprite>();
                }
                else if (bgValue.renderTexture != null)
                {
                    field = GetOrCreateObjectField <RenderTexture>();
                }
                else
                {
                    field = GetOrCreateObjectField <Texture2D>();
                }
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(
                        bgValue.vectorImage != null ? (UnityEngine.Object)bgValue.vectorImage :
                        (bgValue.sprite != null ? (UnityEngine.Object)bgValue.sprite :
                         (bgValue.renderTexture != null ? (UnityEngine.Object)bgValue.renderTexture :
                          (UnityEngine.Object)bgValue.texture)));
                }
            }
            else if (val is Cursor cursorValue)
            {
                // Recreate the cursor fields every time since StyleCursor
                // can be made of different fields (based on the value)
                Clear();

                if (cursorValue.texture != null)
                {
                    var uiTextureField = new ObjectField(m_PropertyName)
                    {
                        value = cursorValue.texture
                    };
                    uiTextureField.RegisterValueChangedCallback(e =>
                    {
                        var currentCursor     = (Cursor)StyleDebug.GetComputedStyleValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        currentCursor.texture = e.newValue as Texture2D;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiTextureField);

                    var uiHotspotField = new Vector2Field("hotspot")
                    {
                        value = cursorValue.hotspot
                    };
                    uiHotspotField.RegisterValueChangedCallback(e =>
                    {
                        var currentCursor     = (Cursor)StyleDebug.GetComputedStyleValue(m_SelectedElement.computedStyle, m_PropertyInfo.id);
                        currentCursor.hotspot = e.newValue;
                        SetPropertyValue(new StyleCursor(currentCursor));
                    });
                    Add(uiHotspotField);
                }
                else
                {
                    int mouseId = cursorValue.defaultCursorId;
                    var uiField = new EnumField(m_PropertyName, (MouseCursor)mouseId);
                    uiField.RegisterValueChangedCallback(e =>
                    {
                        int cursorId = Convert.ToInt32(e.newValue);
                        var cursor   = new Cursor()
                        {
                            defaultCursorId = cursorId
                        };
                        SetPropertyValue(new StyleCursor(cursor));
                    });
                    Add(uiField);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
            }
            else if (val is TextShadow textShadow)
            {
                ColorField colorFieldfield = GetOrCreateFields <ColorField, Color>(m_PropertyName, 0);
                if (!IsFocused(colorFieldfield))
                {
                    colorFieldfield.SetValueWithoutNotify(textShadow.color);
                }

                Vector2Field vector2Field = GetOrCreateFields <Vector2Field, Vector2>("offset", 1);
                if (!IsFocused(vector2Field))
                {
                    vector2Field.SetValueWithoutNotify(textShadow.offset);
                }

                FloatField floatField = GetOrCreateFields <FloatField, float>("blur", 2);
                if (!IsFocused(floatField))
                {
                    floatField.SetValueWithoutNotify(textShadow.blurRadius);
                }

                if (childCount == 3)
                {
                    Add(m_SpecificityLabel);
                }
            }
            else if (val is Rotate rotate)
            {
                FloatField floatField = GetOrCreateFields <FloatField, float>(m_PropertyName, 0);
                if (!IsFocused(floatField))
                {
                    floatField.SetValueWithoutNotify(rotate.angle.value);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
            }
            else if (val is Scale scale)
            {
                Vector3Field vector3Field = GetOrCreateFields <Vector3Field, Vector3>(m_PropertyName, 0);
                if (!IsFocused(vector3Field))
                {
                    vector3Field.SetValueWithoutNotify(scale.value);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
            }
            else if (val is Translate translate)
            {
                StyleLengthField fieldx = GetOrCreateFields <StyleLengthField, StyleLength>(m_PropertyName, 0);
                if (!IsFocused(fieldx))
                {
                    fieldx.SetValueWithoutNotify(translate.x);
                }
                StyleLengthField fieldy = GetOrCreateFields <StyleLengthField, StyleLength>("y", 1);
                if (!IsFocused(fieldy))
                {
                    fieldy.SetValueWithoutNotify(translate.x);
                }
                FloatField floatField = GetOrCreateFields <FloatField, float>("z", 2);
                if (!IsFocused(floatField))
                {
                    floatField.SetValueWithoutNotify(translate.z);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
                SetEnabled(false);
            }
            else if (val is TransformOrigin transformOrigin)
            {
                StyleLengthField fieldx = GetOrCreateFields <StyleLengthField, StyleLength>(m_PropertyName, 0);
                if (!IsFocused(fieldx))
                {
                    fieldx.SetValueWithoutNotify(transformOrigin.x);
                }
                StyleLengthField fieldy = GetOrCreateFields <StyleLengthField, StyleLength>("y", 1);
                if (!IsFocused(fieldy))
                {
                    fieldy.SetValueWithoutNotify(transformOrigin.x);
                }
                FloatField floatField = GetOrCreateFields <FloatField, float>("z", 2);
                if (!IsFocused(floatField))
                {
                    floatField.SetValueWithoutNotify(transformOrigin.z);
                }
                Add(m_SpecificityLabel);
                SetSpecificity(specificity);
                SetEnabled(false);
            }
            else if (val is Enum)
            {
                Enum      enumValue = (Enum)val;
                EnumField field     = GetOrCreateEnumField(enumValue);
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(enumValue);
                }
            }
            else
            {
                var type = val.GetType();
                Debug.Assert(type.IsArrayOrList(), "Expected List type");

                var listValue   = val as System.Collections.IList;
                var valueString = listValue[0].ToString();
                for (int i = 1; i < listValue.Count; i++)
                {
                    valueString += $", {listValue[i]}";
                }
                TextField field = GetOrCreateField <TextField, string>();
                if (!IsFocused(field))
                {
                    field.SetValueWithoutNotify(valueString);
                }
            }

            SetSpecificity(specificity);
        }
Beispiel #20
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();
        }
        private void RefreshUI()
        {
            rootVisualElement.Clear();

            VisualElement topRowElement = new VisualElement();

            topRowElement.AddToClassList("svbm-row");
            rootVisualElement.Add(topRowElement);

            Button refreshButton = new Button(RefreshUI)
            {
                name = "Refresh", text = "Refresh"
            };

            refreshButton.AddToClassList("svbm-cell");
            topRowElement.Add(refreshButton);

            Button saveButton = new Button(() => Bookmarks.Instance?.SaveToJson(Bookmarks.path))
            {
                name = "Save", text = "Save"
            };

            saveButton.AddToClassList("svbm-cell");
            topRowElement.Add(saveButton);

            IMGUIContainer header = new IMGUIContainer(OnCustomGUI);

            header.AddToClassList("sceneLightingButton");
            rootVisualElement.Add(header);

            if (Bookmarks.Count == 0)
            {
                return;
            }


            for (int i = 0; i < Bookmarks.Count; i++)
            {
                var index = i;

                VisualElement bookmarkElement = new VisualElement();
                bookmarkElement.AddToClassList("svbm-row");

                Button loadButton = new Button(() => Bookmarks.Instance[index].Load(SceneView.lastActiveSceneView))
                {
                    name = "LOAD", text = "LOAD"
                };
                loadButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(loadButton);

                Button updateButton = new Button(() => Bookmarks.Instance[index].Save(SceneView.lastActiveSceneView))
                {
                    name = "UPDATE", text = "UPDATE"
                };
                updateButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(updateButton);

                Button deleteButton = new Button(() =>
                {
                    Bookmarks.Instance.viewpoints.RemoveAt(index);
                    RefreshUI();
                })
                {
                    name = "DELETE", text = "DELETE"
                };
                deleteButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(deleteButton);

                TextField nameField = new TextField("")
                {
                    tooltip = "Set this bookmark's menu path / name.\nUse '/' to create a submenu."
                };
                nameField.value = Bookmarks.Instance[index].name;
                nameField.AddToClassList("svbm-cell-text");
                nameField.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].name = x.newValue);
                bookmarkElement.Add(nameField);

                MaskField overridesMask = new MaskField(Enum.GetNames(typeof(Viewpoint.Overrides)).ToList(), (int)Bookmarks.Instance[index].overrides)
                {
                    tooltip = "Set this bookmark's Overrides."
                };
                overridesMask.AddToClassList("svbm-cell-mask");
                overridesMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].overrides = (Viewpoint.Overrides)x.newValue);
                bookmarkElement.Add(overridesMask);

                Toggle orthoToggle = new Toggle("")
                {
                    tooltip = "Enable to set this bookmark's SceneView to Orthographic."
                };
                orthoToggle.value = Bookmarks.Instance[index].settings.ortho;
                orthoToggle.AddToClassList("svbm-cell-checkbox");
                orthoToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.ortho = x.newValue);
                bookmarkElement.Add(orthoToggle);

                Toggle is2dToggle = new Toggle("")
                {
                    tooltip = "Enable to set this bookmark's SceneView to 2D Mode."
                };
                is2dToggle.value = Bookmarks.Instance[index].settings.is2D;
                is2dToggle.AddToClassList("svbm-cell-checkbox");
                is2dToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.is2D = x.newValue);
                bookmarkElement.Add(is2dToggle);

                FloatField fovField = new FloatField()
                {
                    tooltip = "Set this bookmark's Camera Field of View."
                };
                fovField.value = Bookmarks.Instance[index].settings.fov;
                fovField.AddToClassList("svbm-cell-float");
                fovField.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.fov = Mathf.Clamp(x.newValue, 4, 120));
                bookmarkElement.Add(fovField);

                EnumField cameraModeMask = new EnumField("", Bookmarks.Instance[index].settings.mode.drawMode)
                {
                    tooltip = "Set this bookmark's Camera Shading Mode."
                };
                cameraModeMask.AddToClassList("svbm-cell-mask");
                // Catching cases where SceneView.GetBuiltinCameraMode() will fail on some DrawCameraMode such as Normal and User Defined
                cameraModeMask.RegisterValueChangedCallback((x) => {
                    try
                    {
                        Bookmarks.Instance[index].settings.mode = SceneView.GetBuiltinCameraMode((DrawCameraMode)x.newValue);
                    }
                    catch
                    {
                        cameraModeMask.SetValueWithoutNotify(x.previousValue);
                    }
                });
                bookmarkElement.Add(cameraModeMask);

                Toggle lightingToggle = new Toggle("")
                {
                    tooltip = "Enable this bookmark's SceneView Lighting."
                };
                lightingToggle.value = Bookmarks.Instance[index].settings.sceneLighting;
                lightingToggle.AddToClassList("svbm-cell-checkbox");
                lightingToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.sceneLighting = x.newValue);
                bookmarkElement.Add(lightingToggle);

                MaskField viewStatesMask = new MaskField(SceneViewStatesLabels, (int)Bookmarks.Instance[index].settings.sceneViewState.GetFlags())
                {
                    tooltip = "Set this bookmark's SceneView States."
                };
                viewStatesMask.AddToClassList("svbm-cell-mask");
                viewStatesMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.sceneViewState.SetFlags((SceneViewExtensions.SceneViewStateFlags)x.newValue));
                bookmarkElement.Add(viewStatesMask);

                Toggle gridToggle = new Toggle("")
                {
                    tooltip = "Enable this bookmark's SceneView Grid."
                };
                gridToggle.value = Bookmarks.Instance[index].settings.showGrid;
                gridToggle.AddToClassList("svbm-cell-checkbox");
                gridToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.showGrid = x.newValue);
                bookmarkElement.Add(gridToggle);

                Toggle gizmosToggle = new Toggle("")
                {
                    tooltip = "Enable this bookmark's SceneView Gizmos."
                };
                gizmosToggle.value = Bookmarks.Instance[index].settings.drawGizmos;
                gizmosToggle.AddToClassList("svbm-cell-checkbox");
                gizmosToggle.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].settings.drawGizmos = x.newValue);
                bookmarkElement.Add(gizmosToggle);

                LayerMaskField visibleLayerMask = new LayerMaskField("", Bookmarks.Instance[index].visibleLayers)
                {
                    tooltip = "Set this bookmark's Visible Layers."
                };
                visibleLayerMask.AddToClassList("svbm-cell-mask");
                visibleLayerMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].visibleLayers = x.newValue);
                bookmarkElement.Add(visibleLayerMask);

                LayerMaskField lockedLayerMask = new LayerMaskField("", Bookmarks.Instance[index].lockedLayers)
                {
                    tooltip = "Set this bookmark's Locked Layers."
                };
                lockedLayerMask.AddToClassList("svbm-cell-mask");
                lockedLayerMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].lockedLayers = x.newValue);
                bookmarkElement.Add(lockedLayerMask);

                EnumField shortcutMask = new EnumField("", Bookmarks.Instance[index].shortcut)
                {
                    tooltip = "Set this bookmark's shortcut\nBeware this will override any other function the shortcut is associated with."
                };
                shortcutMask.AddToClassList("svbm-cell-mask");
                shortcutMask.RegisterValueChangedCallback((x) => Bookmarks.Instance[index].shortcut = (KeyCode)x.newValue);
                bookmarkElement.Add(shortcutMask);

                Button moveUpButton = new Button(() =>
                {
                    if (index <= 0)
                    {
                        return;
                    }

                    var item = Bookmarks.Instance.viewpoints[index];
                    Bookmarks.Instance.viewpoints.RemoveAt(index);

                    Bookmarks.Instance.viewpoints.Insert(index - 1, item);
                    RefreshUI();
                })
                {
                    name = "Up", text = "Up"
                };
                moveUpButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(moveUpButton);

                Button moveDownButton = new Button(() =>
                {
                    if (index >= Bookmarks.Instance.viewpoints.Count - 1)
                    {
                        return;
                    }

                    var item = Bookmarks.Instance.viewpoints[index];
                    Bookmarks.Instance.viewpoints.RemoveAt(index);

                    Bookmarks.Instance.viewpoints.Insert(index + 1, item);
                    RefreshUI();
                })
                {
                    name = "Down", text = "Dn"
                };
                moveDownButton.AddToClassList("svbm-cell-button");
                bookmarkElement.Add(moveDownButton);

                rootVisualElement.Add(bookmarkElement);
            }
        }
Beispiel #22
0
 private void UpdateOrientationDisplay()
 {
     m_ScreenOrientationEnumField.SetValueWithoutNotify((RenderedScreenOrientation)Screen.orientation);
     m_RendererOrientation.text = ObjectNames.NicifyVariableName(Screen.orientation.ToString());
 }
Beispiel #23
0
        public void CreateGUI()
        {
            try
            {
                VisualElement root = this.rootVisualElement;

                // 加载布局文件
                var visualAsset = EditorHelper.LoadWindowUXML <AssetBundleBuilderWindow>();
                if (visualAsset == null)
                {
                    return;
                }

                visualAsset.CloneTree(root);

                _buildTarget = EditorUserBuildSettings.activeBuildTarget;
                _encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
                _encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList();

                // 输出目录
                string defaultOutputRoot       = AssetBundleBuilderHelper.GetDefaultOutputRoot();
                string pipelineOutputDirectory = AssetBundleBuilderHelper.MakePipelineOutputDirectory(defaultOutputRoot, _buildTarget);
                _buildOutputField = root.Q <TextField>("BuildOutput");
                _buildOutputField.SetValueWithoutNotify(pipelineOutputDirectory);
                _buildOutputField.SetEnabled(false);

                // 构建版本
                _buildVersionField = root.Q <IntegerField>("BuildVersion");
                _buildVersionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildVersion);
                _buildVersionField.RegisterValueChangedCallback(evt =>
                {
                    AssetBundleBuilderSettingData.Setting.BuildVersion = _buildVersionField.value;
                });

                // 构建模式
                _buildModeField = root.Q <EnumField>("BuildMode");
                _buildModeField.Init(AssetBundleBuilderSettingData.Setting.BuildMode);
                _buildModeField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildMode);
                _buildModeField.style.width = 300;
                _buildModeField.RegisterValueChangedCallback(evt =>
                {
                    AssetBundleBuilderSettingData.Setting.BuildMode = (EBuildMode)_buildModeField.value;
                    RefreshWindow();
                });

                // 内置资源标签
                _buildinTagsField = root.Q <TextField>("BuildinTags");
                _buildinTagsField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.BuildTags);
                _buildinTagsField.RegisterValueChangedCallback(evt =>
                {
                    AssetBundleBuilderSettingData.Setting.BuildTags = _buildinTagsField.value;
                });

                // 加密方法
                var encryptionContainer = root.Q("EncryptionContainer");
                if (_encryptionServicesClassNames.Count > 0)
                {
                    int defaultIndex = GetEncryptionDefaultIndex(AssetBundleBuilderSettingData.Setting.EncyptionClassName);
                    _encryptionField             = new PopupField <string>(_encryptionServicesClassNames, defaultIndex);
                    _encryptionField.label       = "Encryption";
                    _encryptionField.style.width = 300;
                    _encryptionField.RegisterValueChangedCallback(evt =>
                    {
                        AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionField.value;
                    });
                    encryptionContainer.Add(_encryptionField);
                }
                else
                {
                    _encryptionField             = new PopupField <string>();
                    _encryptionField.label       = "Encryption";
                    _encryptionField.style.width = 300;
                    encryptionContainer.Add(_encryptionField);
                }

                // 压缩方式
                _compressionField = root.Q <EnumField>("Compression");
                _compressionField.Init(AssetBundleBuilderSettingData.Setting.CompressOption);
                _compressionField.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CompressOption);
                _compressionField.style.width = 300;
                _compressionField.RegisterValueChangedCallback(evt =>
                {
                    AssetBundleBuilderSettingData.Setting.CompressOption = (ECompressOption)_compressionField.value;
                });

                // 附加后缀格式
                _appendExtensionToggle = root.Q <Toggle>("AppendExtension");
                _appendExtensionToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.AppendExtension);
                _appendExtensionToggle.RegisterValueChangedCallback(evt =>
                {
                    AssetBundleBuilderSettingData.Setting.AppendExtension = _appendExtensionToggle.value;
                });

                // 拷贝首包文件
                _copyBuildinTagFilesToggle = root.Q <Toggle>("CopyBuildinFiles");
                _copyBuildinTagFilesToggle.SetValueWithoutNotify(AssetBundleBuilderSettingData.Setting.CopyBuildinTagFiles);
                _copyBuildinTagFilesToggle.RegisterValueChangedCallback(evt =>
                {
                    AssetBundleBuilderSettingData.Setting.CopyBuildinTagFiles = _copyBuildinTagFilesToggle.value;
                });

                // 构建按钮
                var buildButton = root.Q <Button>("Build");
                buildButton.clicked += BuildButton_clicked;;

                RefreshWindow();
            }
            catch (Exception e)
            {
                Debug.LogError(e.ToString());
            }
        }