Пример #1
0
    private void PrepareData(string modelType)
    {
        var inputConfig = new InputConfiguration();

        AssetDirs.CreateAssetDirectory(AssetDirs.TempAssetsDir);
        var assetBundleCreator = new AssetBundleCreator(inputConfig.OutputDir);
        var modelConverter     = new ModelConverter();

        Log.Info("Preprocessing started!");
        var  modelImporter = InitializeModelImporter(modelType, modelConverter, inputConfig.RootDirectory);
        bool loadModel     = true;

        try
        {
            while (loadModel)
            {
                modelImporter.GetModelData();
                assetBundleCreator.Create(modelImporter);
                if (Application.isBatchMode)
                {
                    loadModel = false;
                }
                else
                {
                    loadModel = EditorUtility.DisplayDialog("", "Do you want to load another model?", "Yes", "No");
                }
            }
        }
        finally
        {
            RecursiveDeleter.DeleteRecursivelyWithSleep(AssetDirs.TempAssetsDir);
            Log.Info("Preprocessing finished!");
        }
    }
Пример #2
0
        // Exports finished GameObject to a .prefab
        private void CreatePrefab(ModelLayerInfo layerInfo, GameObject modelGameObject, string objectName)
        {
            string rootAssetsDir = AssetDirs.TempAssetsDir + "/" + Info.Caption;

            AssetDirs.CreateAssetDirectory(rootAssetsDir);

            string prefabPath = rootAssetsDir + "/" + objectName + ".prefab";

            AssetPaths.Add(prefabPath);
            PrefabUtility.SaveAsPrefabAsset(modelGameObject, prefabPath);
        }
Пример #3
0
        // Saves imported model to a Unity-friendly files, to be put in AssetBundles.
        private void SaveFilesForExport(ModelLayerInfo layerInfo, string objectName, Mesh modelMesh, GameObject modelGameObject)
        {
            string rootAssetsDir = AssetDirs.TempAssetsDir + "/" + Info.Caption;

            AssetDirs.CreateAssetDirectory(rootAssetsDir);

            string meshPath = rootAssetsDir + "/" + objectName + ".asset";

            AssetPaths.Add(meshPath);
            AssetDatabase.CreateAsset(modelMesh, meshPath);

            string gameObjectPath = rootAssetsDir + "/" + objectName + ".prefab";

            AssetPaths.Add(gameObjectPath);
            PrefabUtility.SaveAsPrefabAsset(modelGameObject, gameObjectPath);

            if (layerInfo.UseAsIcon)
            {
                PrepareForPreview(modelGameObject);
                LayerAutomaticIconGenerate(modelGameObject);
            }
        }
Пример #4
0
        // Saves imported model to a Unity-friendly files, to be put in AssetBundles.
        private void SaveFilesForExport(GameObject modelGameObject, ModelLayerInfo layerInfo, string objectName)
        {
            string rootAssetsDir = AssetDirs.TempAssetsDir + "/" + Info.Caption;

            AssetDirs.CreateAssetDirectory(rootAssetsDir);

            Mesh   modelMesh = modelGameObject.GetComponent <MeshFilter>().mesh;
            string meshPath  = rootAssetsDir + "/" + objectName + ".asset";

            AssetPaths.Add(meshPath);
            AssetDatabase.CreateAsset(modelMesh, meshPath);

            string rawDataPath = layerInfo.Directory + @"\" + "data.raw";
            // This is strange to copy data first as Asset then copy asset to build dir
            string tmpDataPath = rootAssetsDir + "/tmp_data.bytes";
            string dataPath    = rootAssetsDir + "/" + objectName + "_data.bytes";

            if (File.Exists(tmpDataPath))
            {
                FileUtil.DeleteFileOrDirectory(tmpDataPath);
            }
            FileUtil.CopyFileOrDirectory(rawDataPath, tmpDataPath);
            AssetPaths.Add(dataPath);
            AssetDatabase.Refresh();
            AssetDatabase.CopyAsset(tmpDataPath, dataPath);


            string gameObjectPath = rootAssetsDir + "/" + objectName + ".prefab";

            AssetPaths.Add(gameObjectPath);
            PrefabUtility.SaveAsPrefabAsset(modelGameObject, gameObjectPath);

            if (layerInfo.UseAsIcon)
            {
                PrepareForPreview(modelGameObject);
                LayerAutomaticIconGenerate(modelGameObject);
            }
        }