public ContentBox()
            {
                m_TextContainer = new VisualElement();
                m_TextContainer.AddToClassList("box-model-content-text-container");

                m_WidthTextField = new IntegerField();
                m_WidthTextField.AddToClassList("box-model-textfield");

                m_HeightTextField = new IntegerField();
                m_HeightTextField.AddToClassList("box-model-textfield");

                m_XLabel = new Label("x");

                m_TextContainer.Add(m_WidthTextField);
                m_TextContainer.Add(m_XLabel);
                m_TextContainer.Add(m_HeightTextField);

                m_WidthTextField.value  = 0;
                m_HeightTextField.value = 0;

                m_WidthTextField.RegisterValueChangedCallback(OnWidthChanged);
                m_HeightTextField.RegisterValueChangedCallback(OnHeightChanged);

                Add(m_TextContainer);

                // Sync styles values
                schedule.Execute(SyncValues).Every(100);
            }
Example #2
0
        public IListElement()
        {
            Resources.Templates.ListElement.Clone(this);
            Resources.Templates.ListElementDefaultStyling.AddStyles(this);
            binding = this;

            m_Size = new IntegerField();
            m_Size.AddToClassList(UssClasses.ListElement.Size);
            m_Size.RegisterValueChangedCallback(CountChanged);
            m_Size.RegisterCallback <KeyDownEvent>(TrapKeys);
            m_Size.isDelayed = true;

            var toggle      = this.Q <Toggle>();
            var toggleInput = toggle.Q(className: UssClasses.Unity.ToggleInput);

            toggleInput.AddToClassList(UssClasses.ListElement.ToggleInput);
            toggle.Add(m_Size);

            m_AddItemButton = new Button(OnAddItem)
            {
                text = "+ Add Element"
            };
            m_AddItemButton.AddToClassList(UssClasses.ListElement.AddItemButton);

            m_ContentRoot       = new VisualElement();
            m_ContentRoot.name  = "properties-list-content";
            m_PaginationElement = new PaginationElement();
            Add(m_PaginationElement);
            Add(m_ContentRoot);
            Add(m_AddItemButton);
        }
        void LoadTemplate()
        {
            AddToClassList("timeField");
            m_FieldName = new Label();
            m_FieldName.AddToClassList("timeFieldNameLabel");
            Add(m_FieldName);
            var inputContainer = new VisualElement();

            inputContainer.AddToClassList("timeFieldInputContainer");
            Add(inputContainer);

            m_SecondsField = new FloatField("Seconds");
            m_SecondsField.AddToClassList("timeInput");
            m_SecondsField.RegisterValueChangedCallback(OnTimeInSecondsChanged);
            inputContainer.Add(m_SecondsField);

            m_FrameField = new IntegerField("Frame");
            m_FrameField.AddToClassList("timeInput");
            m_FrameField.RegisterValueChangedCallback(OnFrameChanged);
            inputContainer.Add(m_FrameField);

            SyncToViewModeSetting();

            RegisterCallback <AttachToPanelEvent>(OnAttachToPanel);
            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel);
        }
Example #4
0
        public TracingToolbar(GraphView graphView, Store store)
        {
            m_GraphView = graphView;
            m_Store     = store;

            name = "tracingToolbar";
            AddToClassList("gtf-toolbar");
            AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(PackageTransitionHelper.AssetPath + "VisualScripting/Editor/Plugins/Debugging/TracingToolbar.uxml").CloneTree(this);
            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(PackageTransitionHelper.AssetPath + "VisualScripting/Editor/Menu/VseMenu.uss"));
            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(PackageTransitionHelper.AssetPath + "VisualScripting/Editor/Plugins/Debugging/Tracing.uss"));

            m_PickTargetButton         = this.Q <Button>("pickTargetButton");
            m_PickTargetButton.tooltip = "Pick a target";
            m_PickTargetButton.clickable.clickedWithEventInfo += OnPickTargetButton;
            m_PickTargetLabel         = m_PickTargetButton.Q <Label>("pickTargetLabel");
            m_PickTargetLabel.tooltip = "Choose an entity trace to display";
            m_PickTargetIcon          = m_PickTargetButton.Q(null, "icon");

            m_FirstFrameTracingButton                    = this.Q <Button>("firstFrameTracingButton");
            m_FirstFrameTracingButton.tooltip            = "Go To First Frame";
            m_FirstFrameTracingButton.clickable.clicked += OnFirstFrameTracingButton;

            m_PreviousFrameTracingButton                    = this.Q <Button>("previousFrameTracingButton");
            m_PreviousFrameTracingButton.tooltip            = "Go To Previous Frame";
            m_PreviousFrameTracingButton.clickable.clicked += OnPreviousFrameTracingButton;

            m_PreviousStepTracingButton                    = this.Q <Button>("previousStepTracingButton");
            m_PreviousStepTracingButton.tooltip            = "Go To Previous Step";
            m_PreviousStepTracingButton.clickable.clicked += OnPreviousStepTracingButton;

            m_NextStepTracingButton                    = this.Q <Button>("nextStepTracingButton");
            m_NextStepTracingButton.tooltip            = "Go To Next Step";
            m_NextStepTracingButton.clickable.clicked += OnNextStepTracingButton;

            m_NextFrameTracingButton                    = this.Q <Button>("nextFrameTracingButton");
            m_NextFrameTracingButton.tooltip            = "Go To Next Frame";
            m_NextFrameTracingButton.clickable.clicked += OnNextFrameTracingButton;

            m_LastFrameTracingButton                    = this.Q <Button>("lastFrameTracingButton");
            m_LastFrameTracingButton.tooltip            = "Go To Last Frame";
            m_LastFrameTracingButton.clickable.clicked += OnLastFrameTracingButton;

            m_CurrentFrameTextField = this.Q <IntegerField>("currentFrameTextField");
            m_CurrentFrameTextField.AddToClassList("frameCounterLabel");
            m_CurrentFrameTextField.RegisterCallback <KeyDownEvent>(OnFrameCounterKeyDown);
            m_TotalFrameLabel = this.Q <Label>("totalFrameLabel");
            m_TotalFrameLabel.AddToClassList("frameCounterLabel");

            AddTracingTimeline();
        }
Example #5
0
        public FoldoutNumberField()
        {
            // Used for its dragger.
            var toggleInput = toggle.Q(className: "unity-toggle__input");

            m_DraggerIntegerField      = new IntegerField(" ");
            m_DraggerIntegerField.name = "dragger-integer-field";
            m_DraggerIntegerField.AddToClassList(k_DraggerFieldUssClassName);
            m_DraggerIntegerField.RegisterValueChangedCallback(OnDraggerFieldUpdate);
            toggleInput.Add(m_DraggerIntegerField);

            m_TextField           = new TextField();
            m_TextField.isDelayed = true; // only updates on Enter or lost focus
            m_TextField.AddToClassList(textUssClassName);
            header.hierarchy.Add(m_TextField);
        }
        public TracingToolbar(GraphView graphView, CommandDispatcher commandDispatcher) : base(commandDispatcher, graphView)
        {
            name = "tracingToolbar";
            AddToClassList(ussClassName);
            AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(AssetHelper.AssetPath + "Plugins/Debugging/TracingToolbar.uxml").CloneTree(this);
            styleSheets.Add(AssetDatabase.LoadAssetAtPath <StyleSheet>(AssetHelper.AssetPath + "Plugins/Debugging/Tracing.uss"));

            m_PickTargetButton         = this.SafeQ <Button>("pickTargetButton");
            m_PickTargetButton.tooltip = "Pick a target";
            m_PickTargetButton.clickable.clickedWithEventInfo += OnPickTargetButton;
            m_PickTargetLabel         = m_PickTargetButton.SafeQ <Label>("pickTargetLabel");
            m_PickTargetLabel.tooltip = "Choose an entity trace to display";
            m_PickTargetIcon          = m_PickTargetButton.SafeQ(null, "icon");

            m_FirstFrameTracingButton                    = this.SafeQ <Button>("firstFrameTracingButton");
            m_FirstFrameTracingButton.tooltip            = "Go To First Frame";
            m_FirstFrameTracingButton.clickable.clicked += OnFirstFrameTracingButton;

            m_PreviousFrameTracingButton                    = this.SafeQ <Button>("previousFrameTracingButton");
            m_PreviousFrameTracingButton.tooltip            = "Go To Previous Frame";
            m_PreviousFrameTracingButton.clickable.clicked += OnPreviousFrameTracingButton;

            m_PreviousStepTracingButton                    = this.SafeQ <Button>("previousStepTracingButton");
            m_PreviousStepTracingButton.tooltip            = "Go To Previous Step";
            m_PreviousStepTracingButton.clickable.clicked += OnPreviousStepTracingButton;

            m_NextStepTracingButton                    = this.SafeQ <Button>("nextStepTracingButton");
            m_NextStepTracingButton.tooltip            = "Go To Next Step";
            m_NextStepTracingButton.clickable.clicked += OnNextStepTracingButton;

            m_NextFrameTracingButton                    = this.SafeQ <Button>("nextFrameTracingButton");
            m_NextFrameTracingButton.tooltip            = "Go To Next Frame";
            m_NextFrameTracingButton.clickable.clicked += OnNextFrameTracingButton;

            m_LastFrameTracingButton                    = this.SafeQ <Button>("lastFrameTracingButton");
            m_LastFrameTracingButton.tooltip            = "Go To Last Frame";
            m_LastFrameTracingButton.clickable.clicked += OnLastFrameTracingButton;

            m_CurrentFrameTextField = this.SafeQ <IntegerField>("currentFrameTextField");
            m_CurrentFrameTextField.AddToClassList("frameCounterLabel");
            m_CurrentFrameTextField.RegisterCallback <KeyDownEvent>(OnFrameCounterKeyDown);
            m_TotalFrameLabel = this.SafeQ <Label>("totalFrameLabel");
            m_TotalFrameLabel.AddToClassList("frameCounterLabel");

            AddTracingTimeline();
        }
Example #7
0
        void CreateTracingMenu()
        {
            m_EnableTracingButton         = this.MandatoryQ <ToolbarToggle>("enableTracingButton");
            m_EnableTracingButton.tooltip = "Toggle Tracing For Current Instance";
            m_EnableTracingButton.SetValueWithoutNotify(m_Store.GetState().EditorDataModel.TracingEnabled);
            m_EnableTracingButton.RegisterValueChangedCallback(e => OnToggleTracing?.Invoke(e));

            m_PickTargetButton         = this.Q <Button>("pickTargetButton");
            m_PickTargetButton.tooltip = "Pick a target";
            m_PickTargetButton.clickable.clickedWithEventInfo += OnPickTargetButton;
            m_PickTargetLabel         = m_PickTargetButton.Q <Label>("pickTargetLabel");
            m_PickTargetLabel.tooltip = "Choose an entity trace to display";
            m_PickTargetIcon          = m_PickTargetButton.Q(null, "icon");

            m_FirstFrameTracingButton                    = this.Q <Button>("firstFrameTracingButton");
            m_FirstFrameTracingButton.tooltip            = "Go To First Frame";
            m_FirstFrameTracingButton.clickable.clicked += OnFirstFrameTracingButton;

            m_PreviousFrameTracingButton                    = this.Q <Button>("previousFrameTracingButton");
            m_PreviousFrameTracingButton.tooltip            = "Go To Previous Frame";
            m_PreviousFrameTracingButton.clickable.clicked += OnPreviousFrameTracingButton;

            m_PreviousStepTracingButton                    = this.Q <Button>("previousStepTracingButton");
            m_PreviousStepTracingButton.tooltip            = "Go To Previous Step";
            m_PreviousStepTracingButton.clickable.clicked += OnPreviousStepTracingButton;

            m_NextStepTracingButton                    = this.Q <Button>("nextStepTracingButton");
            m_NextStepTracingButton.tooltip            = "Go To Next Step";
            m_NextStepTracingButton.clickable.clicked += OnNextStepTracingButton;

            m_NextFrameTracingButton                    = this.Q <Button>("nextFrameTracingButton");
            m_NextFrameTracingButton.tooltip            = "Go To Next Frame";
            m_NextFrameTracingButton.clickable.clicked += OnNextFrameTracingButton;

            m_LastFrameTracingButton                    = this.Q <Button>("lastFrameTracingButton");
            m_LastFrameTracingButton.tooltip            = "Go To Last Frame";
            m_LastFrameTracingButton.clickable.clicked += OnLastFrameTracingButton;

            m_CurrentFrameTextField = this.Q <IntegerField>("currentFrameTextField");
            m_CurrentFrameTextField.AddToClassList("frameCounterLabel");
            m_CurrentFrameTextField.RegisterCallback <KeyDownEvent>(OnFrameCounterKeyDown);
            m_TotalFrameLabel = this.Q <Label>("totalFrameLabel");
            m_TotalFrameLabel.AddToClassList("frameCounterLabel");
        }
Example #8
0
        public Slider(int val, int min, int max, EventCallback <int> cb)
        {
            Callback = cb;
            Value    = val;

            contentContainer.AddToClassList("bounded-int");
            contentContainer.AddToClassList("range");

            Range = new SliderInt {
                highValue = max,
                lowValue  = min,
                value     = val
            };

            Min = new IntegerField {
                value = min
            };
            Current = new IntegerField {
                value = val
            };
            Max = new IntegerField {
                value = max
            };

            Min.AddToClassList("min-value");
            Current.AddToClassList("current-value");
            Max.AddToClassList("max-value");

            var Fields = new VisualElement();

            Fields.AddToClassList("input-fields");

            Fields.Add(Min);
            Fields.Add(Current);
            Fields.Add(Max);

            contentContainer.Add(Range);
            contentContainer.Add(Fields);

            Range.RegisterValueChangedCallback(CurrentChanged);
            Min.RegisterValueChangedCallback(MinChanged);
            Current.RegisterValueChangedCallback(CurrentChanged);
            Max.RegisterValueChangedCallback(MaxChanged);
        }
        internal override void Apply(VisualElement container)
        {
            /// <sample>
            // Get a reference to the field from UXML and assign it its value.
            var uxmlField = container.Q <IntegerField>("the-uxml-field");

            uxmlField.value = 42;

            // Create a new field, disable it, and give it a style class.
            var csharpField = new IntegerField("C# Field");

            csharpField.SetEnabled(false);
            csharpField.AddToClassList("some-styled-field");
            csharpField.value = uxmlField.value;
            container.Add(csharpField);

            // Mirror value of uxml field into the C# field.
            uxmlField.RegisterCallback <ChangeEvent <int> >((evt) =>
            {
                csharpField.value = evt.newValue;
            });
            /// </sample>
        }
Example #10
0
            public BoxModelElement(BoxType boxType, VisualElement content,
                                   VisualElement topTextFieldContainer, VisualElement bottomTextFieldContainer)
            {
                string title = "";

                switch (boxType)
                {
                case BoxType.Margin:
                    title = "margin";
                    break;

                case BoxType.Border:
                    title = "border";
                    break;

                case BoxType.Padding:
                    title = "padding";
                    break;
                }

                this.boxType = boxType;

                m_Title = new Label(title);
                m_Title.AddToClassList("box-model-title");

                m_CenterContent = content;
                m_CenterContent.AddToClassList("box-model-center-content");

                m_LeftTextField = new IntegerField();
                m_LeftTextField.AddToClassList("box-model-textfield");
                m_LeftTextField.RegisterValueChangedCallback(e => OnTextFieldValueChanged(e, SideChanged.Left));

                m_RightTextField = new IntegerField();
                m_RightTextField.AddToClassList("box-model-textfield");
                m_RightTextField.RegisterValueChangedCallback(e => OnTextFieldValueChanged(e, SideChanged.Right));

                m_TopTextField = new IntegerField();
                m_TopTextField.AddToClassList("box-model-textfield");
                m_TopTextField.RegisterValueChangedCallback(e => OnTextFieldValueChanged(e, SideChanged.Top));

                m_FakeTopTextField = new IntegerField();
                m_FakeTopTextField.AddToClassList("box-model-textfield");
                m_FakeTopTextField.visible = false;

                m_BottomTextField = new IntegerField();
                m_BottomTextField.AddToClassList("box-model-textfield");
                m_BottomTextField.RegisterValueChangedCallback(e => OnTextFieldValueChanged(e, SideChanged.Bottom));

                m_FakeBottomTextField = new IntegerField();
                m_FakeBottomTextField.AddToClassList("box-model-textfield");
                m_FakeBottomTextField.visible = false;

                m_Left = new VisualElement();
                m_Left.AddToClassList("box-model-side");
                m_Left.Add(m_LeftTextField);

                m_Right = new VisualElement();
                m_Right.AddToClassList("box-model-side");
                m_Right.Add(m_RightTextField);

                m_Center = new VisualElement();
                m_Center.AddToClassList("box-model-center");

                m_CenterTop = new VisualElement();
                m_CenterTop.AddToClassList("box-model-center-top");
                m_CenterTop.Add(m_FakeTopTextField);
                topTextFieldContainer.Add(m_TopTextField);

                m_CenterBottom = new VisualElement();
                m_CenterBottom.AddToClassList("box-model-center-bottom");
                m_CenterBottom.Add(m_FakeBottomTextField);
                bottomTextFieldContainer.Add(m_BottomTextField);

                m_Center.Add(m_CenterTop);
                m_Center.Add(m_CenterContent);
                m_Center.Add(m_CenterBottom);

                Add(m_Title);
                Add(m_Left);
                Add(m_Center);
                Add(m_Right);

                // Sync styles values
                schedule.Execute(SyncValues).Every(100);
            }
        public override VisualElement CreateInspectorGUI()
        {
            if (Selection.activeObject is null || Selection.objects.Length == 0)
            {
                return(base.CreateInspectorGUI());
            }
            if (!GetType().IsSubclassOf(typeof(ScriptableObject)) || categoryList is null || categoryList.Count == 0)
            {
                return(base.CreateInspectorGUI());
            }
            if (!idConfig.AAIConfiguration().enableCustomEditors)
            {
                return(base.CreateInspectorGUI());
            }

            var baseStyleSheet = idConfig.GetStyleSheet("AAIDefaultEditorBase");

            if (defaultStyleSheet is null)
            {
                defaultStyleSheet = idConfig.GetStyleSheet("AAIDefaultEditorStyle");
            }
            if (defaultStyleSheet is null)
            {
                Debug.Log("Could not locate AAIDefaultEditorStyle");
            }

            serializedObject.Update();

            defaultRoot = new VisualElement();

            defaultRoot.styleSheets.Add(baseStyleSheet);
            defaultRoot.styleSheets.Add(defaultStyleSheet);
            defaultRoot.AddToClassList("rootContainer");

            var boxContainer = new Box();

            boxContainer.AddToClassList("mainBoxContainer");

            if (beforeDefaultElements == null)
            {
                beforeDefaultElements = new VisualElement();
            }
            beforeDefaultElements.name = "beforeDefaultElements";
            beforeDefaultElements.AddToClassList("beforeDefaultElements");
            defaultRoot.Add(beforeDefaultElements);

            categoryList.ForEach(x =>
            {
                if (x is null)
                {
                    return;
                }
                x.AddToClassList("categoryFoldout");
                boxContainer.Add(x);
            });

            m_ScrollView = new ScrollView();
            boxContainer.Add(m_ScrollView);

            keyData = classDataDictionary.Keys.ToList();

            #region Property Iteration

            var property = serializedObject.GetIterator();
            if (property.NextVisible(true))
            {
                do
                {
                    // -- Shortening name for ease of typing -------------
                    var propPath = property.propertyPath;

                    // -- Skip over excluded fields ----------------------
                    if (excludedFields.Contains(propPath) && serializedObject.targetObject != null)
                    {
                        continue;
                    }

                    // -- Property row VisualElement ---------------------
                    var propertyRow    = new VisualElement();
                    var propertyColumn = new VisualElement();
                    propertyRow.AddToClassList("propertyRow");
                    propertyColumn.AddToClassList("propertyColumn");

                    // -- Property fallback field ------------------------
                    var propertyField = new PropertyField(property)
                    {
                        name = "PropertyField:" + propPath
                    };

                    // -- Determine if current property is field data ----
                    if (!classDataDictionary[Enumerable.First(keyData)].fieldDatas.Keys.Contains(propPath))
                    {
                        switch (propPath)
                        {
                        case "m_Script" when serializedObject.targetObject != null:
                            propertyField.visible = false;     // @formatter:off
                            propertyField.SetEnabled(false);
                            break;

                        default:
                            if (property.IsReallyArray() && serializedObject.targetObject != null)
                            {
                                var copiedProperty    = property.Copy();
                                var imDefaultProperty = new IMGUIContainer(() =>
                                {
                                    DoDrawDefaultIMGUIProperty(serializedObject, copiedProperty);
                                })
                                {
                                    name = propPath
                                };
                                m_ScrollView.Add(imDefaultProperty);
                            }
                            break;     // @formatter:on
                        }
                    }
                    else
                    {
                        var propertyData = classDataDictionary[Enumerable.First(keyData)].fieldDatas[propPath];
                        switch (propertyData.fieldInfo)
                        {
                        // -- String/TextField Elements --------------
                        case FieldInfo a when a.FieldType == typeof(string):
                        case FieldInfo b when b.FieldType == typeof(PropertyName):
                            if (defaultEditorDebug)
                            {
                                Debug.Log($"String: {propPath}");
                            }

                            var propertyTextLabel = new Label(property.displayName);
                            propertyTextLabel.name = $"{propPath}Label";
                            var propertyTextField = new TextField
                            {
                                bindingPath = propPath,
                                name        = $"{propPath}Text"
                            };

                            if (propertyData.categoryAttr.toolTip != "")
                            {
                                propertyTextLabel.tooltip = propertyData.categoryAttr.toolTip;
                                propertyTextField.tooltip = propertyData.categoryAttr.toolTip;
                            }

                            propertyTextLabel.AddToClassList("propertyTextLabel");
                            propertyTextField.AddToClassList("propertyTextField");
                            propertyRow.Add(propertyTextLabel);
                            propertyRow.Add(propertyTextField);
                            boxContainer.Q(propertyData.categoryAttr.category).Add(propertyRow);
                            break;

                        // -- Integer Elements -----------------------
                        case FieldInfo a when a.FieldType == typeof(int):
                            if (defaultEditorDebug)
                            {
                                Debug.Log($"Integer: {propPath}");
                            }
                            var propertyIntegerLabel = new Label(property.displayName);
                            propertyIntegerLabel.name = $"{propPath}Label";
                            var propertyIntegerField = new IntegerField
                            {
                                bindingPath = propPath,
                                name        = $"{propPath}Integer"
                            };

                            if (propertyData.categoryAttr.toolTip != "")
                            {
                                propertyIntegerLabel.tooltip = propertyData.categoryAttr.toolTip;
                                propertyIntegerField.tooltip = propertyData.categoryAttr.toolTip;
                            }

                            propertyIntegerLabel.AddToClassList("propertyIntegerLabel");
                            propertyIntegerField.AddToClassList("propertyIntegerField");
                            propertyRow.Add(propertyIntegerLabel);
                            propertyRow.Add(propertyIntegerField);
                            boxContainer.Q(propertyData.categoryAttr.category).Add(propertyRow);
                            break;

                        // -- Float Elements -------------------------
                        case FieldInfo a when a.FieldType == typeof(float):
                            if (defaultEditorDebug)
                            {
                                Debug.Log($"Float: {propPath}");
                            }

                            var propertyFloatLabel = new Label(property.displayName);
                            propertyFloatLabel.name = $"{propPath}Label";
                            var propertyFloatField = new FloatField
                            {
                                bindingPath = propPath,
                                name        = $"{propPath}Float"
                            };

                            if (propertyData.categoryAttr.toolTip != "")
                            {
                                propertyFloatLabel.tooltip = propertyData.categoryAttr.toolTip;
                                propertyFloatField.tooltip = propertyData.categoryAttr.toolTip;
                            }

                            propertyFloatLabel.AddToClassList("propertyFloatLabel");
                            propertyFloatField.AddToClassList("propertyFloatField");
                            propertyRow.Add(propertyFloatLabel);
                            propertyRow.Add(propertyFloatField);
                            boxContainer.Q(propertyData.categoryAttr.category).Add(propertyRow);
                            break;

                        // -- Bool/Toggle Elements -------------------
                        case FieldInfo a when a.FieldType == typeof(bool):
                        case FieldInfo b when b.FieldType == typeof(Toggle):
                            if (defaultEditorDebug)
                            {
                                Debug.Log($"Toggle: {propPath}");
                            }

                            var propertyToggleLabel = new Label(property.displayName);
                            propertyToggleLabel.name = $"{propPath}ToggleLabel";
                            var propertyToggleSpacer = new VisualElement();
                            var propertyToggleField  = new Toggle
                            {
                                bindingPath = propPath,
                                name        = $"{propPath}ToggleField"
                            };

                            if (propertyData.categoryAttr.toolTip != "")
                            {
                                propertyToggleLabel.tooltip = propertyData.categoryAttr.toolTip;
                                propertyToggleField.tooltip = propertyData.categoryAttr.toolTip;
                            }


                            propertyToggleLabel.AddToClassList("propertyToggleLabel");
                            propertyToggleLabel.AddToClassList("propertyToggleSpacer");
                            propertyToggleField.AddToClassList("propertyToggleField");
                            propertyRow.Add(propertyToggleLabel);
                            propertyRow.Add(propertyToggleField);
                            propertyRow.Add(propertyToggleSpacer);
                            propertyRow.RemoveFromClassList("propertyRow");
                            propertyRow.AddToClassList("propertyToggleRow");
                            boxContainer.Q(propertyData.categoryAttr.category).Add(propertyRow);
                            break;

                        // -- Dictionary Elements --------------------
                        case FieldInfo a when typeof(IDictionary).IsAssignableFrom(a.FieldType):
                        case FieldInfo b when typeof(IDictionary).IsSubclassOf(b.FieldType):
                            var dictionaryFoldout = new Foldout {
                                text = property.displayName
                            };
                            dictionaryFoldout.AddToClassList("arrayFoldout");
                            dictionaryFoldout.value = false;

                            if (propertyData.categoryAttr.toolTip != "")
                            {
                                dictionaryFoldout.tooltip = propertyData.categoryAttr.toolTip;
                                propertyColumn.tooltip    = propertyData.categoryAttr.toolTip;
                            }

                            dictionaryFoldout.Add(propertyField);
                            propertyColumn.Add(dictionaryFoldout);
                            boxContainer.Q(propertyData.categoryAttr.category).Add(propertyColumn);
                            break;

                        // -- List/Set Elements ----------------------
                        case FieldInfo a when typeof(IList).IsAssignableFrom(a.FieldType):
                        case FieldInfo b when typeof(IList).IsSubclassOf(b.FieldType):
                        case FieldInfo c when typeof(ISet <>).IsAssignableFrom(c.FieldType):
                        case FieldInfo d when typeof(ISet <>).IsSubclassOf(d.FieldType):
                            var arrayElementBuilder = new ArrayElementBuilder(property, propertyData);

                            if (propertyData.categoryAttr.toolTip != "")
                            {
                                propertyRow.tooltip = propertyData.categoryAttr.toolTip;
                            }

                            propertyRow.Add(arrayElementBuilder);
                            boxContainer.Q(propertyData.categoryAttr.category).Add(propertyRow);
                            break;

                        // -- Object Elements ----------------------
                        case FieldInfo a when a.FieldType == typeof(Object):
                        case FieldInfo b when typeof(Object).IsSubclassOf(b.FieldType):
                        case FieldInfo c when typeof(Object).IsAssignableFrom(c.FieldType):
                            var propertyObjectLabel = new Label(property.displayName);
                            propertyObjectLabel.name = $"{propPath}ObjectLabel";
                            var propertyObjectField = new ObjectField
                            {
                                objectType  = propertyData.fieldType,
                                bindingPath = propPath,
                                name        = $"{propPath}ObjectField"
                            };

                            if (propertyData.categoryAttr.toolTip != "")
                            {
                                propertyObjectLabel.tooltip = propertyData.categoryAttr.toolTip;
                                propertyObjectField.tooltip = propertyData.categoryAttr.toolTip;
                            }

                            propertyObjectLabel.AddToClassList("propertyObjectLabel");
                            propertyObjectField.AddToClassList("propertyObjectField");
                            propertyRow.Add(propertyObjectLabel);
                            propertyRow.Add(propertyObjectField);
                            boxContainer.Q(propertyData.categoryAttr.category).Add(propertyRow);
                            if (defaultEditorDebug)
                            {
                                Debug.Log($"Fallback Test: Name: {propPath} Type: {property.type} Array: {property.isArray} : {property.propertyType}");
                            }
                            break;

                        default:
                            if (property.IsReallyArray())
                            {
                                propertyColumn.Add(propertyField);
                                boxContainer.Q(propertyData.categoryAttr.category).Add(propertyColumn);
                            }

                            // else propertyColumn.Add(propertyField);
                            //
                            if (propertyData.categoryAttr.toolTip != "")
                            {
                                propertyColumn.tooltip = propertyData.categoryAttr.toolTip;
                            }

                            //
                            // boxContainer.Q(propertyData.categoryAttr.category).Add(propertyColumn);
                            break;
                        }
                    }
                } while (property.NextVisible(false));
            }

            #endregion

            foreach (var foldoutList in m_ScrollView.Query <Foldout>().ToList())
            {
                foldoutList.RegisterValueChangedCallback(e =>
                {
                    // TODO Remove this:
                    if (!(e.target is Foldout fd))
                    {
                        return;
                    }
                    Debug.Log($" {fd.name}");
                    var path      = fd.bindingPath;
                    var container = m_ScrollView.Q <IMGUIContainer>(path);
                    RecomputeSize(container);
                });
            }

            foreach (var foldoutList in m_ScrollView.Query <AnimatedFoldout>().ToList())
            {
                foldoutList.RegisterValueChangedCallback(e =>
                {
                    // TODO Remove this:
                    if (!(e.target is Foldout fd))
                    {
                        return;
                    }
                    Debug.Log($" {fd.name}");
                    var path      = fd.bindingPath;
                    var container = m_ScrollView.Q <IMGUIContainer>(path);
                    RecomputeSize(container);
                });
            }

            VisualElement defaultCategory = null;
            for (var i = 0; i < categoryList.Count; i++)
            {
                VisualElement x;
                if (isAnimated)
                {
                    x = categoryList[i].Q <AnimatedFoldout>();
                }
                else
                {
                    x = categoryList[i].Q <Foldout>();
                }
                if (x.name != "Default")
                {
                    continue;
                }
                defaultCategory = x;
                break;
            }

            if (defaultCategory.childCount == 0)
            {
                defaultCategory.style.display = DisplayStyle.None;
            }

            if (isAnimated)
            {
                var listItems = boxContainer.Query <AnimatedFoldout>().ToList();
                listItems.ForEach(x => foldout.Add((AnimatedFoldout)x));
            }
            else
            {
                var listItems = boxContainer.Query <Foldout>().ToList();
                listItems.ForEach(x => foldout.Add((Foldout)x));
            }

            foldout.ForEach(x =>
            {
                Toggle toggleItem;
                if (isAnimated)
                {
                    var item        = (AnimatedFoldout)x;
                    var contentItem = item.Q(null, AnimatedFoldout.expanderUssClassName);
                    contentItem.ToggleInClassList("categoryFoldoutClosed");
                    item.Q(null, "unity-toggle__checkmark").AddToClassList("toggleCheckmark");
                    item.RegisterCallback((ChangeEvent <bool> evt) =>
                    {
                        var targetElement = evt.target as VisualElement;

                        if (targetElement == item)
                        {
                            item.value = evt.newValue;
                        }

                        if (targetElement.parent == item || targetElement == item || targetElement.contentContainer == item)
                        {
                            item.value = evt.newValue;
                            // if (evt.newValue) item.contentContainer.style.display = DisplayStyle.Flex;

                            // if (!evt.newValue) // @formatter:off
                            // {
                            //     item.schedule.Execute(() =>
                            //     {
                            //         item.contentContainer.style.display = DisplayStyle.None;
                            //     }).StartingIn(500);
                            //     item.schedule.Execute(() =>
                            //     {
                            //         contentItem.style.display = DisplayStyle.None;
                            //     }).StartingIn(600); // @formatter:on
                            // }
                        }
                        else
                        {
                            item.expander.TriggerExpanderResize(true);
                        }
                    }); // @formatter:on
                }
                else
                {
                    var item   = (Foldout)x;
                    toggleItem = item.Q <Toggle>();
                    toggleItem.ToggleInClassList("categoryFoldoutClosed");
                    item.Q(null, "unity-toggle__checkmark").AddToClassList("toggleCheckmark");
                }
            });

            serializedObject.ApplyModifiedProperties();

            if (afterDefaultElements == null)
            {
                afterDefaultElements = new VisualElement();
            }
            afterDefaultElements.name = "afterDefaultElements";
            afterDefaultElements.AddToClassList("afterDefaultElements");

            boxContainer.Add(afterDefaultElements);
            defaultRoot.Add(boxContainer);

            defaultRoot.RegisterCallback <GeometryChangedEvent>(ExecutePostBuildTask);
            defaultRoot.schedule.Execute(ExecuteLocalDeferredTask).StartingIn(0);

            return(defaultRoot);
        }
Example #12
0
        // ######################## INITS ######################## //

        #region CONSTRUCTORS

        public ColorSlider()
        {
            // load styles
            styleSheets.Add(Resources.Load <StyleSheet>("ColorSlider_styles"));
            styleSheets.Add(Resources.Load <StyleSheet>("Styles"));

            // create and initialize gradient texture
            _gradientTexture = new Texture2D(2, 1, TextureFormat.RGBA32, false, QualitySettings.activeColorSpace == ColorSpace.Gamma)
            {
                hideFlags           = HideFlags.HideAndDontSave,
                wrapMode            = TextureWrapMode.Clamp,
                filterMode          = FilterMode.Bilinear,
                alphaIsTransparency = true
            };

            _gradientTexture.SetPixel(0, 0, Color.clear);
            _gradientTexture.SetPixel(1, 0, Color.clear);
            _gradientTexture.Apply();


            // set up alpha background
            TiledImage background = TiledImage.CreateBackground(Resources.Load <Texture2D>("Images/AlphaCheckerboard"));

            background.AddToClassList("unity-base-slider--horizontal");
            background.AddToClassList("unity-base-slider__tracker");
            background.style.backgroundColor = Color.clear;

            // set as child of the first element in the hierarchy of the slider
            IEnumerator <VisualElement> children = Children().GetEnumerator();

            children.MoveNext();
            children.Current.Add(background);
            children.Dispose();

            background.SendToBack();

            // add a field for the value to be displayed
            IntegerField valueField = new IntegerField();

            valueField.AddToClassList(UssClasses.FILL_HEIGHT);
            valueField.AddToClassList("color-slider-value-field");
            Add(valueField);

            // set up the background of the slider (unity calls this the tracker). This is what holds the gradient texture
            VisualElement tracker = this.Q("unity-tracker");

            tracker.AddToClassList(UssClasses.FULL);
            tracker.AddToClassList(UssClasses.NO_SLICE);
            tracker.style.backgroundImage = _gradientTexture;


            // set up the handle
            VisualElement handle = this.Q("unity-dragger");

            handle.AddToClassList("color-slider-handle");
            handle.AddToClassList(UssClasses.FILL_HEIGHT);
            handle.style.position = Position.Absolute;

#if UNITY_2019_3_OR_NEWER
            // remove handle border
            VisualElement handleBorder = this.Q("unity-dragger-border");
            handleBorder.visible = false;
#endif


            // set up the label
            labelElement.AddToClassList("color-slider-label");
            labelElement.AddToClassList(UssClasses.FILL_HEIGHT);

            // register callbacks
            this.RegisterValueChangedCallback(evt => valueField.SetValueWithoutNotify((int)evt.newValue));
            valueField.RegisterValueChangedCallback(evt =>
            {
                float clampedValue = Mathf.Clamp(evt.newValue, lowValue, highValue);
                valueField.SetValueWithoutNotify((int)clampedValue);
                value = clampedValue;
            });
        }