// [MenuItem("NPVox/Select All Instances &s", true)] static bool Validate() { UnityEngine.Object[] objects = Selection.objects; for (int i = 0; i < objects.Length; i++) { NPipeContainer o = objects[i] as NPipeContainer; if (o) { NPipeIImportable[] outputPipes = NPipelineUtils.FindOutputPipes(NPipelineUtils.GetImportables(AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(o)))); foreach (NPipeIImportable imp in outputPipes) { if (imp is NPVoxMeshOutput) { return(true); } } } NPVoxMeshInstance inst = objects[i] as NPVoxMeshInstance; if (inst) { return(true); } } return(false); }
public override void OnInspectorGUI() { NPVoxCubeSimplifierInstance instance = (NPVoxCubeSimplifierInstance)target; string path = AssetDatabase.GetAssetPath(instance); bool isTemplate = path.Length > 0 && AssetDatabase.AssetPathToGUID(path) == NPVoxConstants.GAMEPOBJECT_TEMPLATE; if (isTemplate) { GUILayout.Label("This is the Prefab used to construct new instances of your models.\nAdjust as your liking, but don't move or rename it!"); return; } instance.UpdateMesh(); DrawDefaultInspector(); if (instance.CubeSimplifier == null) { GUILayout.Label("NPVox: No NP Vox Cube Simplifier assigned."); return; } bool isPrefab = PrefabUtility.GetPrefabParent(target) == null && PrefabUtility.GetPrefabObject(target) != null; if (!isPrefab) { if (GUILayout.Button("Align (Shortcut ALT+a)")) { Align(instance.transform); } } // NPVoxMeshOutput[] meshOutputs = NPipelineUtils.GetByType<NPVoxMeshOutput>(instance.CubeSimplifier as UnityEngine.Object); // if (meshOutputs.Length > 0) { if (GUILayout.Button("Switch to Mesh Output Instance")) { NPVoxMeshInstance meshOutputInstance = instance.gameObject.AddComponent <NPVoxMeshInstance>(); meshOutputInstance.MeshFactory = (NPVoxMeshOutput)instance.CubeSimplifier.InputMeshFactory; meshOutputInstance.UpdateMesh(); instance.gameObject.GetComponent <MeshRenderer>().sharedMaterial = instance.CubeSimplifier.SourceMaterial; DestroyImmediate(instance, true); return; } } if (GUILayout.Button("Select Pipe Container (Edit Import Settings)")) { Selection.objects = new Object[] { AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(instance.CubeSimplifier), typeof(NPipeContainer)) }; } if (GUILayout.Button("Invalidate Pipe Container Deep ")) { NPipelineUtils.InvalidateAndReimportAllDeep(AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(instance.CubeSimplifier), typeof(NPipeContainer))); } }
static void MakeVoxPrefabs() { var path = EditorUtility.SaveFolderPanel( "Select target folder for the generated Prefabs ", "Prefabs", "Select Path for the generated Prefabs"); path = path.Remove(0, path.LastIndexOf("Assets")); if (path.Length != 0) { Object[] SelectedObjects = Selection.objects; int generatedCount = 0; foreach (Object o in SelectedObjects) { NPipeContainer container = o as NPipeContainer; if (!container) { continue; } NPVoxMeshOutput[] output = NPipelineUtils.GetByType <NPVoxMeshOutput>(container); foreach (NPVoxMeshOutput pipe in output) { NPVoxMeshInstance instance = pipe.Instatiate().GetComponent <NPVoxMeshInstance>(); string prefabPath = Path.Combine(path, instance.name) + ".prefab"; PrefabUtility.CreatePrefab(prefabPath, instance.gameObject); GameObject.DestroyImmediate(instance.gameObject); generatedCount++; } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); if (generatedCount > 0) { Debug.Log("Generated " + generatedCount + " Prefabs"); } else { Debug.LogWarning("No NPVoxMetadata selected"); } } }
public GameObject Instatiate() { #if UNITY_EDITOR string gameobjectTemplatePath = UnityEditor.AssetDatabase.GUIDToAssetPath(NPVoxConstants.GAMEPOBJECT_TEMPLATE); if (gameobjectTemplatePath == null) { UnityEngine.Debug.LogWarning( "NPVox: Could not find the Gameobject Template with GUID '" + NPVoxConstants.GAMEPOBJECT_TEMPLATE + "', if you removed the Asset, please create a new Asset and set it's GUID in Preferences -> NPVox" ); return(null); } GameObject templatePrefab = (GameObject)UnityEditor.AssetDatabase.LoadAssetAtPath(gameobjectTemplatePath, typeof(GameObject)); GameObject go = (GameObject)GameObject.Instantiate(templatePrefab); NPVoxMeshInstance instance = go.GetComponent <NPVoxMeshInstance>(); if (!instance) { go.AddComponent <NPVoxMeshInstance>(); } instance.MeshFactory = this; string assetPath = UnityEditor.AssetDatabase.GetAssetPath(this); Object mainAsset = UnityEditor.AssetDatabase.LoadMainAssetAtPath(assetPath); if (mainAsset) { instance.name = mainAsset.name; } if ((instance.MeshFactory is NPVoxProcessorBase <Mesh>) && ((NPVoxProcessorBase <Mesh>)instance.MeshFactory).StorageMode == NPipeStorageMode.ATTACHED) { instance.SharedMash = instance.MeshFactory.GetProduct(); } UnityEditor.Undo.RegisterCreatedObjectUndo(go, "Created a new NPVoxInstance"); UnityEditor.Selection.objects = new Object[] { instance.gameObject }; return(instance.gameObject); #else Debug.Log("Not yet supported"); return(null); #endif }
static void MenuNew() { UnityEngine.Object[] objects = Selection.objects; for (int i = 0; i < objects.Length; i++) { NPipeContainer o = objects[i] as NPipeContainer; if (o) { NPipeIImportable[] outputPipes = NPipelineUtils.FindOutputPipes(NPipelineUtils.GetImportables(AssetDatabase.LoadAllAssetsAtPath(AssetDatabase.GetAssetPath(o)))); foreach (NPipeIImportable imp in outputPipes) { if (imp is NPVoxMeshOutput) { ((NPVoxMeshOutput)imp).Instatiate(); } } } NPVoxMeshInstance inst = objects[i] as NPVoxMeshInstance; if (inst) { ((NPVoxMeshOutput)inst.meshFactory).Instatiate(); } } }
public override void OnInspectorGUI() { NPVoxMeshInstance instance = (NPVoxMeshInstance)target; string path = AssetDatabase.GetAssetPath(instance); bool isTemplate = path.Length > 0 && AssetDatabase.AssetPathToGUID(path) == NPVoxConstants.GAMEPOBJECT_TEMPLATE; if (isTemplate) { GUILayout.Label("This is the Prefab used to construct new instances of your models.\nAdjust as your liking, but don't move or rename it!"); return; } DrawDefaultInspector(); if (instance.MeshFactory == null) { GUILayout.Label("NPVox: No NP Vox Mesh Factory assigned."); return; } if ((instance.MeshFactory is NPVoxProcessorBase <Mesh>) && ((NPVoxProcessorBase <Mesh>)instance.MeshFactory).StorageMode == NPipeStorageMode.ATTACHED) { if (instance.SharedMash != instance.MeshFactory.GetProduct()) { Undo.RecordObject(instance, "Updated shared mesh"); instance.SharedMash = instance.MeshFactory.GetProduct(); } } else { GUILayout.Label( "NPVox: The Storage Mode is not set to ATTACHED, thus you are not able to preview the item in the editor, sorry"); GUILayout.Label(" to see any preview during Editor time.\n", new GUILayoutOption[] { }); if (instance.SharedMash != null) { Undo.RecordObject(instance, "Unset shared mesh"); } instance.SharedMash = null; } bool isPrefab = PrefabUtility.GetPrefabParent(target) == null && PrefabUtility.GetPrefabObject(target) != null; if (!isPrefab) { if (GUILayout.Button("Align (Shortcut ALT+a)")) { Align(instance.transform); } } NPVoxCubeSimplifier[] simplifiers = NPipelineUtils.FindNextPipeOfType <NPVoxCubeSimplifier>(NPipelineUtils.GetImportables(AssetDatabase.GetAssetPath(instance.MeshFactory as UnityEngine.Object)), instance.MeshFactory); if (simplifiers.Length > 0) { if (GUILayout.Button("Switch to Cube Simplifier instance")) { NPVoxCubeSimplifierInstance cubeSimplifier = instance.gameObject.AddComponent <NPVoxCubeSimplifierInstance>(); cubeSimplifier.CubeSimplifier = simplifiers[0]; cubeSimplifier.UpdateMesh(); DestroyImmediate(instance, true); return; } } else { if (GUILayout.Button("Create Cube Simplifier")) { string assetPath = AssetDatabase.GetAssetPath(instance.MeshFactory as UnityEngine.Object); NPVoxCubeSimplifier simplifier = (NPVoxCubeSimplifier)NPipelineUtils.CreateAttachedPipe(assetPath, typeof(NPVoxCubeSimplifier), instance.MeshFactory); simplifier.TextureAtlas = (NPVoxTextureAtlas)UnityEditor.AssetDatabase.LoadAssetAtPath(UnityEditor.AssetDatabase.GUIDToAssetPath("b3ed00785c29642baae5806625c1d3c1"), typeof(NPVoxTextureAtlas)); simplifier.SourceMaterial = instance.GetComponent <MeshRenderer>().sharedMaterial; AssetDatabase.SaveAssets(); } } if (GUILayout.Button("Select Pipe Container (Edit Import Settings)")) { Selection.objects = new Object[] { AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(instance.meshFactory), typeof(NPipeContainer)) }; } if (GUILayout.Button("Invalidate Pipe Container Deep ")) { NPipelineUtils.InvalidateAndReimportAllDeep(AssetDatabase.LoadAssetAtPath(AssetDatabase.GetAssetPath(instance.meshFactory), typeof(NPipeContainer))); } }