コード例 #1
0
    private static bool ImportVoxModel(string asset)
    {
        string filename = Path.GetFileNameWithoutExtension(asset);
        string basename = Path.GetDirectoryName(asset);

        EnsureDirectoriesExist(basename);
        string         pipelinePath  = Path.Combine(Path.Combine(basename, "Pipeline/"), filename + ".asset");
        NPipeContainer pipeContainer = NPipelineUtils.GetContainerForVoxPath(asset);

        if (!pipeContainer)
        {
            if (File.Exists(pipelinePath))
            {
                // We don't need this anymore, as assets are reimported by the NPipeImporter anyway
                // AssetDatabase.ImportAsset(asset, ImportAssetOptions.Default);
//                Debug.Log("Did not create Pipeline for asset '" + asset + "' due to pipeline not yet ready (no problem as will get imported by the NPipeContainer anyway)");
                return(false);
            }

            Debug.Log("Creating Pipeline for Voxmodel: " + asset);

            NPipeContainer template;
            bool           unavailable;
            NPVoxUtils.LoadTemplateMetadata(out template, out unavailable);
            if (template == null)
            {
                if (!unavailable)
                {
                    // We don't need this anymore, as assets are reimported by the NPipeImporter anyway
                    // AssetDatabase.ImportAsset(asset, ImportAssetOptions.Default);
                    // Debug.Log("Delay import of '" + asset + "' due to template not yet ready");
                    Debug.Log("did not import '" + asset + "' due to template not yet ready");
                }
                return(false);
            }

            pipeContainer = NPipelineUtils.ClonePipeContainer(template, pipelinePath);
        }

        NPipeIImportable[] importables = NPipelineUtils.GetImportables(pipeContainer);
        // NPipeIImportable[] outputPipes = NPipelineUtils.FindOutputPipes(importables);

        foreach (NPipeIImportable importable in importables)
        {
            if (importable is NPVoxMagickaSource)
            {
                ((NPVoxMagickaSource)importable).VoxModelUUID = AssetDatabase.AssetPathToGUID(asset);
            }

            importable.Invalidate();
            EditorUtility.SetDirty(importable as UnityEngine.Object);
        }

        AssetDatabase.SaveAssets();
        AssetDatabase.ImportAsset(pipelinePath, ImportAssetOptions.ForceSynchronousImport); // try ForceSynchronousImport
        return(true);
    }
コード例 #2
0
    override public void OnAssetCreated()
    {
        base.OnAssetCreated();
        NPVoxMeshOutput output = NPipelineUtils.GetByType <NPVoxMeshOutput>(NPVoxUtils.GetTemplatePipeline())[0];

        MeshFactory              = (NPVoxMeshOutput)output.Clone();
        MeshFactory.StorageMode  = NPipeStorageMode.RESOURCE_CACHE;
        MeshFactory.Input        = null;
        MeshFactory.InstanceName = "_TEMPLATE_";
        NPipelineUtils.CreateAttachedPipe(UnityEditor.AssetDatabase.GetAssetPath(this), MeshFactory);
        UnityEditor.AssetDatabase.SaveAssets();
    }