public void EndCommit() { if (generatedBrushes == null) return; var bounds = BoundsUtilities.GetBounds(generatedBrushes); if (!bounds.IsEmpty()) {/* var center = bounds.Center - operationGameObject.transform.position; GeometryUtility.MoveControlMeshVertices(generatedBrushes, -center); SurfaceUtility.TranslateSurfacesInWorldSpace(generatedBrushes, -center); operationGameObject.transform.position += center;*/ ControlMeshUtility.RebuildShapes(generatedBrushes); var models = operationGameObject.GetComponentsInParent<CSGModel>(includeInactive: true); var model = models.Length == 0 ? null : models[0]; model.forceUpdate = true; InternalCSGModelManager.CheckForChanges(forceHierarchyUpdate: true); Undo.CollapseUndoOperations(undoGroupIndex); Cleanup(); if (generatedGameObjects != null && generatedGameObjects.Length > 0) Selection.objects = generatedGameObjects; Reset(); } if (shapeCommitted != null) shapeCommitted(); }
static void RunEditorUpdate() { if (!RealtimeCSG.CSGSettings.EnableRealtimeCSG) { return; } if (EditorApplication.isPlayingOrWillChangePlaymode) { return; } UpdateLoop.UpdateOnSceneChange(); try { if (!ColorSettings.isInitialized) { ColorSettings.Update(); } InternalCSGModelManager.CheckForChanges(forceHierarchyUpdate: false); TooltipUtility.CleanCache(); } catch (Exception ex) { Debug.LogException(ex); } }
public static void UpdateSelection(bool forceUpdate = false) { InitTools(); GetTargetSelection(ref selectedNodes, ref selectedOthers); if (!instance.filteredSelection.UpdateSelection(selectedNodes, selectedOthers) && !forceUpdate) { return; } InternalCSGModelManager.skipCheckForChanges = true; try { InternalCSGModelManager.CheckForChanges(); } finally { InternalCSGModelManager.skipCheckForChanges = false; } foreach (var tool in brushTools) { tool.SetTargets(instance.filteredSelection); } }
public void EndCommit() { if (generatedBrushes == null) { return; } var bounds = BoundsUtilities.GetBounds(generatedBrushes); if (!bounds.IsEmpty()) { var center = bounds.Center - operationGameObject.transform.position; GeometryUtility.MoveControlMeshVertices(generatedBrushes, -center); SurfaceUtility.TranslateSurfacesInWorldSpace(generatedBrushes, -center); ControlMeshUtility.RebuildShapes(generatedBrushes); operationGameObject.transform.position += center; InternalCSGModelManager.CheckForChanges(forceHierarchyUpdate: true); Undo.CollapseUndoOperations(undoGroupIndex); Cleanup(); if (generatedGameObjects != null && generatedGameObjects.Length > 0) { Selection.objects = generatedGameObjects; } Reset(); } if (shapeCommitted != null) { shapeCommitted(); } }
public static CSGBrush CreateBrushInstanceInScene(MenuCommand command) { var parent = GetTransformForMenu(command); var lastUsedModelTransform = !SelectionUtility.LastUsedModel ? null : SelectionUtility.LastUsedModel.transform; if (lastUsedModelTransform == null && !parent) { lastUsedModelTransform = CreateModelInstanceInScene(parent).transform; parent = lastUsedModelTransform; } else if (!parent) { parent = lastUsedModelTransform; } var name = UnityEditor.GameObjectUtility.GetUniqueNameForSibling(parent, "Brush"); var gameObject = new GameObject(name); var brush = gameObject.AddComponent <CSGBrush>(); gameObject.transform.SetParent(parent, true); gameObject.transform.position = new Vector3(0.5f, 0.5f, 0.5f); // this aligns it's vertices to the grid BrushFactory.CreateCubeControlMesh(out brush.ControlMesh, out brush.Shape, Vector3.one); UnityEditor.Selection.activeGameObject = gameObject; Undo.RegisterCreatedObjectUndo(gameObject, "Created brush"); InternalCSGModelManager.CheckForChanges(); InternalCSGModelManager.UpdateMeshes(); return(brush); }
public static void SetPassThroughOnSelected() { var modified = false; foreach (var gameObject in Selection.gameObjects) { var obj = gameObject.GetComponent(CSGOperationType); if (!obj) { continue; } var operation = obj as CSGOperation; if (operation.PassThrough) { continue; } modified = true; Undo.RecordObject(operation, "Modifying csg operation of operation component"); operation.PassThrough = true; } if (!modified) { return; } InternalCSGModelManager.CheckForChanges(); EditorApplication.RepaintHierarchyWindow(); }
public static CSGOperation CreateOperationInstanceInScene(MenuCommand command) { var parent = GetTransformForMenu(command); var lastUsedModelTransform = !SelectionUtility.LastUsedModel ? null : SelectionUtility.LastUsedModel.transform; if (lastUsedModelTransform == null && !parent) { lastUsedModelTransform = CreateModelInstanceInScene(parent).transform; parent = lastUsedModelTransform; } else if (!parent) { parent = lastUsedModelTransform; } var name = UnityEditor.GameObjectUtility.GetUniqueNameForSibling(parent, "Operation");; var gameObject = new GameObject(name); gameObject.transform.SetParent(parent, true); var operation = gameObject.AddComponent <CSGOperation>(); UnityEditor.Selection.activeGameObject = gameObject; Undo.RegisterCreatedObjectUndo(gameObject, "Created operation"); InternalCSGModelManager.CheckForChanges(); InternalCSGModelManager.UpdateMeshes(); return(operation); }
public static GameObject CreateOperation(Transform parent, string name, bool worldPositionStays) { var gameObject = CreateGameObject(parent, name, worldPositionStays); //var operation = gameObject.AddComponent <CSGOperation>(); Undo.RegisterCreatedObjectUndo(gameObject, "Created operation"); InternalCSGModelManager.CheckForChanges(); return(gameObject); }
public static GameObject CreateBrush(ControlMesh controlMesh, Shape shape, Transform parent, string name, bool worldPositionStays) { var gameObject = CreateGameObject(parent, name, worldPositionStays); var brush = gameObject.AddComponent <CSGBrush>(); brush.ControlMesh = controlMesh; brush.Shape = shape; gameObject.SetActive(shape != null && controlMesh != null); Undo.RegisterCreatedObjectUndo(gameObject, "Created brush"); InternalCSGModelManager.CheckForChanges(); return(gameObject); }
protected void UpdateOperationType(CSGOperationType opType) { if (operationGameObject != null) { var operation = operationGameObject.GetComponent<CSGOperation>(); if (operation != null) operation.OperationType = opType; var brush = operationGameObject.GetComponent<CSGBrush>(); if (brush != null) brush.OperationType = opType; } InternalCSGModelManager.CheckForChanges(); EditorApplication.RepaintHierarchyWindow(); }
public static CSGModel CreateModelInstanceInScene(bool selectModel) { var gameObject = new GameObject("Model"); gameObject.name = UnityEditor.GameObjectUtility.GetUniqueNameForSibling(null, "Model"); var model = InternalCSGModelManager.CreateCSGModel(gameObject); if (selectModel) { UnityEditor.Selection.activeGameObject = gameObject; } SelectionUtility.LastUsedModel = model; Undo.RegisterCreatedObjectUndo(gameObject, "Created model"); InternalCSGModelManager.CheckForChanges(); return(model); }
private void ImportMap() { string path = EditorUtility.OpenFilePanel("Import Quake 1 Map", "", "map"); if (path.Length != 0) { var mapImporter = target as RCSGQ1MapImporter; EditorUtility.DisplayProgressBar("RealtimeCSG: Importing Quake 1 Map", "Parsing Quake 1 Map File (*.map)...", 0.0f); var importer = new Quake1Importer.MapImporter(); importer.adjustTexturesForValve = mapImporter.adjustTexturesForValve; var map = importer.Import(path); Quake1Importer.MapWorldConverter.Import(mapImporter.transform, map); //Importers.Quake1.MapWorldConverter.Import(csgModel, map); //BrushFactory.CreateBrushFromPlanes() //UnityEditor.Selection.activeGameObject = gameObject; //Undo.RegisterCreatedObjectUndo(gameObject, "Created brush"); InternalCSGModelManager.CheckForChanges(); InternalCSGModelManager.UpdateMeshes(); } try { } catch (System.Exception ex) { EditorUtility.ClearProgressBar(); EditorUtility.DisplayDialog("Quake 1 Map Import", "An exception occurred while importing the map:\r\n" + ex.Message, "Ohno!"); } EditorUtility.ClearProgressBar(); //Oper //BrushFactory.CreateBrushFromPlanes }
public static CSGModel CreateModelInstanceInScene(Transform parent) { var gameObject = new GameObject("Model"); gameObject.name = UnityEditor.GameObjectUtility.GetUniqueNameForSibling(null, "Model"); var model = InternalCSGModelManager.CreateCSGModel(gameObject); UnityEditor.Selection.activeGameObject = gameObject; SelectionUtility.LastUsedModel = model; if (parent) { gameObject.transform.SetParent(parent, false); } Undo.RegisterCreatedObjectUndo(gameObject, "Created model"); InternalCSGModelManager.CheckForChanges(); return(model); }
public static void ModifyOperationsOnSelected(Foundation.CSGOperationType operationType) { var modified = false; foreach (var gameObject in Selection.gameObjects) { var obj = gameObject.GetComponent(CSGBrushType); if (obj) { var brush = obj as CSGBrush; if (brush.OperationType != operationType) { modified = true; Undo.RecordObject(brush, "Modifying csg operation of brush component"); brush.OperationType = operationType; } } obj = gameObject.GetComponent(CSGOperationType); if (obj) { var operation = obj as CSGOperation; if (operation.OperationType == operationType) { continue; } modified = true; Undo.RecordObject(operation, "Modifying csg operation of operation component"); operation.PassThrough = false; operation.OperationType = operationType; } } if (modified) { InternalCSGModelManager.CheckForChanges(); EditorApplication.RepaintHierarchyWindow(); } }
internal override bool UpdateBaseShape(bool registerUndo = true) { if (settings.vertices == null || settings.vertices.Length == 0) editMode = EditMode.CreatePlane; if (editMode == EditMode.CreatePlane) return false; float radius = SphereRadius; if (editMode == EditMode.CreateShape) { brushPosition = settings.vertices[0]; //extrusionPoints[0].Vertex = settings.vertices[0]; radius = (settings.vertices[0] - worldPosition).magnitude; } GenerateBrushObjects(1); if (radius == 0 || generatedBrushes == null || generatedBrushes.Length < 1) { InternalCSGModelManager.skipCheckForChanges = false; HideGenerateBrushes(); return false; } //UpdateBrushOperation(height); bool failures = false; bool modifiedHierarchy = false; if (generatedGameObjects != null && generatedGameObjects.Length > 0) { for (int i = generatedGameObjects.Length - 1; i >= 0; i--) { if (generatedGameObjects[i]) continue; ArrayUtility.RemoveAt(ref generatedGameObjects, i); } } if (generatedGameObjects == null || generatedGameObjects.Length == 0) { Cancel(); return false; } if (generatedGameObjects != null && generatedGameObjects.Length > 0) { if (registerUndo) Undo.RecordObjects(generatedGameObjects, "Created Sphere"); var brush = generatedBrushes[0]; if (brush && brush.gameObject) { ControlMesh newControlMesh; Shape newShape; if (GenerateSphere(radius, settings.sphereSplits, parentModel, brush, out newControlMesh, out newShape)) { if (!brush.gameObject.activeSelf) { modifiedHierarchy = true; brush.gameObject.SetActive(true); } brush.Shape = newShape; brush.ControlMesh = newControlMesh; if (registerUndo) EditorUtility.SetDirty(brush); ControlMeshUtility.UpdateBrushMesh(brush, brush.ControlMesh, brush.Shape); } else { failures = true; if (brush.gameObject.activeSelf) { modifiedHierarchy = true; brush.gameObject.SetActive(false); } } } } try { InternalCSGModelManager.skipCheckForChanges = true; if (registerUndo) EditorUtility.SetDirty(this); //CSGModelManager.External.SetDirty(parentModel.modelNodeID); InternalCSGModelManager.CheckForChanges(forceHierarchyUpdate: modifiedHierarchy); } finally { InternalCSGModelManager.skipCheckForChanges = false; } return !failures; }
protected bool UpdateExtrudedShape(bool registerUndo = true) { if (polygons == null || polygons.Length == 0) { return(false); } bool failures = false; bool modifiedHierarchy = false; if (HaveExtrusion) { UpdateBrushOperation(); if (generatedGameObjects != null && generatedGameObjects.Length > 0) { for (int i = generatedGameObjects.Length - 1; i >= 0; i--) { if (generatedGameObjects[i]) { continue; } ArrayUtility.RemoveAt(ref generatedGameObjects, i); } } if (generatedGameObjects == null || generatedGameObjects.Length == 0) { Cancel(); return(false); } if (generatedGameObjects != null && generatedGameObjects.Length > 0) { if (registerUndo) { Undo.RecordObjects(generatedGameObjects, "Extruded shape"); } int brushIndex = 0; for (int slice = 0; slice < extrusionPoints.Length - 1; slice++) { for (int p = 0; p < polygons.Length; p++) { var brush = generatedBrushes[brushIndex]; brushIndex++; if (!brush || !brush.gameObject) { continue; } var direction = haveForcedDirection ? forcedDirection : buildPlane.normal; var distance = new CSGPlane(direction, extrusionPoints[slice].Position).Distance(extrusionPoints[slice + 1].Position); if (float.IsInfinity(distance) || float.IsNaN(distance)) { distance = 1.0f; } var poly2dToWorldMatrix = brush.transform.worldToLocalMatrix * Matrix4x4.TRS(extrusionPoints[slice].Position, Quaternion.FromToRotation(MathConstants.upVector3, buildPlane.normal), Vector3.one); // * parentModel.transform.localToWorldMatrix; ControlMesh newControlMesh; Shape newShape; if (!CreateControlMeshForBrushIndex(parentModel, brush, polygons[p], poly2dToWorldMatrix, distance, out newControlMesh, out newShape)) { failures = true; if (brush.gameObject.activeSelf) { modifiedHierarchy = true; brush.gameObject.SetActive(false); } continue; } if (!brush.gameObject.activeSelf) { modifiedHierarchy = true; brush.gameObject.SetActive(true); } brush.ControlMesh.SetDirty(); if (registerUndo) { EditorUtility.SetDirty(brush); } } } } } else { if (generatedGameObjects != null) { if (registerUndo) { Undo.RecordObjects(generatedGameObjects, "Extruded brush"); } InternalCSGModelManager.skipCheckForChanges = false; int brushIndex = 0; for (int slice = 0; slice < extrusionPoints.Length - 1; slice++) { for (int p = 0; p < polygons.Length; p++) { if (p >= generatedBrushes.Length) { continue; } var brush = generatedBrushes[brushIndex]; brushIndex++; brush.ControlMesh.SetDirty(); if (registerUndo) { EditorUtility.SetDirty(brush); } } } HideGenerateBrushes(); } } try { InternalCSGModelManager.skipCheckForChanges = true; if (registerUndo) { EditorUtility.SetDirty(this); } //CSGModelManager.External.SetDirty(parentModel.modelNodeID); InternalCSGModelManager.CheckForChanges(forceHierarchyUpdate: modifiedHierarchy); } finally { InternalCSGModelManager.skipCheckForChanges = false; } if (shapeEdges != null && smearTextures) { CSGBrush lastBrush = null; int lastSurfaceIndex = -1; for (int slice = 0; slice < extrusionPoints.Length - 1; slice++) { for (int se = 0; se < shapeEdges.Length; se++) { var brushIndex = shapeEdges[se].PolygonIndex + (slice * shapeEdges.Length); var surfaceIndex = shapeEdges[se].EdgeIndex; if (brushIndex < 0 || brushIndex >= generatedBrushes.Length || surfaceIndex == -1) { continue; } var brush = generatedBrushes[brushIndex]; if (brush && brush.brushNodeID != CSGNode.InvalidNodeID) { if (lastBrush && lastBrush.brushNodeID != CSGNode.InvalidNodeID) { SurfaceUtility.CopyLastMaterial(brush, surfaceIndex, false, lastBrush, lastSurfaceIndex, false, registerUndo = false); } else { brush.Shape.TexGens[surfaceIndex].Translation = Vector3.zero; brush.Shape.TexGens[surfaceIndex].Scale = Vector2.one; brush.Shape.TexGens[surfaceIndex].RotationAngle = 0; } lastBrush = brush; lastSurfaceIndex = surfaceIndex; } } } } InternalCSGModelManager.RefreshMeshes(); return(!failures); }
static public void OnInspectorGUI(Editor editor, UnityEngine.Object[] targets) { TooltipUtility.InitToolTip(editor); try { var models = new CSGModel[targets.Length]; for (int i = targets.Length - 1; i >= 0; i--) { models[i] = targets[i] as CSGModel; if (!models[i]) { ArrayUtility.RemoveAt(ref models, i); } } CSG_GUIStyleUtility.InitStyles(); ShowRealtimeCSGDisabledMessage(); if (models.Length > 0 && models.Length == targets.Length) { CSGModelComponentInspectorGUI.OnInspectorGUI(targets); return; } var filteredSelection = EditModeManager.FilteredSelection; var targetNodes = filteredSelection.NodeTargets; var targetModels = filteredSelection.ModelTargets; var targetBrushes = filteredSelection.BrushTargets; var targetOperations = filteredSelection.OperationTargets; if (targetNodes == null) { return; } bool?isPrefab = false; PrefabInstantiateBehaviour?prefabBehaviour = PrefabInstantiateBehaviour.Reference; PrefabSourceAlignment? prefabSourceAlignment = PrefabSourceAlignment.AlignedTop; PrefabDestinationAlignment?prefabDestinationAlignment = PrefabDestinationAlignment.AlignToSurface; if (targetNodes.Length > 0) { var gameObject = targetNodes[0].gameObject; isPrefab = CSGPrefabUtility.IsPrefabAsset(gameObject); prefabBehaviour = targetNodes[0].PrefabBehaviour; prefabSourceAlignment = targetNodes[0].PrefabSourceAlignment; prefabDestinationAlignment = targetNodes[0].PrefabDestinationAlignment; for (int i = 1; i < targetNodes.Length; i++) { gameObject = targetNodes[i].gameObject; var currentIsPrefab = CSGPrefabUtility.IsPrefabAsset(gameObject); var currentPrefabBehaviour = targetNodes[i].PrefabBehaviour; var currentPrefabSourceAlignment = targetNodes[i].PrefabSourceAlignment; var currentPrefabDestinationAlignment = targetNodes[i].PrefabDestinationAlignment; if (isPrefab.HasValue && isPrefab.Value != currentIsPrefab) { isPrefab = null; } if (prefabBehaviour.HasValue && prefabBehaviour.Value != currentPrefabBehaviour) { prefabBehaviour = null; } if (prefabSourceAlignment.HasValue && prefabSourceAlignment.Value != currentPrefabSourceAlignment) { prefabSourceAlignment = null; } if (prefabDestinationAlignment.HasValue && prefabDestinationAlignment.Value != currentPrefabDestinationAlignment) { prefabDestinationAlignment = null; } } } GUILayout.BeginVertical(GUI.skin.box); { if (isPrefab.HasValue && isPrefab.Value) { EditorGUILayout.LabelField(PrefabLabelContent); } else { EditorGUILayout.LabelField(RaySnappingLabelContent); TooltipUtility.SetToolTip(RaySnappingBehaviourTooltip); } EditorGUI.indentLevel++; { if (isPrefab.HasValue && isPrefab.Value) { EditorGUI.showMixedValue = !prefabBehaviour.HasValue; var prefabBehavour = prefabBehaviour.HasValue ? prefabBehaviour.Value : PrefabInstantiateBehaviour.Reference; EditorGUI.BeginChangeCheck(); { prefabBehavour = (PrefabInstantiateBehaviour)EditorGUILayout.EnumPopup(PrefabInstantiateBehaviourContent, prefabBehavour); TooltipUtility.SetToolTip(PrefabInstantiateBehaviourTooltip); } if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes"); for (int i = 0; i < targetNodes.Length; i++) { targetNodes[i].PrefabBehaviour = prefabBehavour; } } EditorGUI.showMixedValue = false; } EditorGUI.showMixedValue = !prefabDestinationAlignment.HasValue; var destinationAlignment = prefabDestinationAlignment.HasValue ? prefabDestinationAlignment.Value : PrefabDestinationAlignment.AlignToSurface; EditorGUI.BeginChangeCheck(); { destinationAlignment = (PrefabDestinationAlignment)EditorGUILayout.EnumPopup(DestinationAlignmentContent, destinationAlignment); TooltipUtility.SetToolTip(DestinationAlignmentTooltip); } if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes"); for (int i = 0; i < targetNodes.Length; i++) { targetNodes[i].PrefabDestinationAlignment = destinationAlignment; } } EditorGUI.showMixedValue = false; EditorGUI.showMixedValue = !prefabSourceAlignment.HasValue; var sourceAlignment = prefabSourceAlignment.HasValue ? prefabSourceAlignment.Value : PrefabSourceAlignment.AlignedFront; EditorGUI.BeginChangeCheck(); { sourceAlignment = (PrefabSourceAlignment)EditorGUILayout.EnumPopup(SourceAlignmentContent, sourceAlignment); TooltipUtility.SetToolTip(SourceAlignmentTooltip); } if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes"); for (int i = 0; i < targetNodes.Length; i++) { targetNodes[i].PrefabSourceAlignment = sourceAlignment; } } EditorGUI.showMixedValue = false; } EditorGUI.indentLevel--; } GUILayout.EndVertical(); GUILayout.Space(10); if (targetModels.Length == 0) { int invalidOperationType = 999; bool? handleAsOne = null; bool selMixedValues = false; CSGOperationType operationType = (CSGOperationType)invalidOperationType; bool opMixedValues = false; if (targetBrushes.Length > 0) { operationType = targetBrushes[0].OperationType; } for (int b = 1; b < targetBrushes.Length; b++) { var brush = targetBrushes[b]; if (operationType != brush.OperationType) { opMixedValues = true; } } foreach (var operation in targetOperations) { if (operationType == (CSGOperationType)invalidOperationType) { operationType = operation.OperationType; } else if (operationType != operation.OperationType) { opMixedValues = true; } if (!handleAsOne.HasValue) { handleAsOne = operation.HandleAsOne; } else if (handleAsOne.Value != operation.HandleAsOne) { selMixedValues = true; } } GUILayout.BeginVertical(GUI.skin.box); { bool passThroughValue = false; if (targetBrushes.Length == 0 && targetOperations.Length > 0) // only operations { bool?passThrough = targetOperations[0].PassThrough; for (int i = 1; i < targetOperations.Length; i++) { if (passThrough.HasValue && passThrough.Value != targetOperations[i].PassThrough) { passThrough = null; break; } } opMixedValues = !passThrough.HasValue || passThrough.Value; var ptMixedValues = !passThrough.HasValue; passThroughValue = passThrough.HasValue ? passThrough.Value : false; if (CSG_EditorGUIUtility.PassThroughButton(passThroughValue, ptMixedValues)) { Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes"); foreach (var operation in targetOperations) { operation.PassThrough = true; } InternalCSGModelManager.CheckForChanges(); EditorApplication.RepaintHierarchyWindow(); } if (passThroughValue) { operationType = (CSGOperationType)255; } } EditorGUI.BeginChangeCheck(); { operationType = CSG_EditorGUIUtility.ChooseOperation(operationType, opMixedValues); } if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(targetNodes, "Changed CSG operation of nodes"); foreach (var brush in targetBrushes) { brush.OperationType = operationType; } foreach (var operation in targetOperations) { operation.PassThrough = false; operation.OperationType = operationType; } InternalCSGModelManager.CheckForChanges(); EditorApplication.RepaintHierarchyWindow(); } } GUILayout.EndVertical(); if (targetOperations.Length == 0 && targetModels.Length == 0) { GUILayout.Space(10); if (targetBrushes.Length == 1) { GUILayout.BeginVertical(GUI.skin.box); { EditorGUI.indentLevel++; OpenSurfaces = EditorGUILayout.Foldout(OpenSurfaces, SurfacesContent); EditorGUI.indentLevel--; if (OpenSurfaces) { var targetShape = targetBrushes[0].Shape; var texGens = targetShape.TexGens; var texGenFlagArray = targetShape.TexGenFlags; for (int t = 0; t < texGens.Length; t++) { GUILayout.Space(2); var texGenFlags = texGenFlagArray[t]; var material = targetShape.TexGens[t].RenderMaterial; var physicsMat = targetShape.TexGens[t].PhysicsMaterial; EditorGUI.BeginChangeCheck(); { GUILayout.BeginHorizontal(); { GUILayout.Space(4); material = CSG_EditorGUIUtility.MaterialImage(material); GUILayout.Space(2); GUILayout.BeginVertical(); { //EditorGUI.BeginDisabledGroup(texGenFlags != TexGenFlags.None); { material = EditorGUILayout.ObjectField(material, typeof(Material), true) as Material; } //EditorGUI.EndDisabledGroup(); physicsMat = EditorGUILayout.ObjectField(physicsMat, typeof(PhysicMaterial), true) as PhysicMaterial; texGenFlags = EditModeCommonGUI.OnSurfaceFlagButtons(texGenFlags); } GUILayout.EndVertical(); GUILayout.Space(4); } GUILayout.EndHorizontal(); } if (EditorGUI.EndChangeCheck()) { var selectedBrushSurfaces = new [] { new SelectedBrushSurface(targetBrushes[0], t) }; using (new UndoGroup(selectedBrushSurfaces, "discarding surface")) { texGenFlagArray[t] = texGenFlags; targetShape.TexGens[t].RenderMaterial = material; targetShape.TexGens[t].PhysicsMaterial = physicsMat; } } GUILayout.Space(4); } } } GUILayout.EndVertical(); } } if (handleAsOne.HasValue) { EditorGUI.BeginChangeCheck(); { EditorGUI.showMixedValue = selMixedValues; handleAsOne = EditorGUILayout.Toggle(HandleAsOneLabel, handleAsOne.Value); } if (EditorGUI.EndChangeCheck()) { Undo.RecordObjects(targetNodes, "Changed CSG operation 'Handle as one object'"); foreach (var operation in targetOperations) { operation.HandleAsOne = handleAsOne.Value; } EditorApplication.RepaintHierarchyWindow(); } } } #if false if (targetNodes.Length == 1) { var node = targetNodes[0]; var brush = node as CSGBrush; if (brush != null) { var brush_cache = CSGSceneManager.GetBrushCache(brush); if (brush_cache == null || brush_cache.childData == null || brush_cache.childData.modelTransform == null) { EditorGUILayout.LabelField("brush-cache: null"); } else { EditorGUILayout.LabelField("node-id: " + brush.brushNodeID); } } var operation = node as CSGOperation; if (operation != null) { var operation_cache = CSGSceneManager.GetOperationCache(operation); if (operation_cache == null || operation_cache.childData == null || operation_cache.childData.modelTransform == null) { EditorGUILayout.LabelField("operation-cache: null"); } else { EditorGUILayout.LabelField("operation-id: " + operation.operationNodeID); } } var model = node as CSGModel; if (model != null) { var model_cache = CSGSceneManager.GetModelCache(model); if (model_cache == null || model_cache.meshContainer == null) { EditorGUILayout.LabelField("model-cache: null"); } else { EditorGUILayout.LabelField("model-id: " + model.modelNodeID); } } } #endif } finally { TooltipUtility.DrawToolTip(getLastRect: true, goUp: true); } }
public void DragPerform(SceneView sceneView) { try { InternalCSGModelManager.skipCheckForChanges = true; if (visualDragGameObject == null) { CreateVisualObjects(sceneView != null); } if (sceneView && haveNoParent && !containsModel) { var model = SelectionUtility.LastUsedModel; if (!model) { model = OperationsUtility.CreateModelInstanceInScene(selectModel: false); InternalCSGModelManager.EnsureInitialized(model); InternalCSGModelManager.CheckTransformChanged(); InternalCSGModelManager.OnHierarchyModified(); } var parent = model.transform; int counter = 0; foreach (var obj in visualDragGameObject) { if (!obj) { continue; } if (obj.activeSelf) { obj.transform.SetParent(parent, false); obj.transform.SetSiblingIndex(hoverSiblingIndex + counter); counter++; } } } if (visualDragGameObject != null) { var selection = new List <GameObject>(); for (int i = visualDragGameObject.Count - 1; i >= 0; i--) { if (!visualDragGameObject[i]) { continue; } if (visualDragGameObject[i].activeSelf) { Undo.RegisterCreatedObjectUndo(visualDragGameObject[i], "Instantiated prefab"); selection.Add(visualDragGameObject[i]); } else { GameObject.DestroyImmediate(visualDragGameObject[i]); } } visualDragGameObject = null; if (selection.Count > 0) { UnityEditor.Selection.objects = selection.ToArray(); } } if (sceneView) { for (int i = 0; i < SceneView.sceneViews.Count; i++) { var sceneview = SceneView.sceneViews[i] as SceneView; if (!sceneview) { continue; } if (sceneview.camera.pixelRect.Contains(Event.current.mousePosition)) { sceneview.Focus(); } } } visualDragGameObject = null; InternalCSGModelManager.CheckForChanges(forceHierarchyUpdate: true); } finally { InternalCSGModelManager.skipCheckForChanges = false; RealtimeCSG.CSGGrid.ForcedGridCenter = prevForcedGridCenter; RealtimeCSG.CSGGrid.ForcedGridRotation = prevForcedGridRotation; RealtimeCSG.CSGGrid.ForceGrid = false; } }
public static void EnsureBuildFinished() { InternalCSGModelManager.CheckForChanges(true); }
static void ShowCSGOperations(bool isSceneGUI, EditModePlace tool, FilteredSelection filteredSelection) { bool operations_enabled = (tool != null && filteredSelection.NodeTargets.Length > 0 && filteredSelection.NodeTargets.Length == (filteredSelection.BrushTargets.Length + filteredSelection.OperationTargets.Length)); EditorGUI.BeginDisabledGroup(!operations_enabled); { bool mixedValues = tool == null || ((filteredSelection.BrushTargets.Length == 0) && (filteredSelection.OperationTargets.Length == 0)); CSGOperationType operationType = CSGOperationType.Additive; if (tool != null) { if (filteredSelection.BrushTargets.Length > 0) { operationType = filteredSelection.BrushTargets[0].OperationType; for (int i = 1; i < filteredSelection.BrushTargets.Length; i++) { if (filteredSelection.BrushTargets[i].OperationType != operationType) { mixedValues = true; } } } else if (filteredSelection.OperationTargets.Length > 0) { operationType = filteredSelection.OperationTargets[0].OperationType; } if (filteredSelection.OperationTargets.Length > 0) { for (int i = 0; i < filteredSelection.OperationTargets.Length; i++) { if (filteredSelection.OperationTargets[i].OperationType != operationType) { mixedValues = true; } } } } GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none); { bool passThroughValue = false; if (tool != null && filteredSelection.BrushTargets.Length == 0 && filteredSelection.OperationTargets.Length > 0 && filteredSelection.OperationTargets.Length == filteredSelection.NodeTargets.Length) // only operations { bool?passThrough = filteredSelection.OperationTargets[0].PassThrough; for (int i = 1; i < filteredSelection.OperationTargets.Length; i++) { if (passThrough.HasValue && passThrough.Value != filteredSelection.OperationTargets[i].PassThrough) { passThrough = null; break; } } mixedValues = !passThrough.HasValue || passThrough.Value; var ptMixedValues = !passThrough.HasValue; passThroughValue = passThrough.HasValue ? passThrough.Value : false; if (CSG_EditorGUIUtility.PassThroughButton(passThroughValue, ptMixedValues)) { Undo.RecordObjects(filteredSelection.OperationTargets, "Changed CSG operation of nodes"); foreach (var operation in filteredSelection.OperationTargets) { operation.PassThrough = true; } InternalCSGModelManager.CheckForChanges(); EditorApplication.RepaintHierarchyWindow(); } if (passThroughValue) { operationType = (CSGOperationType)255; } } EditorGUI.BeginChangeCheck(); { operationType = CSG_EditorGUIUtility.ChooseOperation(operationType, mixedValues); } if (EditorGUI.EndChangeCheck() && tool != null) { Undo.RecordObjects(filteredSelection.NodeTargets, "Changed CSG operation of nodes"); for (int i = 0; i < filteredSelection.BrushTargets.Length; i++) { filteredSelection.BrushTargets[i].OperationType = operationType; } for (int i = 0; i < filteredSelection.OperationTargets.Length; i++) { filteredSelection.OperationTargets[i].PassThrough = false; filteredSelection.OperationTargets[i].OperationType = operationType; } InternalCSGModelManager.CheckForChanges(); EditorApplication.RepaintHierarchyWindow(); } } GUILayout.EndVertical(); } EditorGUI.EndDisabledGroup(); }
internal override bool UpdateBaseShape(bool registerUndo = true) { if (editMode == EditMode.CreatePlane) { return(false); } var length = StairsDepth; if (length <= 0) { InternalCSGModelManager.skipCheckForChanges = false; HideGenerateBrushes(); return(false); } var worldToLocalRotation = GetWorldToLocalRotation(); var localToWorldRotation = Quaternion.Inverse(worldToLocalRotation); brushPosition = localToWorldRotation * settings.bounds.Min; var totalSteps = TotalSteps; if (!GenerateBrushObjects(totalSteps)) { InternalCSGModelManager.skipCheckForChanges = false; HideGenerateBrushes(); return(false); } if (registerUndo) { Undo.RecordObjects(generatedBrushes, "Created Linear Stairs"); } if (!GenerateStairs(generatedBrushes, totalSteps, StepDepth, StepHeight, StepDepth, StairsDepth, StairsWidth, StairsHeight, ExtraDepth, ExtraHeight, StairsBottom)) { InternalCSGModelManager.skipCheckForChanges = false; HideGenerateBrushes(); return(false); } if (registerUndo) { MarkAllBrushesDirty(); } try { InternalCSGModelManager.skipCheckForChanges = true; if (registerUndo) { EditorUtility.SetDirty(this); } InternalCSGModelManager.External.SetDirty(parentModel.modelNodeID); InternalCSGModelManager.CheckForChanges(forceHierarchyUpdate: true); //DebugEditorWindow.PrintDebugInfo(); } finally { InternalCSGModelManager.skipCheckForChanges = false; } return(true); }