コード例 #1
0
ファイル: Loader.cs プロジェクト: tuita520/AssetGraph
        void Load(BuildTarget target,
                  Model.NodeData node,
                  IEnumerable <Model.ConnectionData> connectionsToOutput,
                  PerformGraph.Output Output)
        {
            if (connectionsToOutput == null || Output == null)
            {
                return;
            }

            var outputSource = new List <AssetReference>();

            var loadPath    = GetLoadPath(target);
            var targetFiles = AssetDatabase.FindAssets("", new string[] { loadPath });

            foreach (var assetGuid in targetFiles)
            {
                var targetFilePath = AssetDatabase.GUIDToAssetPath(assetGuid);

                if (!TypeUtility.IsLoadingAsset(targetFilePath))
                {
                    continue;
                }

                // Skip folders
                var type = TypeUtility.GetMainAssetTypeAtPath(targetFilePath);
                if (type == typeof(UnityEditor.DefaultAsset) && AssetDatabase.IsValidFolder(targetFilePath))
                {
                    continue;
                }

                var r = AssetReferenceDatabase.GetReference(targetFilePath);

                if (r == null)
                {
                    continue;
                }

                if (outputSource.Contains(r))
                {
                    continue;
                }

                if (IsIgnored(targetFilePath))
                {
                    continue;
                }

                outputSource.Add(r);
            }

            var output = new Dictionary <string, List <AssetReference> > {
                { "0", outputSource }
            };

            var dst = (connectionsToOutput == null || !connectionsToOutput.Any())?
                      null : connectionsToOutput.First();

            Output(dst, output);
        }
コード例 #2
0
            public bool Validate()
            {
                bool          changed       = false;
                List <string> removingItems = null;

                foreach (var guid in m_graphGuids)
                {
                    var path = AssetDatabase.GUIDToAssetPath(guid);
                    if (string.IsNullOrEmpty(path) || !File.Exists(path) || TypeUtility.GetMainAssetTypeAtPath(path) != typeof(Model.ConfigGraph))
                    {
                        if (removingItems == null)
                        {
                            removingItems = new List <string> ();
                        }
                        removingItems.Add(guid);
                    }
                }

                if (removingItems != null)
                {
                    RemoveGraphRange(removingItems);
                    changed = true;
                }
                return(changed);
            }
コード例 #3
0
        private void CollectDependencies(string groupKey, AssetReference asset, ref Dictionary <string, List <string> > collector)
        {
            var dependencies = AssetDatabase.GetDependencies(new [] { asset.importFrom });

            var keyName = String.IsNullOrEmpty(asset.variantName)
                    ? groupKey
                    : $"{groupKey}.{asset.variantName}";

            foreach (var d in dependencies)
            {
                // AssetBundle must not include script asset
                if (TypeUtility.GetMainAssetTypeAtPath(d) == typeof(MonoScript))
                {
                    continue;
                }

                if (!collector.ContainsKey(d))
                {
                    collector[d] = new List <string>();
                }
                if (!collector[d].Contains(keyName))
                {
                    collector[d].Add(keyName);
                    collector[d].Sort();
                }
            }
        }
コード例 #4
0
 /// <summary>
 /// Creates the reference.
 /// </summary>
 /// <returns>The reference.</returns>
 /// <param name="importFrom">Import from.</param>
 public static AssetReference CreateReference(string importFrom)
 {
     return(new AssetReference(
                guid: Guid.NewGuid(),
                assetDatabaseId: AssetDatabase.AssetPathToGUID(importFrom),
                importFrom: importFrom,
                assetType: TypeUtility.GetMainAssetTypeAtPath(importFrom)
                ));
 }
コード例 #5
0
            public DragAndDropData(DragAndDropArgs a)
            {
                args         = a;
                draggedNodes = DragAndDrop.GetGenericData("GraphCollectionDetailTree.DraggedItems") as List <GraphCollectionDetailTreeItem>;

                foreach (var path in DragAndDrop.paths)
                {
                    if (TypeUtility.GetMainAssetTypeAtPath(path) == typeof(Model.ConfigGraph))
                    {
                        if (graphGuids == null)
                        {
                            graphGuids = new List <string>();
                        }

                        graphGuids.Add(AssetDatabase.AssetPathToGUID(path));
                    }
                }
            }
コード例 #6
0
        public static Type FindAssetFilterType(string assetPath)
        {
            var importerType = TypeUtility.GetAssetImporterTypeAtPath(assetPath);

            if (importerType != null)
            {
                return(importerType);
            }

            // not specific type importer. should determine their type by extension.
            var extension = Path.GetExtension(assetPath).ToLower();

            if (IgnoredAssetTypeExtension.Contains(extension))
            {
                return(null);
            }

            return(TypeUtility.GetMainAssetTypeAtPath(assetPath));
        }
コード例 #7
0
        private void CollectDependencies(string groupKey, string[] assetPaths, ref Dictionary <string, List <string> > collector)
        {
            var dependencies = AssetDatabase.GetDependencies(assetPaths);

            foreach (var d in dependencies)
            {
                // AssetBundle must not include script asset
                if (TypeUtility.GetMainAssetTypeAtPath(d) == typeof(MonoScript))
                {
                    continue;
                }

                if (!collector.ContainsKey(d))
                {
                    collector[d] = new List <string>();
                }
                if (!collector[d].Contains(groupKey))
                {
                    collector[d].Add(groupKey);
                    collector[d].Sort();
                }
            }
        }
コード例 #8
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            EditorGUILayout.HelpBox("Overwrite Import Setting: Overwrite import settings of incoming assets.", MessageType.Info);
            editor.UpdateNodeName(node);

            // prevent inspector flicking by new Editor changing active selction
            node.SetActive(true);

            using (new EditorGUILayout.VerticalScope()) {
                Type importerType = null;
                Type assetType    = null;

                var referenceImporter = GetReferenceAssetImporter(node.Data, false);
                if (referenceImporter != null)
                {
                    importerType = referenceImporter.GetType();
                    assetType    = TypeUtility.GetMainAssetTypeAtPath(AssetDatabase.GUIDToAssetPath(m_referenceAssetGuid));
                }
                else
                {
                    GUILayout.Space(10f);
                    using (new EditorGUILayout.VerticalScope(GUI.skin.box)) {
                        EditorGUILayout.HelpBox("Import setting type can be set by incoming asset, or you can specify by selecting.", MessageType.Info);
                        using (new EditorGUILayout.HorizontalScope()) {
                            EditorGUILayout.LabelField("Importer Type");
                            if (GUILayout.Button("", "Popup", GUILayout.MinWidth(150f)))
                            {
                                var menu = new GenericMenu();

                                var guiMap   = ImporterConfiguratorUtility.GetImporterConfiguratorGuiNameTypeMap();
                                var guiNames = guiMap.Keys.ToArray();

                                for (var i = 0; i < guiNames.Length; i++)
                                {
                                    var index = i;
                                    menu.AddItem(
                                        new GUIContent(guiNames [i]),
                                        false,
                                        () => {
                                        ResetConfig(node.Data);
                                        m_configureImporterFor = guiMap [guiNames [index]];
                                        // call Validate
                                        NodeGUIUtility.NodeEventHandler(new NodeEvent(NodeEvent.EventType.EVENT_NODE_UPDATED, node));
                                    }
                                        );
                                }
                                menu.ShowAsContext();
                            }
                        }
                    }
                    return;
                }

                if (importerType != null && assetType != null)
                {
                    GUILayout.Space(10f);
                    DoCustomAssetGUI(assetType, importerType, node, editor, onValueChanged);
                }

                // get reference importer again (enabling custom asset this time)
                referenceImporter = GetReferenceAssetImporter(node.Data, true);

                if (referenceImporter != null)
                {
                    var configurator = m_configuratorInstance.Get <IAssetImporterConfigurator> (editor.CurrentEditingGroup);
                    if (configurator != null)
                    {
                        GUILayout.Space(10f);

                        Action onChangedAction = () => {
                            using (new RecordUndoScope(string.Format("Change {0} Setting", node.Name), node)) {
                                m_configuratorInstance.Set(editor.CurrentEditingGroup, configurator);
                                onValueChanged();
                            }
                        };

                        configurator.OnInspectorGUI(referenceImporter, editor.CurrentEditingGroup, onChangedAction);
                    }

                    if (m_importerEditor == null)
                    {
                        m_importerEditor = Editor.CreateEditor(referenceImporter);
                    }
                }

                if (m_importerEditor != null)
                {
                    GUILayout.Space(10f);
                    GUILayout.Label(string.Format("Import Setting ({0})", importerType.Name));
                    m_importerEditor.OnInspectorGUI();
                }

                GUILayout.Space(40f);
                using (new EditorGUILayout.HorizontalScope(GUI.skin.box)) {
                    GUILayout.Space(4f);
                    EditorGUILayout.LabelField("Clear Saved Import Setting");

                    if (GUILayout.Button("Clear"))
                    {
                        if (EditorUtility.DisplayDialog("Clear Saved Import Setting",
                                                        string.Format("Do you want to reset saved import setting for \"{0}\"? This operation is not undoable.", node.Name), "OK", "Cancel"))
                        {
                            ResetConfig(node.Data);
                        }
                    }
                }
            }
        }
コード例 #9
0
        public override void OnInspectorGUI(NodeGUI node, AssetReferenceStreamManager streamManager, NodeGUIEditor editor, Action onValueChanged)
        {
            EditorGUILayout.HelpBox("Build Player: Build Player.", MessageType.Info);
            editor.UpdateNodeName(node);

            if (m_buildOptions == null)
            {
                return;
            }

            GUILayout.Space(10f);

            //Show target configuration tab
            editor.DrawPlatformSelector(node);
            using (new EditorGUILayout.VerticalScope(GUI.skin.box))
            {
                var disabledScope = editor.DrawOverrideTargetToggle(node, m_buildOptions.ContainsValueOf(editor.CurrentEditingGroup), (bool enabled) =>
                {
                    using (new RecordUndoScope("Remove Target Build Settings", node, true))
                    {
                        if (enabled)
                        {
                            m_buildOptions[editor.CurrentEditingGroup]   = m_buildOptions.DefaultValue;
                            m_buildLocations[editor.CurrentEditingGroup] = m_buildLocations.DefaultValue;
                            m_playerName[editor.CurrentEditingGroup]     = m_playerName.DefaultValue;
                            m_scenes[editor.CurrentEditingGroup]         = m_scenes.DefaultValue;
                        }
                        else
                        {
                            m_buildOptions.Remove(editor.CurrentEditingGroup);
                            m_buildLocations.Remove(editor.CurrentEditingGroup);
                            m_playerName.Remove(editor.CurrentEditingGroup);
                            m_scenes.Remove(editor.CurrentEditingGroup);
                        }
                        onValueChanged();
                    }
                });

                using (disabledScope)
                {
                    using (var scrollScope = new EditorGUILayout.ScrollViewScope(m_scroll))
                    {
                        m_scroll = scrollScope.scrollPosition;
                        GUILayout.Label("Player Build Location", "BoldLabel");
                        var newBuildLocation = editor.DrawFolderSelector("", "Select Build Location",
                                                                         m_buildLocations[editor.CurrentEditingGroup],
                                                                         Application.dataPath + "/../"
                                                                         );
                        if (newBuildLocation.StartsWith(Application.dataPath))
                        {
                            throw new NodeException("You can not build player inside Assets directory.",
                                                    "Select build location outside Assets directory.",
                                                    node.Data);
                        }

                        if (newBuildLocation != m_buildLocations[editor.CurrentEditingGroup])
                        {
                            using (new RecordUndoScope("Change Build Location", node, true))
                            {
                                m_buildLocations[editor.CurrentEditingGroup] = newBuildLocation;
                                onValueChanged();
                            }
                        }
                        GUILayout.Space(4f);
                        var newPlayerName = EditorGUILayout.TextField("Player Name", m_playerName[editor.CurrentEditingGroup]);
                        if (newPlayerName != m_playerName[editor.CurrentEditingGroup])
                        {
                            using (new RecordUndoScope("Change Player Name", node, true))
                            {
                                m_playerName[editor.CurrentEditingGroup] = newPlayerName;
                                onValueChanged();
                            }
                        }

                        GUILayout.Space(10f);
                        GUILayout.Label("Build Options", "BoldLabel");
                        int buildOptions = m_buildOptions[editor.CurrentEditingGroup];
                        foreach (var option in Model.Settings.BuildPlayerOptionsSettings)
                        {
                            // contains keyword == enabled. if not, disabled.
                            bool isEnabled = (buildOptions & (int)option.option) != 0;

                            var result = EditorGUILayout.ToggleLeft(option.description, isEnabled);
                            if (result != isEnabled)
                            {
                                using (new RecordUndoScope("Change Build Option", node, true))
                                {
                                    buildOptions = (result) ?
                                                   ((int)option.option | buildOptions) :
                                                   (((~(int)option.option)) & buildOptions);
                                    m_buildOptions[editor.CurrentEditingGroup] = buildOptions;
                                    onValueChanged();
                                }
                            }
                        }

                        var scenesInProject = AssetDatabase.FindAssets("t:Scene");
                        if (scenesInProject.Length > 0)
                        {
                            GUILayout.Space(10f);
                            GUILayout.Label("Scenes", "BoldLabel");

                            using (new EditorGUILayout.VerticalScope(GUI.skin.box))
                            {
                                var scenesSelected = m_scenes[editor.CurrentEditingGroup].Split(',');

                                foreach (var sceneGUID in scenesInProject)
                                {
                                    var path = AssetDatabase.GUIDToAssetPath(sceneGUID);
                                    if (string.IsNullOrEmpty(path))
                                    {
                                        ArrayUtility.Remove(ref scenesSelected, sceneGUID);
                                        m_scenes[editor.CurrentEditingGroup] = string.Join(",", scenesSelected);
                                        onValueChanged();
                                        continue;
                                    }
                                    var type = TypeUtility.GetMainAssetTypeAtPath(path);
                                    if (type != typeof(UnityEditor.SceneAsset))
                                    {
                                        continue;
                                    }

                                    var selected    = scenesSelected.Contains(sceneGUID);
                                    var newSelected = EditorGUILayout.ToggleLeft(path, selected);
                                    if (newSelected != selected)
                                    {
                                        using (new RecordUndoScope("Change Scene Selection", node, true))
                                        {
                                            if (newSelected)
                                            {
                                                ArrayUtility.Add(ref scenesSelected, sceneGUID);
                                            }
                                            else
                                            {
                                                ArrayUtility.Remove(ref scenesSelected, sceneGUID);
                                            }
                                            m_scenes[editor.CurrentEditingGroup] = string.Join(",", scenesSelected);
                                            onValueChanged();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }