private List <GameObject> InvertSelection(List <GameObject> selectedGameObjects) { List <GameObject> invertedSelection = new List <GameObject>(); foreach (GameObject obj in UtilitiesToolExtensions.GetAllGameObjects()) { if (!selectedGameObjects.Contains(obj)) { invertedSelection.Add(obj); } } return(invertedSelection); }
private void OnGUI() { foreach (var foldout in allFoldoutHeadertoggles) { foldout.ShowHeader(); } GUILayout.FlexibleSpace(); UtilitiesToolExtensions.DrawSplitter(); EditorGUILayout.LabelField("Options", EditorStyles.boldLabel); _inverse = EditorGUILayout.Toggle("Invert selection", _inverse); _isolate = EditorGUILayout.Toggle("Isolate selection", _isolate); EditorGUILayout.LabelField(_logBox, EditorStyles.helpBox, GUILayout.Height(30)); if (GUILayout.Button("Reset Values")) { ResetValues(); } if (GUILayout.Button("Select objects")) { SelectObjects(); } }
void OnGUI() { EditorGUILayout.LabelField("Search for transforms", EditorStyles.boldLabel); _searchOptionsIndex = EditorGUILayout.Popup(_searchOptionsIndex, _searchOptions); switch (_searchOptionsIndex) { case 0: ManualSelection(); break; case 1: SearchByName(); break; case 2: SearchByTag(); break; default: break; } EditorGUILayout.Space(5); if (_transformElements.Count > 0) { _showSelectedObjects = EditorGUILayout.Foldout(_showSelectedObjects, $"{_transformElements.Count} objects selected"); } else if (_transformElements.Count == 0) { _showSelectedObjects = false; EditorGUILayout.LabelField("No objects selected"); } if (_showSelectedObjects) { scrollPos = EditorGUILayout.BeginScrollView(scrollPos, false, true, EditorStyles.textArea, EditorStyles.textArea, EditorStyles.textArea, GUILayout.Width(300), GUILayout.Height(150)); List <TransformElement> transformelementsToDelete = new List <TransformElement>(); foreach (var te in _transformElements) { EditorGUILayout.BeginHorizontal(); GUILayout.Label(te.TheGameObject.name); if (GUILayout.Button("X", GUILayout.Width(25))) { transformelementsToDelete.Add(te); } EditorGUILayout.EndHorizontal(); } if (transformelementsToDelete.Count != 0) { foreach (var te in transformelementsToDelete) { if (_transformElements.Contains(te)) { _transformElements.Remove(te); } } transformelementsToDelete.Clear(); } EditorGUILayout.EndScrollView(); } GUILayout.Space(10); // POSITION #region _randomizePosition = EditorGUILayout.ToggleLeft("Randomize Position", _randomizePosition); if (_randomizePosition) { EditorGUI.indentLevel++; _positionType = (RelationType)EditorGUILayout.EnumPopup(_positionType); _posMinRange = EditorGUILayout.Vector3Field("Minimum position range", _posMinRange); _posMaxRange = EditorGUILayout.Vector3Field("Maximum position range", _posMaxRange); EditorGUI.indentLevel--; } GUILayout.Space(10); #endregion // ROTATION #region _randomizerotation = EditorGUILayout.ToggleLeft("Randomize Rotation", _randomizerotation); if (_randomizerotation) { EditorGUI.indentLevel++; _rotationType = (RelationType)EditorGUILayout.EnumPopup(_rotationType); _rotMinRange = EditorGUILayout.Vector3Field("Minimum rotation range", _rotMinRange); _rotMaxRange = EditorGUILayout.Vector3Field("Maximum rotation range", _rotMaxRange); EditorGUI.indentLevel--; } GUILayout.Space(10); #endregion // SCALE #region _randomizeScale = EditorGUILayout.ToggleLeft("Randomize Scale", _randomizeScale); if (_randomizeScale) { EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); _scaleType = (RelationType)EditorGUILayout.EnumPopup(_scaleType); _seperateAxisScale = EditorGUILayout.ToggleLeft("Separate Axis", _seperateAxisScale, GUILayout.MaxWidth(150)); EditorGUILayout.EndHorizontal(); if (_seperateAxisScale) { EditorGUI.indentLevel++; _scaleMinRange = EditorGUILayout.Vector3Field("Minimum scale range", _scaleMinRange); _scaleMaxRange = EditorGUILayout.Vector3Field("Maximum scale range", _scaleMaxRange); EditorGUI.indentLevel--; } else { _minUniformScale = EditorGUILayout.FloatField("Minimum scale range", _minUniformScale, GUILayout.MaxWidth(250)); _maxUniformScale = EditorGUILayout.FloatField("Maximum scale range", _maxUniformScale, GUILayout.MaxWidth(250)); EditorGUI.indentLevel--; } if (GUILayout.Button("Reset Scale to 1")) { foreach (var gameObject in _gameObjects) { gameObject.transform.localScale = Vector3.one; } } } GUILayout.Space(10); #endregion GUILayout.FlexibleSpace(); UtilitiesToolExtensions.DrawSplitter(); EditorGUILayout.LabelField("Options", EditorStyles.boldLabel); _interCollision = EditorGUILayout.BeginToggleGroup("Avoid overlap", _interCollision); EditorGUILayout.BeginHorizontal(); _overlapOptionsIndex = EditorGUILayout.Popup(_overlapOptionsIndex, _overlapOptions); _addChildren = EditorGUILayout.Toggle("Include children", _addChildren); EditorGUILayout.EndToggleGroup(); EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Reset Values")) { ResetValues(); } if (GUILayout.Button("Apply")) { RecordeUndoForSelectedObjects(); _allcollidersInSelection.Clear(); _allMeshRenderers.Clear(); foreach (var transformElement in _transformElements) { if (_overlapOptionsIndex == 0) // Use colliders { if (transformElement.TheGameObject.GetComponent <Collider>() != null) { _allcollidersInSelection.Add(transformElement.TheGameObject.GetComponent <Collider>()); } } if (_overlapOptionsIndex == 1) // Use meshrenderers { if (transformElement.TheGameObject.GetComponent <MeshRenderer>() != null) { _allMeshRenderers.Add(transformElement.TheGameObject.GetComponent <MeshRenderer>()); } } } foreach (var transformElement in _transformElements) { bool collisionResult = false; int iteration = 0; do { if (_randomizePosition) { Vector3 currentPosition = transformElement.originalPosition; Vector3 offsetPosition = new Vector3(UnityEngine.Random.Range(_posMinRange.x, _posMaxRange.x), UnityEngine.Random.Range(_posMinRange.y, _posMaxRange.y), UnityEngine.Random.Range(_posMinRange.z, _posMaxRange.z)); if (_positionType == RelationType.Absolute) { transformElement.TheGameObject.transform.localPosition = offsetPosition; } else if (_positionType == RelationType.Relative) { transformElement.TheGameObject.transform.localPosition = currentPosition + offsetPosition; } } if (_randomizerotation) { Quaternion currentRotation = transformElement.TheGameObject.transform.localRotation; Quaternion offsetRotation = Quaternion.Euler(UnityEngine.Random.Range(_rotMinRange.x, _rotMaxRange.x), UnityEngine.Random.Range(_rotMinRange.y, _rotMaxRange.y), UnityEngine.Random.Range(_rotMinRange.z, _rotMaxRange.z)); if (_rotationType == RelationType.Absolute) { transformElement.TheGameObject.transform.localRotation = offsetRotation; } else if (_rotationType == RelationType.Relative) { transformElement.TheGameObject.transform.localRotation = currentRotation * offsetRotation; } } if (_randomizeScale) { Vector3 currentScale = transformElement.TheGameObject.transform.localScale; Vector3 offsetScale; if (_seperateAxisScale) { offsetScale = new Vector3(UnityEngine.Random.Range(_scaleMinRange.x, _scaleMaxRange.x), UnityEngine.Random.Range(_scaleMinRange.y, _scaleMaxRange.y), UnityEngine.Random.Range(_scaleMinRange.z, _scaleMaxRange.z)); } else { float randomRangeValue = UnityEngine.Random.Range(_minUniformScale, _maxUniformScale); offsetScale = new Vector3(randomRangeValue, randomRangeValue, randomRangeValue); } switch (_scaleType) { case RelationType.Absolute: transformElement.TheGameObject.transform.localScale = Vector3.Scale(Vector3.one, offsetScale); break; case RelationType.Relative: transformElement.TheGameObject.transform.localScale = Vector3.Scale(transformElement.originalScale, offsetScale); break; default: break; } } if (_overlapOptionsIndex == 0) { if (_addChildren) { collisionResult = CheckIntercollisionChildren(transformElement.TheGameObject, typeof(Collider)); } else { collisionResult = CheckIntercollision(transformElement.TheGameObject.GetComponent <Collider>()); } } else if (_overlapOptionsIndex == 1) { if (_addChildren) { collisionResult = CheckIntercollisionChildren(transformElement.TheGameObject, typeof(MeshRenderer)); } else { collisionResult = CheckIntercollision(transformElement.TheGameObject.GetComponent <MeshRenderer>()); } } iteration++; if (iteration >= 100) { Debug.Log($"Couldn't fit {transformElement.TheGameObject.name} after 100 tries"); } }while (collisionResult && _interCollision && iteration < 100); } } }
public List <GameObject> Select() { List <GameObject> filteredGameObjects = new List <GameObject>(); GameObject[] allGameObjects = UtilitiesToolExtensions.GetAllGameObjects(); foreach (var go in allGameObjects) { if (_isPrefab) { PrefabAssetType assetType = PrefabUtility.GetPrefabAssetType(go); if (assetType == PrefabAssetType.Regular) { filteredGameObjects.Add(go); continue; } } if (_isStatic) { if (go.isStatic == true) { filteredGameObjects.Add(go); continue; } } if (_isActive) { if (go.activeInHierarchy == true) { filteredGameObjects.Add(go); continue; } } switch (_objecttypesIndex) { case 0: break; case 1: CheckTypeAndAddToList <MeshRenderer>(go, filteredGameObjects); break; case 2: CheckTypeAndAddToList <Light>(go, filteredGameObjects); break; case 3: CheckTypeAndAddToList <Terrain>(go, filteredGameObjects); break; case 4: CheckTypeAndAddToList <Camera>(go, filteredGameObjects); break; case 5: CheckTypeAndAddToList <AudioSource>(go, filteredGameObjects); break; case 6: CheckTypeAndAddToList <ParticleSystem>(go, filteredGameObjects); break; case 7: if (CheckEmptyGameObject(go)) { filteredGameObjects.Add(go); } break; case 8: if (CheckEmptyGameObject(go) && go.transform.childCount == 0) { filteredGameObjects.Add(go); } break; case 9: CheckTypeAndAddToList <ReflectionProbe>(go, filteredGameObjects); break; case 10: CheckTypeAndAddToList <WindZone>(go, filteredGameObjects); break; default: break; } } return(filteredGameObjects); }
private void OnGUI() { EditorGUILayout.BeginVertical("helpbox"); EditorGUILayout.LabelField("Array Object", EditorStyles.boldLabel); _objectToArray = (GameObject)EditorGUILayout.ObjectField(_objectToArray, typeof(GameObject), true); if (GUILayout.Button("Add selected")) { _objectToArray = (GameObject)Selection.activeObject; } if (_objectToArray != null) { assetType = PrefabUtility.GetPrefabAssetType(_objectToArray); } EditorGUILayout.EndVertical(); // --------- ARRAY TRANSFORMATION --------- // EditorGUILayout.BeginVertical("helpbox"); EditorGUILayout.LabelField("Array Transformation", EditorStyles.boldLabel); EditorGUI.indentLevel++; _moveTransformation = EditorGUILayout.Vector3Field("Move", _moveTransformation); _incrementalTotalMoveIndex = EditorGUILayout.Popup(_incrementalTotalMoveIndex, _incrementalTotal); GUILayout.Space(10); _rotationTransformation = EditorGUILayout.Vector3Field("Rotation", _rotationTransformation); _incrementalTotalrotateIndex = EditorGUILayout.Popup(_incrementalTotalrotateIndex, _incrementalTotal); GUILayout.Space(10); if (_uniformScale) { _uniformScaleValue = EditorGUILayout.FloatField("Scale:", _uniformScaleValue); _ScaleTransformation = new Vector3(_uniformScaleValue, _uniformScaleValue, _uniformScaleValue); } else { _ScaleTransformation = EditorGUILayout.Vector3Field("Scale:", _ScaleTransformation); } _uniformScale = EditorGUILayout.ToggleLeft("Uniform", _uniformScale); _incrementalTotalScaleIndex = EditorGUILayout.Popup(_incrementalTotalScaleIndex, _incrementalTotal); EditorGUI.indentLevel--; EditorGUILayout.EndVertical(); // --------- ARRAY DIMENSION --------- // EditorGUILayout.BeginVertical("helpbox"); EditorGUILayout.LabelField("Array Dimension", EditorStyles.boldLabel); EditorGUI.indentLevel++; _dimensionIndex = EditorGUILayout.Popup(_dimensionIndex, _dimension); switch (_dimensionIndex) { case 0: OneDimensionCount = EditorGUILayout.IntField("1D Count:", OneDimensionCount); break; case 1: TwoDimensionCount = EditorGUILayout.Vector2IntField("2D Count:", TwoDimensionCount); _incrementalRowOffset2D = EditorGUILayout.Vector3Field("Incremental Row Offset", _incrementalRowOffset2D); break; case 2: ThreeDimensionCount = EditorGUILayout.Vector3IntField("3D Count:", ThreeDimensionCount); _incrementalRowOffset3D = EditorGUILayout.Vector3Field("Incremental Row Offset", _incrementalRowOffset3D); break; default: break; } EditorGUI.indentLevel--; EditorGUILayout.EndVertical(); // ----------------------------------- // // -------------- OPTIONS ------------- // EditorGUILayout.BeginVertical("helpbox"); EditorGUILayout.LabelField("Options", EditorStyles.boldLabel); _avoidChildren = EditorGUILayout.Toggle(new GUIContent("Don't include children", "Avoid all children from the object to be instantiated. For prefabs, this function will be ignored as it is not possible to destroy prefab's children"), _avoidChildren); _instantiateAsChildren = (Transform)EditorGUILayout.ObjectField(new GUIContent("Instantiate as child of", "Every instance will become a child of the selected object"), _instantiateAsChildren, typeof(Transform), true); _keepAsPrefab = EditorGUILayout.Toggle(new GUIContent("Keep as prefab", "If the object to be instanciated is a prefab, keep every copy as an instance of that prefab"), _keepAsPrefab); EditorGUILayout.EndVertical(); // ----------------------------------- // EditorGUILayout.BeginVertical("helpbox"); EditorGUILayout.LabelField($"Total instances in array: {_instancesAmount}"); EditorGUILayout.EndVertical(); GUILayout.FlexibleSpace(); UtilitiesToolExtensions.DrawSplitter(); _previewVisible = GUILayout.Toggle(_previewVisible, "Preview", "Button"); if (_previewVisible && GUI.changed) { PreviewArray(); _isShowingPreview = true; } else if (!_previewVisible && _isShowingPreview) { RemovePreviewArray(); _isShowingPreview = false; } if (GUILayout.Button("Reset Values")) { ResetValues(); } if (GUILayout.Button("Create array")) { CreateArray(); _previewVisible = false; } }