/// <inheritdoc /> public override void Create(string outputPath, object arg) { var actor = arg as Actor; if (actor == null) { // Create default prefab root object actor = new EmptyActor(); actor.Name = "Root"; // Cleanup it after usage Object.Destroy(actor, 20.0f); } PrefabManager.CreatePrefab(actor, outputPath, true); }
/// <inheritdoc /> public override void Create(string outputPath, object arg) { if (!(arg is Actor actor)) { // Create default prefab root object actor = new EmptyActor { Name = "Root" }; // Cleanup it after usage Object.Destroy(actor, 20.0f); } PrefabManager.CreatePrefab(actor, outputPath, true); }
public override void OnInspectorGUI() { if (!TerrainManager.HasValidTerrain()) { GUILayout.Label("Create or load a map to continue..."); return; } if (assets == null) { GUILayout.Label("Asset bundles are not currently loaded..."); return; } PrefabManager instance = (PrefabManager)target; GUILayout.Label("Prefab Spawner", EditorStyles.boldLabel); GUILayout.Space(5f); GUILayout.Label("To spawn a prefab select it from the dropdown and hit 'Spawn'", EditorStyles.wordWrappedMiniLabel); GUILayout.Space(5f); Index = EditorGUILayout.Popup(Index, assets); if (GUILayout.Button("Spawn")) { RaycastHit rayHit; if (Physics.Raycast(SceneView.lastActiveSceneView.camera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 1.0f)), out rayHit, Mathf.Infinity, 1 << 8 | 1 << 9)) { GameObject gameObject = PrefabManager.CreatePrefab(assets[Index], "Decor", rayHit.point, Quaternion.identity, Vector3.one); Debug.Log(string.Concat("Spawned ", assets[Index], " at ", rayHit.point)); } else { Debug.Log("Look at the terrain to spawn a prefab"); } } }
void AddPrefabCreators(string dir, ShapeCreatorTreeNode parent) { EditorProject project = EditorApp.Project; int iIcon = EditorManager.GUI.ShapeTreeImages.AddBitmap(Path.Combine(EditorManager.AppDataDir, @"bitmaps\Shapes\lock_ok.png"), Color.Magenta); int iCategoryIcon = EditorManager.GUI.ShapeTreeImages.AddBitmap(Path.Combine(EditorManager.AppDataDir, @"bitmaps\Shapes\folder_new.png"), Color.Magenta); // Create the prefab category, if still missing ShapeCreatorTreeNode catParent = null; if (parent == null) { catParent = this.AddCategory(null, "Prefabs", iCategoryIcon); } else { catParent = this.AddCategory(parent, dir.Substring(dir.LastIndexOf('\\')), iCategoryIcon); } // Iterate all subdirectories string[] directories = Directory.GetDirectories(dir); foreach (string directory in directories) { AddPrefabCreators(directory, catParent); } // Iterate all files string[] files = Directory.GetFiles(dir, "*.prefab"); Array.Sort(files, new NaturalFileNameComparer()); foreach (string filename in files) { string relname = project.MakeRelative(filename); PrefabDesc desc = PrefabManager.CreatePrefab(relname); if (!desc.Loaded) { continue; } // Get the name of the prefab string _name = desc.Name; if (_name == null || _name == "") { _name = relname; } // Apply the search filter if (!searchPanel.MatchesFilter(_name)) { continue; } // Add the category path to the tree ShapeCreatorTreeNode cat = catParent; string catName = desc.Category; if (catName != null && catName != "") { cat = AddCategoryPath(catParent, catName, "\\", -1); } AddCreator(cat, desc, _name, iIcon); } // Check whether any prefab creators has been added if (catParent.Nodes.Count == 0) { catParent.Remove(); } }
private void button_Export_Click(object sender, EventArgs e) { List <PrefabEntry> sel = Selection; if (sel.Count == 0) { return; } EditorManager.Progress.ShowProgressDialog("Export Prefabs", true); float fStep = 100.0f / (float)sel.Count; EditorManager.GUI.UIUpdateLock++; foreach (PrefabEntry entry in sel) { ListViewItem.ListViewSubItem subitem = entry.ListItem.SubItems[1]; ListViewItem.ListViewSubItem coloritem = subitem; subitem.Text = "Exporting..."; EditorManager.Progress.StatusString = "Exporting " + entry.RelFilename; coloritem.ForeColor = Color.Black; PrefabDesc desc = PrefabManager.CreatePrefab(entry.PrefabFile.FullName); if (EditorManager.Progress.WantsAbort) { break; } if (desc == null) { subitem.Text = "Loading failed"; coloritem.ForeColor = Color.Red; continue; } if (!desc.Loaded) { subitem.Text = "Loading failed : " + desc.LastError; coloritem.ForeColor = Color.Red; continue; } if (entry.VPrefabFile != null && entry.VPrefabFile.IsReadOnly) { subitem.Text = "Target file is read-only" + desc.LastError; coloritem.ForeColor = Color.OrangeRed; continue; } if (!PrefabManager.BINARY_SAVER.SaveToBinaryFile(desc)) { subitem.Text = "Export failed"; coloritem.ForeColor = Color.Red; continue; } subitem.Text = "Export successful"; coloritem.ForeColor = Color.Green; entry.Success = true; entry.VPrefabFile = new FileInfo(entry.VPrefabName); listView_Prefabs.Refresh(); EditorManager.Progress.Percentage += fStep; if (EditorManager.Progress.WantsAbort) { break; } } EditorManager.Progress.HideProgressDialog(); EditorManager.GUI.UIUpdateLock--; }