public static void PasteRigidbodies() { int i = 0; foreach (GameObject obj in GameObjectsWithRigidBodies) { if (obj.GetComponent <Rigidbody>() == null) { GUIutilities.CopyComponent(RigidBodies[i], obj); } i++; } }
public static void CopyAllRigidbodies() { var rigidbodyContainer = returnOrCreateObjectWithName("Rigidbody Container"); var tmp = GameObject.FindObjectsOfType <Rigidbody>().ToList(); RigidBodies = new List <Rigidbody>(tmp.Count); GameObjectsWithRigidBodies = tmp.Select(x => x.gameObject).ToList(); int i = 0; foreach (Component rigidbody in tmp) { GameObject newGOtmp = new GameObject(); RigidBodies.Add((Rigidbody)GUIutilities.CopyComponent(rigidbody, newGOtmp)); newGOtmp.transform.parent = rigidbodyContainer.transform; newGOtmp.SetActive(false); i++; } }
void DropObjectsMenu() { // Title GUIutilities.WriteTitle("Add Prefabs"); EditorGUILayout.BeginVertical(); AddPrefabOptions(objGlobalSettings, true); for (int i = 0; i < spawnableObjects.Count; i++) { if (spawnableObjects[i].prefab != null) { AddPrefabOptions(spawnableObjects[i], false); } else { spawnableObjects.Remove(spawnableObjects[i]); } } EditorGUILayout.EndVertical(); EditorGUILayout.Space(); EditorGUILayout.Space(); }
private void OnGUI() { GUIutilities.WriteTitle("Global Options"); EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); PhysicsUtilities.physicActive = EditorGUILayout.ToggleLeft(new GUIContent("Is Physics Active", "Toggle the physics engine - this will not affect the objects (RIGHT CTRL)' rigidbodies"), PhysicsUtilities.physicActive, GUILayout.Width(150)); showEffectGraphics = EditorGUILayout.ToggleLeft(" Effects Graphics (ALT)", showEffectGraphics); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); PhysicsUtilities.physicsScatter = EditorGUILayout.ToggleLeft(new GUIContent("Physics Scatter", "Scatter objects with rigidbodies and colliders, so that they will respond to physics (SHIFT+D)"), PhysicsUtilities.physicsScatter); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(new GUIContent("Dropping Flux", "Change the amount of objects spawned when mouse is dragged"), GUILayout.Width(100)); dropFlux = EditorGUILayout.Slider(dropFlux, 0, 3); EditorGUILayout.EndHorizontal(); EditorGUI.indentLevel--; EditorGUILayout.Space(); //GUIutilities.WriteTitle("Root Options"); GUIStyle labelStyle2 = new GUIStyle("foldout"); labelStyle2.fontStyle = FontStyle.Bold; labelStyle2.fontSize = 11; labelStyle2.active.textColor = Color.black; showRootOption = GUIutilities.SimpleFoldOut("Root Options", showRootOption); if (showRootOption) { EditorGUI.indentLevel++; EditorGUILayout.BeginHorizontal(); if (rootContainer != null) { EditorGUILayout.LabelField("Name Root: " + rootContainer.name); } else { GUIStyle labelStyle = new GUIStyle("label"); labelStyle.fontStyle = FontStyle.Bold; EditorGUILayout.LabelField("No root selected! Start dropping and a root will be created.", labelStyle, GUILayout.Height(20)); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("New Root")) { rootContainer = new GameObject("New Root Container"); } if (GUILayout.Button(new GUIContent("Mark as Root", "Mark the selected gameObject in the hierarchy as a root"))) { rootContainer = (Selection.activeObject as GameObject); } if (rootContainer == null) { GUI.enabled = false; } else { GUI.enabled = true; } if (GUILayout.Button(new GUIContent("Delete Root", "Delete current root including the child objects"))) { if (EditorUtility.DisplayDialog("Delete Root", "Are you sure you want to delete the root container with all its object? This action cannot be undone", "Yes", "No")) { DestroyImmediate(rootContainer); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); bool buttonPressed = false; if (GUILayout.Button(new GUIContent("Delete Rbody in Root (SHIFT+A)", "Delete all Rigidbody in objects within " + rootContainer + " root. This will not delete colliders."))) { DeleteRigidbodyInRoot(); buttonPressed = true; } if (GUILayout.Button(new GUIContent("Add Rbody in Root (SHIFT+S)", "Add Rigidbody to every objects within " + rootContainer + " root. This will not add colliders"))) { AddRigidbodyInRoot(); buttonPressed = true; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button(new GUIContent("Delete Colliders in Root", "Delete colliders in the objects within " + rootContainer + " root. This will not delete the rigidbodies."))) { DeleteColliderInRoot(); buttonPressed = true; } if (GUILayout.Button(new GUIContent("Add Colliders in Root", "Add collider to every objects within " + rootContainer + " root. This will not add the rigibodies"))) { AddColliderInRoot(); buttonPressed = true; } if (buttonPressed) { messageStopwatch.Reset(); messageStopwatch.Start(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField(message, GUILayout.Height(18)); if (messageStopwatch.ElapsedMilliseconds > 3000) { message = "Output"; messageStopwatch.Reset(); } EditorGUI.indentLevel--; } GUILayout.Box("", new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(1) }); EditorGUILayout.Separator(); int oldIndex = mainMenuIndex; if (mainMenuIndex == -1) { dropMenuSelected = false; explosionMenuSelected = false; } if (mainMenuIndex == 0) { dropMenuSelected = true; explosionMenuSelected = false; } if (mainMenuIndex == 1) { dropMenuSelected = false; explosionMenuSelected = true; } GUI.enabled = true; EditorGUILayout.BeginHorizontal(); dropMenuSelected = GUILayout.Toggle(dropMenuSelected, mainMenuIcons[0], new GUIStyle("Button")); explosionMenuSelected = GUILayout.Toggle(explosionMenuSelected, mainMenuIcons[1], new GUIStyle("Button")); EditorGUILayout.EndHorizontal(); if (dropMenuSelected != oldDropMenuSelected) { if (dropMenuSelected) { explosionMenuSelected = false; oldExplosionMenuSelected = false; } } if (explosionMenuSelected != oldExplosionMenuSelected) { if (explosionMenuSelected) { dropMenuSelected = false; oldDropMenuSelected = false; } } oldExplosionMenuSelected = explosionMenuSelected; oldDropMenuSelected = dropMenuSelected; if (dropMenuSelected) { mainMenuIndex = 0; showEffectGraphics = false; } else if (explosionMenuSelected) { mainMenuIndex = 1; showEffectGraphics = true; } else { mainMenuIndex = -1; } scrollView = EditorGUILayout.BeginScrollView(scrollView); switch (mainMenuIndex) { case -1: EditorGUILayout.LabelField("Created by Valerio Biscione"); break; case 0: if (spawnableObjects.Count == 0) { GUIStyle labelStyle = new GUIStyle("label"); labelStyle.fontStyle = FontStyle.Bold; labelStyle.fontSize = 14; labelStyle.normal.textColor = Color.red; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("To start, drop a gameObject from the hierarchy \ninto here!", labelStyle, GUILayout.Height(40)); EditorGUILayout.EndHorizontal(); } else { EditorGUILayout.LabelField("Drop gameObjects here"); } DropObjectsMenu(); break; case 1: EditorGUILayout.HelpBox("Physics Effect. Hold down the SPACEBAR to activate the selected effect", MessageType.None); bool newSelection = false; if (oldIndex != mainMenuIndex) { newSelection = true; } DrawEffectMenu(newSelection); break; } CheckDragDrop(); ShortCut(); EditorGUILayout.EndScrollView(); }
void AddPrefabOptions(SpawnableObject spawnablePrefab, bool isGlobal) { EditorGUI.indentLevel++; bool isDelete = false; EditorGUILayout.BeginHorizontal(); // Enable spawnablePrefab.spawn = GUILayout.Toggle(spawnablePrefab.spawn, spawnablePrefab.prefab != null ? spawnablePrefab.prefab.name : "Global settings", new GUIStyle("Button"), GUILayout.Width(100)); GUI.enabled = !spawnablePrefab.optionDelete; // Disable other button GUI.enabled = true; // options if (!spawnablePrefab.optionDelete) { spawnablePrefab.isRotationX = GUILayout.Toggle(spawnablePrefab.isRotationX, "X", new GUIStyle("Button")); spawnablePrefab.isRotationY = GUILayout.Toggle(spawnablePrefab.isRotationY, "Y", new GUIStyle("Button")); spawnablePrefab.isRotationZ = GUILayout.Toggle(spawnablePrefab.isRotationZ, "Z", new GUIStyle("Button")); spawnablePrefab.isScale = GUILayout.Toggle(spawnablePrefab.isScale, "Scale", new GUIStyle("Button")); spawnablePrefab.showOption = GUILayout.Toggle(spawnablePrefab.showOption, "See Settings", new GUIStyle("Button")); if (isGlobal) { if (GUILayout.Toggle(spawnablePrefab.optionDelete, "Delete", new GUIStyle("Button"), GUILayout.Width(60))) { if (EditorUtility.DisplayDialog("Delete All Spawning Object", "This will delete all the object set for spawning. Are you sure to continue?", "Yes", "No")) { spawnableObjects = new List <SpawnableObject>(); } } } } // Delete if (!isGlobal) { if (!spawnablePrefab.optionDelete) { spawnablePrefab.optionDelete = GUILayout.Toggle(spawnablePrefab.optionDelete, "Delete", new GUIStyle("Button"), GUILayout.Width(60)); } else { if (GUIutilities.Button("Back", Color.white, 50, 18)) { spawnablePrefab.optionDelete = false; } if (GUIutilities.Button("Delete", Color.white, 50, 18)) { spawnableObjects.Remove(spawnablePrefab); isDelete = true; } } } EditorGUILayout.EndHorizontal(); if (!isDelete && spawnablePrefab.showOption) { EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Vertical Offset", GUILayout.Width(100)); spawnablePrefab.minOffset = EditorGUILayout.FloatField("", spawnablePrefab.minOffset, GUILayout.Width(50)); spawnablePrefab.offset = EditorGUILayout.Slider(spawnablePrefab.offset, spawnablePrefab.minOffset, spawnablePrefab.maxOffset); spawnablePrefab.maxOffset = EditorGUILayout.FloatField("", spawnablePrefab.maxOffset, GUILayout.Width(50)); EditorGUILayout.EndHorizontal(); if (spawnablePrefab.isScale) { GUIutilities.sliderMinMaxRange("Scale", ref spawnablePrefab.minScale, ref spawnablePrefab.maxScale, 0, 10); } if (spawnablePrefab.isRotationX) { GUIutilities.sliderMinMaxRange("X", ref spawnablePrefab.xMinRot, ref spawnablePrefab.xMaxRot, -180, 180); } if (spawnablePrefab.isRotationY) { GUIutilities.sliderMinMaxRange("Y", ref spawnablePrefab.yMinRot, ref spawnablePrefab.yMaxRot, -180, 180); } if (spawnablePrefab.isRotationZ) { GUIutilities.sliderMinMaxRange("Z", ref spawnablePrefab.zMinRot, ref spawnablePrefab.zMaxRot, -180, 180); } EditorGUILayout.Space(); } if (isGlobal) { EditorGUILayout.Space(); } EditorGUI.indentLevel--; }
private void DrawEffectMenu(bool newSelection) { if (newSelection) { Tools.current = Tool.None; } GUIutilities.WriteTitle("Physic Effects Mode"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); physicModeCheck[0] = EditorGUILayout.ToggleLeft("All Rigidbodies", physicModeCheck[0], GUILayout.Width(150)); if (rootContainer == null) { physicModeCheck[0] = true; GUI.enabled = false; } else { GUI.enabled = true; } physicModeCheck[1] = EditorGUILayout.ToggleLeft("Only in Root Container", physicModeCheck[1]); GUI.enabled = true; EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); GUIutilities.WriteTitle("Physic Effect (SPACEBAR to activate)"); for (int i = 0; i < oldPhysicModeCheck.Length; i++) { if (oldPhysicModeCheck[i] != physicModeCheck[i]) { if (physicModeCheck[i] == true) { for (int j = 0; j < oldPhysicModeCheck.Length; j++) { if (j == i) { continue; } physicModeCheck[j] = false; } break; } else { physicModeCheck[i] = true; } } } for (int i = 0; i < oldPhysicModeCheck.Length; i++) { oldPhysicModeCheck[i] = physicModeCheck[i]; if (physicModeCheck[i]) { physicsMode = (PhysicsMode)i; } } physicsEffects = (PhysicsEffects)GUILayout.SelectionGrid((int)physicsEffects, convertEnumToStringArray(), convertEnumToStringArray().Length); if (physicsEffects == PhysicsEffects.Explosion) { EditorGUILayout.Space(); GUIutilities.SliderMinMax("Vertical Offset", ref ExplosionParams.minVerticalOffset, ref ExplosionParams.maxVerticalOffset, ref ExplosionParams.verticalOffset, 100); GUIutilities.SliderMinMax("Radius", ref ExplosionParams.minRadius, ref ExplosionParams.maxRadius, ref ExplosionParams.radius, 100); GUIutilities.SliderMinMax("Power", ref ExplosionParams.minPower, ref ExplosionParams.maxPower, ref ExplosionParams.power, 100); } if (physicsEffects == PhysicsEffects.SimpleForce) { EditorGUILayout.Space(); GUIutilities.SliderMinMax("Vertical Offset", ref SimpleForceParams.minVerticalOffset, ref SimpleForceParams.maxVerticalOffset, ref SimpleForceParams.verticalOffset, 100); GUIutilities.SliderMinMax("Radius", ref SimpleForceParams.minRadius, ref SimpleForceParams.maxRadius, ref SimpleForceParams.radius, 100); GUIutilities.simpleSlider("powerX", ref SimpleForceParams.powerX, -100, 100, 100); GUIutilities.simpleSlider("powerY", ref SimpleForceParams.powerY, 0, 100, 100); GUIutilities.simpleSlider("powerZ", ref SimpleForceParams.powerZ, -100, 100, 100); } if (physicsEffects == PhysicsEffects.BlackHole) { EditorGUILayout.Space(); GUIutilities.SliderMinMax("Vertical Offset", ref BlackHoleParams.minVerticalOffset, ref BlackHoleParams.maxVerticalOffset, ref BlackHoleParams.verticalOffset, 100); GUIutilities.SliderMinMax("Radius", ref BlackHoleParams.minRadius, ref BlackHoleParams.maxRadius, ref BlackHoleParams.radius, 100); GUIutilities.SliderMinMax("Power", ref BlackHoleParams.minPower, ref BlackHoleParams.maxPower, ref BlackHoleParams.power, 100); GUIutilities.SliderMinMax(new GUIContent("Modifier", "Modifies the internal equation for the black hole. A value between 1 and 2 appears to create a blob; a value from 0 to 1 creates an oscillating system. Not all values have been tested. Use at your own risk!!"), ref BlackHoleParams.minModifier, ref BlackHoleParams.maxModifier, ref BlackHoleParams.modifier, 100); } }