protected override string GetNodeTypeString(RouteNode node) { var cableNode = node as CableRouteNode; return(GUI.AddColorTag(cableNode.Type.ToString().SplitCamelCase(), GetColor(cableNode))); }
public override void OnPreTargetMembersGUI(GUISkin skin) { // TODO: Improvements. // - "Copy-paste" shape. // 1. Select object with primitive shape(s) // 2. Select object to copy the shape(s) to // - Move from-to existing bodies or create a new body. // - Mesh object operations. // * Simplify assembly // * Multi-select to create meshes // - Inspect element (hold 'i'). if (!AgXUnity.Utils.Math.IsUniform(Assembly.transform.lossyScale, 1.0E-3f)) { Debug.LogWarning("Scale of AgXUnity.Assembly transform isn't uniform. If a child rigid body is moving under this transform the (visual) behavior is undefined.", Assembly); } bool rbButtonPressed = false; bool shapeButtonPressed = false; bool constraintButtonPressed = false; GUI.ToolsLabel(skin); GUILayout.BeginHorizontal(); { GUILayout.Space(12); using (GUI.ToolButtonData.ColorBlock) { rbButtonPressed = GUILayout.Button(GUI.MakeLabel("RB", true, "Assembly rigid body tool"), GUI.ConditionalCreateSelectedStyle(m_mode == Mode.RigidBody, skin.button), GUILayout.Width(30f), GUI.ToolButtonData.Height); shapeButtonPressed = GUILayout.Button(GUI.MakeLabel("Shape", true, "Assembly shape tool"), GUI.ConditionalCreateSelectedStyle(m_mode == Mode.Shape, skin.button), GUILayout.Width(54f), GUI.ToolButtonData.Height); constraintButtonPressed = GUILayout.Button(GUI.MakeLabel("Constraint", true, "Assembly constraint tool"), GUI.ConditionalCreateSelectedStyle(m_mode == Mode.Constraint, skin.button), GUILayout.Width(80f), GUI.ToolButtonData.Height); } } GUILayout.EndHorizontal(); HandleModeGUI(skin); if (rbButtonPressed) { ChangeMode(Mode.RigidBody); } if (shapeButtonPressed) { ChangeMode(Mode.Shape); } if (constraintButtonPressed) { ChangeMode(Mode.Constraint); } }
private void HandleModeRigidBodyGUI(GUISkin skin) { GUI.Separator3D(); using (GUI.AlignBlock.Center) { if (m_subMode == SubMode.SelectRigidBody) { GUILayout.Label(GUI.MakeLabel("Select rigid body object in scene view.", true), skin.label); } else { GUILayout.Label(GUI.MakeLabel("Select object(s) in scene view.", true), skin.label); } } GUI.Separator(); bool selectionHasRigidBody = m_selection.Find(entry => entry.Object.GetComponentInParent <RigidBody>() != null) != null; bool createNewRigidBodyPressed = false; bool addToExistingRigidBodyPressed = false; bool moveToNewRigidBodyPressed = false; GUILayout.BeginHorizontal(); { GUILayout.Space(12); GUILayout.BeginVertical(); { UnityEngine.GUI.enabled = m_selection.Count == 0 || !selectionHasRigidBody; createNewRigidBodyPressed = GUILayout.Button(GUI.MakeLabel("Create new" + (m_selection.Count == 0 ? " (empty)" : ""), false, "Create new rigid body with selected objects"), skin.button, GUILayout.Width(128)); UnityEngine.GUI.enabled = m_selection.Count > 0 && Assembly.GetComponentInChildren <RigidBody>() != null; addToExistingRigidBodyPressed = GUILayout.Button(GUI.MakeLabel("Add to existing", false, "Add selected objects to existing rigid body"), GUI.ConditionalCreateSelectedStyle(m_subMode == SubMode.SelectRigidBody, skin.button), GUILayout.Width(100)); UnityEngine.GUI.enabled = selectionHasRigidBody; moveToNewRigidBodyPressed = GUILayout.Button(GUI.MakeLabel("Move to new", false, "Move objects that already contains a rigid body to a new rigid body"), skin.button, GUILayout.Width(85)); UnityEngine.GUI.enabled = true; } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); GUI.Separator3D(); // Creates new rigid body and move selected objects to it (as children). if (createNewRigidBodyPressed || moveToNewRigidBodyPressed) { CreateOrMoveToRigidBodyFromSelectionEntries(m_selection); m_selection.Clear(); } // Toggle to select a rigid body in scene view to move the current selection to. else if (addToExistingRigidBodyPressed) { // This will toggle if sub-mode already is SelectRigidBody. ChangeSubMode(SubMode.SelectRigidBody); } // The user has chosen a rigid body to move the current selection to. if (m_rbSelection != null) { CreateOrMoveToRigidBodyFromSelectionEntries(m_selection, m_rbSelection.RigidBody.gameObject); m_selection.Clear(); ChangeSubMode(SubMode.None); } }
public override void OnPostTargetMembersGUI(GUISkin skin) { GUI.Separator(); using (new GUILayout.HorizontalScope()) { EditorGUI.BeginDisabledGroup(!Application.isPlaying); if (GUILayout.Button(GUI.MakeLabel("Save current step as (.agx)...", false, "Save scene in native file format when the editor is in play mode."), skin.button)) { string result = EditorUtility.SaveFilePanel("Save scene as .agx", "Assets", UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name, "agx"); if (result != string.Empty) { var success = Simulation.SaveToNativeFile(result); if (success) { Debug.Log("Successfully wrote simulation to file: " + result); } } } if (GUILayout.Button(GUI.MakeLabel("Open in AGX native viewer", false, "Creates Lua file, saves current scene to an .agx file and executes luaagx.exe."), skin.button)) { Simulation.OpenInAgXViewer(); } EditorGUI.EndDisabledGroup(); } GUI.Separator(); Simulation.SavePreFirstStep = GUI.Toggle(GUI.MakeLabel("Dump initial (.agx):"), Simulation.SavePreFirstStep, skin.button, skin.label); EditorGUI.BeginDisabledGroup(!Simulation.SavePreFirstStep); { using (new GUILayout.HorizontalScope()) { GUILayout.Space(26); Simulation.SavePreFirstStepPath = GUILayout.TextField(Simulation.SavePreFirstStepPath, skin.textField); if (GUILayout.Button(GUI.MakeLabel("...", false, "Open file panel"), skin.button, GUILayout.Width(28))) { string result = EditorUtility.SaveFilePanel("Path to initial dump (including file name and extension)", SaveInitialPath, UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene().name, "agx"); if (result != string.Empty) { SaveInitialPath = result; var fileInfo = new System.IO.FileInfo(SaveInitialPath); if (fileInfo.Extension == ".agx" || fileInfo.Extension == ".aagx") { Simulation.SavePreFirstStepPath = SaveInitialPath; } else { Debug.Log("Unknown file extension: " + fileInfo.Extension); } } } } } EditorGUI.EndDisabledGroup(); }
private void HandleKeyHandlerGUI(GUIContent name, Utils.KeyHandler keyHandler, GUISkin skin) { const int keyButtonWidth = 90; GUILayout.BeginHorizontal(); { keyHandler.Enable = GUI.Toggle(name, keyHandler.Enable, skin.button, GUI.Align(skin.label, TextAnchor.MiddleLeft), new GUILayoutOption[] { GUILayout.Width(ToggleButtonSize), GUILayout.Height(ToggleButtonSize) }, new GUILayoutOption[] { GUILayout.Height(ToggleButtonSize) }); GUILayout.FlexibleSpace(); UnityEngine.GUI.enabled = keyHandler.Enable; for (int iKey = 0; iKey < keyHandler.NumKeyCodes; ++iKey) { GUIContent buttonLabel = keyHandler.IsDetectingKey(iKey) ? GUI.MakeLabel("Detecting...") : GUI.MakeLabel(keyHandler.Keys[iKey].ToString()); bool toggleDetecting = GUILayout.Button(buttonLabel, skin.button, GUILayout.Width(keyButtonWidth), GUILayout.Height(ToggleButtonSize)); if (toggleDetecting) { keyHandler.DetectKey(this, !keyHandler.IsDetectingKey(iKey), iKey); } } Rect dropDownButtonRect = new Rect(); GUILayout.BeginVertical(GUILayout.Height(ToggleButtonSize)); { GUIStyle tmp = new GUIStyle(skin.button); tmp.fontSize = 6; m_showDropDown = GUILayout.Button(GUI.MakeLabel("v", true), tmp, GUILayout.Width(16), GUILayout.Height(14)) ? !m_showDropDown : m_showDropDown; dropDownButtonRect = GUILayoutUtility.GetLastRect(); GUILayout.FlexibleSpace(); } GUILayout.EndVertical(); UnityEngine.GUI.enabled = true; if (m_showDropDown && dropDownButtonRect.Contains(Event.current.mousePosition)) { GenericMenu menu = new GenericMenu(); menu.AddItem(GUI.MakeLabel("Reset to default"), false, () => { if (EditorUtility.DisplayDialog("Reset to default", "Reset key(s) to default?", "OK", "Cancel")) { keyHandler.ResetToDefault(); } }); menu.AddItem(GUI.MakeLabel("Add key"), false, () => { keyHandler.Add(KeyCode.None); }); if (keyHandler.NumKeyCodes > 1) { menu.AddItem(GUI.MakeLabel("Remove key"), false, () => { if (EditorUtility.DisplayDialog("Remove key", "Remove key: " + keyHandler[keyHandler.NumKeyCodes - 1].ToString() + "?", "OK", "Cancel")) { keyHandler.Remove(keyHandler.NumKeyCodes - 1); } }); } menu.ShowAsContext(); } } GUILayout.EndHorizontal(); if (UnityEngine.GUI.changed) { EditorUtility.SetDirty(this); } }
public void OnInspectorGUI(GUISkin skin) { using (GUI.AlignBlock.Center) GUILayout.Label(GUI.MakeLabel("AgXUnity Editor Settings", 24, true), skin.label); GUI.Separator3D(); // BuiltInToolsTool settings GUI. { using (GUI.AlignBlock.Center) GUILayout.Label(GUI.MakeLabel("Built in tools", 16, true), skin.label); //GUI.Separator(); HandleKeyHandlerGUI(GUI.MakeLabel("Select game object"), BuiltInToolsTool_SelectGameObjectKeyHandler, skin); HandleKeyHandlerGUI(GUI.MakeLabel("Select rigid body game object"), BuiltInToolsTool_SelectRigidBodyKeyHandler, skin); HandleKeyHandlerGUI(GUI.MakeLabel("Pick handler (scene view)"), BuiltInToolsTool_PickHandlerKeyHandler, skin); GUI.Separator(); } // Developer settings. { using (GUI.AlignBlock.Center) GUILayout.Label(GUI.MakeLabel("AGXUnity Developer", 16, true), skin.label); AutoFetchAGXUnityDlls = GUI.Toggle(GUI.MakeLabel("Auto fetch AGXUnity/AGXUnityEditor"), AutoFetchAGXUnityDlls, skin.button, GUI.Align(skin.label, TextAnchor.MiddleLeft), new GUILayoutOption[] { GUILayout.Width(ToggleButtonSize), GUILayout.Height(ToggleButtonSize) }, new GUILayoutOption[] { GUILayout.Height(ToggleButtonSize) }); using (new EditorGUI.DisabledScope(!AutoFetchAGXUnityDlls)) { using (new GUILayout.HorizontalScope()) { GUILayout.Space(ToggleButtonSize + 4); GUILayout.Label(GUI.MakeLabel("Checkout directory"), skin.label, GUILayout.Width(160)); var statusColor = AGXUnityCheckoutDirValid ? Color.Lerp(Color.white, Color.green, 0.2f) : Color.Lerp(Color.white, Color.red, 0.2f); var textFieldStyle = new GUIStyle(skin.textField); var prevColor = UnityEngine.GUI.backgroundColor; UnityEngine.GUI.backgroundColor = statusColor; AGXUnityCheckoutDir = GUILayout.TextField(AGXUnityCheckoutDir, skin.textField); UnityEngine.GUI.backgroundColor = prevColor; if (GUILayout.Button(GUI.MakeLabel("...", false, "Open file panel"), skin.button, GUILayout.Width(28))) { AGXUnityCheckoutDir = EditorUtility.OpenFolderPanel("AGXUnity checkout directory", AGXUnityCheckoutDir, ""); } } } GUI.Separator(); } GUI.Separator3D(); }
public void OnInspectorGUI(GUISkin skin) { GUILayout.BeginHorizontal(); { GUILayout.Label(GUI.MakeLabel("Disable: ", true), skin.label); GUILayout.Label(SelectGameObjectDropdownMenuTool.GetGUIContent(m_mainObject), skin.textField); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); GUILayout.Label(GUI.MakeLabel(GUI.Symbols.Synchronized.ToString()), skin.label); GUILayout.BeginVertical(); { if (m_selected.Count == 0) { GUILayout.Label(GUI.MakeLabel("None", true), skin.label, GUILayout.Width(180)); } else { int removeIndex = -1; for (int i = 0; i < m_selected.Count; ++i) { GUILayout.BeginHorizontal(); { GUILayout.Label(SelectGameObjectDropdownMenuTool.GetGUIContent(m_selected[i]), GUI.Align(skin.textField, TextAnchor.MiddleLeft), GUILayout.Height(20)); using (GUI.NodeListButtonColor) if (GUILayout.Button(GUI.MakeLabel(GUI.Symbols.ListEraseElement.ToString()), skin.button, GUILayout.Width(18), GUILayout.Height(18))) { removeIndex = i; } } GUILayout.EndHorizontal(); } if (removeIndex >= 0) { m_selected.RemoveAt(removeIndex); } } } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); GUILayout.Space(12); bool applyPressed = false; bool cancelPressed = false; GUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); UnityEngine.GUI.enabled = m_selected.Count > 0; applyPressed = GUILayout.Button(GUI.MakeLabel("Apply", true, "Apply current configuration"), skin.button, GUILayout.Width(86), GUILayout.Height(26)); UnityEngine.GUI.enabled = true; GUILayout.BeginVertical(); { GUILayout.Space(11); cancelPressed = GUILayout.Button(GUI.MakeLabel("Cancel", false, "Cancel/reset"), skin.button, GUILayout.Width(64), GUILayout.Height(18)); } GUILayout.EndVertical(); } GUILayout.EndHorizontal(); if (applyPressed) { string selectedGroupName = m_mainObject.GetInstanceID().ToString(); string mainObjectGroupName = ""; for (int i = 0; i < m_selected.Count; ++i) { mainObjectGroupName += m_selected[i].GetInstanceID().ToString() + (i != m_selected.Count - 1 ? "_" : ""); } m_mainObject.GetOrCreateComponent <CollisionGroups>().AddGroup(mainObjectGroupName, ShouldPropagateToChildren(m_mainObject)); foreach (var selected in m_selected) { selected.GetOrCreateComponent <CollisionGroups>().AddGroup(selectedGroupName, ShouldPropagateToChildren(selected)); } CollisionGroupsManager.Instance.SetEnablePair(mainObjectGroupName, selectedGroupName, false); PerformRemoveFromParent(); } else if (cancelPressed) { PerformRemoveFromParent(); } }
public void OnInspectorGUI(GUISkin skin) { if (AttachmentFrameTool == null || AttachmentFrameTool.AttachmentPair == null) { PerformRemoveFromParent(); return; } using (new GUI.Indent(16)) { GUILayout.BeginHorizontal(); { GUILayout.Label(GUI.MakeLabel("Name", true), skin.label, GUILayout.Width(64)); m_createConstraintData.Name = GUILayout.TextField(m_createConstraintData.Name, skin.textField, GUILayout.ExpandWidth(true)); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(GUI.MakeLabel("Type", true), skin.label, GUILayout.Width(64)); using (new GUI.ColorBlock(Color.Lerp(UnityEngine.GUI.color, Color.yellow, 0.1f))) m_createConstraintData.ConstraintType = (ConstraintType)EditorGUILayout.EnumPopup(m_createConstraintData.ConstraintType, skin.button, GUILayout.ExpandWidth(true), GUILayout.Height(18)); } GUILayout.EndHorizontal(); } GUI.Separator3D(); AttachmentFrameTool.OnPreTargetMembersGUI(skin); AttachmentFrameTool.AttachmentPair.Update(); m_createConstraintData.CollisionState = ConstraintTool.ConstraintCollisionsStateGUI(m_createConstraintData.CollisionState, skin); m_createConstraintData.SolveType = ConstraintTool.ConstraintSolveTypeGUI(m_createConstraintData.SolveType, skin); GUI.Separator3D(); var createCancelState = GUI.CreateCancelButtons(m_createConstraintData.AttachmentPair.ReferenceObject != null && m_createConstraintData.AttachmentPair.ReferenceObject.GetComponentInParent <RigidBody>() != null, skin, "Create the constraint"); GUI.Separator3D(); if (createCancelState == GUI.CreateCancelState.Create) { GameObject constraintGameObject = Factory.Create(m_createConstraintData.ConstraintType, m_createConstraintData.AttachmentPair); Constraint constraint = constraintGameObject.GetComponent <Constraint>(); constraintGameObject.name = m_createConstraintData.Name; constraint.CollisionsState = m_createConstraintData.CollisionState; if (MakeConstraintChildToParent) { constraintGameObject.transform.SetParent(Parent.transform); } Undo.RegisterCreatedObjectUndo(constraintGameObject, "New constraint '" + constraintGameObject.name + "' created"); m_createConstraintData.Reset(); } if (createCancelState != GUI.CreateCancelState.Nothing) { PerformRemoveFromParent(); } }