ExecuteMenuItem
How do I use Execute Menu Item
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
Line | Code | Ex.. |
---|---|---|
61 | EditorApplication.ExecuteMenuItem("Window/Photon Unity Networking"); | 1 |
63 | EditorApplication.ExecuteMenuItem("Edit/Project Settings/Tags and Layers"); | 2 |
File name: PhotonView.cs
Copy
59 void OpenPunWizard()
60 {
61 EditorApplication.ExecuteMenuItem("Window/Photon Unity Networking");
62 }
File name: SortingLayerExposedEditor.cs
Copy
15 public override void OnInspectorGUI()
16 {
17 // Get the renderer from the target object
18 var renderer = (target as SortingLayerExposed).gameObject.GetComponent
19
20 // If there is no renderer, we can't do anything
21 if (!renderer)
22 {
23 return;
24 }
25
26 // Expose the sorting layer name
27 //string newSortingLayerName = EditorGUILayout.TextField("Sorting Layer", renderer.sortingLayerName);
28 //if (newSortingLayerName != renderer.sortingLayerName)
29 //{
30 // Undo.RecordObject(renderer, "Edit Sorting Layer Name");
31 // renderer.sortingLayerName = newSortingLayerName;
32 // EditorUtility.SetDirty(renderer);
33 //}
34
35 // Expose the sorting layer ID
36 //int newSortingLayerId = EditorGUILayout.IntField("Sorting Layer ID", renderer.sortingLayerID);
37 //if (newSortingLayerId != renderer.sortingLayerID)
38 //{
39 // Undo.RecordObject(renderer, "Edit Sorting Layer ID");
40 // renderer.sortingLayerID = newSortingLayerId;
41 // EditorUtility.SetDirty(renderer);
42 //}
43
44 // Seanba: Use a popup that is populated with the acceptable sorting layers for the renderer
45 // Also allow the player to bring up the Tag/Layers inspector if they choose so
46 string[] sortLayerNames = GetSortingLayerNames();
47 //int[] sortLayerIds = GetSortingLayerUniqueIDs();
48 //{
49 // StringBuilder builder = new StringBuilder("Sorting Layers = ");
50 // for (int i = 0; i < sortLayerNames.Length; ++i)
51 // {
52 // builder.AppendFormat("({0} = {1},{2}) ", i, sortLayerIds[i], sortLayerNames[i]);
53 // }
54 // Debug.Log(builder.ToString());
55 //}
56
57 int sortLayerSelection = GetSortingLayerIndex(renderer, sortLayerNames);
58
59 GUIContent[] sortingLayerContexts = GetSortingLayerContexts();
60 int newSortingLayerIndex = EditorGUILayout.Popup(new GUIContent("Sorting Layer"), sortLayerSelection, sortingLayerContexts);
61 if (newSortingLayerIndex == sortingLayerContexts.Length - 1)
62 {
63 EditorApplication.ExecuteMenuItem("Edit/Project Settings/Tags and Layers");
64 }
65 else if (newSortingLayerIndex != sortLayerSelection)
66 {
67 //int newSortingLayerId = sortLayerIds[newSortingLayerIndex];
68 string newSortingLayerName = sortLayerNames[newSortingLayerIndex];
69
70 Undo.RecordObject(renderer, "Edit Sorting Layer ID");
71 renderer.sortingLayerName = newSortingLayerName;
72 //renderer.sortingLayerID = newSortingLayerId;
73
74 EditorUtility.SetDirty(renderer);
75 }
76
77 // Expose the manual sorting order within a sort layer
78 int newSortingLayerOrder = EditorGUILayout.IntField("Order in Layer", renderer.sortingOrder);
79 if (newSortingLayerOrder != renderer.sortingOrder)
80 {
81 Undo.RecordObject(renderer, "Edit Sorting Order");
82 renderer.sortingOrder = newSortingLayerOrder;
83 EditorUtility.SetDirty(renderer);
84 }
85 }
ExecuteMenuItem 103 lượt xem
Gõ tìm kiếm nhanh...