CreateModifier() 공개 정적인 메소드

public static CreateModifier ( NodeData node, BuildTarget target ) : IModifier
node NodeData
target BuildTarget
리턴 IModifier
예제 #1
0
        public void Run(BuildTarget target,
                        NodeData node,
                        ConnectionPointData inputPoint,
                        ConnectionData connectionToOutput,
                        Dictionary <string, List <Asset> > inputGroupAssets,
                        List <string> alreadyCached,
                        Action <ConnectionData, Dictionary <string, List <Asset> >, List <string> > Output)
        {
            var incomingAssets = inputGroupAssets.SelectMany(v => v.Value).ToList();

            var modifier = ModifierUtility.CreateModifier(node, target);

            UnityEngine.Assertions.Assert.IsNotNull(modifier);
            bool isAnyAssetModified = false;

            foreach (var asset in incomingAssets)
            {
                var loadedAsset = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(asset.importFrom);
                if (modifier.IsModified(loadedAsset))
                {
                    modifier.Modify(loadedAsset);
                    isAnyAssetModified = true;
                }
            }

            if (isAnyAssetModified)
            {
                // apply asset setting changes to AssetDatabase.
                AssetDatabase.Refresh();
            }

            // Modifier does not add, filter or change structure of group, so just pass given group of assets
            Output(connectionToOutput, inputGroupAssets, null);
        }
        public static void ValidateModifier(
            NodeData node,
            BuildTarget target,
            IEnumerable <PerformGraph.AssetGroups> incoming,
            Action <Type, Type, AssetReference> multipleAssetTypeFound,
            Action noModiferData,
            Action failedToCreateModifier,
            Action <Type, Type> incomingTypeMismatch
            )
        {
            Type expectedType = null;

            if (incoming != null)
            {
                expectedType = TypeUtility.FindFirstIncomingAssetType(incoming);
                if (expectedType != null)
                {
                    foreach (var ag in incoming)
                    {
                        foreach (var assets in ag.assetGroups.Values)
                        {
                            foreach (var a in assets)
                            {
                                Type assetType = a.filterType;
                                if (assetType != expectedType)
                                {
                                    multipleAssetTypeFound(expectedType, assetType, a);
                                }
                            }
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(node.InstanceData[target]))
            {
                noModiferData();
            }

            var modifier = ModifierUtility.CreateModifier(node, target);

            if (null == modifier)
            {
                failedToCreateModifier();
            }

            // if there is no incoming assets, there is no way to check if
            // right type of asset is coming in - so we'll just skip the test
            // expectedType is not null when there is at least one incoming asset
            if (incoming != null && expectedType != null)
            {
                var targetType = ModifierUtility.GetModifierTargetType(modifier);
                if (targetType != expectedType)
                {
                    incomingTypeMismatch(targetType, expectedType);
                }
            }
        }
        public void Run(BuildTarget target,
                        NodeData node,
                        IEnumerable <PerformGraph.AssetGroups> incoming,
                        IEnumerable <ConnectionData> connectionsToOutput,
                        PerformGraph.Output Output,
                        Action <NodeData, string, float> progressFunc)
        {
            if (incoming == null)
            {
                return;
            }
            var modifier = ModifierUtility.CreateModifier(node, target);

            UnityEngine.Assertions.Assert.IsNotNull(modifier);
            bool isAnyAssetModified = false;

            foreach (var ag in incoming)
            {
                foreach (var assets in ag.assetGroups.Values)
                {
                    foreach (var asset in assets)
                    {
                        if (modifier.IsModified(asset.data))
                        {
                            modifier.Modify(asset.data);
                            asset.ReleaseData();
                            isAnyAssetModified = true;
                        }
                    }
                }
            }

            if (isAnyAssetModified)
            {
                // apply asset setting changes to AssetDatabase.
                AssetDatabase.Refresh();
            }

            if (incoming != null && Output != null)
            {
                // Modifier does not add, filter or change structure of group, so just pass given group of assets
                var dst = (connectionsToOutput == null || !connectionsToOutput.Any())?
                          null : connectionsToOutput.First();

                foreach (var ag in incoming)
                {
                    Output(dst, ag.assetGroups);
                }
            }
        }
예제 #4
0
        public static void ValidateModifier(
            NodeData node,
            BuildTarget target,
            List <Asset> incomingAssets,
            Action <Type, Type, Asset> multipleAssetTypeFound,
            Action noModiferData,
            Action failedToCreateModifier,
            Action <Type, Type> incomingTypeMismatch
            )
        {
            Type expectedType = TypeUtility.FindIncomingAssetType(incomingAssets);

            if (expectedType != null)
            {
                foreach (var a  in incomingAssets)
                {
                    Type assetType = TypeUtility.FindTypeOfAsset(a.importFrom);
                    if (assetType != expectedType)
                    {
                        multipleAssetTypeFound(expectedType, assetType, a);
                    }
                }
            }

            if (string.IsNullOrEmpty(node.InstanceData[target]))
            {
                noModiferData();
            }

            var modifier = ModifierUtility.CreateModifier(node, target);

            if (null == modifier)
            {
                failedToCreateModifier();
            }

            // if there is no incoming assets, there is no way to check if
            // right type of asset is coming in - so we'll just skip the test
            if (incomingAssets.Any())
            {
                var targetType = ModifierUtility.GetModifierTargetType(modifier);
                if (targetType != expectedType)
                {
                    incomingTypeMismatch(targetType, expectedType);
                }
            }
        }
        private void DoInspectorModifierGUI(NodeGUI node)
        {
            EditorGUILayout.HelpBox("Modifier: Modify asset settings.", MessageType.Info);
            UpdateNodeName(node);

            GUILayout.Space(10f);

            using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                Type incomingType = FindIncomingAssetType(node.Data.InputPoints[0]);

                if (incomingType == null)
                {
                    // if there is no asset input to determine incomingType,
                    // retrieve from assigned Modifier.
                    incomingType = ModifierUtility.GetModifierTargetType(node.Data.ScriptClassName);

                    if (incomingType == null)
                    {
                        EditorGUILayout.HelpBox("Modifier needs a single type of incoming assets.", MessageType.Info);
                        return;
                    }
                }

                var map = ModifierUtility.GetAttributeClassNameMap(incomingType);
                if (map.Count > 0)
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Label("Modifier");
                        var guiName = ModifierUtility.GetModifierGUIName(node.Data.ScriptClassName);
                        if (GUILayout.Button(guiName, "Popup", GUILayout.MinWidth(150f)))
                        {
                            var builders = map.Keys.ToList();

                            if (builders.Count > 0)
                            {
                                NodeGUI.ShowTypeNamesMenu(guiName, builders, (string selectedGUIName) =>
                                {
                                    using (new RecordUndoScope("Change Modifier class", node, true)) {
                                        m_modifier = ModifierUtility.CreateModifier(selectedGUIName, incomingType);
                                        if (m_modifier != null)
                                        {
                                            node.Data.ScriptClassName = ModifierUtility.GUINameToClassName(selectedGUIName, incomingType);
                                            node.Data.InstanceData[currentEditingGroup] = m_modifier.Serialize();
                                        }
                                    }
                                }
                                                          );
                            }
                        }
                    }
                }
                else
                {
                    string[] menuNames = AssetBundleGraphSettings.GUI_TEXT_MENU_GENERATE_MODIFIER.Split('/');
                    EditorGUILayout.HelpBox(
                        string.Format(
                            "No CustomModifier found for {3} type. \n" +
                            "You need to create at least one Modifier script to select script for Modifier. " +
                            "To start, select {0}>{1}>{2} menu and create a new script.",
                            menuNames[1], menuNames[2], menuNames[3], incomingType.FullName
                            ), MessageType.Info);
                }

                GUILayout.Space(10f);

                if (DrawPlatformSelector(node))
                {
                    // if platform tab is changed, renew modifierModifierInstance for that tab.
                    m_modifier = null;
                }
                using (new EditorGUILayout.VerticalScope()) {
                    var disabledScope = DrawOverrideTargetToggle(node, node.Data.InstanceData.ContainsValueOf(currentEditingGroup), (bool enabled) => {
                        if (enabled)
                        {
                            node.Data.InstanceData[currentEditingGroup] = node.Data.InstanceData.DefaultValue;
                        }
                        else
                        {
                            node.Data.InstanceData.Remove(currentEditingGroup);
                        }
                        m_modifier = null;
                    });

                    using (disabledScope) {
                        //reload modifierModifier instance from saved modifierModifier data.
                        if (m_modifier == null)
                        {
                            m_modifier = ModifierUtility.CreateModifier(node.Data, currentEditingGroup);
                            if (m_modifier != null)
                            {
                                node.Data.ScriptClassName = m_modifier.GetType().FullName;
                                if (node.Data.InstanceData.ContainsValueOf(currentEditingGroup))
                                {
                                    node.Data.InstanceData[currentEditingGroup] = m_modifier.Serialize();
                                }
                            }
                        }

                        if (m_modifier != null)
                        {
                            Action onChangedAction = () => {
                                using (new RecordUndoScope("Change Modifier Setting", node)) {
                                    node.Data.ScriptClassName = m_modifier.GetType().FullName;
                                    if (node.Data.InstanceData.ContainsValueOf(currentEditingGroup))
                                    {
                                        node.Data.InstanceData[currentEditingGroup] = m_modifier.Serialize();
                                    }
                                }
                            };

                            m_modifier.OnInspectorGUI(onChangedAction);
                        }
                    }
                }
            }
        }