Exemplo n.º 1
0
        protected void MeshGenerationToggle()
        {
            BGEditorUtility.Horizontal(() =>
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("isMeshGenerationOn"));
                if (!GUILayout.Button(new GUIContent("Remove meshes", "Remove MeshFilter and MeshRenderer components from all child GameObjects with colliders attached"),
                                      GUILayout.Width(120)))
                {
                    return;
                }

                if (MeshColliderAbstract.IsMeshGenerationOn)
                {
                    BGEditorUtility.Inform("Error", "Please, turn off 'isMeshGenerationOn' toggle first.");
                    return;
                }

                var renderer = MeshColliderAbstract.GetComponent <MeshRenderer>();
                if (renderer != null)
                {
                    BGCurve.DestroyIt(renderer);
                }
                var filter = MeshColliderAbstract.GetComponent <MeshFilter>();
                if (filter != null)
                {
                    BGCurve.DestroyIt(filter);
                }
            });
        }
Exemplo n.º 2
0
        private static bool NameHasError(BGCurve curve, string name)
        {
            var error = BGCurvePointField.CheckName(curve, name);

            if (error == null)
            {
                return(false);
            }

            BGEditorUtility.Inform("Error", error);
            return(true);
        }
Exemplo n.º 3
0
        public bool DeleteSelected()
        {
            if (points.Count == 0)
            {
                BGEditorUtility.Inform("Error", "Chose at least one point to delete");
                return(false);
            }

            if (!BGEditorUtility.Confirm("Delete points confirmation", "Are you sure you want to remove " + points.Count + " point(s)?", "Delete"))
            {
                return(false);
            }

            BGCurveEditor.DeletePoints(curve, points.ToArray());

            Clear();
            return(true);
        }
        private void MeshGeneratorEditor()
        {
            BGEditorUtility.VerticalBox(() =>
            {
                BGEditorUtility.Horizontal(() =>
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("isMeshGenerationOn"));
                    if (!GUILayout.Button(new GUIContent("Remove meshes", "Remove MeshFilter and MeshRenderer components from all child GameObjects with colliders attached"),
                                          GUILayout.Width(120)))
                    {
                        return;
                    }

                    if (Collider3DBox.IsMeshGenerationOn)
                    {
                        BGEditorUtility.Inform("Error", "Please, turn off 'isMeshGenerationOn' toggle first.");
                        return;
                    }

                    var colliders = new List <BoxCollider>();
                    Collider3DBox.FillChildrenColliders(colliders);
                    foreach (var collider in colliders)
                    {
                        var renderer = collider.GetComponent <MeshRenderer>();
                        if (renderer != null)
                        {
                            BGCurve.DestroyIt(renderer);
                        }
                        var filter = collider.GetComponent <MeshFilter>();
                        if (filter != null)
                        {
                            BGCurve.DestroyIt(filter);
                        }
                    }
                });

                if (Collider3DBox.IsMeshGenerationOn)
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("MeshMaterial"));
                }
            });
        }
        public bool DeleteSelected()
        {
            if (points.Count == 0)
            {
                BGEditorUtility.Inform("Error", "Chose at least one point to delete");
                return(false);
            }

            if (!BGEditorUtility.Confirm("Delete points confirmation", "Are you sure you want to remove " + points.Count + " point(s)?", "Delete"))
            {
                return(false);
            }

            curve.Transaction(() => { foreach (var point in points)
                                      {
                                          curve.Delete(point);
                                      }
                              });

            Clear();
            return(true);
        }
Exemplo n.º 6
0
        // ================================================================================ Inspector
        public override void OnInspectorGui()
        {
            var settings = Settings;

            editorSelection.Reset();

            // ======================================== Top section
            InspectorTopSection();

            // ======================================== Points
            GUILayout.Space(5);

            if (Curve.PointsCount > 0)
            {
                BGEditorUtility.VerticalBox(() =>
                {
                    var temp = BGCurveSettingsForEditor.DisableInspectorPointMenu;
                    BGCurveSettingsForEditor.DisableInspectorPointMenu = BGEditorUtility.ButtonOnOff(ref temp, "Points menu [" + Curve.PointsCount + "]", "Show points in Editor inspector",
                                                                                                     HiddenPointMenuColor,
                                                                                                     new GUIContent("Show", "Click to show points menu"),
                                                                                                     new GUIContent("Hide", "Click to hide points menu"), () =>
                    {
                        const string title = "Reverse points";

                        if (!GUILayout.Button(new GUIContent(title, "Reverse all points, but keep curve intact")))
                        {
                            return;
                        }

                        if (Curve.PointsCount < 2)
                        {
                            BGEditorUtility.Inform(title, "There should be at least 2 points. Curve has " + Curve.PointsCount);
                            return;
                        }
                        if (!BGEditorUtility.Confirm(title, "Are you sure you want to reverse the order of " + Curve.PointsCount + " points? Curve will remain intact.", "Reverse"))
                        {
                            return;
                        }

                        Curve.Reverse();
                    });

                    //show points!
                    if (!BGCurveSettingsForEditor.DisableInspectorPointMenu)
                    {
                        SwapVector2Labels(Curve.Mode2D, () => Curve.ForEach((point, index, count) => editorPoint.OnInspectorGui(point, index, settings)));
                    }
                });

                // ======================================== Selections operations
                editorSelection.InspectorSelectionOperations();

                //warning
                BGEditorUtility.HelpBox("Selection mode is on", MessageType.Warning, !editorSelection.Changed && editorSelection.HasSelected());
            }
            else
            {
                BGEditorUtility.HorizontalBox(() =>
                {
                    EditorGUILayout.LabelField("No points!");

                    if (BGEditorUtility.ButtonWithIcon(BGBinaryResources.BGAdd123, "Add new point at (0,0,0) local coordinates"))
                    {
                        BGCurveEditor.AddPoint(Curve, new BGCurvePoint(Curve, Vector3.zero, settings.ControlType, Vector3.right, Vector3.left), 0);
                    }
                });
            }

            if (!editorSelection.Changed)
            {
                return;
            }

            Editor.Repaint();
            SceneView.RepaintAll();
        }
        public override void OnInspectorGui()
        {
            settings = SerializedObject.FindProperty("settings");
            var settingsObj = Settings;

            // Save & Load
            showSaveLoad = EditorGUILayout.Foldout(showSaveLoad, "Save and load settings");
            if (showSaveLoad)
            {
                BGEditorUtility.VerticalBox(() =>
                {
                    var path = BGCurveSettingsOperations.GetPath();

                    BGEditorUtility.HelpBox("Folder is not set", MessageType.Info, path == null, () =>
                    {
                        EditorGUILayout.LabelField("Folder", path);

                        BGEditorUtility.HelpBox("Folder is not found", MessageType.Warning, !BGCurveSettingsOperations.IsValid(path), () =>
                        {
                            // =================================  Load settings
                            var all = BGCurveSettingsOperations.GetAll();

                            BGEditorUtility.HelpBox("Folder does not have any settings", MessageType.Warning, all == null || all.Length == 0, () =>
                            {
                                BGEditorUtility.Horizontal(() =>
                                {
                                    var options = new List <GUIContent> {
                                        new GUIContent("")
                                    };
                                    options.AddRange(all.Select(setting => new GUIContent(setting)));
                                    var selected = EditorGUILayout.Popup(new GUIContent("Load", "Load a specified settings for current object"), 0, options.ToArray());
                                    if (selected > 0)
                                    {
                                        var newSettings = BGCurveSettingsOperations.Load(options[selected].text);
                                        if (newSettings != null)
                                        {
                                            BGPrivateField.SetSettings(Curve, newSettings);
                                            EditorUtility.SetDirty(Curve);
                                            lastOperation = options[selected].text + " was loaded";
                                        }
                                        else
                                        {
                                            lastOperation = "Unable to load a settings " + options[selected].text;
                                        }
                                    }

                                    if (GUILayout.Button(new GUIContent("Reload", "Reload settings from disk. This operation does not change settings for the curent object.")))
                                    {
                                        BGCurveSettingsOperations.Reload(BGCurveSettingsOperations.GetPath());
                                        lastOperation = "Settings was reloaded from disk";
                                    }
                                });
                            });

                            // =================================  Save settings
                            BGEditorUtility.Horizontal(() =>
                            {
                                newAssetName = EditorGUILayout.TextField(new GUIContent("Save", "Save current setting on disk"), newAssetName);
                                if (!GUILayout.Button(new GUIContent("Save", "Save current setting on disk")))
                                {
                                    return;
                                }

                                if (newAssetName == null || newAssetName.Trim().Equals(""))
                                {
                                    BGEditorUtility.Inform("Invalid asset name", "Please, enter the name for new asset");
                                }
                                else
                                {
                                    lastOperation = BGCurveSettingsOperations.Save(settingsObj, newAssetName) ? newAssetName + " was saved on disk" : "Unable to save " + newAssetName + " on disk";
                                }
                            });

                            BGEditorUtility.HelpBox(lastOperation, MessageType.Info, lastOperation != null);
                        });
                    });

                    BGEditorUtility.Horizontal(() =>
                    {
                        if (GUILayout.Button(new GUIContent("Save as default", "Save current settings as default for future curves")))
                        {
                            lastOperation = BGCurveSettingsOperations.SaveDefault(settingsObj) ? "Current settings was saved as default" : "Unable to save settings on disk as default";
                        }

                        if (GUILayout.Button(new GUIContent("Chose a folder", "Chose a folder where to store settings files")))
                        {
                            BGCurveSettingsOperations.ChoseDir();
                        }
                    });
                });
            }

            EditorGUILayout.HelpBox("All fields settings are under Fields tab", MessageType.Warning);

            BGEditorUtility.ChangeCheck(() =>
            {
                //Points
                BGEditorUtility.VerticalBox(() =>
                {
                    //Hide handles
                    EditorGUILayout.PropertyField(Find("hideHandles"));

                    EditorGUILayout.PropertyField(Find("newPointDistance"));
                    EditorGUILayout.PropertyField(Find("showPointMenu"));
                    EditorGUILayout.PropertyField(Find("restrictGizmoz"));
                    if (settingsObj.RestrictGizmozSettings.Valid && settingsObj.RestrictGizmozSettings.HasValue)
                    {
                        EditorGUILayout.HelpBox("Gizmos are shown for specified points only", MessageType.Warning);
                    }
                });

                var tangentProp = Find("showTangents");

                //curve
                BGEditorUtility.FadeGroup(showCurveProp, () =>
                {
//                    EditorGUILayout.PropertyField(Find("showCurveMode"));
                    EditorGUILayout.PropertyField(Find("showCurveOption"));
                    EditorGUILayout.PropertyField(Find("sections"));
                    EditorGUILayout.PropertyField(Find("vRay"));
                    EditorGUILayout.PropertyField(Find("lineColor"));

                    //tangents
                    BGEditorUtility.VerticalBox(() =>
                    {
                        EditorGUILayout.PropertyField(tangentProp);
                        if (settingsObj.ShowTangents)
                        {
                            BGEditorUtility.Indent(1, () =>
                            {
                                EditorGUILayout.PropertyField(Find("tangentsSize"));
                                EditorGUILayout.PropertyField(Find("tangentsPerSection"));
                                EditorGUILayout.PropertyField(Find("tangentsColor"));
                            });
                        }
                    });
                });
            }, () =>
            {
                //if any change
                SerializedObject.ApplyModifiedProperties();
                SceneView.RepaintAll();
            });
        }
Exemplo n.º 8
0
        protected override void AdditionalParams()
        {
            EditorGUILayout.PropertyField(serializedObject.FindProperty("width"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("height"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("heightOffset"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("lengthExtends"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("material"));
            EditorGUILayout.PropertyField(serializedObject.FindProperty("isTrigger"));

            BGEditorUtility.VerticalBox(() =>
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("heightAxisMode"));
                if (Collider3DBox.HeightAxisMode == BGCcCollider3DBox.HeightAxisModeEnum.Custom)
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("customHeightAxis"));
                }
                EditorGUILayout.PropertyField(serializedObject.FindProperty("heightAxisRotation"));
            });
            BGEditorUtility.VerticalBox(() =>
            {
                BGEditorUtility.Horizontal(() =>
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("isMeshGenerationOn"));
                    if (!GUILayout.Button(new GUIContent("Remove meshes", "Remove MeshFilter and MeshRenderer components from all child GameObjects with colliders attached"),
                                          GUILayout.Width(120)))
                    {
                        return;
                    }

                    if (Collider3DBox.IsMeshGenerationOn)
                    {
                        BGEditorUtility.Inform("Error", "Please, turn off 'isMeshGenerationOn' toggle first.");
                        return;
                    }

                    var colliders = new List <BoxCollider>();
                    Collider3DBox.FillChildrenColliders(colliders);
                    foreach (var collider in colliders)
                    {
                        var renderer = collider.GetComponent <MeshRenderer>();
                        if (renderer != null)
                        {
                            BGCurve.DestroyIt(renderer);
                        }
                        var filter = collider.GetComponent <MeshFilter>();
                        if (filter != null)
                        {
                            BGCurve.DestroyIt(filter);
                        }
                    }
                });

                if (Collider3DBox.IsMeshGenerationOn)
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("MeshMaterial"));
                }
            });

            BGEditorUtility.VerticalBox(() =>
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("generateKinematicRigidbody"));
                if (!Collider3DBox.GenerateKinematicRigidbody)
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("Rigidbody"));
                }
            });


            base.AdditionalParams();
        }