protected virtual bool StartEditMode(Camera camera) { if (editMode == EditMode.EditShape || editMode == EditMode.ExtrudeShape) { return false; } Undo.RecordObject(this, "Created shape"); if (GUIUtility.hotControl == shapeId) { GUIUtility.hotControl = 0; GUIUtility.keyboardControl = 0; EditorGUIUtility.SetWantsMouseJumping(0); EditorGUIUtility.editingTextField = false; } CalculateWorldSpaceTangents(camera); brushPosition = buildPlane.Project(ShapeSettings.GetCenter(buildPlane)); editMode = EditMode.EditShape; CSGPlane newPlane = buildPlane; ShapeSettings.CalculatePlane(ref newPlane); if (newPlane.normal.sqrMagnitude != 0) buildPlane = newPlane; if (ModelTraits.IsModelEditable(geometryModel)) SelectionUtility.LastUsedModel = geometryModel; UpdateBaseShape(); //StartExtrudeMode(); //GrabHeightHandle(ignoreFirstMouseUp: true); return true; }
void OnPrefabInstanceUpdated(GameObject instance) { var models = instance.GetComponentsInChildren <CSGModel>(); if (models == null || models.Length == 0) { return; } ModelTraits.OnPrefabInstanceUpdated(models); }
protected bool GenerateBrushObjects(int brushObjectCount, bool inGridSpace = true) { Undo.IncrementCurrentGroup(); undoGroupIndex = Undo.GetCurrentGroup(); var lastUsedModel = SelectionUtility.LastUsedModel; if (!ModelTraits.IsModelEditable(lastUsedModel)) { lastUsedModel = null; } var lastUsedModelTransform = !lastUsedModel ? null : lastUsedModel.transform; if (!lastUsedModelTransform || !lastUsedModel.isActiveAndEnabled) { if (prevSelection != null && prevSelection.Length > 0) { for (int i = 0; i < prevSelection.Length; i++) { UnityEngine.Object obj = prevSelection[i]; CSGBrush brush = obj as CSGBrush; MonoBehaviour mono = obj as MonoBehaviour; GameObject go = obj as GameObject; if (!brush) { if (mono) { brush = mono.GetComponentInChildren <CSGBrush>(); } if (go) { brush = go.GetComponentInChildren <CSGBrush>(); } } if (!brush) { continue; } if ((brush.gameObject.hideFlags & (HideFlags.HideInHierarchy | HideFlags.NotEditable | HideFlags.DontSaveInBuild)) != 0) { continue; } if (brush.ChildData == null || brush.ChildData.ModelTransform == null) { continue; } var model = brush.ChildData.Model; if (!model || !model.isActiveAndEnabled) { continue; } lastUsedModelTransform = brush.ChildData.ModelTransform; break; } } } if (generatedBrushes != null && generatedBrushes.Length > 0) { for (int i = generatedBrushes.Length - 1; i >= 0; i--) { if (generatedBrushes[i]) { continue; } ArrayUtility.RemoveAt(ref generatedBrushes, i); } for (int i = generatedGameObjects.Length - 1; i >= 0; i--) { if (generatedGameObjects[i]) { var brush = generatedGameObjects[i].GetComponentInChildren <CSGBrush>(); if (brush && ArrayUtility.Contains(generatedBrushes, brush)) { continue; } } ArrayUtility.RemoveAt(ref generatedGameObjects, i); } } if (generatedGameObjects == null || generatedGameObjects.Length != brushObjectCount) { if (generatedBrushes != null && generatedBrushes.Length > 0) { for (int i = 0; i < generatedBrushes.Length; i++) { InternalCSGModelManager.OnDestroyed(generatedBrushes[i]); GameObject.DestroyImmediate(generatedBrushes[i]); } } if (generatedGameObjects != null && generatedGameObjects.Length > 0) { for (int i = 0; i < generatedGameObjects.Length; i++) { GameObject.DestroyImmediate(generatedGameObjects[i]); } } if (parentGameObject != null) { GameObject.DestroyImmediate(parentGameObject); } //DebugEditorWindow.PrintDebugInfo(); if (lastUsedModelTransform == null) { parentGameObject = OperationsUtility.CreateGameObject(lastUsedModelTransform, "Model", true); InternalCSGModelManager.CreateCSGModel(parentGameObject); parentModel = parentGameObject.GetComponent <CSGModel>(); Undo.RegisterCreatedObjectUndo(parentGameObject, "Created model"); if (brushObjectCount > 1) { operationGameObject = OperationsUtility.CreateGameObject(parentGameObject.transform, "Operation", true); var transform = operationGameObject.transform; SetBrushTransformation(transform); var operation = operationGameObject.AddComponent <CSGOperation>(); if (CurrentCSGOperationType != invalidCSGOperationType) { operation.OperationType = CurrentCSGOperationType; } operation.HandleAsOne = true; Undo.RegisterCreatedObjectUndo(operationGameObject, "Created operation"); parentTransform = operationGameObject.transform; } else { parentTransform = parentGameObject.transform; } } else if (brushObjectCount > 1) { parentModel = lastUsedModelTransform.GetComponent <CSGModel>(); parentGameObject = OperationsUtility.CreateGameObject(lastUsedModelTransform, "Brushes", true); var transform = parentGameObject.transform; SetBrushTransformation(transform); operationGameObject = parentGameObject; var operation = operationGameObject.AddComponent <CSGOperation>(); if (CurrentCSGOperationType != invalidCSGOperationType) { operation.OperationType = CurrentCSGOperationType; } operation.HandleAsOne = true; parentTransform = operationGameObject.transform; Undo.RegisterCreatedObjectUndo(parentGameObject, "Created brush"); } else { parentGameObject = null; operationGameObject = null; parentTransform = lastUsedModelTransform; parentModel = lastUsedModelTransform.GetComponent <CSGModel>(); } generatedGameObjects = new GameObject[brushObjectCount]; generatedBrushes = new CSGBrush[brushObjectCount]; for (int p = 0; p < brushObjectCount; p++) { string name; if (brushObjectCount == 1) { name = "Brush"; } else { name = "Brush (" + p + ")"; } var gameObject = OperationsUtility.CreateGameObject(parentTransform, name, false); gameObject.SetActive(false); var brushComponent = gameObject.AddComponent <CSGBrush>(); if (operationGameObject == null) { if (CurrentCSGOperationType != invalidCSGOperationType) { brushComponent.OperationType = CurrentCSGOperationType; } operationGameObject = gameObject; var transform = gameObject.transform; SetBrushTransformation(transform); } generatedBrushes[p] = brushComponent; generatedBrushes[p].ControlMesh = new ControlMesh(); generatedBrushes[p].Shape = new Shape(); Undo.RegisterCreatedObjectUndo(gameObject, "Created brush"); generatedGameObjects[p] = gameObject; } //InternalCSGModelManager.Refresh(forceHierarchyUpdate: true); // brushes not registered at this point!?? //DebugEditorWindow.PrintDebugInfo(); //Selection.objects = generatedGameObjects; } else { UpdateBrushPosition(); } return(generatedBrushes != null && generatedBrushes.Length > 0 && generatedBrushes.Length == brushObjectCount); }
public static bool UpdateModelSettings() { var forceHierarchyUpdate = false; for (var i = 0; i < Models.Length; i++) { var model = Models[i]; if (!ModelTraits.IsModelEditable(model)) { continue; } var modelModified = false; var invertedWorld = model.InvertedWorld; if (invertedWorld) { if (model.infiniteBrush == null) { CSGBrush infiniteBrush = null; var childNodes = model.GetComponentsInChildren <CSGBrush>(); for (int c = 0; c < childNodes.Length; c++) { if (childNodes[c].Flags == BrushFlags.InfiniteBrush) { if (infiniteBrush != null) { UnityEngine.Object.DestroyImmediate(childNodes[c]); } else { infiniteBrush = childNodes[c]; } } } if (infiniteBrush == null) { var gameObject = new GameObject("*hidden infinite brush*"); gameObject.hideFlags = MeshInstanceManager.ComponentHideFlags; gameObject.transform.SetParent(model.transform, false); infiniteBrush = gameObject.AddComponent <CSGBrush>(); } model.infiniteBrush = infiniteBrush; model.infiniteBrush.Flags = BrushFlags.InfiniteBrush; modelModified = true; } if (model.infiniteBrush.transform.GetSiblingIndex() != 0) { model.infiniteBrush.transform.SetSiblingIndex(0); modelModified = true; } } else { if (model.infiniteBrush) { if (model.infiniteBrush.gameObject) { UnityEngine.Object.DestroyImmediate(model.infiniteBrush.gameObject); } model.infiniteBrush = null; modelModified = true; } } if (modelModified) { var childBrushes = model.GetComponentsInChildren <CSGBrush>(); for (int j = 0; j < childBrushes.Length; j++) { if (!childBrushes[j] || childBrushes[j].ControlMesh == null) { continue; } childBrushes[j].ControlMesh.Generation++; } forceHierarchyUpdate = true; } } return(forceHierarchyUpdate); }
public static bool UpdateMeshes(System.Text.StringBuilder text = null, bool forceUpdate = false) { if (EditorApplication.isPlaying || EditorApplication.isPlayingOrWillChangePlaymode) { return(false); } if (inUpdateMeshes) { return(false); } MeshInstanceManager.Update(); var unityMeshUpdates = 0.0; var getMeshDescriptionTime = 0.0; getMeshInstanceTime = 0.0; getModelMeshesTime = 0.0; updateMeshTime = 0.0; inUpdateMeshes = true; try { if (External == null) { return(false); } if (forcedUpdateRequired) { forceUpdate = true; forcedUpdateRequired = false; } var modelCount = Models.Length; if (modelCount == 0) { return(false); } for (var i = 0; i < modelCount; i++) { var model = Models[i]; if (!forceUpdate && !model.forceUpdate) { continue; } if (!ModelTraits.IsModelEditable(model)) { continue; } External.SetDirty(model.modelNodeID); model.forceUpdate = false; } // update the model meshes if (!External.UpdateAllModelMeshes()) { return(false); // nothing to do } MeshGeneration++; bool haveUpdates = forceUpdate; for (var i = 0; i < modelCount; i++) { var model = Models[i]; if (!(new CSGTreeNode { nodeID = model.modelNodeID }.Dirty)) { continue; } var meshContainer = model.generatedMeshes; if (!meshContainer) { continue; } EnsureInitialized(model); bool needToUpdateMeshes; var startGetMeshDescriptionTime = EditorApplication.timeSinceStartup; { needToUpdateMeshes = External.GetMeshDescriptions(model, ref __meshDescriptions); } getMeshDescriptionTime += EditorApplication.timeSinceStartup - startGetMeshDescriptionTime; if (!ModelTraits.IsModelEditable(model)) { continue; } if (!needToUpdateMeshes) { continue; } __foundHelperSurfaces.Clear(); __foundGeneratedMeshInstance.Clear(); __unfoundMeshInstances.Clear(); { var startUnityMeshUpdates = EditorApplication.timeSinceStartup; for (int meshIndex = 0; meshIndex < __meshDescriptions.Length; meshIndex++) { if (!ValidateMesh(__meshDescriptions[meshIndex])) { continue; } haveUpdates = true; var renderSurfaceType = MeshInstanceManager.GetSurfaceType(__meshDescriptions[meshIndex], model.Settings); if (renderSurfaceType == RenderSurfaceType.Normal || renderSurfaceType == RenderSurfaceType.ShadowOnly || renderSurfaceType == RenderSurfaceType.Collider || renderSurfaceType == RenderSurfaceType.Trigger) { GeneratedMeshInstance meshInstance; if (TryGetMeshInstance(meshContainer, model, model.Settings, __meshDescriptions[meshIndex], renderSurfaceType, out meshInstance)) { if (meshInstance != null) { __foundGeneratedMeshInstance.Add(meshInstance); } else { __unfoundMeshInstances.Add(meshIndex); } } } if (renderSurfaceType != RenderSurfaceType.Normal) { HelperSurfaceDescription helperSurface; if (TryGetHelperSurfaceDescription(meshContainer, model, model.Settings, __meshDescriptions[meshIndex], renderSurfaceType, out helperSurface)) { if (helperSurface != null) { __foundHelperSurfaces.Add(helperSurface); } else { __unfoundMeshInstances.Add(meshIndex); } } } } var unusedInstances = MeshInstanceManager.FindUnusedMeshInstances(meshContainer, __foundGeneratedMeshInstance, __foundHelperSurfaces); foreach (int meshIndex in __unfoundMeshInstances) { haveUpdates = true; var renderSurfaceType = MeshInstanceManager.GetSurfaceType(__meshDescriptions[meshIndex], model.Settings); if (renderSurfaceType == RenderSurfaceType.Normal || renderSurfaceType == RenderSurfaceType.ShadowOnly || renderSurfaceType == RenderSurfaceType.Collider || renderSurfaceType == RenderSurfaceType.Trigger) { var meshInstance = GenerateMeshInstance(meshContainer, model, model.Settings, __meshDescriptions[meshIndex], renderSurfaceType, unusedInstances); if (meshInstance != null) { __foundGeneratedMeshInstance.Add(meshInstance); } } if (renderSurfaceType != RenderSurfaceType.Normal) { var helperSurface = GenerateHelperSurfaceDescription(meshContainer, model, model.Settings, __meshDescriptions[meshIndex], renderSurfaceType); __foundHelperSurfaces.Add(helperSurface); } } MeshInstanceManager.UpdateContainerComponents(meshContainer, __foundGeneratedMeshInstance, __foundHelperSurfaces); unityMeshUpdates += (EditorApplication.timeSinceStartup - startUnityMeshUpdates); } } if (haveUpdates) { MeshInstanceManager.UpdateHelperSurfaceVisibility(force: true); } if (text != null) { text.AppendFormat(System.Globalization.CultureInfo.InvariantCulture, "All mesh generation {0:F} ms " + "+ retrieving {1:F} ms " + "+ Unity mesh updates {2:F} ms " + "+ overhead {3:F} ms. ", getMeshDescriptionTime * 1000, getModelMeshesTime * 1000, updateMeshTime * 1000, (unityMeshUpdates - (getModelMeshesTime + updateMeshTime)) * 1000); } return(true); } finally { inUpdateMeshes = false; } }
private void OnPrefabSaving(GameObject obj) { ModelTraits.OnPrefabSaving(obj); }
/* * static void OnGUIContentsMaterialInspector(Material material, bool mixedValues) * { * //if (materialEditor == null || prevMaterial != material) * { * var editor = materialEditor as Editor; * Editor.CreateCachedEditor(material, typeof(MaterialEditor), ref editor); * materialEditor = editor as MaterialEditor; * } * * if (materialEditor != null) * { * EditorGUI.showMixedValue = mixedValues; * try * { * materialEditor.DrawHeader(); * if (materialEditor.PropertiesGUI()) * { * materialEditor.PropertiesChanged(); * } * } * catch * {} * EditorGUI.showMixedValue = false; * } * } */ private static void OnGUIContents(bool isSceneGUI, EditModeSurface tool) { EditModeCommonGUI.StartToolGUI(); var selectedBrushSurfaces = (tool == null) ? new SelectedBrushSurface[0] : tool.GetSelectedSurfaces(); var enabled = selectedBrushSurfaces.Length > 0; EditorGUI.BeginDisabledGroup(!enabled); { Material material = null; var currentTexGen = new TexGen(); var haveTexgen = false; var multipleColors = !enabled; var multipleTranslationX = !enabled; var multipleTranslationY = !enabled; var multipleScaleX = !enabled; var multipleScaleY = !enabled; var multipleRotationAngle = !enabled; var multipleMaterials = !enabled; bool?textureLocked = null; bool foundHelperMaterial = false; RenderSurfaceType?firstRenderSurfaceType = null; Material firstMaterial = null; if (selectedBrushSurfaces.Length > 0) { for (var i = 0; i < selectedBrushSurfaces.Length; i++) { var brush = selectedBrushSurfaces[i].brush; if (!brush) { continue; } var surfaceIndex = selectedBrushSurfaces[i].surfaceIndex; if (surfaceIndex >= brush.Shape.Surfaces.Length) { Debug.LogWarning("surface_index >= brush.Shape.Surfaces.Length"); continue; } var texGenIndex = brush.Shape.Surfaces[surfaceIndex].TexGenIndex; if (texGenIndex >= brush.Shape.TexGens.Length) { Debug.LogWarning("texGen_index >= brush.Shape.TexGens.Length"); continue; } var brushCache = InternalCSGModelManager.GetBrushCache(brush); var model = (brushCache != null) ? brushCache.childData.Model : null; Material foundMaterial; var texGenFlags = brush.Shape.TexGenFlags[texGenIndex]; if (model && (!model.IsRenderable || model.ShadowsOnly)) { foundHelperMaterial = true; if (!firstRenderSurfaceType.HasValue) { firstRenderSurfaceType = ModelTraits.GetModelSurfaceType(model); } foundMaterial = null; } else if ((texGenFlags & TexGenFlags.NoRender) == TexGenFlags.NoRender) { foundHelperMaterial = true; if (!firstRenderSurfaceType.HasValue) { if ((texGenFlags & TexGenFlags.NoCastShadows) != TexGenFlags.NoCastShadows) { firstRenderSurfaceType = RenderSurfaceType.ShadowOnly; } else if ((texGenFlags & TexGenFlags.NoCollision) != TexGenFlags.NoCollision) { firstRenderSurfaceType = RenderSurfaceType.Collider; } else { firstRenderSurfaceType = RenderSurfaceType.Hidden; } } foundMaterial = null; } else { var surfaceMaterial = brush.Shape.TexGens[texGenIndex].RenderMaterial; if (!foundHelperMaterial) { var surfaceType = MaterialUtility.GetMaterialSurfaceType(surfaceMaterial); if (!firstRenderSurfaceType.HasValue) { firstRenderSurfaceType = surfaceType; } foundHelperMaterial = surfaceType != RenderSurfaceType.Normal; } foundMaterial = surfaceMaterial; } if ((texGenFlags & TexGenFlags.WorldSpaceTexture) == TexGenFlags.WorldSpaceTexture) { if (i == 0) { textureLocked = false; } else if (textureLocked.HasValue && textureLocked.Value) { textureLocked = null; } } else { if (i == 0) { textureLocked = true; } else if (textureLocked.HasValue && !textureLocked.Value) { textureLocked = null; } } if (foundMaterial != material) { if (!material) { firstMaterial = foundMaterial; material = foundMaterial; } else { multipleMaterials = true; } } if (!haveTexgen) { currentTexGen = brush.Shape.TexGens[texGenIndex]; haveTexgen = true; } else { if (!multipleColors) { var color = brush.Shape.TexGens[texGenIndex].Color; multipleColors = currentTexGen.Color.a != color.a || currentTexGen.Color.b != color.b || currentTexGen.Color.g != color.g || currentTexGen.Color.r != color.r; } if (!multipleScaleX || !multipleScaleY) { var scale = brush.Shape.TexGens[texGenIndex].Scale; multipleScaleX = multipleScaleX || currentTexGen.Scale.x != scale.x; multipleScaleY = multipleScaleY || currentTexGen.Scale.y != scale.y; } if (!multipleTranslationX || !multipleTranslationY) { var translation = brush.Shape.TexGens[texGenIndex].Translation; multipleTranslationX = multipleTranslationX || currentTexGen.Translation.x != translation.x; multipleTranslationY = multipleTranslationY || currentTexGen.Translation.y != translation.y; } if (!multipleRotationAngle) { var rotationAngle = brush.Shape.TexGens[texGenIndex].RotationAngle; multipleRotationAngle = currentTexGen.RotationAngle != rotationAngle; } } } if (foundHelperMaterial && !firstMaterial) { if (firstRenderSurfaceType.HasValue) { firstMaterial = MaterialUtility.GetSurfaceMaterial(firstRenderSurfaceType.Value); } else { firstMaterial = MaterialUtility.HiddenMaterial; } } } GUILayout.BeginVertical(isSceneGUI ? materialDoubleWidth : CSG_GUIStyleUtility.ContentEmpty); { GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none); { /* * Color new_color; * EditorGUI.BeginChangeCheck(); * { * EditorGUI.showMixedValue = multipleColors; * // why doesn't the colorfield return a modified color? * try * { * new_color = EditorGUILayout.ColorField(GUIContent.none, currentTexGen.Color); * } * catch * { * new_color = currentTexGen.Color; * } * } * if (EditorGUI.EndChangeCheck() || currentTexGen.Color != new_color) * { * SurfaceUtility.SetColors(selectedBrushSurfaces, new_color); * } */ if (isSceneGUI) { GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { EditorGUI.BeginDisabledGroup(material == null); { GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty); { GUILayout.Space(1); /* * Color new_color; * EditorGUI.BeginChangeCheck(); * { * EditorGUI.showMixedValue = multipleColors; * // why doesn't the colorfield return a modified color? * try * { * new_color = EditorGUILayout.ColorField(GUIContent.none, currentTexGen.Color); * } * catch * { * new_color = currentTexGen.Color; * } * } * if (EditorGUI.EndChangeCheck() || currentTexGen.Color != new_color) * { * SurfaceUtility.SetColors(selectedBrushSurfaces, new_color); * } * * GUILayout.Space(1); */ Material newMaterial; EditorGUI.BeginChangeCheck(); { EditorGUI.showMixedValue = multipleMaterials; newMaterial = EditorGUILayout.ObjectField(material, typeof(Material), true) as Material; EditorGUI.showMixedValue = false; } if (EditorGUI.EndChangeCheck()) { if (newMaterial) { SurfaceUtility.SetMaterials(selectedBrushSurfaces, newMaterial); CSGSettings.DefaultMaterial = newMaterial; CSGSettings.Save(); } } } GUILayout.EndVertical(); GUILayout.Space(1); } EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); GUILayout.Space(4); GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { GUILayout.Space(2); OnGUIContentsMaterialImage(isSceneGUI, firstMaterial, multipleMaterials, selectedBrushSurfaces); GUILayout.BeginHorizontal(materialWidth); { GUILayout.FlexibleSpace(); GUILayout.BeginVertical(materialHeight); { OnGUIContentsJustify(isSceneGUI, selectedBrushSurfaces); GUILayout.FlexibleSpace(); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); GUILayout.FlexibleSpace(); } GUILayout.EndHorizontal(); } } GUILayout.EndVertical(); if (!isSceneGUI) { EditorGUILayout.Space(); } if (currentTexGen.Scale.x == 0.0f) { currentTexGen.Scale.x = 1.0f; } if (currentTexGen.Scale.y == 0.0f) { currentTexGen.Scale.y = 1.0f; } const float scale_round = 10000.0f; currentTexGen.Scale.x = Mathf.RoundToInt(currentTexGen.Scale.x * scale_round) / scale_round; currentTexGen.Scale.y = Mathf.RoundToInt(currentTexGen.Scale.y * scale_round) / scale_round; currentTexGen.Translation.x = Mathf.RoundToInt(currentTexGen.Translation.x * scale_round) / scale_round; currentTexGen.Translation.y = Mathf.RoundToInt(currentTexGen.Translation.y * scale_round) / scale_round; currentTexGen.RotationAngle = Mathf.RoundToInt(currentTexGen.RotationAngle * scale_round) / scale_round; var leftStyle = isSceneGUI ? EditorStyles.miniButtonLeft : GUI.skin.button; var middleStyle = isSceneGUI ? EditorStyles.miniButtonMid : GUI.skin.button; var rightStyle = isSceneGUI ? EditorStyles.miniButtonRight : GUI.skin.button; GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none); { EditorGUI.BeginChangeCheck(); { EditorGUI.showMixedValue = !textureLocked.HasValue; textureLocked = EditorGUILayout.ToggleLeft(ContentLockTexture, textureLocked.HasValue ? textureLocked.Value : false); TooltipUtility.SetToolTip(ToolTipLockTexture); } if (EditorGUI.EndChangeCheck()) { SurfaceUtility.SetTextureLock(selectedBrushSurfaces, textureLocked.Value); } } GUILayout.EndVertical(); GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none); { GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { if (isSceneGUI) { EditorGUILayout.LabelField(ContentUVScale, EditorStyles.miniLabel, labelWidth); } else { EditorGUILayout.LabelField(ContentUVScale, largeLabelWidth); } TooltipUtility.SetToolTip(ToolTipScaleUV); GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { if (!isSceneGUI) { EditorGUILayout.LabelField(ContentUSymbol, unitWidth); } EditorGUI.BeginChangeCheck(); { EditorGUI.showMixedValue = multipleScaleX; currentTexGen.Scale.x = EditorGUILayout.FloatField(currentTexGen.Scale.x, minFloatFieldWidth); } if (EditorGUI.EndChangeCheck()) { SurfaceUtility.SetScaleX(selectedBrushSurfaces, currentTexGen.Scale.x); } if (!isSceneGUI) { EditorGUILayout.LabelField(ContentVSymbol, unitWidth); } EditorGUI.BeginChangeCheck(); { EditorGUI.showMixedValue = multipleScaleY; currentTexGen.Scale.y = EditorGUILayout.FloatField(currentTexGen.Scale.y, minFloatFieldWidth); } if (EditorGUI.EndChangeCheck()) { SurfaceUtility.SetScaleY(selectedBrushSurfaces, currentTexGen.Scale.y); } } GUILayout.EndHorizontal(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { if (isSceneGUI) { EditorGUILayout.LabelField(ContentOffset, EditorStyles.miniLabel, labelWidth); } else { EditorGUILayout.LabelField(ContentOffset, largeLabelWidth); } TooltipUtility.SetToolTip(ToolTipOffsetUV); GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { if (!isSceneGUI) { EditorGUILayout.LabelField(ContentUSymbol, unitWidth); } EditorGUI.BeginChangeCheck(); { EditorGUI.showMixedValue = multipleTranslationX; currentTexGen.Translation.x = EditorGUILayout.FloatField(currentTexGen.Translation.x, minFloatFieldWidth); } if (EditorGUI.EndChangeCheck()) { SurfaceUtility.SetTranslationX(selectedBrushSurfaces, currentTexGen.Translation.x); } if (!isSceneGUI) { EditorGUILayout.LabelField(ContentVSymbol, unitWidth); } EditorGUI.BeginChangeCheck(); { EditorGUI.showMixedValue = multipleTranslationY; currentTexGen.Translation.y = EditorGUILayout.FloatField(currentTexGen.Translation.y, minFloatFieldWidth); } if (EditorGUI.EndChangeCheck()) { SurfaceUtility.SetTranslationY(selectedBrushSurfaces, currentTexGen.Translation.y); } } GUILayout.EndHorizontal(); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { if (isSceneGUI) { EditorGUILayout.LabelField(ContentRotate, EditorStyles.miniLabel, labelWidth); } else { EditorGUILayout.LabelField(ContentRotate, largeLabelWidth); } TooltipUtility.SetToolTip(ToolTipRotation); if (!isSceneGUI) { GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty); } GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { EditorGUI.BeginChangeCheck(); { EditorGUI.showMixedValue = multipleRotationAngle; currentTexGen.RotationAngle = EditorGUILayout.FloatField(currentTexGen.RotationAngle, minFloatFieldWidth); if (!isSceneGUI) { EditorGUILayout.LabelField(ContentAngleSymbol, unitWidth); } } if (EditorGUI.EndChangeCheck()) { SurfaceUtility.SetRotationAngle(selectedBrushSurfaces, currentTexGen.RotationAngle); } } GUILayout.EndHorizontal(); var buttonWidth = isSceneGUI ? new GUILayoutOption[] { angleButtonWidth } : new GUILayoutOption[0]; GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { if (GUILayout.Button(ContentRotate90Negative, leftStyle, buttonWidth)) { SurfaceUtility.AddRotationAngle(selectedBrushSurfaces, -90.0f); } TooltipUtility.SetToolTip(ToolTipRotate90Negative); if (GUILayout.Button(ContentRotate90Positive, rightStyle, buttonWidth)) { SurfaceUtility.AddRotationAngle(selectedBrushSurfaces, +90.0f); } TooltipUtility.SetToolTip(ToolTipRotate90Positive); } GUILayout.EndHorizontal(); if (!isSceneGUI) { GUILayout.EndVertical(); } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); if (!isSceneGUI) { EditorGUILayout.Space(); } GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none); { GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { if (!isSceneGUI) { GUILayout.Label(ContentFit, largeLabelWidth); } else { GUILayout.Label(ContentFit, EditorStyles.miniLabel, smallLabelWidth); } if (GUILayout.Button(ContentFitX, leftStyle)) { SurfaceUtility.FitSurfaceX(selectedBrushSurfaces); } TooltipUtility.SetToolTip(ToolTipFitX); if (GUILayout.Button(ContentFitXY, middleStyle)) { SurfaceUtility.FitSurface(selectedBrushSurfaces); } TooltipUtility.SetToolTip(ToolTipFitXY); if (GUILayout.Button(ContentFitY, rightStyle)) { SurfaceUtility.FitSurfaceY(selectedBrushSurfaces); } TooltipUtility.SetToolTip(ToolTipFitY); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { if (!isSceneGUI) { GUILayout.Label(ContentReset, largeLabelWidth); } else { GUILayout.Label(ContentReset, EditorStyles.miniLabel, smallLabelWidth); } if (GUILayout.Button(ContentResetX, leftStyle)) { SurfaceUtility.ResetSurfaceX(selectedBrushSurfaces); } TooltipUtility.SetToolTip(ToolTipResetX); if (GUILayout.Button(ContentResetXY, middleStyle)) { SurfaceUtility.ResetSurface(selectedBrushSurfaces); } TooltipUtility.SetToolTip(ToolTipResetXY); if (GUILayout.Button(ContentResetY, rightStyle)) { SurfaceUtility.ResetSurfaceY(selectedBrushSurfaces); } TooltipUtility.SetToolTip(ToolTipResetY); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { if (!isSceneGUI) { GUILayout.Label(ContentFlip, largeLabelWidth); } else { GUILayout.Label(ContentFlip, EditorStyles.miniLabel, smallLabelWidth); } if (GUILayout.Button(ContentFlipX, leftStyle)) { SurfaceUtility.FlipX(selectedBrushSurfaces); } TooltipUtility.SetToolTip(ToolTipFlipX); if (GUILayout.Button(ContentFlipXY, middleStyle)) { SurfaceUtility.FlipXY(selectedBrushSurfaces); } TooltipUtility.SetToolTip(ToolTipFlipXY); if (GUILayout.Button(ContentFlipY, rightStyle)) { SurfaceUtility.FlipY(selectedBrushSurfaces); } TooltipUtility.SetToolTip(ToolTipFlipY); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { if (!isSceneGUI) { GUILayout.Label(ContentScale, largeLabelWidth); } else { GUILayout.Label(ContentScale, EditorStyles.miniLabel, smallLabelWidth); } if (GUILayout.Button(ContentDoubleScale, leftStyle)) { SurfaceUtility.MultiplyScale(selectedBrushSurfaces, 2.0f); } TooltipUtility.SetToolTip(ToolTipDoubleScale); if (GUILayout.Button(ContentHalfScale, rightStyle)) { SurfaceUtility.MultiplyScale(selectedBrushSurfaces, 0.5f); } TooltipUtility.SetToolTip(ToolTipHalfScale); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); if (!isSceneGUI) { EditorGUILayout.Space(); } if (!isSceneGUI) { OnGUIContentsJustify(isSceneGUI, selectedBrushSurfaces); } if (!isSceneGUI) { EditorGUILayout.Space(); } GUILayout.BeginVertical(isSceneGUI ? GUI.skin.box : GUIStyle.none); { EditModeCommonGUI.OnSurfaceFlagButtons(selectedBrushSurfaces, isSceneGUI); GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { EditorGUI.BeginDisabledGroup(!SurfaceUtility.CanSmooth(selectedBrushSurfaces)); { if (GUILayout.Button(ContentSmoothSurfaces, leftStyle)) { SurfaceUtility.Smooth(selectedBrushSurfaces); } TooltipUtility.SetToolTip(ToolTipSmoothSurfaces); } EditorGUI.EndDisabledGroup(); EditorGUI.BeginDisabledGroup(!SurfaceUtility.CanUnSmooth(selectedBrushSurfaces)); { if (GUILayout.Button(ContentUnSmoothSurfaces, rightStyle)) { SurfaceUtility.UnSmooth(selectedBrushSurfaces); } TooltipUtility.SetToolTip(ToolTipUnSmoothSurfaces); } EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); if (!isSceneGUI) { EditorGUILayout.Space(); Material new_material; GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { EditorGUILayout.LabelField(ContentMaterial, largeLabelWidth); GUILayout.BeginVertical(CSG_GUIStyleUtility.ContentEmpty); { EditorGUI.BeginChangeCheck(); { EditorGUI.showMixedValue = multipleMaterials; new_material = EditorGUILayout.ObjectField(material, typeof(Material), true) as Material; EditorGUI.showMixedValue = false; } if (EditorGUI.EndChangeCheck()) { if (!new_material) { new_material = MaterialUtility.MissingMaterial; } SurfaceUtility.SetMaterials(selectedBrushSurfaces, new_material); } } GUILayout.Space(2); GUILayout.BeginHorizontal(CSG_GUIStyleUtility.ContentEmpty); { GUILayout.Space(5); OnGUIContentsMaterialImage(isSceneGUI, firstMaterial, multipleMaterials, selectedBrushSurfaces); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); } GUILayout.EndHorizontal(); // Unity won't let us do this //GUILayout.BeginVertical(GUIStyleUtility.ContentEmpty); //OnGUIContentsMaterialInspector(first_material, multiple_materials); //GUILayout.EndVertical(); } } GUILayout.EndVertical(); } EditorGUI.EndDisabledGroup(); EditorGUI.showMixedValue = false; }
public static void DoSelectionClick(SceneView sceneView, bool ignoreInvisibleSurfaces = true) { var camera = sceneView.camera; GameObject gameobject; SceneQueryUtility.FindClickWorldIntersection(camera, Event.current.mousePosition, out gameobject, ignoreInvisibleSurfaces); gameobject = SceneQueryUtility.FindSelectionBase(gameobject); var selectedObjectsOnClick = new List <int>(Selection.instanceIDs); bool addedSelection = false; if (EditorGUI.actionKey) { if (gameobject != null) { var instanceID = gameobject.GetInstanceID(); if (selectedObjectsOnClick.Contains(instanceID)) { selectedObjectsOnClick.Remove(instanceID); } else { selectedObjectsOnClick.Add(instanceID); addedSelection = true; } if (selectedObjectsOnClick.Count == 0) { Selection.activeTransform = null; } else { Selection.instanceIDs = selectedObjectsOnClick.ToArray(); } } } else if (Event.current.shift) { if (gameobject != null) { var instanceID = gameobject.GetInstanceID(); selectedObjectsOnClick.Add(instanceID); Selection.instanceIDs = selectedObjectsOnClick.ToArray(); addedSelection = true; } } else if (Event.current.alt) { if (gameobject != null) { var instanceID = gameobject.GetInstanceID(); selectedObjectsOnClick.Remove(instanceID); Selection.instanceIDs = selectedObjectsOnClick.ToArray(); return; } } else { Selection.activeGameObject = gameobject; addedSelection = true; } if (!addedSelection) { foreach (var item in Selection.GetFiltered(typeof(CSGBrush), SelectionMode.Deep)) { var brush = item as CSGBrush; if (brush.ChildData == null || !ModelTraits.IsModelEditable(brush.ChildData.Model)) { continue; } SelectionUtility.LastUsedModel = brush.ChildData.Model; break; } } else if (gameobject != null) { var brush = gameobject.GetComponent <CSGBrush>(); if (brush != null) { if (brush.ChildData == null || !ModelTraits.IsModelEditable(brush.ChildData.Model)) { return; } SelectionUtility.LastUsedModel = brush.ChildData.Model; } } }
public static void HideUnselectedObjects() { Undo.IncrementCurrentGroup(); var undoGroupIndex = Undo.GetCurrentGroup(); var selected = Selection.gameObjects.ToList(); var selectedIDs = new HashSet <int>(); var models = InternalCSGModelManager.Models; for (var i = 0; i < models.Length; i++) { var model = models[i]; if (!ModelTraits.IsModelSelectable(model)) { continue; } if (!model.generatedMeshes) { continue; } var meshContainerChildren = model.generatedMeshes.GetComponentsInChildren <Transform>(); foreach (var child in meshContainerChildren) { selected.Add(child.gameObject); } } for (int i = 0; i < selected.Count; i++) // we keep adding parents, and their parents until we hit the root-objects { selectedIDs.Add(selected[i].GetInstanceID()); var transform = selected[i].transform; var parent = transform.parent; if (parent == null) { continue; } selected.Add(parent.gameObject); } for (var sceneIndex = 0; sceneIndex < SceneManager.sceneCount; sceneIndex++) { var activeScene = SceneManager.GetSceneAt(sceneIndex); var rootGameObjects = activeScene.GetRootGameObjects(); for (var i = 0; i < rootGameObjects.Length; i++) { var children = rootGameObjects[i].GetComponentsInChildren <Transform>(); for (var c = 0; c < children.Length; c++) { var transform = children[c]; var gameObject = transform.gameObject; if (!gameObject.activeInHierarchy || (gameObject.hideFlags != HideFlags.None)) { continue; } if (selectedIDs.Contains(gameObject.GetInstanceID())) { continue; } Undo.RecordObject(gameObject, "Hiding Object"); gameObject.SetActive(false); } } } Undo.CollapseUndoOperations(undoGroupIndex); }
public bool UpdateSelection(HashSet <CSGNode> newTargetNodes, HashSet <Transform> newTargetOthers) { if (newTargetNodes == null) { newTargetNodes = new HashSet <CSGNode>(); } if (newTargetOthers == null) { newTargetOthers = new HashSet <Transform>(); } this.RemovedNodes = null; this.RemovedOthers = null; this.AddedNodes = null; this.AddedOthers = null; var foundRemovedNodes = new List <CSGNode>(); if (this.NodeTargets != null && this.NodeTargets.Length > 0) { if (newTargetNodes.Count == 0) { foundRemovedNodes.AddRange(this.NodeTargets); } else { for (int i = 0; i < this.NodeTargets.Length; i++) { if (!this.NodeTargets[i] || !newTargetNodes.Contains(this.NodeTargets[i])) { foundRemovedNodes.Add(this.NodeTargets[i]); } } } } var foundRemovedOthers = new List <Transform>(); if (this.OtherTargets != null && this.OtherTargets.Length > 0) { if (newTargetOthers.Count == 0) { foundRemovedOthers.AddRange(this.OtherTargets); } else { for (int i = 0; i < this.OtherTargets.Length; i++) { if (!this.OtherTargets[i] || !newTargetOthers.Contains(this.OtherTargets[i])) { foundRemovedOthers.Add(this.OtherTargets[i]); } } } } var originalTargetNodeCount = (this.NodeTargets == null) ? 0 : this.NodeTargets.Length; var originalTargetOtherCount = (this.OtherTargets == null) ? 0 : this.OtherTargets.Length; // If our counts are the same and nothing is removed (and nothing could've been added), nothing has changed. if (newTargetNodes.Count == originalTargetNodeCount && newTargetOthers.Count == originalTargetOtherCount && foundRemovedNodes.Count == 0 && foundRemovedOthers.Count == 0) { return(false); } Validate(); foreach (var node in foundRemovedNodes) { ArrayUtility.Remove(ref this.NodeTargets, node); var brush = node as CSGBrush; if (brush != null) { ArrayUtility.Remove(ref this.BrushTargets, brush); continue; } var operation = node as CSGOperation; if (node is CSGOperation) { ArrayUtility.Remove(ref this.OperationTargets, operation); continue; } var model = node as CSGModel; if (node is CSGModel) { ArrayUtility.Remove(ref this.ModelTargets, model); continue; } } foreach (var other in foundRemovedOthers) { ArrayUtility.Remove(ref this.OtherTargets, other); } var foundAddedNodes = new List <CSGNode>(); foreach (var node in newTargetNodes) { if (this.NodeTargets != null && ArrayUtility.Contains(this.NodeTargets, node)) { continue; } if (this.NodeTargets == null) { this.NodeTargets = new CSGNode[] { node }; } else { ArrayUtility.Add(ref this.NodeTargets, node); } foundAddedNodes.Add(node); if (CSGPrefabUtility.IsPrefabAsset(node.gameObject)) { continue; } var brush = node as CSGBrush; if (brush != null) { if (this.BrushTargets == null) { this.BrushTargets = new CSGBrush[] { brush } } ; else { ArrayUtility.Add(ref this.BrushTargets, brush); } continue; } var operation = node as CSGOperation; if (node is CSGOperation) { if (this.OperationTargets == null) { this.OperationTargets = new CSGOperation[] { operation } } ; else { ArrayUtility.Add(ref this.OperationTargets, operation); } continue; } var model = node as CSGModel; if (node is CSGModel) { if (this.ModelTargets == null) { this.ModelTargets = new CSGModel[] { model } } ; else { ArrayUtility.Add(ref this.ModelTargets, model); } continue; } } var foundAddedOthers = new List <Transform>(); foreach (var other in newTargetOthers) { if (this.OtherTargets != null && ArrayUtility.Contains(this.OtherTargets, other)) { continue; } if (this.OtherTargets == null) { this.OtherTargets = new Transform[] { other } } ; else { ArrayUtility.Add(ref this.OtherTargets, other); } foundAddedOthers.Add(other); } for (int i = foundAddedNodes.Count - 1; i >= 0; i--) { var node = foundAddedNodes[i]; var brush = node as CSGBrush; if (brush != null) { if (brush.ChildData == null || brush.ChildData.Model == null) { continue; } var childModel = brush.ChildData.Model; if (ModelTraits.IsModelEditable(childModel)) { SelectionUtility.LastUsedModel = childModel; } break; } var operation = node as CSGOperation; if (operation != null) { if (operation.ChildData == null || operation.ChildData.Model == null) { continue; } SelectionUtility.LastUsedModel = operation.ChildData.Model; break; } var model = node as CSGModel; if (ModelTraits.IsModelEditable(model)) { SelectionUtility.LastUsedModel = model; break; } } this.RemovedNodes = foundRemovedNodes.ToArray(); this.RemovedOthers = foundRemovedOthers.ToArray(); this.AddedNodes = foundAddedNodes.ToArray(); this.AddedOthers = foundAddedOthers.ToArray(); return(foundAddedNodes.Count > 0 || foundRemovedNodes.Count > 0 || foundAddedOthers.Count > 0 || foundRemovedOthers.Count > 0); }