MenuItems.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using BansheeEngine;
  7. namespace BansheeEditor
  8. {
  9. /// <summary>
  10. /// Contains various menu item callbacks for the main editor menu bar.
  11. /// </summary>
  12. static class MenuItems
  13. {
  14. /// <summary>
  15. /// Adds a camera component to the currently selected scene object.
  16. /// </summary>
  17. [MenuItem("Components/Camera", 7050)]
  18. private static void AddCamera()
  19. {
  20. SceneObject so = Selection.SceneObject;
  21. if (so == null)
  22. return;
  23. UndoRedo.RecordSO(so, false, "Added a Camera component");
  24. Camera cam = so.AddComponent<Camera>();
  25. cam.Main = true;
  26. EditorApplication.SetSceneDirty();
  27. }
  28. /// <summary>
  29. /// Adds a renderable component to the currently selected scene object.
  30. /// </summary>
  31. [MenuItem("Components/Renderable", 7049)]
  32. private static void AddRenderable()
  33. {
  34. SceneObject so = Selection.SceneObject;
  35. if (so == null)
  36. return;
  37. UndoRedo.RecordSO(so, false, "Added a Renderable component");
  38. so.AddComponent<Renderable>();
  39. EditorApplication.SetSceneDirty();
  40. }
  41. /// <summary>
  42. /// Adds a point light component to the currently selected scene object.
  43. /// </summary>
  44. [MenuItem("Components/Point light", 7048)]
  45. private static void AddPointLight()
  46. {
  47. SceneObject so = Selection.SceneObject;
  48. if (so == null)
  49. return;
  50. UndoRedo.RecordSO(so, false, "Added a Light component");
  51. Light light = so.AddComponent<Light>();
  52. light.Type = LightType.Point;
  53. EditorApplication.SetSceneDirty();
  54. }
  55. /// <summary>
  56. /// Adds a spot light component to the currently selected scene object.
  57. /// </summary>
  58. [MenuItem("Components/Spot light", 7047)]
  59. private static void AddSpotLight()
  60. {
  61. SceneObject so = Selection.SceneObject;
  62. if (so == null)
  63. return;
  64. UndoRedo.RecordSO(so, false, "Added a Light component");
  65. Light light = so.AddComponent<Light>();
  66. light.Type = LightType.Spot;
  67. EditorApplication.SetSceneDirty();
  68. }
  69. /// <summary>
  70. /// Adds a directional light component to the currently selected scene object.
  71. /// </summary>
  72. [MenuItem("Components/Directional light", 7046)]
  73. private static void AddDirectionalLight()
  74. {
  75. SceneObject so = Selection.SceneObject;
  76. if (so == null)
  77. return;
  78. UndoRedo.RecordSO(so, false, "Added a Light component");
  79. Light light = so.AddComponent<Light>();
  80. light.Type = LightType.Directional;
  81. EditorApplication.SetSceneDirty();
  82. }
  83. /// <summary>
  84. /// Adds a GUI widget component to the currently selected scene object.
  85. /// </summary>
  86. [MenuItem("Components/GUI widget", 7045)]
  87. private static void AddGUIWidget()
  88. {
  89. SceneObject so = Selection.SceneObject;
  90. if (so == null)
  91. return;
  92. UndoRedo.RecordSO(so, false, "Added a GUIWidget component");
  93. so.AddComponent<GUIWidget>();
  94. EditorApplication.SetSceneDirty();
  95. }
  96. /// <summary>
  97. /// Creates a new empty scene object.
  98. /// </summary>
  99. [MenuItem("Scene Objects/Scene Object", 8051)]
  100. [ToolbarItem("SceneObject", ToolbarIcon.NewSceneObject, "Creates a new empty scene object", 1601, true)]
  101. private static void AddEmptySO()
  102. {
  103. SceneObject so = UndoRedo.CreateSO("SceneObject", "New scene object");
  104. Selection.SceneObject = so;
  105. EditorApplication.SetSceneDirty();
  106. }
  107. /// <summary>
  108. /// Creates a new scene object with a camera component.
  109. /// </summary>
  110. [MenuItem("Scene Objects/Camera", 8050)]
  111. [ToolbarItem("Camera", ToolbarIcon.NewCamera, "New camera", 1600, false)]
  112. private static void AddCameraSO()
  113. {
  114. SceneObject so = UndoRedo.CreateSO("Camera", "Created a Camera");
  115. Camera cam = so.AddComponent<Camera>();
  116. cam.Main = true;
  117. Selection.SceneObject = so;
  118. EditorApplication.SetSceneDirty();
  119. }
  120. /// <summary>
  121. /// Creates a new scene object with a renderable component.
  122. /// </summary>
  123. [MenuItem("Scene Objects/Renderable", 8049)]
  124. [ToolbarItem("Renderable", ToolbarIcon.NewRenderable, "New renderable", 1599)]
  125. private static void AddRenderableSO()
  126. {
  127. SceneObject so = UndoRedo.CreateSO("Renderable", "Created a Renderable");
  128. so.AddComponent<Renderable>();
  129. Selection.SceneObject = so;
  130. EditorApplication.SetSceneDirty();
  131. }
  132. /// <summary>
  133. /// Creates a new scene object with a point light component.
  134. /// </summary>
  135. [MenuItem("Scene Objects/Point light", 8048)]
  136. [ToolbarItem("Point light", ToolbarIcon.NewPointLight, "New point light", 1598)]
  137. private static void AddPointLightSO()
  138. {
  139. SceneObject so = UndoRedo.CreateSO("Point light", "Created a Light");
  140. Light light = so.AddComponent<Light>();
  141. light.Type = LightType.Point;
  142. Selection.SceneObject = so;
  143. EditorApplication.SetSceneDirty();
  144. }
  145. /// <summary>
  146. /// Creates a new scene object with a spot light component.
  147. /// </summary>
  148. [MenuItem("Scene Objects/Spot light", 8047)]
  149. [ToolbarItem("Spot light", ToolbarIcon.NewSpotLight, "New spot light", 1597)]
  150. private static void AddSpotLightSO()
  151. {
  152. SceneObject so = UndoRedo.CreateSO("Spot light", "Created a Light");
  153. Light light = so.AddComponent<Light>();
  154. light.Type = LightType.Spot;
  155. Selection.SceneObject = so;
  156. EditorApplication.SetSceneDirty();
  157. }
  158. /// <summary>
  159. /// Creates a new scene object with a directional light component.
  160. /// </summary>
  161. [MenuItem("Scene Objects/Directional light", 8046)]
  162. [ToolbarItem("Directional light", ToolbarIcon.NewDirLight, "New directional light", 1596)]
  163. private static void AddDirectionalLightSO()
  164. {
  165. SceneObject so = UndoRedo.CreateSO("Directional light", "Created a Light");
  166. Light light = so.AddComponent<Light>();
  167. light.Type = LightType.Directional;
  168. Selection.SceneObject = so;
  169. EditorApplication.SetSceneDirty();
  170. }
  171. /// <summary>
  172. /// Creates a new scene object with a GUI widget component.
  173. /// </summary>
  174. [MenuItem("Scene Objects/GUI widget", 8045)]
  175. private static void AddGUIWidgetSO()
  176. {
  177. SceneObject so = UndoRedo.CreateSO("GUIWidget", "Created a GUIWidget");
  178. so.AddComponent<GUIWidget>();
  179. Selection.SceneObject = so;
  180. EditorApplication.SetSceneDirty();
  181. }
  182. /// <summary>
  183. /// Creates a new scene object with a box primitive.
  184. /// </summary>
  185. [MenuItem("Scene Objects/3D primitives/Box", 8100)]
  186. [ToolbarItem("Cube", ToolbarIcon.NewCube, "Creates a scene object with a box primitive", 1700, true)]
  187. private static void Add3DBox()
  188. {
  189. SceneObject so = UndoRedo.CreateSO("Box", "Created a box");
  190. Renderable renderable = so.AddComponent<Renderable>();
  191. renderable.Mesh = Builtin.Box;
  192. Selection.SceneObject = so;
  193. EditorApplication.SetSceneDirty();
  194. }
  195. /// <summary>
  196. /// Creates a new scene object with a sphere primitive.
  197. /// </summary>
  198. [MenuItem("Scene Objects/3D primitives/Sphere", 8099)]
  199. [ToolbarItem("Sphere", ToolbarIcon.NewSphere, "Creates a scene object with a sphere primitive", 1699)]
  200. private static void Add3DSphere()
  201. {
  202. SceneObject so = UndoRedo.CreateSO("Sphere", "Created a sphere");
  203. Renderable renderable = so.AddComponent<Renderable>();
  204. renderable.Mesh = Builtin.Sphere;
  205. Selection.SceneObject = so;
  206. EditorApplication.SetSceneDirty();
  207. }
  208. /// <summary>
  209. /// Creates a new scene object with a cone primitive.
  210. /// </summary>
  211. [MenuItem("Scene Objects/3D primitives/Cone", 8098)]
  212. [ToolbarItem("Cone", ToolbarIcon.NewCone, "Creates a scene object with a cone primitive", 1698)]
  213. private static void Add3DCone()
  214. {
  215. SceneObject so = UndoRedo.CreateSO("Cone", "Created a cone");
  216. Renderable renderable = so.AddComponent<Renderable>();
  217. renderable.Mesh = Builtin.Cone;
  218. Selection.SceneObject = so;
  219. EditorApplication.SetSceneDirty();
  220. }
  221. /// <summary>
  222. /// Creates a new scene object with a quad primitive.
  223. /// </summary>
  224. [MenuItem("Scene Objects/3D primitives/Quad", 8097)]
  225. [ToolbarItem("Quad", ToolbarIcon.NewQuad, "Creates a scene object with a quad primitive", 1697)]
  226. private static void Add3DQuad()
  227. {
  228. SceneObject so = UndoRedo.CreateSO("Quad", "Created a quad");
  229. Renderable renderable = so.AddComponent<Renderable>();
  230. renderable.Mesh = Builtin.Quad;
  231. Selection.SceneObject = so;
  232. EditorApplication.SetSceneDirty();
  233. }
  234. /// <summary>
  235. /// Creates a new scene object with a disc primitive.
  236. /// </summary>
  237. [MenuItem("Scene Objects/3D primitives/Disc", 8096)]
  238. private static void Add3DDisc()
  239. {
  240. SceneObject so = UndoRedo.CreateSO("Disc", "Created a disc");
  241. Renderable renderable = so.AddComponent<Renderable>();
  242. renderable.Mesh = Builtin.Disc;
  243. Selection.SceneObject = so;
  244. EditorApplication.SetSceneDirty();
  245. }
  246. /// <summary>
  247. /// Applies changes from the prefab instance to the prefab resource.
  248. /// </summary>
  249. [MenuItem("Scene Objects/Apply prefab", 8025, true)]
  250. private static void ApplyPrefab()
  251. {
  252. SceneObject so = Selection.SceneObject;
  253. if (so == null)
  254. return;
  255. PrefabUtility.ApplyPrefab(so);
  256. }
  257. /// <summary>
  258. /// Reverts a prefab instance to the original state of its prefab.
  259. /// </summary>
  260. [MenuItem("Scene Objects/Revert to prefab", 8024)]
  261. private static void RevertToPrefab()
  262. {
  263. SceneObject so = Selection.SceneObject;
  264. if (so == null)
  265. return;
  266. UndoRedo.RecordSO(so, true, "Reverting \"" + so.Name + "\" to prefab.");
  267. PrefabUtility.RevertPrefab(so);
  268. EditorApplication.SetSceneDirty();
  269. }
  270. /// <summary>
  271. /// Breaks a link between a prefab and its instance.
  272. /// </summary>
  273. [MenuItem("Scene Objects/Break prefab link", 8023)]
  274. private static void BreakPrefabLink()
  275. {
  276. SceneObject so = Selection.SceneObject;
  277. if (so == null)
  278. return;
  279. UndoRedo.BreakPrefab(so, "Breaking prefab link for " + so.Name);
  280. EditorApplication.SetSceneDirty();
  281. }
  282. /// <summary>
  283. /// Cuts the currently selected scene object or resource.
  284. /// </summary>
  285. [MenuItem("Edit/Cut", 9450, true)]
  286. public static void Cut()
  287. {
  288. if (Selection.SceneObjects != null && Selection.SceneObjects.Length > 0)
  289. {
  290. HierarchyWindow win = EditorWindow.GetWindow<HierarchyWindow>();
  291. if (win != null)
  292. win.CutSelection();
  293. }
  294. else if (Selection.ResourcePaths != null && Selection.ResourcePaths.Length > 0)
  295. {
  296. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  297. if (win != null)
  298. win.CutSelection();
  299. }
  300. }
  301. /// <summary>
  302. /// Copies the currently selected scene object or resource.
  303. /// </summary>
  304. [MenuItem("Edit/Copy", 9449)]
  305. public static void Copy()
  306. {
  307. if (Selection.SceneObjects != null && Selection.SceneObjects.Length > 0)
  308. {
  309. HierarchyWindow win = EditorWindow.GetWindow<HierarchyWindow>();
  310. if (win != null)
  311. win.CopySelection();
  312. }
  313. else if (Selection.ResourcePaths != null && Selection.ResourcePaths.Length > 0)
  314. {
  315. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  316. if (win != null)
  317. win.CopySelection();
  318. }
  319. }
  320. /// <summary>
  321. /// Pastes the scene objects or resources that were previously cut or copied.
  322. /// </summary>
  323. [MenuItem("Edit/Paste", 9448)]
  324. public static void Paste()
  325. {
  326. // TODO - This is slightly wrong in case both windows have something in their paste buffer (unify them?)
  327. {
  328. HierarchyWindow win = EditorWindow.GetWindow<HierarchyWindow>();
  329. if (win != null)
  330. win.PasteToSelection();
  331. }
  332. {
  333. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  334. if (win != null)
  335. win.PasteToSelection();
  336. }
  337. }
  338. /// <summary>
  339. /// Deletes currently selected scene objects or resources.
  340. /// </summary>
  341. [MenuItem("Edit/Delete", 9447)]
  342. public static void Delete()
  343. {
  344. if (Selection.SceneObjects != null && Selection.SceneObjects.Length > 0)
  345. {
  346. HierarchyWindow win = EditorWindow.GetWindow<HierarchyWindow>();
  347. if (win != null)
  348. win.DeleteSelection();
  349. }
  350. else if (Selection.ResourcePaths != null && Selection.ResourcePaths.Length > 0)
  351. {
  352. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  353. if (win != null)
  354. win.DeleteSelection();
  355. }
  356. }
  357. /// <summary>
  358. /// Duplicates currently selected scene objects or resources.
  359. /// </summary>
  360. [MenuItem("Edit/Duplicate", 9446)]
  361. public static void Duplicate()
  362. {
  363. if (Selection.SceneObjects != null && Selection.SceneObjects.Length > 0)
  364. {
  365. HierarchyWindow win = EditorWindow.GetWindow<HierarchyWindow>();
  366. if (win != null)
  367. win.DuplicateSelection();
  368. }
  369. else if (Selection.ResourcePaths != null && Selection.ResourcePaths.Length > 0)
  370. {
  371. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  372. if (win != null)
  373. win.DuplicateSelection();
  374. }
  375. }
  376. }
  377. }