void CreateDefaultTools() { m_DefaultTools.Clear(); for (int i = 0; i < (int)Tool.Custom; i++) { var button = new ToolButton((Tool)i); button.displayChanged += () => EditorToolbarUtility.SetupChildrenAsButtonStrip(m_DefaultTools); m_DefaultTools.Add(button); } foreach (var type in EditorToolManager.activeToolContext.GetAdditionalToolTypes()) { if (!typeof(EditorTool).IsAssignableFrom(type)) { Debug.LogError($"{type} must be assignable to EditorTool, and not abstract."); continue; } var addl = EditorToolManager.GetSingleton(type) as EditorTool; var button = new ComponentToolButton <EditorTool>(addl); m_DefaultTools.Add(button); } EditorToolbarUtility.SetupChildrenAsButtonStrip(m_DefaultTools); }
internal static void DoContextualToolbarOverlay() { GUILayout.BeginHorizontal(GUIStyle.none, GUILayout.MinWidth(210), GUILayout.Height(30)); EditorToolManager.GetComponentToolsForSharedTracker(s_EditorToolModes); if (s_EditorToolModes.Count > 0) { EditorGUI.BeginChangeCheck(); EditorGUILayout.EditorToolbar(s_EditorToolModes); if (EditorGUI.EndChangeCheck()) { foreach (var inspector in InspectorWindow.GetInspectors()) { foreach (var editor in inspector.tracker.activeEditors) { editor.Repaint(); } } } } else { var fontStyle = EditorStyles.label.fontStyle; EditorStyles.label.fontStyle = FontStyle.Italic; GUILayout.Label(Styles.noToolsAvailable, EditorStyles.centeredGreyMiniLabel); EditorStyles.label.fontStyle = fontStyle; } GUILayout.EndHorizontal(); }
void Refresh() { for (int i = childCount - 1; i > -1; i--) { RemoveAt(i); } AddToClassList("toolbar-contents"); if ((EditorToolManager.GetCustomEditorToolsCount(false) + EditorToolManager.availableComponentContextCount) < 1) { return; } EditorToolManager.GetComponentToolsForSharedTracker(s_EditorTools); s_SortedTools.Clear(); // Display available tools grouped by their target component foreach (var tool in s_EditorTools) { var component = tool.target; if (component == null) { continue; } if (!s_SortedTools.TryGetValue(component, out List <EditorTool> editorTools)) { editorTools = new List <EditorTool>(); s_SortedTools.Add(component, editorTools); } editorTools.Add(tool); } foreach (var kvp in s_SortedTools) { var tools = new VisualElement() { name = "Component Tools" }; tools.AddToClassList("toolbar-contents"); foreach (var tool in kvp.Value) { tools.Add(new ComponentToolButton <EditorTool>(tool)); } EditorToolbarUtility.SetupChildrenAsButtonStrip(tools); Add(tools); } }
public static void EditorToolbarForTarget(GUIContent content, UObject target) { if (target == null) { throw new ArgumentNullException("target"); } if (target is Editor editor) { target = editor.target; } EditorToolManager.GetComponentTools(x => x.target == target, s_CustomEditorTools, true); using (new PrefixScope(content)) EditorToolbar <EditorTool>(s_CustomEditorTools); s_CustomEditorTools.Clear(); }
/// <summary> /// Toggles the state of active editor tool with the type passed in. /// </summary> /// <remarks> /// This will change the current active editor tool if the type passed in /// is not the same as the current active editor tool. Otherwise, it will /// set the View Mode tool as the current active editor tool. /// </remarks> /// <param name="type"> /// The type of editor tool. This must be inherited from EditorTool. /// </param> public static void ToggleActiveEditorTool(Type type) { if (ToolManager.activeToolType != type) { SetActiveEditorTool(type); } else { // Switch out of TilemapEditorTool if possible var lastTool = EditorToolManager.GetLastTool(x => !(x is TilemapEditorTool)); if (lastTool != null) { ToolManager.SetActiveTool(lastTool); } else { ToolManager.SetActiveTool(typeof(ViewModeTool)); } } }
public static void ToolContextToolbarForTarget(GUIContent content, UObject target) { if (target == null) { throw new ArgumentNullException("target"); } if (target is Editor editor) { EditorToolManager.GetComponentContexts(x => x.inspector == editor, s_CustomEditorContexts); } else { EditorToolManager.GetComponentContexts(x => x.target == target, s_CustomEditorContexts); } ToolContextToolbar(content, s_CustomEditorContexts); s_CustomEditorTools.Clear(); }
override public void OnInspectorGUI(InitialModuleUI initial) { EditorGUI.BeginChangeCheck(); CollisionTypes type = (CollisionTypes)GUIPopup(s_Texts.collisionType, m_Type, s_Texts.collisionTypes); if (EditorGUI.EndChangeCheck()) { ToolManager.RefreshAvailableTools(); } if (type == CollisionTypes.Plane) { DoListOfPlanesGUI(); } else { GUIPopup(s_Texts.collisionMode, m_CollisionMode, s_Texts.collisionModes); } GUIMinMaxCurve(s_Texts.dampen, m_Dampen); GUIMinMaxCurve(s_Texts.bounce, m_Bounce); GUIMinMaxCurve(s_Texts.lifetimeLoss, m_LifetimeLossOnCollision); GUIFloat(s_Texts.minKillSpeed, m_MinKillSpeed); GUIFloat(s_Texts.maxKillSpeed, m_MaxKillSpeed); GUIFloat(s_Texts.radiusScale, m_RadiusScale); if (type == CollisionTypes.World) { GUIPopup(s_Texts.quality, m_Quality, s_Texts.qualitySettings); EditorGUI.indentLevel++; GUILayerMask(s_Texts.collidesWith, m_CollidesWith); GUIInt(s_Texts.maxCollisionShapes, m_MaxCollisionShapes); if (m_Quality.intValue == 0) { GUIToggle(s_Texts.collidesWithDynamic, m_CollidesWithDynamic); } else { GUIFloat(s_Texts.voxelSize, m_VoxelSize); } EditorGUI.indentLevel--; GUIFloat(s_Texts.colliderForce, m_ColliderForce); EditorGUI.indentLevel++; GUIToggle(s_Texts.multiplyColliderForceByCollisionAngle, m_MultiplyColliderForceByCollisionAngle); GUIToggle(s_Texts.multiplyColliderForceByParticleSpeed, m_MultiplyColliderForceByParticleSpeed); GUIToggle(s_Texts.multiplyColliderForceByParticleSize, m_MultiplyColliderForceByParticleSize); EditorGUI.indentLevel--; } GUIToggle(s_Texts.collisionMessages, m_CollisionMessages); if (EditorGUIUtility.comparisonViewMode == EditorGUIUtility.ComparisonViewMode.None) { EditorGUILayout.BeginVertical("GroupBox"); if (type == CollisionTypes.Plane) { var editorTools = new List <EditorTool>(2); EditorToolManager.GetComponentTools(x => x.GetEditor <EditorTool>() is CollisionModuleTransformTool, editorTools, true); GUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel(s_Texts.sceneTools, ParticleSystemStyles.Get().label, ParticleSystemStyles.Get().label); EditorGUILayout.EditorToolbar(editorTools); GUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); m_PlaneVisualizationType = (PlaneVizType)GUIPopup(s_Texts.visualization, (int)m_PlaneVisualizationType, s_Texts.planeVizTypes); if (EditorGUI.EndChangeCheck()) { EditorPrefs.SetInt("PlaneColisionVizType", (int)m_PlaneVisualizationType); } EditorGUI.BeginChangeCheck(); m_ScaleGrid = GUIFloat(s_Texts.scalePlane, m_ScaleGrid, "f2"); if (EditorGUI.EndChangeCheck()) { m_ScaleGrid = Mathf.Max(0f, m_ScaleGrid); EditorPrefs.SetFloat("ScalePlaneColision", m_ScaleGrid); } } else { GUILayout.Label(s_Texts.sceneTools, ParticleSystemStyles.Get().label); } EditorGUI.BeginChangeCheck(); s_VisualizeBounds = GUIToggle(s_Texts.visualizeBounds, s_VisualizeBounds); if (EditorGUI.EndChangeCheck()) { EditorPrefs.SetBool("VisualizeBounds", s_VisualizeBounds); } EditorGUILayout.EndVertical(); } }