void _initializeProgram() { storedProg = null; prog = null; progGUI = null; // Look for a program stored in the asset. storedProg = KMImportSettings.ProgramForMesh(assetGUID, meshPath); if (storedProg != null) { // Create a copy of the program to work with. prog = ScriptableObject.CreateInstance <KMProcessorProgram>(); EditorUtility.CopySerialized(storedProg, prog); int numProcessors = prog.processors.Length; for (int i = 0; i < numProcessors; ++i) { KrablMesh.Processor proc = prog.processors[i]; KrablMesh.Processor clone = ScriptableObject.CreateInstance(proc.GetType()) as KrablMesh.Processor; EditorUtility.CopySerialized(proc, clone); clone.hideFlags = HideFlags.DontSave; prog.processors[i] = clone; } prog.hideFlags = HideFlags.DontSave; progGUI = (KMProcessorProgramGUI)Editor.CreateEditor(prog); if (progGUI != null) { progGUI.usedByMeshImporter = true; } } }
bool _processMesh(GameObject container, Mesh umesh) { #if UNITY_4_3 || UNITY_4_4 || UNITY_4_5 if (umesh.blendShapeCount > 0) { Debug.Log("Krabl Mesh Processors can not yet process meshes with blendshapes."); return(false); } #endif string assetGUID = AssetDatabase.AssetPathToGUID(assetPath); //Debug.Log("Container guid: " + assetGUID); string meshPath = KrablMesh.UnityEditorUtils.MeshPathInAsset(umesh, container); //Debug.Log("Meshpath: " + meshPath); KMProcessorProgram program = KMImportSettings.ProgramForMesh(assetGUID, meshPath); if (program == null) { return(false); } if (program.bypass) { return(true); } // Debug.Log("KMImportProcessor Process " + container.name + "/" + umesh.name + " PRG: " + ((program == null) ? "NULL" : program.ToString()), umesh); KrablMesh.Processor[] processors = program.processors; if (true) //program.importTriggeredByInspector == true) { // Set up progress indicators { program.importTriggeredByInspector = false; float numEnabled = 0.0f; for (int i = 0; i < processors.Length; ++i) { if (processors[i].enabled) { numEnabled += 1.0f; } } float progStep = (numEnabled > 0.0f) ? 1.0f / numEnabled : 1.0f; float progOffset = 0.0f; string title = ProgressTitle(program); for (int i = 0; i < processors.Length; ++i) { if (processors[i].enabled == true) { float offset = progOffset; processors[i].progressDelegate = delegate(string text, float val) { EditorUtility.DisplayProgressBar(title, text, val * progStep + offset); }; progOffset += progStep; } } } Mesh processedMesh = program.Process(umesh, EditorUserBuildSettings.selectedBuildTargetGroup.ToString()); processedMesh.name = umesh.name; if (program.unityOptimizeMesh) { ; } EditorUtility.ClearProgressBar(); // Store Revision to program program.importRevision = importRevision; EditorUtility.SetDirty(program); //AssetDatabase.SaveAssets(); if (program.targetPath.Equals("replace")) { umesh.Clear(); EditorUtility.CopySerialized(processedMesh, umesh); } else { _outputToAsset(processedMesh, program.targetPath); } GameObject.DestroyImmediate(processedMesh); return(true); }