示例#1
0
        public override void Prepare(BuildTarget target,
                                     Model.NodeData node,
                                     IEnumerable <PerformGraph.AssetGroups> incoming,
                                     IEnumerable <Model.ConnectionData> connectionsToOutput,
                                     PerformGraph.Output Output)
        {
            if (m_configureImporterFor != null)
            {
                CreateConfigurator(node, m_configureImporterFor);
            }

            if (string.IsNullOrEmpty(m_referenceAssetGuid))
            {
                // give a try first in sampling file
                var a = AssetReferenceUtility.FindFirstIncomingAssetReference(incoming);
                if (a != null)
                {
                    CreateConfigurator(node, a.importerType);
                }
            }

            ValidateInputSetting(node, target, incoming);

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

                if (incoming != null)
                {
                    foreach (var ag in incoming)
                    {
                        Output(dst, ag.assetGroups);
                    }
                }
                else
                {
                    Output(dst, new Dictionary <string, List <AssetReference> >());
                }
            }
        }
示例#2
0
        private void ValidateInputSetting(
            Model.NodeData node,
            BuildTarget target,
            IEnumerable <PerformGraph.AssetGroups> incoming)
        {
            var  firstAsset             = AssetReferenceUtility.FindFirstIncomingAssetReference(incoming);
            Type firstAssetImporterType = null;

            // check if first Asset has importer
            if (firstAsset != null)
            {
                firstAssetImporterType = firstAsset.importerType;
                if (firstAssetImporterType == null)
                {
                    throw new NodeException(string.Format("Incoming asset '{0}' does not have importer. (type={1}) Perhaps you want to use Modifier instead?",
                                                          firstAsset.fileNameAndExtension, firstAsset.assetType.FullName),
                                            "Add ScriptedImporter for this type of asset or replace this node to use Modifier.",
                                            node);
                }
            }

            // check if all incoming assets are the same asset types
            if (firstAssetImporterType != null)
            {
                foreach (var ag in incoming)
                {
                    foreach (var assets in ag.assetGroups.Values)
                    {
                        foreach (var a in assets)
                        {
                            if (a.importerType != firstAssetImporterType)
                            {
                                throw new NodeException(
                                          string.Format("ImportSetting expect {0}, but different type of incoming asset is found({1}, {2})", firstAssetImporterType.FullName, a.fileNameAndExtension, a.importerType),
                                          string.Format("Remove {0} from node input, or change this importer type.", a.fileName),
                                          node);
                            }
                        }
                    }
                }
            }

            // check if there is a valid reference asset
            if (!string.IsNullOrEmpty(m_referenceAssetGuid))
            {
                var referenceImporter = GetReferenceAssetImporter(node, false);

                if (referenceImporter == null)
                {
                    throw new NodeException("Reference importer not found.",
                                            "Configure reference importer from inspector", node);
                }
            }

            // check if there is a valid custom setting asset
            if (m_useCustomSettingAsset && CustomSettingAsset == null)
            {
                throw new NodeException("You must select custom setting asset.",
                                        "Select custom setting asset.", node);
            }

            // check if reference asset type matches with incoming asset types
            if (firstAssetImporterType != null)
            {
                Type targetType = GetReferenceAssetImporter(node, false).GetType();
                if (targetType != firstAssetImporterType)
                {
                    throw new NodeException(
                              string.Format("Incoming asset type is does not match with this ImportSetting (Expected type:{0}, Incoming type:{1}).", targetType.FullName, firstAssetImporterType.FullName),
                              string.Format("Remove {0} from incoming assets.", firstAsset.fileName), node);
                }
            }

            // check if there is valid configurator for this asset importer
            var importer = GetReferenceAssetImporter(node, true);

            if (importer != null)
            {
                var configuratorType = ImporterConfiguratorUtility.GetConfiguratorTypeFor(importer.GetType());
                if (configuratorType == null)
                {
                    throw new NodeException(
                              string.Format("Configurator for {0} not found.", importer.GetType().FullName),
                              string.Format("Add CustomAssetImporterConfigurator."),
                              node);
                }

                var c = m_configuratorInstance.Get <IAssetImporterConfigurator> (target);
                if (c == null)
                {
                    throw new NodeException("Failed to get configurator for " + importer.GetType().FullName,
                                            "You may need to reset this node.", node);
                }
            }
        }