public static void OnDrawGizmosDebugRenderManager(DebugRenderManager manager, GizmoType gizmoType) { if (!manager.isActiveAndEnabled) { return; } HandleColorizedBodies(manager); HandleContacts(manager); }
private static void HandleContacts(DebugRenderManager manager) { if (!manager.RenderContacts) { return; } Gizmos.color = manager.ContactColor; foreach (var contact in manager.ContactList) { Gizmos.DrawMesh(Constraint.GetOrCreateGizmosMesh(), contact.Point, Quaternion.FromToRotation(Vector3.up, contact.Normal), manager.ContactScale * Spawner.Utils.FindConstantScreenSizeScale(contact.Point, Camera.current) * Vector3.one); } }
private static void HandleColorizedBodies(DebugRenderManager manager) { // List containing active tools decisions of what could be considered selected. var toolsSelections = new List <Tool.VisualizedSelectionData>(); // Active assembly tool has special rendering needs. Tools.AssemblyTool assemblyTool = null; Tool.TraverseActive(activeTool => { if (assemblyTool == null && activeTool is Tools.AssemblyTool) { assemblyTool = activeTool as Tools.AssemblyTool; } if (activeTool.VisualizedSelection != null && !toolsSelections.Contains(activeTool.VisualizedSelection)) { toolsSelections.Add(activeTool.VisualizedSelection); } }); bool highlightMouseOverObject = manager.HighlightMouseOverObject; // Find if we've any active selections. bool selectionActive = (highlightMouseOverObject && Manager.MouseOverObject != null) || toolsSelections.Count > 0 || (assemblyTool != null && assemblyTool.HasActiveSelections()) || Array.Exists(Selection.gameObjects, go => { return(go.GetComponent <Shape>() != null || go.GetComponent <RigidBody>() != null); }); if (!selectionActive) { m_colorHandler.TimeInterpolator.Reset(); } // Early exist if we're not visualizing the bodies nor have active selections. bool active = manager.ColorizeBodies || selectionActive || assemblyTool != null; if (!active) { return; } try { using (m_colorHandler.BeginEndScope()) { // Create unique colors for each rigid body in the scene. { var bodies = UnityEngine.Object.FindObjectsOfType <RigidBody>(); Array.Sort(bodies, (b1, b2) => { return(b1.GetInstanceID() > b2.GetInstanceID() ? -1 : 1); }); foreach (var body in bodies) { // Create the color for all bodies for the colors to be consistent. m_colorHandler.GetOrCreateColor(body); if (manager.ColorizeBodies && body.enabled && body.gameObject.activeInHierarchy) { m_colorHandler.Colorize(body); } } } // An active assembly tool will (atm) render objects in a different // way and, e.g., render colorized bodies despite manager.VisualizeBodies. if (assemblyTool != null) { assemblyTool.OnRenderGizmos(m_colorHandler); } // Handling objects selected in the editor. { GameObject[] editorSelections = Selection.gameObjects; foreach (var editorSelection in editorSelections) { HandleSelectedGameObject(editorSelection, ObjectsGizmoColorHandler.SelectionType.ConstantColor); } } // Handling objects selected in our tools. { foreach (var toolSelection in toolsSelections) { HandleSelectedGameObject(toolSelection.Object, ObjectsGizmoColorHandler.SelectionType.VaryingIntensity); } } if (highlightMouseOverObject) { HandleSelectedGameObject(Manager.MouseOverObject, ObjectsGizmoColorHandler.SelectionType.VaryingIntensity); } foreach (var filterColorPair in m_colorHandler.ColoredMeshFilters) { Gizmos.color = filterColorPair.Value; Gizmos.matrix = filterColorPair.Key.transform.localToWorldMatrix; Gizmos.DrawWireMesh(filterColorPair.Key.sharedMesh); } Gizmos.matrix = Matrix4x4.identity; } } catch (System.Exception e) { Debug.LogException(e); } }
public DebugRenderManagerTool(DebugRenderManager manager) { Manager = manager; }