public void OnSceneGUI() { // paint prefabs on mouse drag. don't do anything if no mode is selected, otherwise e.g. movement in scene view wouldn't work with alt key pressed if (brushComponent.DrawBrush(editorTarget.brushSettings, out BrushMode brushMode, out RaycastHit raycastHit)) { switch (brushMode) { case BrushMode.ShiftDrag: AddPrefabs(raycastHit); needsPhysicsApplied = true; // consume event Event.current.Use(); break; case BrushMode.ShiftCtrlDrag: RemovePrefabs(raycastHit); // consume event Event.current.Use(); break; } } // info for the scene gui; used to be dynamic and showing number of prefabs (currently is static until refactoring is done) string[] guiInfo = new string[] { "Add prefabs: shift + drag mouse\nRemove prefabs: shift + ctrl + drag mouse\nBrush size: ctrl + mousewheel, Brush rotation: ctrl + shift + mousewheel" }; brushComponent.Layout(guiInfo); // auto physics bool applyAutoPhysics = needsPhysicsApplied && autoPhysicsCollection.Count > 0 && editorTarget.spawnSettings.autoSimulationType != SpawnSettings.AutoSimulationType.None && Event.current.type == EventType.MouseUp; if (applyAutoPhysics) { AutoPhysicsSimulation.ApplyPhysics(editorTarget.physicsSettings, autoPhysicsCollection, editorTarget.spawnSettings.autoSimulationType); autoPhysicsCollection.Clear(); } }
private void SpawnPrefabsAlongSpline() { // see PerformEditorAction { editorTarget.splineModule.PlaceObjects(); editorTarget.splineSettings.dirty = false; // Set the editor spline dirty, so that the changed settings (e.g.control points got dragged in the scene) get updated. // Ensure the control points get saved when they are changed in the scene if we wouldn't do that, they'd only be change when something changes in the inspector EditorUtility.SetDirty(editor.target); } // used for later bool needsPhysicsApplied = true; // auto physics bool applyAutoPhysics = needsPhysicsApplied && editorTarget.spawnSettings.autoSimulationType != SpawnSettings.AutoSimulationType.None; if (applyAutoPhysics) { AutoPhysicsSimulation.ApplyPhysics(editorTarget.physicsSettings, editorTarget.container, editorTarget.spawnSettings.autoSimulationType); } }
public void OnSceneGUI() { // paint prefabs on mouse drag. don't do anything if no mode is selected, otherwise e.g. movement in scene view wouldn't work with alt key pressed if (brushComponent.DrawBrush(editorTarget.brushSettings, out BrushMode brushMode, out RaycastHit raycastHit)) { if (editorTarget.interactionSettings.interactionType == InteractionSettings.InteractionType.AntiGravity) { switch (brushMode) { case BrushMode.ShiftPressed: AntiGravity(raycastHit); needsPhysicsApplied = true; // don't consume event; mustn't be consumed during layout or repaint //Event.current.Use(); break; } } if (editorTarget.interactionSettings.interactionType == InteractionSettings.InteractionType.Magnet) { switch (brushMode) { case BrushMode.ShiftPressed: Attract(raycastHit); needsPhysicsApplied = true; // don't consume event; mustn't be consumed during layout or repaint //Event.current.Use(); break; case BrushMode.ShiftCtrlPressed: Repell(raycastHit); needsPhysicsApplied = true; // don't consume event; mustn't be consumed during layout or repaint //Event.current.Use(); break; } } } // TODO: change text // info for the scene gui; used to be dynamic and showing number of prefabs (currently is static until refactoring is done) string[] guiInfo = new string[] { "Add prefabs: shift + drag mouse\nRemove prefabs: shift + ctrl + drag mouse\nBrush size: ctrl + mousewheel, Brush rotation: ctrl + shift + mousewheel" }; brushComponent.Layout(guiInfo); // auto physics bool applyAutoPhysics = needsPhysicsApplied && editorTarget.spawnSettings.autoSimulationType != SpawnSettings.AutoSimulationType.None && Event.current.type == EventType.MouseUp; if (applyAutoPhysics) { AutoPhysicsSimulation.ApplyPhysics(editorTarget.physicsSettings, editorTarget.container, editorTarget.spawnSettings.autoSimulationType); } }
private void StartSimulation() { Transform[] containerChildren = PrefabUtils.GetContainerChildren(editorTarget.container); AutoPhysicsSimulation.ApplyPhysics(editorTarget.physicsSettings, containerChildren, SpawnSettings.AutoSimulationType.Continuous); }