MenuItems.cs 16 KB

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