Example #1
0
        public static bool ConstraintConnectedFrameSyncGUI(bool enabled, GUISkin skin)
        {
            using (new GUI.Indent(12)) {
                enabled = GUI.Toggle(GUI.MakeLabel("Connected frame animated", true), enabled, skin.button, skin.label);
            }

            return(enabled);
        }
Example #2
0
        private void OnShapeListGUI(GUISkin skin)
        {
            if (!GUI.Foldout(EditorData.Instance.GetData(RigidBody, "Shapes"), GUI.MakeLabel("Shapes", true), skin))
            {
                return;
            }

            Shape[] shapes = RigidBody.GetComponentsInChildren <Shape>();
            if (shapes.Length == 0)
            {
                using (new GUI.Indent(12))
                    GUILayout.Label(GUI.MakeLabel("Empty", true), skin.label);
                return;
            }

            using (new GUI.Indent(12)) {
                foreach (var shape in shapes)
                {
                    GUI.Separator();
                    if (!GUI.Foldout(EditorData.Instance.GetData(RigidBody,
                                                                 shape.GetInstanceID().ToString()),
                                     GUI.MakeLabel("[" + GUI.AddColorTag(shape.GetType().Name, Color.Lerp(Color.green, Color.black, 0.4f)) + "] " + shape.name),
                                     skin))
                    {
                        continue;
                    }

                    GUI.Separator();
                    using (new GUI.Indent(12)) {
                        Undo.RecordObjects(shape.GetUndoCollection(), "Shape");

                        shape.enabled = GUI.Toggle(GUI.MakeLabel("Enable"), shape.enabled, skin.button, skin.label);
                        if (shape is AgXUnity.Collide.Mesh)
                        {
                            GUI.Separator();

                            var newMeshSource = GUI.ShapeMeshSourceGUI((shape as AgXUnity.Collide.Mesh).SourceObjects.FirstOrDefault(), skin);
                            if (newMeshSource != null)
                            {
                                (shape as AgXUnity.Collide.Mesh).SetSourceObject(newMeshSource);
                            }
                        }
                        GUI.Separator();
                        BaseEditor <Shape> .Update(shape, shape, skin);
                    }
                }
            }
        }
Example #3
0
        private void HandleConstraintControllerGUI(ElementaryConstraintController controller, GUISkin skin)
        {
            var    controllerType    = controller.GetControllerType();
            var    controllerTypeTag = controllerType.ToString().Substring(0, 1);
            string dimString         = "[" + GUI.AddColorTag(controllerTypeTag,
                                                             controllerType == Constraint.ControllerType.Rotational ?
                                                             Color.Lerp(UnityEngine.GUI.color, Color.red, 0.75f) :
                                                             Color.Lerp(UnityEngine.GUI.color, Color.green, 0.75f)) + "] ";

            if (GUI.Foldout(Selected(SelectedFoldout.Controller,
                                     controllerTypeTag + ConstraintUtils.FindName(controller)),
                            GUI.MakeLabel(dimString + ConstraintUtils.FindName(controller), true),
                            skin,
                            OnFoldoutStateChange))
            {
                using (new GUI.Indent(12)) {
                    controller.Enable = GUI.Toggle(GUI.MakeLabel("Enable", controller.Enable), controller.Enable, skin.button, skin.label);
                    BaseEditor <ElementaryConstraint> .Update(controller, controller, skin);
                }
            }
        }
        public override void OnPreTargetMembersGUI(GUISkin skin)
        {
            GUILayout.Label(GUI.MakeLabel("Debug render manager", 16, true), GUI.Align(skin.label, TextAnchor.MiddleCenter));

            GUI.Separator();

            Manager.RenderShapes = GUI.Toggle(GUI.MakeLabel("Debug render shapes"), Manager.RenderShapes, skin.button, skin.label);
            GUI.MaterialEditor(GUI.MakeLabel("Shape material"), 100, Manager.ShapeRenderMaterial, skin, newMaterial => Manager.ShapeRenderMaterial = newMaterial, true);

            GUI.Separator();

            using (new GUILayout.HorizontalScope()) {
                Manager.RenderContacts = GUI.Toggle(GUI.MakeLabel("Render contacts"), Manager.RenderContacts, skin.button, skin.label);
                Manager.ContactColor   = EditorGUILayout.ColorField(Manager.ContactColor);
            }

            Manager.ContactScale = EditorGUILayout.Slider(GUI.MakeLabel("Scale"), Manager.ContactScale, 0.0f, 1.0f);

            GUI.Separator();

            Manager.ColorizeBodies = GUI.Toggle(GUI.MakeLabel("Colorize bodies",
                                                              false,
                                                              "Every rigid body instance will be rendered with a unique color (wire framed)."),
                                                Manager.ColorizeBodies,
                                                skin.button,
                                                skin.label);
            Manager.HighlightMouseOverObject = GUI.Toggle(GUI.MakeLabel("Highlight mouse over object",
                                                                        false,
                                                                        "Highlight mouse over object in scene view."),
                                                          Manager.HighlightMouseOverObject,
                                                          skin.button,
                                                          skin.label);
            Manager.IncludeInBuild = GUI.Toggle(GUI.MakeLabel("Include in build",
                                                              false,
                                                              "Include debug rendering when building the project."),
                                                Manager.IncludeInBuild,
                                                skin.button,
                                                skin.label);
        }
Example #5
0
        private void HandleKeyHandlerGUI(GUIContent name, Utils.KeyHandler keyHandler, GUISkin skin)
        {
            const int keyButtonWidth  = 90;
            const int keyButtonHeight = 18;

            GUILayout.BeginHorizontal();
            {
                keyHandler.Enable = GUI.Toggle(name,
                                               keyHandler.Enable,
                                               skin.button,
                                               GUI.Align(skin.label, TextAnchor.MiddleLeft),
                                               new GUILayoutOption[] { GUILayout.Width(keyButtonHeight), GUILayout.Height(keyButtonHeight) },
                                               new GUILayoutOption[] { GUILayout.Height(keyButtonHeight) });
                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(keyButtonHeight));
                    if (toggleDetecting)
                    {
                        keyHandler.DetectKey(this, !keyHandler.IsDetectingKey(iKey), iKey);
                    }
                }

                Rect dropDownButtonRect = new Rect();
                GUILayout.BeginVertical(GUILayout.Height(keyButtonHeight));
                {
                    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);
            }
        }
Example #6
0
        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();
        }
        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();
        }