Beispiel #1
0
    private static void ExtractTexture(string texFolder, string filePath)
    {
        //extract Texture
        ModelImporter mi = AssetImporter.GetAtPath(filePath) as ModelImporter;

        if (mi.ExtractTextures(texFolder))
        {
            Debug.Log($"Extract texture:{texFolder}");
        }
    }
    void OnPreprocessAsset()
    {
        PlayerSettings.stripUnusedMeshComponents = false;
        AssetImporter importer = (AssetImporter)assetImporter;

        if (importer.assetPath.Contains("iBEGOOExporter/Resources"))
        {
            try
            {
                //end of directory path, start of file name
                int fileNamePos = importer.assetPath.LastIndexOf("/", System.StringComparison.CurrentCulture);

                //end of file name, start of file extension
                int fileExtPos = importer.assetPath.LastIndexOf(".", System.StringComparison.CurrentCulture);
                //parent directory with trailing slash
                string filePath = importer.assetPath.Substring(0, fileNamePos + 1);

                //isolated file name
                string fileName = importer.assetPath.Substring(fileNamePos + 1, fileExtPos - filePath.Length);
                //extension with "."
                string fileExt = importer.assetPath.Substring(fileExtPos);


                if (filePath.ToLower().Contains(humanoidpath) && fileExt.ToLower().Contains("fbx"))
                {
                    ModelImporter modelImporter = (ModelImporter)importer;
                    modelImporter.animationType = ModelImporterAnimationType.Human;
                    modelImporter.ExtractTextures(assetPath);
                }
                if ((filePath.ToLower().Contains("props") || filePath.ToLower().Contains("sets") || filePath.ToLower().Contains("models")) && fileExt.ToLower().Contains("fbx"))
                {
                    assetImporter.assetBundleName = fileName;
                }
            }
            catch
            {
                //
                int    folderNamePos = importer.assetPath.Substring(0, importer.assetPath.Length - 2).LastIndexOf("/", System.StringComparison.CurrentCulture);
                string folderName    = importer.assetPath.Substring(folderNamePos + 1, importer.assetPath.Length - 1 - folderNamePos);

                //assetImporter.assetBundleName = folderName;
            }


            //assetImporter.assetBundleName = fileName;
        }


        AddAlwaysIncludedShader("Standard");
    }
Beispiel #3
0
        public static void ExtractTexturesAndMaterials(string assetPath)
        {
            assetPath = assetPath.Replace("\\", "/");
            if (assetPath.StartsWith(Application.dataPath))
            {
                assetPath = "Assets" + assetPath.Substring(Application.dataPath.Length);
            }
            AssetImporter assetImporter = AssetImporter.GetAtPath(assetPath);
            ModelImporter modelImporter = assetImporter as ModelImporter;

            string[] outputFilePieces = assetPath.Split('/');
            string   outputDir        = string.Join("/", outputFilePieces.Take(outputFilePieces.Length - 1));

            modelImporter.ExtractTextures(outputDir);
            AssetDatabase.Refresh();
            ExtractMaterialsFromAsset(assetImporter, outputDir);
        }
Beispiel #4
0
        internal static bool ExtractTextures(string assetPath, ModelImporter modelImporter)
        {
            bool result = false;

            string modelPath         = Path.GetDirectoryName(assetPath);
            string texturesDirectory = Path.Combine(modelPath, "textures");

            if (modelImporter.ExtractTextures(texturesDirectory))
            {
                AssetDatabase.Refresh(ImportAssetOptions.Default);
                result = true;
                Debug.Log("Extracted textures");
            }
            else
            {
                Debug.LogError("Failed to extract textures");
            }

            return(result);
        }
    void OnPreprocessModel()
    {
        ModelImporter modelImporter = assetImporter as ModelImporter;

        // Model Settings
        modelImporter.importCameras = false;
        modelImporter.importLights  = false;

        // Rig settings
        modelImporter.animationType = ModelImporterAnimationType.Human;

        // Animatino Settings
        modelImporter.importAnimation = false;


        // Material
        if (!modelImporter.ExtractTextures(@"Assets/Textures"))
        {
            Debug.LogError("Failed to extract textures");
        }
    }