Skip to content

Commit 8475d47

Browse files
author
Sander van Rossen
committed
Some files that weren't correctly added to previous commits
1 parent 1940133 commit 8475d47

File tree

10 files changed

+94
-29
lines changed

10 files changed

+94
-29
lines changed

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Control/Managers/InternalCSGModelManager.Lifetime.cs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using UnityEngine;
44
using System.Linq;
@@ -65,11 +65,35 @@ public static void Shutdown()
6565
#endregion
6666

6767
#region UndoRedoPerformed
68+
internal static bool IgnoreMaterials = false;
6869
public static void UndoRedoPerformed()
6970
{
7071
BrushOutlineManager.ClearOutlines();
7172

7273
CheckForChanges(forceHierarchyUpdate: true);
74+
75+
if (!IgnoreMaterials)
76+
{
77+
foreach (var brush in Brushes)
78+
{
79+
try
80+
{
81+
//brush.EnsureInitialized();
82+
if (brush.Shape != null)
83+
ShapeUtility.CheckMaterials(brush.Shape);
84+
}
85+
finally { }
86+
}
87+
foreach (var brush in Brushes)
88+
{
89+
try
90+
{
91+
InternalCSGModelManager.CheckSurfaceModifications(brush, true);
92+
//InternalCSGModelManager.ValidateBrush(brush);
93+
}
94+
finally { }
95+
}
96+
}
7397
}
7498
#endregion
7599

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/Data/SceneQuery/SceneQueryUtility.cs

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,11 @@ public static CSGModel EndPicking(HideFlagsState state, UnityEngine.GameObject p
525525
return null;
526526
}
527527

528-
static GameObject FindFirstWorldIntersection(Camera camera, Vector2 screenPos, Vector3 worldRayStart, Vector3 worldRayEnd, List<GameObject> ignoreGameObjects = null, List<CSGBrush> ignoreBrushes = null, bool ignoreInvisibleSurfaces = true)
528+
static GameObject FindFirstWorldIntersection(Camera camera, Vector2 screenPos, Vector3 worldRayStart, Vector3 worldRayEnd, out MeshRenderer meshRenderer, out int materialIndex, List<GameObject> ignoreGameObjects = null, List<CSGBrush> ignoreBrushes = null, bool ignoreInvisibleSurfaces = true)
529529
{
530+
meshRenderer = null;
531+
materialIndex = 0;
532+
530533
var wireframeShown = CSGSettings.IsWireframeShown(camera);
531534

532535
TryAgain:
@@ -537,7 +540,10 @@ static GameObject FindFirstWorldIntersection(Camera camera, Vector2 screenPos, V
537540
var ignoreGameObjectArray = (ignoreGameObjects == null || ignoreGameObjects.Count == 0) ? null : ignoreGameObjects.ToArray();
538541
{
539542
var flagState = BeginPicking(ignoreGameObjectArray);
540-
try { gameObject = HandleUtility.PickGameObject(screenPos, false, ignoreGameObjectArray); }
543+
try
544+
{
545+
gameObject = HandleUtility.PickGameObject(screenPos, ignoreGameObjectArray, out materialIndex);
546+
}
541547
finally { model = EndPicking(flagState, gameObject); }
542548
}
543549

@@ -580,14 +586,17 @@ static GameObject FindFirstWorldIntersection(Camera camera, Vector2 screenPos, V
580586
if (ReferenceEquals(gameObject, null) ||
581587
!gameObject)
582588
return null;
583-
584-
// Make sure our found gameobject isn't sneakily a CSG related object (should not happen at this point)
585-
if (!gameObject.GetComponent<CSGModel>() &&
586-
!gameObject.GetComponent<CSGBrush>() &&
587-
!gameObject.GetComponent<CSGOperation>() &&
588-
!gameObject.GetComponent<GeneratedMeshInstance>() &&
589-
!gameObject.GetComponent<GeneratedMeshes>())
590-
return gameObject;
589+
590+
// Make sure our found gameobject isn't sneakily a CSG related object (should not happen at this point)
591+
if (!gameObject.GetComponent<CSGModel>() &&
592+
!gameObject.GetComponent<CSGBrush>() &&
593+
!gameObject.GetComponent<CSGOperation>() &&
594+
!gameObject.GetComponent<GeneratedMeshInstance>() &&
595+
!gameObject.GetComponent<GeneratedMeshes>())
596+
{
597+
meshRenderer = gameObject.GetComponent<MeshRenderer>();
598+
return gameObject;
599+
}
591600

592601
// If we're not ignoring something, just return null after all
593602
if (ignoreGameObjects == null)
@@ -598,9 +607,24 @@ static GameObject FindFirstWorldIntersection(Camera camera, Vector2 screenPos, V
598607
goto TryAgain;
599608
}
600609

610+
public static bool FindClickWorldIntersection(Camera camera, Vector2 screenPos, out GameObject foundObject, bool ignoreInvisibleSurfaces = true, bool ignoreDeepClick = false)
611+
{
612+
MeshRenderer meshRenderer = null;
613+
int materialIndex= 0;
614+
return FindClickWorldIntersection(camera, screenPos, out foundObject, out meshRenderer, out materialIndex, ignoreInvisibleSurfaces, ignoreDeepClick);
615+
}
616+
617+
public static void ClearDeepClick()
618+
{
619+
clearDeepClick = true;
620+
}
601621

602-
public static bool FindClickWorldIntersection(Camera camera, Vector2 screenPos, out GameObject foundObject, bool ignoreInvisibleSurfaces = true)
622+
static bool clearDeepClick = false;
623+
624+
public static bool FindClickWorldIntersection(Camera camera, Vector2 screenPos, out GameObject foundObject, out MeshRenderer meshRenderer, out int materialIndex, bool ignoreInvisibleSurfaces = true, bool ignoreDeepClick = false)
603625
{
626+
meshRenderer = null;
627+
materialIndex = 0;
604628
foundObject = null;
605629
if (!camera)
606630
return false;
@@ -610,16 +634,21 @@ public static bool FindClickWorldIntersection(Camera camera, Vector2 screenPos,
610634
var worldRayVector = (worldRay.direction * (camera.farClipPlane - camera.nearClipPlane));
611635
var worldRayEnd = worldRayStart + worldRayVector;
612636

613-
// If we moved our mouse, reset our ignore list
614-
if (_prevSceenPos != screenPos ||
615-
_prevCamera != camera)
616-
ResetDeepClick();
637+
// If we moved our mouse, reset our ignore list
638+
if (_prevSceenPos != screenPos ||
639+
_prevCamera != camera ||
640+
ignoreDeepClick ||
641+
clearDeepClick)
642+
{
643+
ResetDeepClick();
644+
clearDeepClick = false;
645+
}
617646

618647
_prevSceenPos = screenPos;
619648
_prevCamera = camera;
620649

621650
// Get the first click that is not in our ignore list
622-
foundObject = FindFirstWorldIntersection(camera, screenPos, worldRayStart, worldRayEnd, deepClickIgnoreGameObjectList, deepClickIgnoreBrushList, ignoreInvisibleSurfaces);
651+
foundObject = FindFirstWorldIntersection(camera, screenPos, worldRayStart, worldRayEnd, out meshRenderer, out materialIndex, deepClickIgnoreGameObjectList, deepClickIgnoreBrushList, ignoreInvisibleSurfaces);
623652

624653
// If we haven't found anything, try getting the first item in our list that's either a brush or a regular gameobject (loop around)
625654
if (object.Equals(foundObject, null))

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/DragAndDrop/ISceneDragTool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal interface ISceneDragTool
1111
bool ValidateDrop (SceneView sceneView);
1212
bool ValidateDropPoint (SceneView sceneView);
1313
void Reset ();
14-
bool DragUpdated (Transform transformInInspector, Rect selectionRect);
14+
bool DragUpdated (SceneView sceneView, Transform transformInInspector, Rect selectionRect);
1515
bool DragUpdated (SceneView sceneView);
1616
void DragPerform (SceneView sceneView);
1717
void DragExited (SceneView sceneView);

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModeManager.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,8 @@ public static void OnSceneGUI(SceneView sceneView)
580580

581581
if (RealtimeCSG.CSGSettings.EnableRealtimeCSG)
582582
{
583-
if (sceneView && sceneWindowType != EventType.Used && !SceneDragToolManager.IsDraggingObjectInScene)
583+
if (sceneView && sceneWindowType != EventType.Used &&
584+
(!SceneDragToolManager.IsDraggingObjectInScene || EditMode == ToolEditMode.Surfaces))
584585
{
585586
if (currentEditorWindows.Count == 0)
586587
{

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModeSelection.GUI.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ static void HandleSceneGUI(int id)
4848
TooltipUtility.InitToolTip(sceneView);
4949
var originalSkin = GUI.skin;
5050
{
51-
OnEditModeSelectionSceneGUI();
51+
if (!SceneDragToolManager.IsDraggingObjectInScene)
52+
OnEditModeSelectionSceneGUI();
5253

5354
var viewRect = new Rect(4, 0, sceneView.position.width, sceneView.position.height - (CSG_GUIStyleUtility.BottomToolBarHeight + 4));
5455
GUILayout.BeginArea(viewRect);
@@ -59,7 +60,7 @@ static void HandleSceneGUI(int id)
5960
}
6061
GUILayout.EndArea();
6162

62-
if (RealtimeCSG.CSGSettings.EnableRealtimeCSG)
63+
if (RealtimeCSG.CSGSettings.EnableRealtimeCSG && !SceneDragToolManager.IsDraggingObjectInScene)
6364
SceneViewBottomBarGUI.ShowGUI(sceneView, haveOffset: false);
6465
}
6566
GUI.skin = originalSkin;

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModes/EditMode.Edit.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2377,6 +2377,7 @@ public void HandleEvents(SceneView sceneView, Rect sceneRect)
23772377
{
23782378
if (GUIUtility.hotControl != 0)
23792379
break;
2380+
SceneQueryUtility.ClearDeepClick();
23802381
if (HavePointSelection && (Event.current.commandName == "SoftDelete" || Event.current.commandName == "Delete")) { Event.current.Use(); break; }
23812382
if (Keys.CancelActionKey.IsKeyPressed()) { Event.current.Use(); break; }
23822383
if (Keys.SnapToGridKey.IsKeyPressed()) { Event.current.Use(); break; }

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModes/EditMode.Place.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ public Vector3 LocalSpacePivotCenter
190190
[SerializeField] ControlMesh[] backupControlMeshes = null; // brush
191191
#endregion
192192

193-
public void OnEnableTool() { toolIsEnabled = true; Tools.hidden = shouldHideTool; ResetTool(); }
194-
public void OnDisableTool() { toolIsEnabled = false; Tools.hidden = false; ResetTool(); }
193+
public void OnEnableTool() { toolIsEnabled = true; Tools.hidden = shouldHideTool; ResetTool(); }
194+
public void OnDisableTool() { toolIsEnabled = false; Tools.hidden = false; ResetTool(); }
195195

196196
public void SetTargets(FilteredSelection filteredSelection)
197197
{
@@ -424,7 +424,7 @@ void UpdateTargetBoundsHandles(Camera camera)
424424
renderLocalCenterPoints[4] = new Vector3(centerX, centerY, minZ);
425425
renderLocalCenterPoints[5] = new Vector3(centerX, centerY, maxZ);
426426

427-
for (int i=0;i< BoundsUtilities.AABBEdgeIndices.Length; i++)
427+
for (int i = 0; i < BoundsUtilities.AABBEdgeIndices.Length; i++)
428428
{
429429
var index1 = BoundsUtilities.AABBEdgeIndices[i][0];
430430
var index2 = BoundsUtilities.AABBEdgeIndices[i][1];
@@ -609,7 +609,13 @@ public bool UndoRedoPerformed()
609609
//CSGModelManager.Refresh(forceHierarchyUpdate: true);
610610
return false;
611611
}
612-
public bool DeselectAll() { Selection.activeTransform = null; return false; }
612+
613+
public bool DeselectAll()
614+
{
615+
SceneQueryUtility.ClearDeepClick();
616+
Selection.activeTransform = null;
617+
return false;
618+
}
613619

614620
public void RecenterPivot()
615621
{
@@ -1695,6 +1701,7 @@ public void HandleEvents(SceneView sceneView, Rect sceneRect)
16951701

16961702
case EventType.KeyDown:
16971703
{
1704+
SceneQueryUtility.ClearDeepClick();
16981705
if (Tools.viewTool != ViewTool.FPS && Keys.CloneDragActivate.IsKeyPressed()) { cloneDragKeyPressed = true; Event.current.Use(); break; }
16991706
if (Keys.HandleSceneKeyDown(EditModeManager.CurrentTool, false)) { Event.current.Use(); break; }
17001707
if (Keys.FlipSelectionX.IsKeyPressed()) { Event.current.Use(); break; }

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModes/EditMode.Surface.GUI.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ public static Rect GetLastSceneGUIRect(EditModeSurface tool)
10111011

10121012
static Vector2 scrollbarPosition = Vector2.zero;
10131013

1014-
1014+
10151015
static Rect sceneGUIRect = new Rect(0, 0, 232, 0);
10161016
public static void OnSceneGUI(Rect windowRect, EditModeSurface tool)
10171017
{

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModes/EditMode.Surface.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ void RestoreBackupTexgens()
459459

460460
EditMode SetHoverOn(EditMode editModeType, int target, int index = -1)
461461
{
462-
hoverOnTarget = target;
462+
hoverOnTarget = target;
463463
if (target == -1)
464464
{
465465
hoverOnSurfaceIndex = -1;
@@ -1088,6 +1088,7 @@ public void HandleEvents(SceneView sceneView, Rect sceneRect)
10881088

10891089
case EventType.KeyDown:
10901090
{
1091+
SceneQueryUtility.ClearDeepClick();
10911092
if (Keys.CancelActionKey.IsKeyPressed()) { Event.current.Use(); break; }
10921093
if (Keys.CopyMaterialTexGen.IsKeyPressed()) { if (dragMode == DragMode.None) dragMode = DragMode.TextureCopy; Event.current.Use(); break; }
10931094
if (Keys.HandleSceneKeyDown(EditModeManager.CurrentTool, false)) { Event.current.Use(); break; }
@@ -1307,7 +1308,7 @@ public void HandleEvents(SceneView sceneView, Rect sceneRect)
13071308
if ( nearestControl != -1)
13081309
{
13091310
surfaceState.UnHoverAll();
1310-
1311+
13111312
if (newEditMode == EditMode.None)
13121313
{
13131314
for (int s = 0; s < surfaceState.surfaceSelectState.Length; s++)

RealtimeCSG/Assets/Plugins/RealtimeCSG/Editor/Scripts/View/GUI/EditModeGUI/EditModes/Generators/Generator.Base.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ protected void HandleKeyboard(EventType type)
301301
{
302302
case EventType.ValidateCommand:
303303
case EventType.KeyDown:
304-
{
304+
{
305+
SceneQueryUtility.ClearDeepClick();
305306
if (Keys.PerformActionKey.IsKeyPressed() ||
306307
Keys.DeleteSelectionKey.IsKeyPressed() ||
307308
Keys.CancelActionKey.IsKeyPressed())

0 commit comments

Comments
 (0)