Esempio n. 1
0
        private NodeFoldoutState NodeFoldout(Route <NodeT> .ValidatedNode validatedNode)
        {
            if (s_invalidNodeStyle == null)
            {
                s_invalidNodeStyle = new GUIStyle(InspectorEditor.Skin.Label);
                s_invalidNodeStyle.normal.background = GUI.CreateColoredTexture(1,
                                                                                1,
                                                                                Color.Lerp(UnityEngine.GUI.color,
                                                                                           Color.red,
                                                                                           0.75f));
            }

            var state = new NodeFoldoutState();
            var node  = validatedNode.Node;

            var verticalScope = !validatedNode.Valid ?
                                new EditorGUILayout.VerticalScope(s_invalidNodeStyle) :
                                null;
            var horizontalScope = node == Selected ?
                                  new EditorGUILayout.HorizontalScope(InspectorEditor.Skin.Label) :
                                  new EditorGUILayout.HorizontalScope(InspectorEditor.Skin.TextArea);

            state.Foldout = InspectorGUI.Foldout(GetFoldoutData(node),
                                                 GUI.MakeLabel(GetNodeTypeString(node) + ' ' +
                                                               SelectGameObjectDropdownMenuTool.GetGUIContent(node.Parent).text,
                                                               !validatedNode.Valid,
                                                               validatedNode.ErrorString),
                                                 newState =>
            {
                Selected = newState ? node : null;
                EditorUtility.SetDirty(Parent);
            });

            state.InsertBefore = InspectorGUI.Button(MiscIcon.EntryInsertBefore,
                                                     true,
                                                     "Insert a new node before this node.",
                                                     GUILayout.Width(18));
            state.InsertAfter = InspectorGUI.Button(MiscIcon.EntryInsertAfter,
                                                    true,
                                                    "Insert a new node after this node.",
                                                    GUILayout.Width(18));
            state.Erase = InspectorGUI.Button(MiscIcon.EntryRemove,
                                              true,
                                              "Remove this node from the route.",
                                              GUILayout.Width(18));
            horizontalScope?.Dispose();
            verticalScope?.Dispose();

            return(state);
        }
        private void HandleCollisionGroupEntry(CollisionGroupEntry entry)
        {
            bool buttonPressed = false;

            GUILayout.BeginHorizontal();
            {
                entry.Tag     = GUILayout.TextField(entry.Tag, InspectorEditor.Skin.TextField);
                buttonPressed = InspectorGUI.Button(MiscIcon.ContextDropdown,
                                                    true,
                                                    "Add collision group.",
                                                    1.1f,
                                                    GUILayout.Width(18));
            }
            GUILayout.EndHorizontal();

            if (buttonPressed)
            {
                m_findActiveGroupNameEntry = m_findActiveGroupNameEntry == entry ? null : entry;

                if (m_findActiveGroupNameEntry != null)
                {
                    m_groups = (from cg in Object.FindObjectsOfType <CollisionGroups>()
                                from cgEntry in cg.Groups
                                select cgEntry.Tag).Distinct().ToList();
                    m_groups.Sort(new StringLowerComparer());
                }
            }

            if (m_findActiveGroupNameEntry == entry && buttonPressed)
            {
                GenericMenu groupNameMenu = new GenericMenu();
                groupNameMenu.AddDisabledItem(GUI.MakeLabel("Groups in scene"));
                groupNameMenu.AddSeparator(string.Empty);
                foreach (var groupName in m_groups)
                {
                    groupNameMenu.AddItem(GUI.MakeLabel(groupName), groupName == m_findActiveGroupNameEntry.Tag, () =>
                    {
                        m_findActiveGroupNameEntry.Tag = groupName;
                        m_findActiveGroupNameEntry     = null;
                    });
                }

                groupNameMenu.ShowAsContext();
            }
        }
Esempio n. 3
0
        public bool Update(Rect rect, bool isFirst, bool isLast)
        {
            var buttonType = isFirst && isFirst == isLast ? InspectorGUISkin.ButtonType.Normal :
                             isFirst                      ? InspectorGUISkin.ButtonType.Left :
                             isLast                       ? InspectorGUISkin.ButtonType.Right :
                             InspectorGUISkin.ButtonType.Middle;
            var toggleDropdown = InspectorGUI.Button(rect,
                                                     Icon,
                                                     UnityEngine.GUI.enabled,
                                                     InspectorEditor.Skin.GetButton(true, buttonType),
                                                     "Create new " +
                                                     State.ShapeType.ToString().ToLower() +
                                                     "as parent of the selected object(s).");

            if (toggleDropdown)
            {
                State.DropdownEnabled = !State.DropdownEnabled;
            }

            return(toggleDropdown);
        }
Esempio n. 4
0
        public void OnInspectorGUI()
        {
            InspectorGUI.OnDropdownToolBegin($"Disable collisions between {m_mainObject.name} and other objects selected in Scene View.");

            var skin         = InspectorEditor.Skin;
            var emptyContent = GUI.MakeLabel(" ");

            EditorGUILayout.LabelField(GUI.MakeLabel("Disable: ", true),
                                       SelectGameObjectDropdownMenuTool.GetGUIContent(m_mainObject),
                                       skin.TextArea);


            EditorGUILayout.LabelField(emptyContent,
                                       GUI.MakeLabel(GUI.Symbols.ArrowLeftRight.ToString()));

            if (m_selected.Count == 0)
            {
                EditorGUILayout.LabelField(emptyContent,
                                           GUI.MakeLabel("Select object(s) in scene view" + AwaitingUserActionDots()),
                                           skin.TextArea);
            }
            else
            {
                int removeIndex = -1;
                for (int i = 0; i < m_selected.Count; ++i)
                {
                    GUILayout.BeginHorizontal();
                    {
                        EditorGUILayout.LabelField(emptyContent,
                                                   SelectGameObjectDropdownMenuTool.GetGUIContent(m_selected[i]),
                                                   skin.TextArea);
                        if (InspectorGUI.Button(MiscIcon.EntryRemove,
                                                true,
                                                "Remove pair.",
                                                GUILayout.Width(14)))
                        {
                            removeIndex = i;
                        }
                    }
                    GUILayout.EndHorizontal();
                }

                if (removeIndex >= 0)
                {
                    m_selected.RemoveAt(removeIndex);
                }
            }

            var applyCancelState = InspectorGUI.PositiveNegativeButtons(m_selected.Count > 0,
                                                                        "Apply",
                                                                        "Apply current configuration.",
                                                                        "Cancel");

            if (applyCancelState == InspectorGUI.PositiveNegativeResult.Positive)
            {
                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 ? "_" : "");
                }

                Undo.SetCurrentGroupName("Disabling collisions");
                var undoGroupId = Undo.GetCurrentGroup();

                if (m_mainObject.GetComponent <CollisionGroups>() == null)
                {
                    Undo.AddComponent <CollisionGroups>(m_mainObject);
                }

                Undo.RecordObject(m_mainObject.GetComponent <CollisionGroups>(), "Adding collision group");
                m_mainObject.GetComponent <CollisionGroups>().AddGroup(mainObjectGroupName,
                                                                       ShouldPropagateToChildren(m_mainObject));
                foreach (var selected in m_selected)
                {
                    if (selected.GetComponent <CollisionGroups>() == null)
                    {
                        Undo.AddComponent <CollisionGroups>(selected);
                    }
                    Undo.RecordObject(selected.GetComponent <CollisionGroups>(), "Adding collision group");
                    selected.GetComponent <CollisionGroups>().AddGroup(selectedGroupName,
                                                                       ShouldPropagateToChildren(selected));
                }

                // TopMenu.GetOrCreate works with Undo.
                Undo.RecordObject(TopMenu.GetOrCreateUniqueGameObject <CollisionGroupsManager>(),
                                  "Adding collision group to manager.");

                CollisionGroupsManager.Instance.SetEnablePair(mainObjectGroupName, selectedGroupName, false);

                Undo.CollapseUndoOperations(undoGroupId);

                PerformRemoveFromParent();
            }
            else if (applyCancelState == InspectorGUI.PositiveNegativeResult.Negative)
            {
                PerformRemoveFromParent();
            }

            InspectorGUI.OnDropdownToolEnd();
        }
Esempio n. 5
0
        private void ActivateLicenseGUI()
        {
            GUILayout.Label(GUI.MakeLabel("Activate license", true), InspectorEditor.Skin.Label);
            var selectLicenseRect = GUILayoutUtility.GetLastRect();

            selectLicenseRect.x    += selectLicenseRect.width;
            selectLicenseRect.width = 28;
            selectLicenseRect.x    -= selectLicenseRect.width;
            selectLicenseRect.y    -= EditorGUIUtility.standardVerticalSpacing;
            var selectLicensePressed = InspectorGUI.Button(selectLicenseRect,
                                                           MiscIcon.Locate,
                                                           UnityEngine.GUI.enabled,
                                                           "Select license file on this computer",
                                                           1.25f);

            if (selectLicensePressed)
            {
                var sourceLicense = EditorUtility.OpenFilePanel("Copy AGX Dynamics license file",
                                                                ".",
                                                                $"{AGXUnity.LicenseManager.GetLicenseExtension( AGXUnity.LicenseInfo.LicenseType.Service ).Remove( 0, 1 )}," +
                                                                $"{AGXUnity.LicenseManager.GetLicenseExtension( AGXUnity.LicenseInfo.LicenseType.Legacy ).Remove( 0, 1 )}");
                if (!string.IsNullOrEmpty(sourceLicense))
                {
                    var targetLicense = AGXUnity.IO.Environment.FindUniqueFilename($"{LicenseDirectory}/{Path.GetFileName( sourceLicense )}").PrettyPath();
                    if (EditorUtility.DisplayDialog("Copy AGX Dynamics license",
                                                    $"Copy \"{sourceLicense}\" to \"{targetLicense}\"?",
                                                    "Yes",
                                                    "Cancel"))
                    {
                        try {
                            File.Copy(sourceLicense, targetLicense, false);
                            StartUpdateLicenseInformation();
                            GUIUtility.ExitGUI();
                        }
                        catch (ExitGUIException) {
                            throw;
                        }
                        catch (System.Exception e) {
                            Debug.LogException(e);
                        }
                    }
                }
            }

            using (InspectorGUI.IndentScope.Single) {
                m_licenseActivateData.Id = EditorGUILayout.TextField(GUI.MakeLabel("License Id"),
                                                                     m_licenseActivateData.Id,
                                                                     InspectorEditor.Skin.TextField);
                if (m_licenseActivateData.Id.Any(c => !char.IsDigit(c)))
                {
                    m_licenseActivateData.Id = new string( m_licenseActivateData.Id.Where(c => char.IsDigit(c)).ToArray());
                }
                m_licenseActivateData.Password = EditorGUILayout.PasswordField(GUI.MakeLabel("Activation Code"),
                                                                               m_licenseActivateData.Password);

                InspectorGUI.SelectFolder(GUI.MakeLabel("License File Directory"),
                                          LicenseDirectory,
                                          "License file directory",
                                          newDirectory =>
                {
                    newDirectory = newDirectory.PrettyPath();

                    if (string.IsNullOrEmpty(newDirectory))
                    {
                        newDirectory = "Assets";
                    }

                    if (!Directory.Exists(newDirectory))
                    {
                        Debug.LogWarning($"Invalid license directory: {newDirectory} - directory doesn't exist.");
                        return;
                    }
                    else if (!IO.Utils.IsValidProjectFolder(newDirectory))
                    {
                        Debug.LogWarning($"Invalid license directory: {newDirectory} - directory has to be in the project.");
                        return;
                    }
                    LicenseDirectory = newDirectory;
                });

                using (new GUI.EnabledBlock(UnityEngine.GUI.enabled &&
                                            m_licenseActivateData.Id.Length > 0 &&
                                            m_licenseActivateData.Password.Length > 0)) {
                    // It isn't possible to press this button during activation.
                    if (UnityEngine.GUI.Button(EditorGUI.IndentedRect(EditorGUILayout.GetControlRect()),
                                               GUI.MakeLabel(AGXUnity.LicenseManager.IsBusy ?
                                                             "Activating..." :
                                                             "Activate"),
                                               InspectorEditor.Skin.Button))
                    {
                        AGXUnity.LicenseManager.ActivateAsync(System.Convert.ToInt32(m_licenseActivateData.Id),
                                                              m_licenseActivateData.Password,
                                                              LicenseDirectory,
                                                              success =>
                        {
                            if (success)
                            {
                                m_licenseActivateData = IdPassword.Empty();
                            }
                            else
                            {
                                Debug.LogError("License Error: ".Color(Color.red) + AGXUnity.LicenseManager.LicenseInfo.Status);
                            }

                            StartUpdateLicenseInformation();

                            UnityEngine.GUI.FocusControl("");
                        });
                    }
                }
            }
        }
Esempio n. 6
0
        public override void OnPreTargetMembersGUI()
        {
            var isMultiSelect = AttachmentPairs.Length > 1;

            Undo.RecordObjects(AttachmentPairs, "Constraint Attachment");

            var skin          = InspectorEditor.Skin;
            var guiWasEnabled = UnityEngine.GUI.enabled;

            var connectedFrameSynchronized = AttachmentPairs.All(ap => ap.Synchronized);

            EditorGUILayout.LabelField(GUI.MakeLabel("Reference frame", true), skin.Label);
            InspectorGUI.HandleFrames(AttachmentPairs.Select(ap => ap.ReferenceFrame).ToArray(), 1);

            GUILayout.Space(4);

            var rect     = EditorGUILayout.GetControlRect(false, EditorGUIUtility.singleLineHeight);
            var orgWidth = rect.xMax;

            UnityEngine.GUI.Label(EditorGUI.IndentedRect(rect),
                                  GUI.MakeLabel("Connected frame", true),
                                  InspectorEditor.Skin.Label);

            var buttonWidth        = 1.1f * EditorGUIUtility.singleLineHeight;
            var buttonHeightOffset = 1.0f;

            rect.x     = EditorGUIUtility.labelWidth + InspectorGUI.LayoutMagicNumber;
            rect.y    -= buttonHeightOffset;
            rect.width = buttonWidth;
            var toggleSynchronized = InspectorGUI.Button(rect,
                                                         connectedFrameSynchronized ?
                                                         MiscIcon.SynchEnabled :
                                                         MiscIcon.SynchDisabled,
                                                         true,
                                                         "Toggle synchronized with reference frame.",
                                                         1.17f);

            rect.x    += rect.width + 2.0f;
            rect.width = orgWidth - rect.x;
            rect.y    += buttonHeightOffset;

            UnityEngine.GUI.Label(rect,
                                  GUI.MakeLabel($"{( connectedFrameSynchronized ? "Synchronized" : "Free" )}"),
                                  InspectorEditor.Skin.Label);

            if (toggleSynchronized)
            {
                foreach (var ap in AttachmentPairs)
                {
                    ap.Synchronized = !connectedFrameSynchronized;
                }

                if (!isMultiSelect && AttachmentPairs[0].Synchronized)
                {
                    ConnectedFrameTool.TransformHandleActive = false;
                }
            }

            UnityEngine.GUI.enabled = !connectedFrameSynchronized && !isMultiSelect;
            InspectorGUI.HandleFrames(AttachmentPairs.Select(ap => ap.ConnectedFrame).ToArray(), 1);
            UnityEngine.GUI.enabled = guiWasEnabled;
        }
        public override void OnPreTargetMembersGUI()
        {
            var refMaterial = Material;
            var mixedPreset = Targets.Any(target => (target as DeformableTerrainMaterial).PresetName != refMaterial.PresetName);

            using (new InspectorGUI.IndentScope((InspectorGUI.IndentScope.Level > 0 ? -1 : 0))) {
                var resetButtonWidth = EditorGUIUtility.singleLineHeight;
                var rect             = EditorGUILayout.GetControlRect();
                var totalRectWidth   = rect.width;

                var availablePresets = DeformableTerrainMaterial.GetAvailablePresets().ToArray();
                var presetIndex      = FindPresetIndex(availablePresets,
                                                       refMaterial.PresetName);
                var invalidPreset = presetIndex < 0;
                EditorGUI.showMixedValue = mixedPreset || invalidPreset;
                if (invalidPreset)
                {
                    InspectorGUI.WarningLabel($"Material preset name {refMaterial.PresetName} doesn't exist in the material presets library.");
                }

                rect.width = EditorGUIUtility.labelWidth;
                EditorGUI.PrefixLabel(rect, GUI.MakeLabel("Preset"), InspectorEditor.Skin.Label);

                rect.x    += rect.width;
                rect.width = totalRectWidth - EditorGUIUtility.labelWidth - resetButtonWidth;
                EditorGUI.BeginChangeCheck();
                var newPresetIndex = EditorGUI.Popup(rect, Mathf.Max(presetIndex, 0), availablePresets, InspectorEditor.Skin.Popup);
                if (EditorGUI.EndChangeCheck() && invalidPreset)
                {
                    invalidPreset = false;
                }
                EditorGUI.showMixedValue = false;

                rect.x    += rect.width;
                rect.width = resetButtonWidth;
                var resetButtonPressed = InspectorGUI.Button(rect,
                                                             MiscIcon.ResetDefault,
                                                             !invalidPreset,
                                                             $"Reset values to default for preset: {refMaterial.PresetName}",
                                                             0.9f);

                if (!invalidPreset &&
                    newPresetIndex != presetIndex &&
                    EditorUtility.DisplayDialog("Library preset -> " + availablePresets[newPresetIndex],
                                                $"Change preset from {refMaterial.PresetName} to {availablePresets[ newPresetIndex ]}?\n" +
                                                "All current values will be overwritten.",
                                                "Yes", "No"))
                {
                    foreach (var material in GetTargets <DeformableTerrainMaterial>())
                    {
                        material.SetPresetNameAndUpdateValues(availablePresets[newPresetIndex]);
                    }
                }

                if (resetButtonPressed &&
                    EditorUtility.DisplayDialog("Reset values to default",
                                                $"Reset preset {refMaterial.PresetName} to default?",
                                                "Yes", "No"))
                {
                    foreach (var material in GetTargets <DeformableTerrainMaterial>())
                    {
                        material.ResetToPresetDefault();
                    }
                }

                InspectorGUI.Separator();
            }
        }
Esempio n. 8
0
        private void RouteGUI()
        {
            var addNewPressed       = false;
            var insertBeforePressed = false;
            var insertAfterPressed  = false;
            var erasePressed        = false;

            NodeT listOpNode = null;

            Undo.RecordObject(Route, "Route changed");

            if (InspectorGUI.Foldout(EditorData.Instance.GetData(Parent,
                                                                 "Route",
                                                                 entry => { entry.Bool = true; }),
                                     GUI.MakeLabel("Route")))
            {
                var validatedRoute = Route.GetValidated();
                foreach (var validatedNode in validatedRoute)
                {
                    var node = validatedNode.Node;
                    using (InspectorGUI.IndentScope.Single) {
                        var foldoutState = NodeFoldout(validatedNode);
                        if (foldoutState.Foldout)
                        {
                            OnPreFrameGUI(node);

                            InspectorGUI.HandleFrame(node, 1);

                            OnPostFrameGUI(node);
                        }

                        if (listOpNode == null && foldoutState.ButtonPressed)
                        {
                            listOpNode = node;
                        }

                        insertBeforePressed = insertBeforePressed || foldoutState.InsertBefore;
                        insertAfterPressed  = insertAfterPressed || foldoutState.InsertAfter;
                        erasePressed        = erasePressed || foldoutState.Erase;
                    }

                    if (GUILayoutUtility.GetLastRect().Contains(Event.current.mousePosition) &&
                        Event.current.type == EventType.MouseDown &&
                        Event.current.button == 0)
                    {
                        Selected = node;
                    }
                }

                GUILayout.BeginHorizontal();
                {
                    InspectorGUI.Separator(1, EditorGUIUtility.singleLineHeight);

                    addNewPressed = InspectorGUI.Button(MiscIcon.EntryAdd,
                                                        true,
                                                        "Add new node to the route.",
                                                        GUILayout.Width(18));

                    if (listOpNode == null && addNewPressed)
                    {
                        listOpNode = Route.LastOrDefault();
                    }
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                InspectorGUI.Separator(1, 3);
            }

            if (addNewPressed || insertBeforePressed || insertAfterPressed)
            {
                NodeT newRouteNode = null;
                // Clicking "Add" will not copy data from last node.
                newRouteNode = listOpNode != null?
                               addNewPressed?
                               RouteNode.Create <NodeT>(null, listOpNode.Position, listOpNode.Rotation) :
                                   RouteNode.Create <NodeT>(listOpNode.Parent, listOpNode.LocalPosition, listOpNode.LocalRotation) :
                                       RouteNode.Create <NodeT>();

                OnNodeCreate(newRouteNode, listOpNode, addNewPressed);

                if (addNewPressed)
                {
                    Route.Add(newRouteNode);
                }
                if (insertBeforePressed)
                {
                    Route.InsertBefore(newRouteNode, listOpNode);
                }
                if (insertAfterPressed)
                {
                    Route.InsertAfter(newRouteNode, listOpNode);
                }

                if (newRouteNode != null)
                {
                    CreateRouteNodeTool(newRouteNode);
                    Selected = newRouteNode;
                }
            }
            else if (listOpNode != null && erasePressed)
            {
                Selected = null;
                Route.Remove(listOpNode);
            }
        }
        public override void OnPreTargetMembersGUI()
        {
            var  skin          = InspectorEditor.Skin;
            var  disabledPairs = Manager.DisabledPairs;
            bool clearPressed  = false;
            bool addPressed    = false;
            CollisionGroupEntryPair erasePair = null;

            GUILayout.Label(GUI.MakeLabel("Add pair",
                                          true),
                            skin.LabelMiddleCenter);

            GUILayout.BeginVertical(skin.TextArea);
            {
                HandleCollisionGroupEntryPair(m_groupEntryPairToAdd);

                var buttonState = InspectorGUI.PositiveNegativeButtons(m_groupEntryPairToAdd.First.Tag.Length > 0 ||
                                                                       m_groupEntryPairToAdd.Second.Tag.Length > 0,
                                                                       "Add",
                                                                       "Add pair to disabled pairs.",
                                                                       "Clear");
                addPressed   = buttonState == InspectorGUI.PositiveNegativeResult.Positive;
                clearPressed = buttonState == InspectorGUI.PositiveNegativeResult.Negative;
            }
            GUILayout.EndVertical();

            if (InspectorGUI.Foldout(FoldoutDataEntry, GUI.MakeLabel("Disabled Pairs [" + disabledPairs.Length + "]")))
            {
                using (InspectorGUI.IndentScope.Single) {
                    foreach (var disabledPair in disabledPairs)
                    {
                        GUILayout.BeginHorizontal();
                        {
                            InspectorGUI.Separator(1, EditorGUIUtility.singleLineHeight);

                            if (InspectorGUI.Button(MiscIcon.EntryRemove,
                                                    true,
                                                    "Remove pair from list.",
                                                    GUILayout.Width(18)))
                            {
                                erasePair = disabledPair;
                            }
                        }
                        GUILayout.EndHorizontal();

                        HandleCollisionGroupEntryPair(disabledPair);

                        // TODO GUI: Maybe unnecessary space with correct separator.
                        GUILayout.Space(6.0f);
                    }
                }
            }

            if (clearPressed)
            {
                m_groupEntryPairToAdd.First.Tag = m_groupEntryPairToAdd.Second.Tag = string.Empty;
            }
            if (addPressed)
            {
                Manager.SetEnablePair(m_groupEntryPairToAdd.First.Tag, m_groupEntryPairToAdd.Second.Tag, false);
                m_groupEntryPairToAdd.First.Tag = m_groupEntryPairToAdd.Second.Tag = string.Empty;
                FoldoutDataEntry.Bool           = true;
            }
            if (erasePair != null)
            {
                if (EditorUtility.DisplayDialog("Remove pair",
                                                "Erase disabled pair: " + erasePair.First.Tag + " and " + erasePair.Second.Tag + "?",
                                                "Yes",
                                                "No"))
                {
                    Manager.SetEnablePair(erasePair.First.Tag, erasePair.Second.Tag, true);
                }
            }
        }