Example #1
0
        public JointField(Asset asset, SerializedProperty property, Asset.Metric metric)
        {
            m_Asset    = asset;
            m_Property = property;
            m_Metric   = metric;

            Foldout foldout = new Foldout {
                text = "Joints"
            };

            foldout.AddToClassList("jointToggle");
            foldout.value = property.isExpanded;
            Add(foldout);

            foldout.RegisterValueChangedCallback(evt => ToggleListVisibility());

            Add(m_ListView);
            m_ListView.AddToClassList("jointsListView");
            m_ListView.style.display = property.isExpanded ? DisplayStyle.Flex : DisplayStyle.None;
            Rebuild();

            RegisterCallback <AttachToPanelEvent>(OnAttachToPanel);
            RegisterCallback <DetachFromPanelEvent>(OnDetachFromPanel);

            focusable = true;

            m_ForceDisabled = false;
        }
Example #2
0
        void RegisterEvents()
        {
            itemHandler.clickable.clicked += OnClickHandler;
            expandToggle.RegisterValueChangedCallback(ToggleDisplayChildren);

            itemHandler.AddManipulator(new DragStarterManipulator(this, editor));
            itemHandler.AddManipulator(new DropTargetManipulator(editor, new DropTargetInfo(targetElement)));
        }
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            var root = new Foldout {
                value = property.isExpanded, text = property.displayName
            };

            root.RegisterValueChangedCallback(evt => property.isExpanded = evt.newValue);

            var name = new TextField("Shared Group Name");

            name.BindProperty(property.FindPropertyRelative("m_SharedGroupName"));
            root.Add(name);

            var group = new ObjectField("Shared Group")
            {
                allowSceneObjects = false, objectType = typeof(AddressableAssetGroup)
            };
            var groupProperty = property.FindPropertyRelative("m_SharedGroup");

            group.BindProperty(groupProperty);
            group.RegisterValueChangedCallback(evt => name.style.display = evt.newValue != null ? DisplayStyle.None : DisplayStyle.Flex);
            name.style.display = groupProperty.objectReferenceValue != null ? DisplayStyle.None : DisplayStyle.Flex;
            root.Add(group);

            var localeName = new TextField("Locale Group Name");

            localeName.BindProperty(property.FindPropertyRelative("m_LocaleGroupNamePattern"));
            root.Add(localeName);

            var localeGroupsProperty = property.FindPropertyRelative("m_LocaleGroups");
            var list = new ReorderableList(localeGroupsProperty)
            {
                CreateItemCallback = CreateItem,
                AddCallback        = ShowAddItemMenu,
                RemoveCallback     = RemoveItem,
                ReorderCallback    = MoveItem
            };

            root.Add(list);

            var readOnly = new Toggle("Read Only");

            readOnly.BindProperty(property.FindPropertyRelative("m_MarkEntriesReadOnly"));
            root.Add(readOnly);

            return(root);
        }
Example #4
0
        private void InitShaderInfoFoldout(Foldout fold, string name, bool defaultVal)
        {
            bool val;

            if (this.foldoutInfo.TryGetValue(name, out val))
            {
                fold.value = val;
            }
            else
            {
                fold.value = defaultVal;
            }
            fold.RegisterValueChangedCallback((changed) =>
            {
                this.foldoutInfo[name] = changed.newValue;
            });
        }
Example #5
0
        public override VisualElement Draw(object source, Type type, string label = "", Action <object> onValueChanged = null)
        {
            var control = new OdinValueView()
            {
                Label       = label,
                Value       = source as Object,
                IsOpen      = false,
                AssetAction = onValueChanged,
            };

            var odinView = control.View;

            var view = base.Draw(source, type, label, x => {
                control.Value = x as Object;
                onValueChanged?.Invoke(x);
            });

            var row = new VisualElement();

            var container = new VisualElement()
            {
                style =
                {
                    flexDirection = new StyleEnum <FlexDirection>()
                    {
                        value     = FlexDirection.Row,
                    },
                }
            };

            var foldout = new Foldout();

            {
            }
            container.Add(foldout);
            container.Add(view);

            row.Add(container);
            row.Add(control.View);

            foldout.RegisterValueChangedCallback(x => odinView.visible = x.newValue);

            return(container);
        }
Example #6
0
        protected void AddFoldout(GUIContent content, Func <bool> getter, Action <bool> setter)
        {
            var foldout = new Foldout()
            {
                value   = getter(),
                text    = content.text,
                tooltip = content.tooltip
            };

            foldout.RegisterValueChangedCallback((evt) => {
                setter(evt.newValue);
                onChange();
            });

            // Apply padding:
            foldout.style.paddingLeft = context.globalIndentLevel * 15;

            context.Add(foldout);
        }
        private static Foldout CreateFoldoutInspector(VisualElement element, string title, string foldoutEditorPref)
        {
            var foldout = new Foldout();

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

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

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

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

            return(foldout);
        }
Example #8
0
        public ExpandableElement()
        {
            this.Remove(variableNameText);
            title = new VisualElement
            {
                style =
                {
                    flexDirection = FlexDirection.Row,
                }
            };
            foldout = new Foldout()
            {
                //style =
                //{
                //    color = new StyleColor(Color.white),
                //}
            };
            foldout.value = true;
            foldout.RegisterValueChangedCallback((e) =>
            {
                if (e.newValue)
                {
                    this.Add(elementsContent);
                }
                else
                {
                    this.Remove(elementsContent);
                }
            });
            title.Add(foldout);
            title.Add(variableNameText);
            foldout.style.right          = 18;
            variableNameText.style.right = 18;

            elementsContent = new VisualElement();

            this.Add(title);
            this.Add(elementsContent);
        }
Example #9
0
        public KeyCodeNode()
        {
            Initialize("KeyCode", DefaultNodePosition);

            var foldout = new Foldout();

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

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

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

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

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

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

            valuePort.portName = "keyCode";
            AddOutputPort(valuePort, () => $"KeyCode.{KeyCode}");
            Refresh();
        }
        VisualElement GetSettings(GraphData graphData, Action onChange)
        {
            var element = new VisualElement()
            {
                name = "graphSettings"
            };

            if (graphData.isSubGraph)
            {
                return(element);
            }

            void RegisterActionToUndo(string actionName)
            {
                graphData.owner.RegisterCompleteObjectUndo(actionName);
            }

            // Add Label
            var targetSettingsLabel = new Label("Target Settings");

            targetSettingsLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
            element.Add(new PropertyRow(targetSettingsLabel));

            var targetNameList = graphData.validTargets.Select(x => x.displayName);

            element.Add(new PropertyRow(new Label("Targets")), (row) =>
            {
                row.Add(new IMGUIContainer(() => {
                    EditorGUI.BeginChangeCheck();
                    var activeTargetBitmask = EditorGUILayout.MaskField(graphData.activeTargetBitmask, targetNameList.ToArray(), GUILayout.Width(100f));
                    if (EditorGUI.EndChangeCheck())
                    {
                        RegisterActionToUndo("Change active Targets");
                        graphData.activeTargetBitmask = activeTargetBitmask;
                        graphData.UpdateActiveTargets();
                        m_postChangeTargetSettingsCallback();
                    }
                }));
            });


            // Initialize from the active targets whenever user changes them
            // Is there a way to retain order even with that?
            if (userOrderedTargetNameList.Count != graphData.activeTargets.Count())
            {
                var activeTargetNames = graphData.activeTargets.Select(x => x.displayName);
                userOrderedTargetNameList = activeTargetNames.ToList();
            }

            var reorderableTextListView = new ReorderableListView <string>(userOrderedTargetNameList);

            reorderableTextListView.OnListReorderedCallback += list =>
            {
                userOrderedTargetNameList = (List <string>)list;
                onChange();
            };
            element.Add(reorderableTextListView);

            // Iterate active TargetImplementations
            foreach (var targetName in reorderableTextListView.TextList)
            {
                // Ensure enabled state is being tracked and get value
                bool foldoutActive = true;
                if (!m_TargetFoldouts.TryGetValue(targetName, out foldoutActive))
                {
                    m_TargetFoldouts.Add(targetName, foldoutActive);
                }

                // Create foldout
                var foldout = new Foldout()
                {
                    text = targetName, value = foldoutActive, name = "foldout"
                };
                element.Add(foldout);
                foldout.AddToClassList("MainFoldout");
                foldout.RegisterValueChangedCallback(evt =>
                {
                    // Update foldout value and rebuild
                    m_TargetFoldouts[targetName] = evt.newValue;
                    foldout.value = evt.newValue;
                    onChange();
                });

                if (foldout.value)
                {
                    var target = graphData.validTargets.Find(x => x.displayName == targetName);
                    // Get settings for Target
                    var context = new TargetPropertyGUIContext();
                    target.GetPropertiesGUI(ref context, onChange, RegisterActionToUndo);
                    element.Add(context);
                }
            }

            return(element);
        }
Example #11
0
        VisualElement GetSettings(GraphData graphData, Action onChange)
        {
            var element = new VisualElement()
            {
                name = "graphSettings"
            };

            if (graphData.isSubGraph)
            {
                return(element);
            }

            void RegisterActionToUndo(string actionName)
            {
                graphData.owner.RegisterCompleteObjectUndo(actionName);
            }

            // Add Label
            var targetSettingsLabel = new Label("Target Settings");

            targetSettingsLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
            element.Add(new PropertyRow(targetSettingsLabel));

            var targetList = new ReorderableListView <JsonData <Target> >(
                graphData.m_ActiveTargets,
                "Active Targets",
                false,      // disallow reordering (active list is sorted)
                target => target.value.displayName);

            targetList.GetAddMenuOptions = () => graphData.GetPotentialTargetDisplayNames();

            targetList.OnAddMenuItemCallback +=
                (list, addMenuOptionIndex, addMenuOption) =>
            {
                RegisterActionToUndo("Add Target");
                graphData.SetTargetActive(addMenuOptionIndex);
                m_postChangeTargetSettingsCallback();
            };

            targetList.RemoveItemCallback +=
                (list, itemIndex) =>
            {
                RegisterActionToUndo("Remove Target");
                graphData.SetTargetInactive(list[itemIndex].value);
                m_postChangeTargetSettingsCallback();
            };

            element.Add(targetList);

            // Iterate active TargetImplementations
            foreach (var target in graphData.activeTargets)
            {
                // Ensure enabled state is being tracked and get value
                bool foldoutActive;
                if (!m_TargetFoldouts.TryGetValue(target, out foldoutActive))
                {
                    foldoutActive = true;
                    m_TargetFoldouts.Add(target, foldoutActive);
                }

                // Create foldout
                var foldout = new Foldout()
                {
                    text = target.displayName, value = foldoutActive, name = "foldout"
                };
                element.Add(foldout);
                foldout.AddToClassList("MainFoldout");
                foldout.RegisterValueChangedCallback(evt =>
                {
                    // Update foldout value and rebuild
                    m_TargetFoldouts[target] = evt.newValue;
                    foldout.value            = evt.newValue;
                    onChange();
                });

                if (foldout.value)
                {
                    // Get settings for Target
                    var context = new TargetPropertyGUIContext();
                    target.GetPropertiesGUI(ref context, onChange, RegisterActionToUndo);
                    element.Add(context);
                }
            }

            return(element);
        }
Example #12
0
        protected sealed override void SetupUI()
        {
            var replicatorRowAsset = AssetDatabase.LoadAssetAtPath <VisualTreeAsset>(k_ReplicatorRowPath);

            replicatorRowAsset.CloneTree(this);

            base.SetupUI();

            m_ContentContainer = this.Q <VisualElement>(k_ContentContainerName);

            m_Foldout = this.Q <Foldout>(k_RowFoldoutName);
            m_Foldout.RegisterValueChangedCallback(evt =>
            {
                var expanded = evt.newValue;
                m_ContentContainer.style.display = expanded ? DisplayStyle.Flex : DisplayStyle.None;
                if (expanded)
                {
                    RulesModule.CollapsedNodes.Remove(BackingObject);
                }
                else
                {
                    RulesModule.CollapsedNodes.Add(BackingObject);
                }

                RulesDrawer.BuildReplicatorsList();
            });

            m_Foldout.RegisterCallback <ExecuteCommandEvent>(RulesModule.PickObject);

            if (IsGroup)
            {
                m_Foldout.visible = false;
            }
            else
            {
                var expanded = !RulesModule.CollapsedNodes.Contains(BackingObject);
                m_Foldout.value = expanded;
                m_ContentContainer.style.display = expanded ? DisplayStyle.Flex : DisplayStyle.None;
            }

            m_MatchCountEnum = this.Q <EnumField>(k_MatchCountEnum);
            m_MatchCountEnum.Init(RulesModule.ReplicatorCountOption.Every);
            m_MatchCountEnum.RegisterCallback <ChangeEvent <System.Enum> >(OnChangeMatchCountDropdown);

            m_MaxCountField = this.Q <IntegerField>(k_MaxInstancesName);
            m_MaxCountField.RegisterValueChangedCallback(OnMaxInstanceChanged);

            m_MaxCountField.RegisterCallback <ExecuteCommandEvent>(RulesModule.PickObject);

            SetupProxyPresetUI(m_Entity);

            m_GroupDrillInButton          = this.Q <Button>(k_GroupDrillIn);
            m_GroupDrillInButton.clicked += () =>
            {
                var ruleSet = m_Entity.GetComponent <ProxyRuleSet>();
                RulesModule.RuleSetInstance = ruleSet;
                RulesDrawer.BuildReplicatorsList();
            };

            if (!IsGroup)
            {
                m_GroupDrillInButton.style.display = DisplayStyle.None;
            }

            m_SimMatchCount = this.Q <Label>(k_SimMatchCountName);

            SetupReplicatorRow();

            if (IsGroup)
            {
                m_AddButtonHoverElement.SetEnabled(false);
            }

            CreateAddContentButton();

            RegisterCallback <KeyDownEvent>(OnKeyDown);
        }
Example #13
0
    private void PopulatePresetList()
    {
        ListView list = rootVisualElement.Q <ListView>("ListView");

        list.Clear();

        string lowerFilterValue = this._filterValue.ToLowerInvariant();

        List <ScriptableSettings> settings = GetScriptableSettingFilteredByTags();

        List <BaseRuntimeScriptableSingleton> baseScriptableSingletons = (includeSS.value)? GetScriptableObjectsFilteredByTags(): new List <BaseRuntimeScriptableSingleton>();

        List <ScriptableObject> scriptableObjects = new List <ScriptableObject>(settings);

        scriptableObjects.AddRange(baseScriptableSingletons);
        scriptableObjects.Sort(SettinsSorter);
        for (int i = 0; i < scriptableObjects.Count; i++)
        {
            if (scriptableObjects[i] is ScriptableSettings scriptableSettingsA)
            {
                if (!scriptableSettingsA.TabName.ToLowerInvariant().Contains(lowerFilterValue))
                {
                    continue;
                }
            }
            else if (!scriptableObjects[i].name.ToLowerInvariant().Contains(lowerFilterValue))
            {
                continue;
            }

            VisualElement listContainer = new VisualElement {
                name = "ListContainer"
            };
            Button button = new Button
            {
                text = scriptableObjects[i] is ScriptableSettings scriptableSettingsB
                    ? scriptableSettingsB.TabName           //Es un Settings
                    : scriptableObjects[i].name             //Es un RuntimeSingleton
            };

            //Applying a CSS class to an element
            button.AddToClassList("ListLabel");
            listContainer.Add(button);

            //Inserting element into list
            list.Insert(list.childCount, listContainer);
            ScriptableObject value = scriptableObjects[i];

            if (_selection == value)
            {
                button.style.backgroundColor = new StyleColor(new Color(0.25f, 0.35f, 0.6f, 1f));
                UnityEditor.Editor editor = UnityEditor.Editor.CreateEditor(value);
                rootVisualElement.Q <IMGUIContainer>("Target").onGUIHandler = () => editor.OnInspectorGUI();
                Foldout tagFoldout = rootVisualElement.Q <Foldout>("SettingTagsSelection");

                CreateSettingTagsFoldout(ref tagFoldout, value, _isTagFoldoutOpen);

                tagFoldout.name = "SettingTagsSelection";
                tagFoldout.RegisterValueChangedCallback(x => _isTagFoldoutOpen = x.newValue);
                rootVisualElement.Q <VisualElement>("RightPanel").Add(tagFoldout);
            }

            button.clicked += () => UpdateSelection(value);
            if (value is ScriptableSettings scriptableSettings)
            {
                SetContextMenuManipulator(button, scriptableSettings);
            }
        }
    }
Example #14
0
        public GetComponentNode()
        {
            Initialize("Get Component", DefaultNodePosition);

            var foldout = new Foldout();

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

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

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

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

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

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

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

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

            valuePort.portName = "component";
            AddOutputPort(valuePort, () => $"{InputPortDictionary[inputPort].RequestCode()}.GetComponent<{ComponentType}>()");
            Refresh();
        }
        VisualElement GetSettings(GraphData graphData, Action onChange)
        {
            var element = new VisualElement()
            {
                name = "graphSettings"
            };

            if (graphData.isSubGraph)
            {
                return(element);
            }

            void RegisterActionToUndo(string actionName)
            {
                graphData.owner.RegisterCompleteObjectUndo(actionName);
            }

            // Add Label
            var targetSettingsLabel = new Label("Target Settings");

            targetSettingsLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
            element.Add(new PropertyRow(targetSettingsLabel));

            var targetList = new ReorderableListView <JsonData <Target> >(
                graphData.m_ActiveTargets,
                "Active Targets",
                false,      // disallow reordering (active list is sorted)
                target => target.value.displayName);

            targetList.GetAddMenuOptions = () => graphData.GetPotentialTargetDisplayNames();

            targetList.OnAddMenuItemCallback +=
                (list, addMenuOptionIndex, addMenuOption) =>
            {
                RegisterActionToUndo("Add Target");
                graphData.SetTargetActive(addMenuOptionIndex);
                m_postChangeTargetSettingsCallback();
            };

            targetList.RemoveItemCallback +=
                (list, itemIndex) =>
            {
                RegisterActionToUndo("Remove Target");
                graphData.SetTargetInactive(list[itemIndex].value);
                m_postChangeTargetSettingsCallback();
            };

            element.Add(targetList);

            // Iterate active TargetImplementations
            foreach (var target in graphData.activeTargets)
            {
                // Ensure enabled state is being tracked and get value
                bool foldoutActive;
                if (!m_TargetFoldouts.TryGetValue(target, out foldoutActive))
                {
                    foldoutActive = true;
                    m_TargetFoldouts.Add(target, foldoutActive);
                }

                // Create foldout
                var foldout = new Foldout()
                {
                    text = target.displayName, value = foldoutActive, name = "foldout"
                };
                element.Add(foldout);
                foldout.AddToClassList("MainFoldout");
                foldout.RegisterValueChangedCallback(evt =>
                {
                    // Update foldout value and rebuild
                    m_TargetFoldouts[target] = evt.newValue;
                    foldout.value            = evt.newValue;
                    onChange();
                });

                if (foldout.value)
                {
                    // Get settings for Target
                    var context = new TargetPropertyGUIContext();
                    // Indent the content of the foldout
                    context.globalIndentLevel++;
                    target.GetPropertiesGUI(ref context, onChange, RegisterActionToUndo);
                    context.globalIndentLevel--;
                    element.Add(context);
                }
            }

#if VFX_GRAPH_10_0_0_OR_NEWER
            // Inform the user that VFXTarget is deprecated, if they are using one.
            var activeTargetSRP = graphData.m_ActiveTargets.Where(t => !(t.value is VFXTarget));
            if (graphData.m_ActiveTargets.Any(t => t.value is VFXTarget) && //Use Old VFXTarget
                activeTargetSRP.Any() &&
                activeTargetSRP.All(o => o.value.CanSupportVFX()))
            {
                var vfxWarning = new HelpBoxRow(MessageType.Info);

                var vfxWarningLabel = new Label("The Visual Effect target is deprecated.\n" +
                                                "Use the SRP target(s) instead, and enable 'Support VFX Graph' in the Graph Inspector.\n" +
                                                "Then, you can remove the Visual Effect Target.");

                vfxWarningLabel.style.color      = new StyleColor(Color.white);
                vfxWarningLabel.style.whiteSpace = WhiteSpace.Normal;

                vfxWarning.Add(vfxWarningLabel);
                element.Add(vfxWarning);
            }
#endif

            return(element);
        }
Example #16
0
        public override VisualElement CreatePropertyGUI(SerializedProperty property)
        {
            VisualElement root = new VisualElement();

            Foldout foldout = new Foldout {
                text = property.displayName, value = property.isExpanded
            };

            foldout.RegisterValueChangedCallback((evt) => { property.isExpanded = foldout.value; });

            elements = new VisualElement();
            foldout.contentContainer.Add(elements);

            enabled     = new PropertyField(property.FindPropertyRelative("enabled"));
            randomPitch = new PropertyField(property.FindPropertyRelative("randomPitch"));
            pitch       = new PropertyField(property.FindPropertyRelative("pitch"));

            randomPitchElements = new VisualElement();
            randomPitchElements.AddToClassList("unity-property-field");

            VisualElement basePitchFields = new VisualElement();

            basePitchFields.AddToClassList("unity-base-field");
            basePitchFields.AddToClassList("unity-base-text-field");
            basePitchFields.AddToClassList("unity-float-field");

            Label pitchLabel = new Label("Pitch");

            pitchLabel.AddToClassList("unity-text-element");
            pitchLabel.AddToClassList("unity-label");
            pitchLabel.AddToClassList("unity-base-field__label");
            pitchLabel.AddToClassList("unity-base-text-field__label");
            pitchLabel.AddToClassList("unity-float-field__label");
            pitchLabel.AddToClassList("unity-property-field__label");

            FloatField minPitchField = new FloatField
            {
                bindingPath = property.FindPropertyRelative("minPitch").propertyPath,
            };

            minPitchField.style.flexGrow = 1;
            minPitchField.AddToClassList("unity-property-field__input");

            FloatField maxPitchField = new FloatField
            {
                bindingPath = property.FindPropertyRelative("maxPitch").propertyPath,
            };

            maxPitchField.style.flexGrow = 1;
            maxPitchField.AddToClassList("unity-property-field__input");

            VisualElement pitchFields = new VisualElement()
            {
                name = "pitch-fields"
            };

            pitchFields.style.flexDirection = FlexDirection.Row;
            pitchFields.style.flexGrow      = 1;

            Label minLabel = new Label("Min");

            minLabel.AddToClassList("unity-text-element");
            minLabel.AddToClassList("unity-label");
            minLabel.style.unityTextAlign = TextAnchor.MiddleLeft;

            pitchFields.Add(minLabel);
            pitchFields.Add(minPitchField);

            Label maxLabel = new Label("Max");

            maxLabel.AddToClassList("unity-text-element");
            maxLabel.AddToClassList("unity-label");
            maxLabel.style.unityTextAlign = TextAnchor.MiddleLeft;

            pitchFields.Add(maxLabel);
            pitchFields.Add(maxPitchField);

            basePitchFields.Add(pitchLabel);
            basePitchFields.Add(pitchFields);

            randomPitchElements.Add(basePitchFields);

            changeVolume = new PropertyField(property.FindPropertyRelative("changeVolume"));
            volume       = new PropertyField(property.FindPropertyRelative("volume"));
            audioClips   = new PropertyField(property.FindPropertyRelative("audioClips"));

            elements.Add(enabled);
            elements.Add(randomPitch);
            elements.Add(pitch);
            elements.Add(randomPitchElements);
            elements.Add(changeVolume);
            elements.Add(volume);
            elements.Add(audioClips);

            enabled.RegisterCallback <ChangeEvent <bool> >(x => ToggleEnabled(x.newValue));
            randomPitch.RegisterCallback <ChangeEvent <bool> >(x => ToggleRandomPitch(x.newValue));
            changeVolume.RegisterCallback <ChangeEvent <bool> >(x => ToggleVolume(x.newValue));

            ToggleEnabled(property.FindPropertyRelative("enabled").boolValue);
            ToggleRandomPitch(property.FindPropertyRelative("randomPitch").boolValue);
            ToggleVolume(property.FindPropertyRelative("changeVolume").boolValue);

            root.Add(foldout);

            return(root);
        }
        private void Build()
        {
            var template = Resources.Load <VisualTreeAsset>(Resource.MODEL_COLOUR_EDITOR_TEMPLATE);
            var styles   = Resources.Load <StyleSheet>(Resource.MODEL_COLOUR_STYLES);

            template.CloneTree(rootVisualElement);
            rootVisualElement.styleSheets.Add(styles);

            if (EditorGUIUtility.isProSkin)
            {
                rootVisualElement.AddToClassList("dark-theme");
            }

            // Get references

            _tabEditorButton            = rootVisualElement.Q <Button>("tabEditorButton");
            _tabEditorButton.clicked   += OnTabEditorButtonClicked;
            _tabSettingsButton          = rootVisualElement.Q <Button>("tabSettingsButton");
            _tabSettingsButton.clicked += OnTabSettingsButtonClicked;
            _tabEditor   = rootVisualElement.Q <VisualElement>("tabEditor");
            _tabSettings = rootVisualElement.Q <VisualElement>("tabSettings");
            UpdateTabs();

            _modelField            = rootVisualElement.Q <ObjectField>("selectionModel");
            _modelField.objectType = typeof(GameObject);

            _meshField            = rootVisualElement.Q <ObjectField>("selectionMesh");
            _meshField.objectType = typeof(Mesh);

            _modelsSelected              = rootVisualElement.Q <VisualElement>("selectionModelsSelected");
            _modelsSelectedCountElement  = _modelsSelected.Q <TextElement>("selectionModelsSelectedCount");
            _meshesSelected              = rootVisualElement.Q <VisualElement>("selectionMeshesSelected");
            _meshesSelectedCountElement  = _meshesSelected.Q <TextElement>("selectionMeshesSelectedCount");
            _sceneReferences             = rootVisualElement.Q <VisualElement>("selectionSceneReference");
            _sceneReferencesCountElement = _sceneReferences.Q <TextElement>("selectionSceneReferenceCount");

            _influencesModelVertexColours    = rootVisualElement.Q <TextElement>("influencesModelVertexColours");
            _influencesModelMaterialColours  = rootVisualElement.Q <TextElement>("influencesModelMaterialColours");
            _influencesCustomOverrideColours = rootVisualElement.Q <TextElement>("influencesCustomOverrideColours");

            _previewColorElement = rootVisualElement.Q <ModelColourEditorPreviewElement>("previewColor");
            _previewColorElement.setOverrideColorEvent  += color => _colourPicker.value = color;
            _previewColorElement.onSelectionChangeEvent += (hasSelection, hasColourSlotSelection) =>
            {
                _setColourButton.SetEnabled(hasSelection && _hasSelection);
                _removeColourButton.SetEnabled(hasColourSlotSelection && _hasEditorVertexColour);
                _colourPickerSetColourButton.SetEnabled(hasSelection && _hasSelection);
            };

            _previewModel = rootVisualElement.Q <IMGUIContainer>("previewModel");
            _previewModel.onGUIHandler = OnDrawPreviewModelGUI;

            _colourPicker = rootVisualElement.Q <ColorField>("setColourColourPicker");

            _setColourButton             = rootVisualElement.Q <Button>("setColourButton");
            _setColourButton.clicked    += SetColour;
            _removeColourButton          = rootVisualElement.Q <Button>("removeColourButton");
            _removeColourButton.clicked += RemoveColour;

            _importMaterialColoursGroup = rootVisualElement.Q <VisualElement>("importMaterialColoursGroup");
            _allMaterialColoursGroup    = rootVisualElement.Q <VisualElement>("allMaterialColoursGroup");
            var enableAllMaterialColoursButton  = rootVisualElement.Q <Button>("enableAllMaterialColoursButton");
            var disableAllMaterialColoursButton = rootVisualElement.Q <Button>("disableAllMaterialColoursButton");
            var resetAllMaterialColoursButton   = rootVisualElement.Q <Button>("resetAllMaterialColoursButton");

            enableAllMaterialColoursButton.clicked  += EnableMaterialColours;
            disableAllMaterialColoursButton.clicked += DisableMaterialColours;
            resetAllMaterialColoursButton.clicked   += ResetMaterialColours;

            _colourPickerAsset            = rootVisualElement.Q <ObjectField>("colourPickerAsset");
            _colourPickerAsset.objectType = typeof(AbstractColourPickerTool);
            _colourPickerAsset.RegisterValueChangedCallback(evt => OnColourPickerChanged(evt.newValue));

            _colourPickerAssetFoldout = rootVisualElement.Q <Foldout>("colourPickerAssetFoldout");
            _colourPickerAssetFoldout.RegisterValueChangedCallback(OnColourPickerFoldoutChanged);

            _colourPickerSetColourButton          = rootVisualElement.Q <Button>("colourPickerSetColourButton");
            _colourPickerSetColourButton.clicked += SetColourPickerColours;

            _colourPickerNewButton = rootVisualElement.Q <Button>("newColourPickerButton");
            BuildNewColourPickerMenu();
            _colourPickerNewButton.RegisterCallback <MouseDownEvent>(NewColourPicker);

            _colourPickerInlineScriptableObject = rootVisualElement.Q <IMGUIContainer>("colourPickerInlineScriptableObject");
            _colourPickerInlineScriptableObject.onGUIHandler = OnColourPickerInlineScriptableObjectInspectorGUI;

            _reimportedSelectedButton          = rootVisualElement.Q <Button>("reimportedSelectedButton");
            _reimportedSelectedButton.clicked += ReimportSelected;

            OnSelectionChanged();
        }
        public TransitionInspector()
        {
            text = "Transition";

            _scrollView = new ScrollView(ScrollViewMode.Vertical);
            _scrollView.AddToClassList("content");
            Add(_scrollView);

            Foldout transitionsFoldout = new Foldout()
            {
                value = true, text = "Transitions"
            };

            transitionsFoldout.RegisterValueChangedCallback(e => e.StopPropagation());
            _scrollView.Add(transitionsFoldout);

            _transitions            = new ResizableListView();
            _transitions.name       = "Transitions";
            _transitions.itemHeight = 20;
            _transitions.makeItem   = () =>
            {
                VisualElement container = new VisualElement();

                Label label = new Label()
                {
                    pickingMode = PickingMode.Ignore
                };
                Button removeButton = new Button()
                {
                    text = "X"
                };

                container.Add(label);
                container.Add(removeButton);

                return(container);
            };
            _transitions.bindItem = (item, index) =>
            {
                void Remove()
                {
                    _connection.RemoveTransition(index);
                }

                item.Q <Label>().text = $"{((IStateNode)_connection.Source).Name} >>> {((StateNodeUI)_connection.Destination).Name}";
                Button removeButton = item.Q <Button>();
                removeButton.clicked -= Remove;
                removeButton.clicked += Remove;
            };
            _transitions.onSelectionChange += selection =>
            {
                _selectedTransition = (TransitionInfo)selection.First();
                BindTransitionFields(_selectedTransition);
            };
            _transitions.selectionType = SelectionType.Single;
            _transitions.reorderable   = true;

            transitionsFoldout.Add(_transitions);

            DurationTypeField = new EnumField("Duration Type", DurationType.Fixed);
            DurationTypeField.RegisterValueChangedCallback(e =>
            {
                _selectedTransition.DurationType = (DurationType)e.newValue;
                DurationField.label = (DurationType)e.newValue == DurationType.Fixed ? "Duration (s)" : "Duration (%)";
            });
            _scrollView.Add(DurationTypeField);

            DurationField = new FloatField("Duration (s)");
            DurationField.RegisterValueChangedCallback(e => _selectedTransition.Duration = e.newValue);
            _scrollView.Add(DurationField);

            OffsetTypeField = new EnumField("Offset Type", DurationType.Fixed);
            OffsetTypeField.RegisterValueChangedCallback(e =>
            {
                _selectedTransition.OffsetType = (DurationType)e.newValue;
                OffsetField.label = (DurationType)e.newValue == DurationType.Fixed ? "Offset (s)" : "Offset (%)";
            });
            _scrollView.Add(OffsetTypeField);

            OffsetField = new FloatField("Offset (s)");
            OffsetField.RegisterValueChangedCallback(e => _selectedTransition.Offset = e.newValue);
            _scrollView.Add(OffsetField);

            InterruptionSourceField = new EnumField("Interruption Source", TransitionInterruptionSource.None);
            InterruptionSourceField.RegisterValueChangedCallback(e =>
            {
                TransitionInterruptionSource interruptionSource = (TransitionInterruptionSource)e.newValue;
                _selectedTransition.InterruptionSource          = interruptionSource;

                if (interruptionSource == TransitionInterruptionSource.None || interruptionSource == TransitionInterruptionSource.NextState)
                {
                    OrderedInterruptionToggle.style.display = DisplayStyle.None;
                }
                else
                {
                    OrderedInterruptionToggle.style.display = DisplayStyle.Flex;
                }
            });
            _scrollView.Add(InterruptionSourceField);

            OrderedInterruptionToggle = new Toggle("Ordered Interruption");
            OrderedInterruptionToggle.RegisterValueChangedCallback(e =>
            {
                _selectedTransition.OrderedInterruption = e.newValue;
                e.StopPropagation();
            });
            OrderedInterruptionToggle.style.display = DisplayStyle.None;
            _scrollView.Add(OrderedInterruptionToggle);

            InterruptableByAnyStateToggle = new Toggle("Interruptable By Any State");
            InterruptableByAnyStateToggle.RegisterValueChangedCallback(e =>
            {
                _selectedTransition.InterruptableByAnyState = e.newValue;
                e.StopPropagation();
            });
            _scrollView.Add(InterruptableByAnyStateToggle);

            PlayAfterTransitionToggle = new Toggle("Play After Transition");
            PlayAfterTransitionToggle.RegisterValueChangedCallback(e =>
            {
                _selectedTransition.PlayAfterTransition = e.newValue;
                e.StopPropagation();
            });
            _scrollView.Add(PlayAfterTransitionToggle);

            Foldout conditionsFoldout = new Foldout()
            {
                value = true, text = "Conditions"
            };

            conditionsFoldout.RegisterValueChangedCallback(e => e.StopPropagation());
            _scrollView.Add(conditionsFoldout);

            VisualElement conditionListButtons = new VisualElement();

            conditionListButtons.style.flexDirection = FlexDirection.Row;
            conditionsFoldout.Add(conditionListButtons);

            Button removeConditionButton = new Button(() =>
            {
                if (_conditions.selectedItem == null)
                {
                    return;
                }

                int firstIndex = _conditions.selectedIndex;
                int indexFixer = 0;

                foreach (var index in _conditions.selectedIndices)
                {
                    _selectedTransition.Conditions.RemoveAt(index - indexFixer);
                    indexFixer++;
                }

                _conditions.Refresh();
                _conditions.selectedIndex = Mathf.Min(firstIndex, _selectedTransition.Conditions.Count - 1);
            })
            {
                text = "Remove Condition"
            };

            conditionListButtons.Add(removeConditionButton);

            Button addConditionButton = new Button(() =>
            {
                _selectedTransition.Conditions.Add(new TransitionInfoCondition());
                _conditions.Refresh();
            })
            {
                text = "Add Condition"
            };

            conditionListButtons.Add(addConditionButton);

            _conditions            = new ResizableListView();
            _conditions.name       = "Conditions";
            _conditions.itemHeight = 25;
            _conditions.makeItem   = () =>
            {
                TransitionConditionUI transitionCondition = new TransitionConditionUI();

                return(transitionCondition);
            };
            _conditions.bindItem = (item, index) =>
            {
                ((TransitionConditionUI)item).Bind(_selectedTransition.Conditions[index]);
            };
            _conditions.selectionType = SelectionType.Multiple;
            _conditions.reorderable   = true;
            conditionsFoldout.Add(_conditions);

            RegisterCallback <ChangeEvent <bool> >(e => ToggleInClassList("expanded"));
        }