GetModifierTargetType() public static method

public static GetModifierTargetType ( IModifier m ) : Type
m IModifier
return System.Type
        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);
                }
            }
        }
Esempio n. 2
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);
                        }
                    }
                }
            }
        }