Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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 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);
        }
Ejemplo n.º 3
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();
                    // 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);
        }