MenuItems.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  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. /// Creates a new empty scene object.
  85. /// </summary>
  86. [MenuItem("Scene Objects/Scene Object", 8051)]
  87. [ToolbarItem("SceneObject", ToolbarIcon.NewSceneObject, "Creates a new empty scene object.", 1601, true)]
  88. private static void AddEmptySO()
  89. {
  90. SceneObject so = UndoRedo.CreateSO("SceneObject", "New scene object");
  91. Selection.SceneObject = so;
  92. EditorApplication.SetSceneDirty();
  93. }
  94. /// <summary>
  95. /// Creates a new scene object with a camera component.
  96. /// </summary>
  97. [MenuItem("Scene Objects/Camera", 8050)]
  98. [ToolbarItem("Camera", ToolbarIcon.NewCamera, "New camera", 1600, false)]
  99. private static void AddCameraSO()
  100. {
  101. SceneObject so = UndoRedo.CreateSO("Camera", "Created a Camera");
  102. Camera cam = so.AddComponent<Camera>();
  103. cam.Main = true;
  104. Selection.SceneObject = so;
  105. EditorApplication.SetSceneDirty();
  106. }
  107. /// <summary>
  108. /// Creates a new scene object with a renderable component.
  109. /// </summary>
  110. [MenuItem("Scene Objects/Renderable", 8049)]
  111. [ToolbarItem("Renderable", ToolbarIcon.NewRenderable, "New renderable", 1599)]
  112. private static void AddRenderableSO()
  113. {
  114. SceneObject so = UndoRedo.CreateSO("Renderable", "Created a Renderable");
  115. so.AddComponent<Renderable>();
  116. Selection.SceneObject = so;
  117. EditorApplication.SetSceneDirty();
  118. }
  119. /// <summary>
  120. /// Creates a new scene object with a point light component.
  121. /// </summary>
  122. [MenuItem("Scene Objects/Point light", 8048)]
  123. [ToolbarItem("Point light", ToolbarIcon.NewPointLight, "New point light", 1598)]
  124. private static void AddPointLightSO()
  125. {
  126. SceneObject so = UndoRedo.CreateSO("Point light", "Created a Light");
  127. Light light = so.AddComponent<Light>();
  128. light.Type = LightType.Point;
  129. Selection.SceneObject = so;
  130. EditorApplication.SetSceneDirty();
  131. }
  132. /// <summary>
  133. /// Creates a new scene object with a spot light component.
  134. /// </summary>
  135. [MenuItem("Scene Objects/Spot light", 8047)]
  136. [ToolbarItem("Spot light", ToolbarIcon.NewSpotLight, "New spot light", 1597)]
  137. private static void AddSpotLightSO()
  138. {
  139. SceneObject so = UndoRedo.CreateSO("Spot light", "Created a Light");
  140. Light light = so.AddComponent<Light>();
  141. light.Type = LightType.Spot;
  142. Selection.SceneObject = so;
  143. EditorApplication.SetSceneDirty();
  144. }
  145. /// <summary>
  146. /// Creates a new scene object with a directional light component.
  147. /// </summary>
  148. [MenuItem("Scene Objects/Directional light", 8046)]
  149. [ToolbarItem("Directional light", ToolbarIcon.NewDirLight, "New directional light.", 1596)]
  150. private static void AddDirectionalLightSO()
  151. {
  152. SceneObject so = UndoRedo.CreateSO("Directional light", "Created a Light");
  153. Light light = so.AddComponent<Light>();
  154. light.Type = LightType.Directional;
  155. Selection.SceneObject = so;
  156. EditorApplication.SetSceneDirty();
  157. }
  158. /// <summary>
  159. /// Creates a new scene object with a box primitive.
  160. /// </summary>
  161. [MenuItem("Scene Objects/3D primitives/Box", 8100)]
  162. [ToolbarItem("Cube", ToolbarIcon.NewCube, "Creates a scene object with a box primitive.", 1700, true)]
  163. private static void Add3DBox()
  164. {
  165. SceneObject so = UndoRedo.CreateSO("Box", "Created a box");
  166. Renderable renderable = so.AddComponent<Renderable>();
  167. renderable.Mesh = Builtin.Box;
  168. Selection.SceneObject = so;
  169. EditorApplication.SetSceneDirty();
  170. }
  171. /// <summary>
  172. /// Creates a new scene object with a sphere primitive.
  173. /// </summary>
  174. [MenuItem("Scene Objects/3D primitives/Sphere", 8099)]
  175. [ToolbarItem("Sphere", ToolbarIcon.NewSphere, "Creates a scene object with a sphere primitive.", 1699)]
  176. private static void Add3DSphere()
  177. {
  178. SceneObject so = UndoRedo.CreateSO("Sphere", "Created a sphere");
  179. Renderable renderable = so.AddComponent<Renderable>();
  180. renderable.Mesh = Builtin.Sphere;
  181. Selection.SceneObject = so;
  182. EditorApplication.SetSceneDirty();
  183. }
  184. /// <summary>
  185. /// Creates a new scene object with a cone primitive.
  186. /// </summary>
  187. [MenuItem("Scene Objects/3D primitives/Cone", 8098)]
  188. [ToolbarItem("Cone", ToolbarIcon.NewCone, "Creates a scene object with a cone primitive.", 1698)]
  189. private static void Add3DCone()
  190. {
  191. SceneObject so = UndoRedo.CreateSO("Cone", "Created a cone");
  192. Renderable renderable = so.AddComponent<Renderable>();
  193. renderable.Mesh = Builtin.Cone;
  194. Selection.SceneObject = so;
  195. EditorApplication.SetSceneDirty();
  196. }
  197. /// <summary>
  198. /// Creates a new scene object with a quad primitive.
  199. /// </summary>
  200. [MenuItem("Scene Objects/3D primitives/Quad", 8097)]
  201. [ToolbarItem("Quad", ToolbarIcon.NewQuad, "Creates a scene object with a quad primitive.", 1697)]
  202. private static void Add3DQuad()
  203. {
  204. SceneObject so = UndoRedo.CreateSO("Quad", "Created a quad");
  205. Renderable renderable = so.AddComponent<Renderable>();
  206. renderable.Mesh = Builtin.Quad;
  207. Selection.SceneObject = so;
  208. EditorApplication.SetSceneDirty();
  209. }
  210. /// <summary>
  211. /// Creates a new scene object with a disc primitive.
  212. /// </summary>
  213. [MenuItem("Scene Objects/3D primitives/Disc", 8096)]
  214. private static void Add3DDisc()
  215. {
  216. SceneObject so = UndoRedo.CreateSO("Disc", "Created a disc");
  217. Renderable renderable = so.AddComponent<Renderable>();
  218. renderable.Mesh = Builtin.Disc;
  219. Selection.SceneObject = so;
  220. EditorApplication.SetSceneDirty();
  221. }
  222. /// <summary>
  223. /// Applies changes from the prefab instance to the prefab resource.
  224. /// </summary>
  225. [MenuItem("Scene Objects/Apply prefab", 8025, true)]
  226. private static void ApplyPrefab()
  227. {
  228. SceneObject so = Selection.SceneObject;
  229. if (so == null)
  230. return;
  231. PrefabUtility.ApplyPrefab(so);
  232. }
  233. /// <summary>
  234. /// Reverts a prefab instance to the original state of its prefab.
  235. /// </summary>
  236. [MenuItem("Scene Objects/Revert to prefab", 8024)]
  237. private static void RevertToPrefab()
  238. {
  239. SceneObject so = Selection.SceneObject;
  240. if (so == null)
  241. return;
  242. UndoRedo.RecordSO(so, true, "Reverting \"" + so.Name + "\" to prefab.");
  243. PrefabUtility.RevertPrefab(so);
  244. EditorApplication.SetSceneDirty();
  245. }
  246. /// <summary>
  247. /// Breaks a link between a prefab and its instance.
  248. /// </summary>
  249. [MenuItem("Scene Objects/Break prefab link", 8023)]
  250. private static void BreakPrefabLink()
  251. {
  252. SceneObject so = Selection.SceneObject;
  253. if (so == null)
  254. return;
  255. UndoRedo.BreakPrefab(so, "Breaking prefab link for " + so.Name);
  256. EditorApplication.SetSceneDirty();
  257. }
  258. /// <summary>
  259. /// Cuts the currently selected scene object or resource.
  260. /// </summary>
  261. [MenuItem("Edit/Cut", 9450, true)]
  262. public static void Cut()
  263. {
  264. if (Selection.SceneObjects != null && Selection.SceneObjects.Length > 0)
  265. {
  266. HierarchyWindow win = EditorWindow.GetWindow<HierarchyWindow>();
  267. if (win != null)
  268. win.CutSelection();
  269. }
  270. else if (Selection.ResourcePaths != null && Selection.ResourcePaths.Length > 0)
  271. {
  272. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  273. if (win != null)
  274. win.CutSelection();
  275. }
  276. }
  277. /// <summary>
  278. /// Copies the currently selected scene object or resource.
  279. /// </summary>
  280. [MenuItem("Edit/Copy", 9449)]
  281. public static void Copy()
  282. {
  283. if (Selection.SceneObjects != null && Selection.SceneObjects.Length > 0)
  284. {
  285. HierarchyWindow win = EditorWindow.GetWindow<HierarchyWindow>();
  286. if (win != null)
  287. win.CopySelection();
  288. }
  289. else if (Selection.ResourcePaths != null && Selection.ResourcePaths.Length > 0)
  290. {
  291. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  292. if (win != null)
  293. win.CopySelection();
  294. }
  295. }
  296. /// <summary>
  297. /// Pastes the scene objects or resources that were previously cut or copied.
  298. /// </summary>
  299. [MenuItem("Edit/Paste", 9448)]
  300. public static void Paste()
  301. {
  302. // TODO - This is slightly wrong in case both windows have something in their paste buffer (unify them?)
  303. {
  304. HierarchyWindow win = EditorWindow.GetWindow<HierarchyWindow>();
  305. if (win != null)
  306. win.PasteToSelection();
  307. }
  308. {
  309. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  310. if (win != null)
  311. win.PasteToSelection();
  312. }
  313. }
  314. /// <summary>
  315. /// Deletes currently selected scene objects or resources.
  316. /// </summary>
  317. [MenuItem("Edit/Delete", 9447)]
  318. public static void Delete()
  319. {
  320. if (Selection.SceneObjects != null && Selection.SceneObjects.Length > 0)
  321. {
  322. HierarchyWindow win = EditorWindow.GetWindow<HierarchyWindow>();
  323. if (win != null)
  324. win.DeleteSelection();
  325. }
  326. else if (Selection.ResourcePaths != null && Selection.ResourcePaths.Length > 0)
  327. {
  328. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  329. if (win != null)
  330. win.DeleteSelection();
  331. }
  332. }
  333. /// <summary>
  334. /// Duplicates currently selected scene objects or resources.
  335. /// </summary>
  336. [MenuItem("Edit/Duplicate", 9446)]
  337. public static void Duplicate()
  338. {
  339. if (Selection.SceneObjects != null && Selection.SceneObjects.Length > 0)
  340. {
  341. HierarchyWindow win = EditorWindow.GetWindow<HierarchyWindow>();
  342. if (win != null)
  343. win.DuplicateSelection();
  344. }
  345. else if (Selection.ResourcePaths != null && Selection.ResourcePaths.Length > 0)
  346. {
  347. LibraryWindow win = EditorWindow.GetWindow<LibraryWindow>();
  348. if (win != null)
  349. win.DuplicateSelection();
  350. }
  351. }
  352. }
  353. }