private void OnGUI()
        {
            var foldoutProperty = serializedAsset.FindProperty("sceneFoldoutOpen");

            if (foldoutProperty.boolValue = EditorGUILayoutx.FoldoutHeader("Scene", foldoutProperty.boolValue))
            {
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var solidColor = EditorGUILayout.ColorField(Content.SolidHandleColor, DeformEditorSettings.SolidHandleColor);
                    if (check.changed)
                    {
                        Undo.RecordObject(DeformEditorSettings.SettingsAsset, "Changed Solid Color Settings");
                        DeformEditorSettings.SolidHandleColor = solidColor;
                    }
                }
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var lightColor = EditorGUILayout.ColorField(Content.LightHandleColor, DeformEditorSettings.LightHandleColor);
                    if (check.changed)
                    {
                        Undo.RecordObject(DeformEditorSettings.SettingsAsset, "Changed Light Color Settings");
                        DeformEditorSettings.LightHandleColor = lightColor;
                    }
                }
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var dottedLineSize = EditorGUILayout.FloatField(Content.DottedLineSize, DeformEditorSettings.DottedLineSize);
                    if (check.changed)
                    {
                        Undo.RecordObject(DeformEditorSettings.SettingsAsset, "Changed Dotted Line Size Settings");
                        DeformEditorSettings.DottedLineSize = dottedLineSize;
                    }
                }
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var handleSize = EditorGUILayout.FloatField(Content.ScreenspaceSliderHandleCapSize, DeformEditorSettings.ScreenspaceSliderHandleCapSize);
                    if (check.changed)
                    {
                        Undo.RecordObject(DeformEditorSettings.SettingsAsset, "Changed Handle Size Settings");
                        DeformEditorSettings.ScreenspaceSliderHandleCapSize = handleSize;
                    }
                }
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var angleHandleSize = EditorGUILayout.FloatField(Content.ScreenspaceAngleHandleSize, DeformEditorSettings.ScreenspaceAngleHandleSize);
                    if (check.changed)
                    {
                        Undo.RecordObject(DeformEditorSettings.SettingsAsset, "Changed Angle Handle Size Settings");
                        DeformEditorSettings.ScreenspaceAngleHandleSize = angleHandleSize;
                    }
                }
            }
        }
        public override void OnInspectorGUI()
        {
            var targetType = typeof(DeformEditorSettingsAsset);

            serializedObject.UpdateIfRequiredOrScript();
            SerializedProperty iterator = serializedObject.GetIterator();

            bool currentSectionExpanded = true;

            for (bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
            {
                using (new EditorGUI.DisabledScope(iterator.propertyPath == "m_Script"))
                {
                    var       property  = iterator;
                    FieldInfo fieldInfo = targetType.GetField(property.propertyPath, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
                    if (fieldInfo != null)
                    {
                        var customAttributes = fieldInfo.GetCustomAttributes();

                        foreach (var customAttribute in customAttributes)
                        {
                            if (customAttribute is CollapsibleSection collapsibleSection)
                            {
                                bool collapsed = collapsedSections.Contains(collapsibleSection.Title);
                                currentSectionExpanded = !collapsed;
                                EditorGUI.BeginChangeCheck();
                                bool newExpand = EditorGUILayoutx.FoldoutHeader(collapsibleSection.Title, !collapsed);
                                if (EditorGUI.EndChangeCheck())
                                {
                                    if (newExpand)
                                    {
                                        collapsedSections.Remove(collapsibleSection.Title);
                                    }
                                    else
                                    {
                                        collapsedSections.Add(collapsibleSection.Title);
                                    }
                                }
                            }
                        }
                    }

                    if (currentSectionExpanded)
                    {
                        EditorGUILayout.PropertyField(iterator, true);
                    }
                }
            }
            serializedObject.ApplyModifiedProperties();
        }
Ejemplo n.º 3
0
        protected virtual void DrawDebugInfo()
        {
            if (foldoutDebug = EditorGUILayoutx.FoldoutHeader("Debug Info", foldoutDebug))
            {
                var vertexCount  = 0;
                var modifiedData = DataFlags.None;
                var bounds       = (target as Deformable).GetCurrentMesh().bounds;
                foreach (var t in targets)
                {
                    var deformable = t as Deformable;
                    var mesh       = deformable.GetMesh();

                    if (mesh != null)
                    {
                        vertexCount += deformable.GetMesh().vertexCount;
                    }
                    modifiedData |= deformable.ModifiedDataFlags;
                }

                EditorGUILayout.LabelField($"Vertex Count: {vertexCount}", Styles.WrappedLabel);
                EditorGUILayout.LabelField($"Modified Data: {modifiedData.ToString()}", Styles.WrappedLabel);
                EditorGUILayout.LabelField($"Bounds: {bounds.ToString()}", Styles.WrappedLabel);
            }
        }
Ejemplo n.º 4
0
        public override void OnInspectorGUI()
        {
            serializedObject.UpdateIfRequiredOrScript();
            using (var check = new EditorGUI.ChangeCheckScope())
            {
                EditorGUILayout.PropertyField(properties.UpdateMode, Content.UpdateMode);
                if (check.changed)
                {
                    serializedObject.ApplyModifiedProperties();
                    foreach (var t in targets)
                    {
                        ((Deformable)t).UpdateMode = (UpdateMode)properties.UpdateMode.enumValueIndex;
                    }
                }
            }

            EditorGUILayout.PropertyField(properties.NormalsRecalculation, Content.NormalsRecalculation);
            EditorGUILayout.PropertyField(properties.BoundsRecalculation, Content.BoundsRecalculation);

            if (properties.BoundsRecalculation.hasMultipleDifferentValues || (BoundsRecalculation)properties.BoundsRecalculation.enumValueIndex == BoundsRecalculation.Custom)
            {
                using (new EditorGUI.IndentLevelScope())
                {
                    EditorGUILayout.PropertyField(properties.CustomBounds, Content.CustomBounds);
                }
            }

            EditorGUILayout.PropertyField(properties.ColliderRecalculation, Content.ColliderRecalculation);
            if (properties.ColliderRecalculation.hasMultipleDifferentValues || (ColliderRecalculation)properties.ColliderRecalculation.enumValueIndex == ColliderRecalculation.Auto)
            {
                using (new EditorGUI.IndentLevelScope())
                    EditorGUILayout.PropertyField(properties.MeshCollider, Content.MeshCollider);
            }

            EditorGUILayout.Space();

            deformerList.DoLayoutList();

            var newDeformers = EditorGUILayoutx.DragAndDropArea <Deformer> ();

            if (newDeformers != null && newDeformers.Count > 0)
            {
                Undo.RecordObjects(targets, "Added Deformers");
                foreach (var t in targets)
                {
                    var elements = ((Deformable)t).DeformerElements;
                    foreach (var newDeformer in newDeformers)
                    {
                        elements.Add(new DeformerElement(newDeformer));
                    }
                }

                // I'd like to give a massive thanks and credit to Thomas Ingram for taking time out of his day to
                // solve an abomination of a bug and find this fix. He truly is an editor scripting legend.
                // Changing fields directly with multiple objects selected doesn't dirty the serialized object for some reason.
                // To force it to be dirty you have to call this method.
                serializedObject.SetIsDifferentCacheDirty();
                serializedObject.Update();
            }

            EditorGUILayout.Space();

            using (new EditorGUILayout.HorizontalScope())
            {
                var selectedIndex = GUILayout.Toolbar(-1, Content.UtilityToolbar, EditorStyles.miniButton, GUILayout.MinWidth(0));
                switch (selectedIndex)
                {
                default:
                    throw new System.ArgumentException($"No valid action for toolbar index {selectedIndex}.");

                case -1:
                    break;

                case 0:
                    Undo.RecordObjects(targets, "Cleared Deformers");
                    foreach (var t in targets)
                    {
                        ((Deformable)t).DeformerElements.Clear();
                    }
                    break;

                case 1:
                    Undo.RecordObjects(targets, "Cleaned Deformers");
                    foreach (var t in targets)
                    {
                        ((Deformable)t).DeformerElements.RemoveAll(d => d.Component == null);
                    }
                    break;

                case 2:
                    foreach (var t in targets)
                    {
                        var deformable = t as Deformable;

                        // C:/...<ProjectName>/Assets/
                        var projectPath = Application.dataPath + "/";
                        var assetPath   = EditorUtility.SaveFilePanelInProject("Save Obj", $"{deformable.name}.obj", "obj", "");
                        if (string.IsNullOrEmpty(assetPath))
                        {
                            break;
                        }
                        var fileName = assetPath;
                        // Now that we have a unique asset path we can remove the "Assets/" and ".obj" to get the unique name.
                        // It's pretty gross, but it works and this code doesn't need to be performant.
                        fileName = fileName.Remove(0, 7);
                        fileName = fileName.Remove(fileName.Length - 4, 4);

                        ObjExporter.SaveMesh(deformable.GetMesh(), deformable.GetRenderer(), projectPath, fileName);
                        AssetDatabase.Refresh(ImportAssetOptions.ForceSynchronousImport);
                    }
                    break;

                case 3:
                    foreach (var t in targets)
                    {
                        var deformable = t as Deformable;

                        var assetPath = EditorUtility.SaveFilePanelInProject("Save Mesh Asset", $"{deformable.name}.asset", "asset", "");
                        if (string.IsNullOrEmpty(assetPath))
                        {
                            break;
                        }

                        AssetDatabase.CreateAsset(Instantiate(deformable.GetMesh()), assetPath);
                        AssetDatabase.SaveAssets();
                    }
                    break;
                }
            }

            EditorGUILayout.Space();

            if (foldoutDebug = EditorGUILayoutx.FoldoutHeader("Debug Info", foldoutDebug))
            {
                var vertexCount  = 0;
                var modifiedData = DataFlags.None;
                var bounds       = (target as Deformable).GetMesh().bounds;
                foreach (var t in targets)
                {
                    var deformable = t as Deformable;
                    var mesh       = deformable.GetMesh();

                    if (mesh != null)
                    {
                        vertexCount += deformable.GetMesh().vertexCount;
                    }
                    modifiedData |= deformable.ModifiedDataFlags;
                }

                EditorGUILayout.LabelField($"Vertex Count: {vertexCount}", Styles.WrappedLabel);
                EditorGUILayout.LabelField($"Modified Data: {modifiedData.ToString ()}", Styles.WrappedLabel);
                EditorGUILayout.LabelField($"Bounds: {bounds.ToString ()}", Styles.WrappedLabel);
            }

            serializedObject.ApplyModifiedProperties();

            foreach (var t in targets)
            {
                var deformable = t as Deformable;

                var originalMesh = deformable.GetOriginalMesh();
                if (originalMesh != null && !originalMesh.isReadable)
                {
                    EditorGUILayout.HelpBox(Content.ReadWriteNotEnableAlert, MessageType.Error);
                }
            }

            EditorApplication.QueuePlayerLoopUpdate();
        }
Ejemplo n.º 5
0
        private void OnGUI()
        {
            EditorGUILayout.Space();

            if (GUILayout.Button(Content.CreateDeformable, Styles.Button))
            {
                AddOrCreateDeformable();
            }

            using (new EditorGUILayout.HorizontalScope())
            {
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var rect = GUILayoutUtility.GetRect(1, 1, 18, 18, GUILayout.ExpandWidth(true));
                    rect.width -= Styles.PAD_X * 2;
                    rect.x     += Styles.PAD_X;
                    rect.y     += Styles.PAD_Y * 2;

                    var newSearchQuery = searchField.OnToolbarGUI(rect, searchQuery);
                    if (check.changed)
                    {
                        Undo.RecordObject(this, "Changed Search Query");
                        searchQuery = newSearchQuery;
                    }
                }
            }

            EditorGUILayout.Space();

            using (var scroll = new EditorGUILayout.ScrollViewScope(scrollPosition))
            {
                if (deformerAttributes == null || deformerAttributes.Count == 0)
                {
                    EditorGUILayout.LabelField("No deformers found.", GUILayout.MinWidth(0));
                }
                else
                {
                    filteredDeformerAttributes =
                        (
                            from d in deformerAttributes
                            where string.IsNullOrEmpty(searchQuery) || d.Name.ToLower().Contains(searchQuery.ToLower())
                            select d
                        ).ToList();

                    var drawnCount = 0;
                    for (int i = 0; i < filteredDeformerAttributes.Count; i++)
                    {
                        var current = filteredDeformerAttributes[i];

                        if (drawnCount == 0)
                        {
                            var countInCategory = filteredDeformerAttributes.Count(t => t.Category == current.Category);
                            categoryFoldouts[current.Category] = EditorGUILayoutx.FoldoutHeader($"{current.Category.ToString ()} ({countInCategory})", categoryFoldouts[current.Category], EditorStyles.label);
                        }

                        if (categoryFoldouts[current.Category])
                        {
                            if (GUILayout.Button(new GUIContent(current.Name, current.Description), Styles.Button))
                            {
                                CreateDeformerFromAttribute(current, Event.current.modifiers != EventModifiers.Alt);
                            }
                        }

                        drawnCount++;

                        if (i + 1 < filteredDeformerAttributes.Count)
                        {
                            var next = filteredDeformerAttributes[i + 1];
                            if (next.Category != current.Category)
                            {
                                var countInCategory = filteredDeformerAttributes.Count(t => t.Category == next.Category);
                                categoryFoldouts[next.Category] = EditorGUILayoutx.FoldoutHeader($"{next.Category.ToString ()} ({countInCategory})", categoryFoldouts[next.Category], EditorStyles.label);
                            }
                        }
                    }

                    EditorGUILayout.Space();
                }
                scrollPosition = scroll.scrollPosition;
            }
        }
Ejemplo n.º 6
0
        private void OnGUI()
        {
            var sceneExpandedProperty = serializedAsset.FindProperty(nameof(DeformEditorSettingsAsset.dottedLineSize));

            if (sceneExpandedProperty.isExpanded = EditorGUILayoutx.FoldoutHeader("Scene", sceneExpandedProperty.isExpanded))
            {
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var solidColor = EditorGUILayout.ColorField(Content.SolidHandleColor, DeformEditorSettings.SolidHandleColor);
                    if (check.changed)
                    {
                        Undo.RecordObject(DeformEditorSettings.SettingsAsset, "Changed Solid Color Settings");
                        DeformEditorSettings.SolidHandleColor = solidColor;
                    }
                }
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var lightColor = EditorGUILayout.ColorField(Content.LightHandleColor, DeformEditorSettings.LightHandleColor);
                    if (check.changed)
                    {
                        Undo.RecordObject(DeformEditorSettings.SettingsAsset, "Changed Light Color Settings");
                        DeformEditorSettings.LightHandleColor = lightColor;
                    }
                }
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var dottedLineSize = EditorGUILayout.FloatField(Content.DottedLineSize, DeformEditorSettings.DottedLineSize);
                    if (check.changed)
                    {
                        Undo.RecordObject(DeformEditorSettings.SettingsAsset, "Changed Dotted Line Size Settings");
                        DeformEditorSettings.DottedLineSize = dottedLineSize;
                    }
                }
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var handleSize = EditorGUILayout.FloatField(Content.ScreenspaceSliderHandleCapSize, DeformEditorSettings.ScreenspaceSliderHandleCapSize);
                    if (check.changed)
                    {
                        Undo.RecordObject(DeformEditorSettings.SettingsAsset, "Changed Handle Size Settings");
                        DeformEditorSettings.ScreenspaceSliderHandleCapSize = handleSize;
                    }
                }
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var angleHandleSize = EditorGUILayout.FloatField(Content.ScreenspaceAngleHandleSize, DeformEditorSettings.ScreenspaceAngleHandleSize);
                    if (check.changed)
                    {
                        Undo.RecordObject(DeformEditorSettings.SettingsAsset, "Changed Angle Handle Size Settings");
                        DeformEditorSettings.ScreenspaceAngleHandleSize = angleHandleSize;
                    }
                }
            }

            var importerExpandedProperty = serializedAsset.FindProperty(nameof(DeformEditorSettingsAsset.modelsReadableByDefault));

            if (importerExpandedProperty.isExpanded = EditorGUILayoutx.FoldoutHeader("Importer", importerExpandedProperty.isExpanded))
            {
                using (var check = new EditorGUI.ChangeCheckScope())
                {
                    var modelsReadableByDefault = EditorGUILayout.Toggle(Content.ModelsReadableByDefault, DeformEditorSettings.ModelsReadableByDefault);
                    if (check.changed)
                    {
                        Undo.RecordObject(DeformEditorSettings.SettingsAsset, "Changed Models Readable By Default");
                        DeformEditorSettings.ModelsReadableByDefault = modelsReadableByDefault;
                    }
                }
            }
        }