Exemplo n.º 1
0
        public void ValidateModifier(
            Model.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);
                                }
                            }
                        }
                    }
                }
            }

//			var modifier = ModifierUtility.CreateModifier(node, target);
//
            if (m_instance.Get <IModifier>(target) == null)
            {
                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(m_instance.Get <IModifier>(target));
                if (targetType != expectedType)
                {
                    incomingTypeMismatch(targetType, expectedType);
                }
            }
        }
Exemplo n.º 2
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            EditorGUILayout.HelpBox("Modify Assets Directly: Modify assets.", MessageType.Info);
            editor.UpdateNodeName(node);

            GUILayout.Space(10f);

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

                var modifier = m_instance.Get <IModifier>(editor.CurrentEditingGroup);

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

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

                Dictionary <string, string> map = null;

                if (incomingType != null)
                {
                    map = ModifierUtility.GetAttributeAssemblyQualifiedNameMap(incomingType);
                }

                if (map != null && map.Count > 0)
                {
                    using (new GUILayout.HorizontalScope()) {
                        GUILayout.Label("Modifier");
                        var guiName = ModifierUtility.GetModifierGUIName(m_instance.ClassName);
                        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)) {
                                        modifier = ModifierUtility.CreateModifier(selectedGUIName, incomingType);
                                        m_instance.Set(editor.CurrentEditingGroup, modifier);
                                        onValueChanged();
                                    }
                                }
                                                          );
                            }
                        }

                        MonoScript s = TypeUtility.LoadMonoScript(m_instance.ClassName);

                        using (new EditorGUI.DisabledScope(s == null)) {
                            if (GUILayout.Button("Edit", GUILayout.Width(50)))
                            {
                                AssetDatabase.OpenAsset(s, 0);
                            }
                        }
                    }
                }
                else
                {
                    string[] menuNames = Model.Settings.GUI_TEXT_MENU_GENERATE_MODIFIER.Split('/');

                    if (incomingType == null)
                    {
                        EditorGUILayout.HelpBox(
                            string.Format(
                                "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]
                                ), MessageType.Info);
                    }
                    else
                    {
                        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);

                editor.DrawPlatformSelector(node);
                using (new EditorGUILayout.VerticalScope()) {
                    var disabledScope = editor.DrawOverrideTargetToggle(node, m_instance.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) => {
                        if (enabled)
                        {
                            m_instance.CopyDefaultValueTo(editor.CurrentEditingGroup);
                        }
                        else
                        {
                            m_instance.Remove(editor.CurrentEditingGroup);
                        }
                        onValueChanged();
                    });

                    using (disabledScope) {
                        if (modifier != null)
                        {
                            Action onChangedAction = () => {
                                using (new RecordUndoScope("Change Modifier Setting", node)) {
                                    m_instance.Set(editor.CurrentEditingGroup, modifier);
                                    onValueChanged();
                                }
                            };

                            modifier.OnInspectorGUI(onChangedAction);
                        }
                    }
                }
            }
        }