Exemple #1
0
        private static void DrawUrdfJointData <T>(AGXUnity.IO.URDF.UJoint parent,
                                                  MemberInfo member,
                                                  T jointData)
            where T : struct
        {
            var fieldsAndProperties    = InvokeWrapper.FindFieldsAndProperties(typeof(T));
            var enabledFieldOrProperty = fieldsAndProperties.FirstOrDefault(wrapper => wrapper.Member.Name == "Enabled");

            if (enabledFieldOrProperty == null)
            {
                return;
            }
            var enabled = enabledFieldOrProperty.Get <bool>(jointData);

            using (new GUI.EnabledBlock(enabled)) {
                if (!InspectorGUI.Foldout(GetEditorData(parent, member.Name), InspectorGUI.MakeLabel(member)))
                {
                    return;
                }
                using (InspectorGUI.IndentScope.Single) {
                    foreach (var wrapper in fieldsAndProperties)
                    {
                        if (wrapper == enabledFieldOrProperty)
                        {
                            continue;
                        }

                        var drawer = GetDrawerMethod(wrapper.GetContainingType());
                        drawer.Drawer?.Invoke(null, new object[] { new object[] { jointData }, wrapper });
                    }
                }
            }
        }
Exemple #2
0
        public static object DeformableTerrainShovelExcavationSettingsDrawer(object[] objects, InvokeWrapper wrapper)
        {
            var data = new ExcavationSettingsResult()
            {
                Value = wrapper.Get <DeformableTerrainShovelSettings.ExcavationSettings>(objects[0])
            };

            if (InspectorGUI.Foldout(EditorData.Instance.GetData(objects[0] as Object, wrapper.Member.Name),
                                     InspectorGUI.MakeLabel(wrapper.Member)))
            {
                using (InspectorGUI.IndentScope.Single) {
                    data.Value.Enabled = InspectorGUI.Toggle(GUI.MakeLabel("Enabled"),
                                                             data.Value.Enabled);
                    data.EnabledChanged                 = UnityEngine.GUI.changed;
                    UnityEngine.GUI.changed             = false;
                    data.Value.CreateDynamicMassEnabled = InspectorGUI.Toggle(GUI.MakeLabel("Create Dynamic Mass Enabled"),
                                                                              data.Value.CreateDynamicMassEnabled);
                    data.CreateDynamicMassEnabledChanged = UnityEngine.GUI.changed;
                    UnityEngine.GUI.changed         = false;
                    data.Value.ForceFeedbackEnabled = InspectorGUI.Toggle(GUI.MakeLabel("Force Feedback Enabled"),
                                                                          data.Value.ForceFeedbackEnabled);
                    data.ForceFeedbackEnabledChanged = UnityEngine.GUI.changed;
                    UnityEngine.GUI.changed          = false;
                }
                UnityEngine.GUI.changed = data.ContainsChanges;
            }
            return(data);
        }
Exemple #3
0
        public void Update(InvokeWrapper wrapper, object targetInstance)
        {
            var foldoutBeginAttribute = wrapper.GetAttribute <InspectorGroupBeginAttribute>();

            if (foldoutBeginAttribute != null || wrapper.HasAttribute <InspectorGroupEndAttribute>())
            {
                End();
            }

            if (foldoutBeginAttribute == null)
            {
                return;
            }

            var groupIdentifier = (targetInstance != null ? targetInstance.GetType().FullName : "null") +
                                  "_" + foldoutBeginAttribute.Name;

            Begin(!InspectorGUI.Foldout(EditorData.Instance.GetData(targetInstance as Object,
                                                                    groupIdentifier),
                                        GUI.MakeLabel(foldoutBeginAttribute.Name)));
        }
Exemple #4
0
        public static void DrawUrdfElement(AGXUnity.IO.URDF.Element element,
                                           int elementArrayIndex = -1)
        {
            if (element == null)
            {
                return;
            }

            var dropDownName = string.IsNullOrEmpty(element.Name) ?
                               elementArrayIndex >= 0 ?
                               $"{element.GetType().Name}[{elementArrayIndex}]" :
                               element.GetType().Name :
                               element.Name;

            if (!InspectorGUI.Foldout(GetEditorData(element, dropDownName),
                                      GUI.MakeLabel(InspectorGUISkin.Instance.TagTypename($"Urdf.{element.GetType().Name}") +
                                                    ' ' +
                                                    dropDownName)))
            {
                return;
            }

            using (InspectorGUI.IndentScope.Single) {
                var ignoreName = element is AGXUnity.IO.URDF.Inertial;
                if (!ignoreName)
                {
                    var nameRect = EditorGUILayout.GetControlRect();
                    EditorGUI.PrefixLabel(nameRect, GUI.MakeLabel("Name"), InspectorEditor.Skin.Label);
                    var orgXMax = nameRect.xMax;
                    nameRect.x   += EditorGUIUtility.labelWidth - 14.0f * InspectorGUI.IndentScope.Level;
                    nameRect.xMax = orgXMax;
                    EditorGUI.SelectableLabel(nameRect, element.Name, InspectorEditor.Skin.TextField);
                }

                if (element is AGXUnity.IO.URDF.Pose)
                {
                    DrawUrdfPose(element as AGXUnity.IO.URDF.Pose);
                }
                else if (element is AGXUnity.IO.URDF.Material)
                {
                    DrawUrdfMaterial(element as AGXUnity.IO.URDF.Material);
                    return;
                }

                var properties = GetOrFindProperties(element.GetType());
                var elementArg = new object[] { element };
                var geometry   = element as AGXUnity.IO.URDF.Geometry;
                foreach (var property in properties)
                {
                    // Ignoring Unity specific properties such as "name" and "hideFlags".
                    if (!char.IsUpper(property.Member.Name[0]))
                    {
                        continue;
                    }
                    if (!InspectorEditor.ShouldBeShownInInspector(property.Member))
                    {
                        continue;
                    }

                    var containingType = property.GetContainingType();
                    if (containingType.IsArray)
                    {
                        if (typeof(AGXUnity.IO.URDF.Element).IsAssignableFrom(containingType.GetElementType()))
                        {
                            var array = property.Get <System.Collections.ICollection>(element);
                            if (!InspectorGUI.Foldout(GetEditorData(element, property.Member.Name),
                                                      InspectorGUI.MakeLabel(property.Member,
                                                                             $" [{array.Count}]")))
                            {
                                continue;
                            }

                            using (InspectorGUI.IndentScope.Single) {
                                var arrayIndex = 0;
                                foreach (var arrayItem in array)
                                {
                                    DrawUrdfElement(arrayItem as AGXUnity.IO.URDF.Element, arrayIndex++);
                                }
                            }
                        }
                    }
                    else if (typeof(AGXUnity.IO.URDF.Element).IsAssignableFrom(containingType))
                    {
                        DrawUrdfElement(property.Get <AGXUnity.IO.URDF.Element>(element), -1);
                    }
                    else if (geometry == null || IsValidGeometryProperty(geometry, property))
                    {
                        var drawerMethod = GetDrawerMethod(containingType);
                        drawerMethod.Drawer?.Invoke(null, new object[] { elementArg, property });
                    }
                }
            }
        }
Exemple #5
0
        public static object GenericListDrawer(object[] objects, InvokeWrapper wrapper)
        {
            var list   = wrapper.Get <System.Collections.IList>(objects[0]);
            var target = objects[0] as Object;

            if (InspectorGUI.Foldout(EditorData.Instance.GetData(target, wrapper.Member.Name),
                                     InspectorGUI.MakeLabel(wrapper.Member)))
            {
                object insertElementBefore = null;
                object insertElementAfter  = null;
                object eraseElement        = null;
                var    skin         = InspectorEditor.Skin;
                var    buttonLayout = new GUILayoutOption[]
                {
                    GUILayout.Width(1.0f * EditorGUIUtility.singleLineHeight),
                    GUILayout.Height(1.0f * EditorGUIUtility.singleLineHeight)
                };
                foreach (var listObject in list)
                {
                    using (InspectorGUI.IndentScope.Single) {
                        GUILayout.BeginHorizontal();
                        {
                            InspectorGUI.Separator(1.0f, EditorGUIUtility.singleLineHeight);

                            if (InspectorGUI.Button(MiscIcon.EntryInsertBefore,
                                                    true,
                                                    "Insert new element before this.",
                                                    buttonLayout))
                            {
                                insertElementBefore = listObject;
                            }
                            if (InspectorGUI.Button(MiscIcon.EntryInsertAfter,
                                                    true,
                                                    "Insert new element after this.",
                                                    buttonLayout))
                            {
                                insertElementAfter = listObject;
                            }
                            if (InspectorGUI.Button(MiscIcon.EntryRemove,
                                                    true,
                                                    "Remove this element.",
                                                    buttonLayout))
                            {
                                eraseElement = listObject;
                            }
                        }
                        GUILayout.EndHorizontal();

                        InspectorEditor.DrawMembersGUI(new Object[] { target }, ignored => listObject);
                    }
                }

                InspectorGUI.Separator(1.0f, 0.5f * EditorGUIUtility.singleLineHeight);

                if (list.Count == 0)
                {
                    GUILayout.Label(GUI.MakeLabel("Empty", true), skin.Label);
                }

                bool addElementToList = false;
                GUILayout.BeginHorizontal();
                {
                    GUILayout.FlexibleSpace();
                    addElementToList = InspectorGUI.Button(MiscIcon.EntryInsertAfter,
                                                           true,
                                                           "Add new element.",
                                                           buttonLayout);
                }
                GUILayout.EndHorizontal();

                object newObject = null;
                if (addElementToList || insertElementBefore != null || insertElementAfter != null)
                {
                    newObject = Activator.CreateInstance(list.GetType().GetGenericArguments()[0], new object[] { });
                }

                if (eraseElement != null)
                {
                    list.Remove(eraseElement);
                }
                else if (newObject != null)
                {
                    if (addElementToList || (list.Count > 0 && insertElementAfter != null && insertElementAfter == list[list.Count - 1]))
                    {
                        list.Add(newObject);
                    }
                    else if (insertElementAfter != null)
                    {
                        list.Insert(list.IndexOf(insertElementAfter) + 1, newObject);
                    }
                    else if (insertElementBefore != null)
                    {
                        list.Insert(list.IndexOf(insertElementBefore), newObject);
                    }
                }

                if (eraseElement != null || newObject != null)
                {
                    EditorUtility.SetDirty(target);
                }
            }

            // A bit of a hack until I figure out how to handle multi-selection
            // of lists, if that should be possible at all. We're handling the
            // list from inside this drawer and by returning null the return
            // value isn't propagated to any targets.
            return(null);
        }