Пример #1
0
    private static void AddGrindSurface()
    {
        foreach (var o in Selection.gameObjects)
        {
            var surface = o.GetComponent <GrindSurface>();
            if (surface == null)
            {
                surface = o.AddComponent <GrindSurface>();
            }
            else
            {
                surface.DestroySplines();
            }

            if (GrindSurface.AutoGenerateNewSuraces)
            {
                GrindSplineGenerator.Generate(surface,
                                              new ColliderGenerationSettings()
                {
                    IsEdge = EditorPrefs.GetBool("gsDefault_IsEdge"),
                    AutoDetectEdgeAlignment = EditorPrefs.GetBool("gsDefault_AutoDetectEdgeAlignment"),
                    ColliderType            = (ColliderGenerationSettings.ColliderTypes)EditorPrefs.GetInt("gsDefault_ColliderType")
                });
            }
        }
    }
Пример #2
0
    public override void OnInspectorGUI()
    {
        serializedObject.UpdateIfRequiredOrScript();

        if (grindSurface.GetComponent <GrindSpline>() != null)
        {
            EditorGUILayout.HelpBox("Found GrindSpline on this GameObject. This is not supported. Please remove the GrindSpline or this component.", MessageType.Error);

            GUI.enabled = false;
        }

        EditorGUI.BeginChangeCheck();

        EditorGUILayout.Space();

        // ---------------------------- Splines

        EditorGUILayout.BeginVertical(new GUIStyle("box"));
        {
            EditorGUILayout.LabelField("Splines", EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Add GrindSpline"))
            {
                CreateSpline();

                serializedObject.UpdateIfRequiredOrScript();
            }

            drawSplines = GUILayout.Toggle(drawSplines, new GUIContent("Draw GrindSplines"), new GUIStyle("button"));

            EditorGUILayout.EndHorizontal();

            if (GUILayout.Button("Generate Splines"))
            {
                if (grindSurface.Splines.Count == 0 || EditorUtility.DisplayDialog("Confirm", "Are you sure? This cannot be undone", "Yes", "No!"))
                {
                    grindSurface.DestroySplines();

                    GrindSplineGenerator.Generate(grindSurface);

                    serializedObject.UpdateIfRequiredOrScript();
                    return;
                }
            }

            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(serializedObject.FindProperty("Splines"), true);
            EditorGUI.indentLevel--;
        }
        EditorGUILayout.EndVertical();

        // ---------------------------- Colliders

        EditorGUILayout.BeginVertical(new GUIStyle("box"));
        {
            EditorGUILayout.LabelField("Colliders", EditorStyles.boldLabel);

            if (GUILayout.Button("Generate Colliders"))
            {
                grindSurface.GenerateColliders();
            }

            EditorGUILayout.Separator();

            EditorGUILayout.PropertyField(serializedObject.FindProperty("ColliderType"));

            if (grindSurface.ColliderType == GrindSurface.ColliderTypes.Capsule)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("GeneratedColliderRadius"));
            }
            else
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("GeneratedColliderWidth"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("GeneratedColliderDepth"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("IsEdge"));

                if (serializedObject.FindProperty("IsEdge").boolValue)
                {
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("AutoDetectEdgeAlignment"));

                    if (serializedObject.FindProperty("AutoDetectEdgeAlignment").boolValue == false)
                    {
                        EditorGUILayout.PropertyField(serializedObject.FindProperty("FlipEdge"));
                    }
                }
            }

            EditorGUILayout.PropertyField(serializedObject.FindProperty("ColliderContainer"));

            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(serializedObject.FindProperty("GeneratedColliders"), true);
            EditorGUI.indentLevel--;

            if (EditorGUI.EndChangeCheck())
            {
                serializedObject.ApplyModifiedProperties();
            }
        }
        EditorGUILayout.EndVertical();

        if (GUILayout.Button("Destroy & Reset"))
        {
            if (EditorUtility.DisplayDialog("Confirm", "Are you sure? This cannot be undone", "Yes", "No!"))
            {
                grindSurface.DestroySplines();

                serializedObject.UpdateIfRequiredOrScript();

                return;
            }
        }

        GUI.enabled = true;
    }
Пример #3
0
    public override void OnInspectorGUI()
    {
        serializedObject.UpdateIfRequiredOrScript();

        if (grindSurface.GetComponent <GrindSpline>() != null)
        {
            EditorGUILayout.HelpBox("Found GrindSpline on this GameObject. This is not supported. Please remove the GrindSpline or this component.", MessageType.Error);

            GUI.enabled = false;
        }

        EditorGUI.BeginChangeCheck();

        EditorGUILayout.Space();

        // ---------------------------- Splines

        EditorGUILayout.BeginVertical(new GUIStyle("box"));
        {
            EditorGUILayout.LabelField("Splines", EditorStyles.boldLabel);

            EditorGUILayout.BeginHorizontal();
            {
                if (GUILayout.Button("Add GrindSpline"))
                {
                    CreateSpline();

                    serializedObject.UpdateIfRequiredOrScript();
                }

                drawSplines = GUILayout.Toggle(drawSplines, new GUIContent("Draw GrindSplines"), new GUIStyle("button"));
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            EditorGUILayout.BeginVertical();
            {
                EditorGUILayout.LabelField("Default Spline Settings:");

                EditorGUILayout.PropertyField(serializedObject.FindProperty("SurfaceType"));
                EditorGUILayout.PropertyField(serializedObject.FindProperty("IsRound"));
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.Separator();

            GUI.enabled = grindSurface.Splines.Count > 0;

            if (GUILayout.Button("Generate All Colliders"))
            {
                if (EditorUtility.DisplayDialog("Confirm", "Are you sure? This cannot be undone", "Yes", "No!"))
                {
                    EditorCoroutineUtility.StartCoroutineOwnerless(GenerateSplinesColliders());
                }
            }

            if (GUILayout.Button("Generate All Colliders (Use Generation Settings)"))
            {
                if (EditorUtility.DisplayDialog("Confirm", "Are you sure? This cannot be undone", "Yes", "No!"))
                {
                    EditorCoroutineUtility.StartCoroutineOwnerless(GenerateSplinesColliders(grindSurface.ColliderGenerationSettings));
                }
            }

            if (GUILayout.Button("Destroy All & Reset"))
            {
                if (EditorUtility.DisplayDialog("Confirm", "Are you sure? This cannot be undone", "Yes", "No!"))
                {
                    grindSurface.DestroySplines();

                    serializedObject.UpdateIfRequiredOrScript();

                    return;
                }
            }

            GUI.enabled = true;

            var splines_arr = serializedObject.FindProperty("Splines");
            if (splines_arr.arraySize > 0)
            {
                EditorGUILayout.BeginVertical(new GUIStyle("box"));
                {
                    for (int i = 0; i < splines_arr.arraySize; i++)
                    {
                        var e      = splines_arr.GetArrayElementAtIndex(i);
                        var spline = (GrindSpline)e.objectReferenceValue;
                        EditorGUILayout.BeginHorizontal();

                        EditorGUILayout.ObjectField(spline, typeof(GrindSpline), true);

                        if (GUILayout.Button("Generate Colliders"))
                        {
                            if (EditorUtility.DisplayDialog("Confirm", "Are you sure? This cannot be undone", "Yes", "No!"))
                            {
                                spline.GenerateColliders();
                            }
                        }

                        EditorGUILayout.EndHorizontal();
                    }
                }
                EditorGUILayout.EndVertical();
            }
        }
        EditorGUILayout.EndVertical();

        EditorGUILayout.BeginVertical(new GUIStyle("box"));
        {
            EditorGUILayout.LabelField("GrindSpline Generation (Experimental)", EditorStyles.boldLabel);
            EditorGUILayout.HelpBox("Spline generation is an experimental feature and not yet yielding good results for complex objects. It's pretty good at basic ledges, hubbas, etc.", MessageType.Info, true);

            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(serializedObject.FindProperty("ColliderGenerationSettings"), true);
            EditorGUI.indentLevel--;

            if (GUILayout.Button("Generate Splines"))
            {
                if (grindSurface.Splines.Count == 0 || EditorUtility.DisplayDialog("Confirm", "Are you sure? This cannot be undone", "Yes", "No!"))
                {
                    grindSurface.DestroySplines();

                    GrindSplineGenerator.Generate(grindSurface, grindSurface.ColliderGenerationSettings);

                    serializedObject.UpdateIfRequiredOrScript();
                    return;
                }
            }
        }
        EditorGUILayout.EndVertical();

        GUI.enabled = true;

        if (EditorGUI.EndChangeCheck())
        {
            serializedObject.ApplyModifiedProperties();
        }
    }
Пример #4
0
    private void OnGUI()
    {
        EditorGUILayout.BeginVertical(containerStyle);
        {
            EditorGUILayout.BeginVertical(new GUIStyle("box"));
            {
                EditorGUI.BeginChangeCheck();

                EditorGUILayout.LabelField("Default Surface Settings", EditorStyles.boldLabel);
                gsDefault_IsEdge = EditorGUILayout.Toggle("Is Edge", gsDefault_IsEdge);
                gsDefault_AutoDetectEdgeAlignment = EditorGUILayout.Toggle("Auto Edge Alignment", gsDefault_AutoDetectEdgeAlignment);
                gsDefault_ColliderType            = (GrindSurface.ColliderTypes)EditorGUILayout.EnumPopup("Collider Type", gsDefault_ColliderType);

                if (EditorGUI.EndChangeCheck())
                {
                    EditorPrefs.SetBool(nameof(gsDefault_IsEdge), gsDefault_IsEdge);
                    EditorPrefs.SetBool(nameof(gsDefault_AutoDetectEdgeAlignment), gsDefault_AutoDetectEdgeAlignment);
                    EditorPrefs.SetInt(nameof(gsDefault_ColliderType), (int)gsDefault_ColliderType);
                }
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(new GUIStyle("box"));
            {
                EditorGUILayout.LabelField("Generation Settings", EditorStyles.boldLabel);

                EditorGUI.BeginChangeCheck();

                settings_PointTestOffset    = EditorGUILayout.FloatField("PointTestOffset", settings_PointTestOffset);
                settings_PointTestRadius    = EditorGUILayout.FloatField("PointTestRadius", settings_PointTestRadius);
                settings_MaxHorizontalAngle = EditorGUILayout.FloatField("MaxHorizontalAngle", settings_MaxHorizontalAngle);
                settings_MaxSlope           = EditorGUILayout.FloatField("MaxSlope", settings_MaxSlope);

                if (EditorGUI.EndChangeCheck())
                {
                    EditorPrefs.SetFloat(nameof(settings_PointTestOffset), settings_PointTestOffset);
                    EditorPrefs.SetFloat(nameof(settings_PointTestRadius), settings_PointTestRadius);
                    EditorPrefs.SetFloat(nameof(settings_MaxHorizontalAngle), settings_MaxHorizontalAngle);
                    EditorPrefs.SetFloat(nameof(settings_MaxSlope), settings_MaxSlope);

                    GrindSplineGenerator.PointTestOffset    = settings_PointTestOffset;
                    GrindSplineGenerator.PointTestRadius    = settings_PointTestRadius;
                    GrindSplineGenerator.MaxHorizontalAngle = settings_MaxHorizontalAngle;
                    GrindSplineGenerator.MaxSlope           = settings_MaxSlope;
                }
            }
            EditorGUILayout.EndVertical();

            EditorGUILayout.BeginVertical(new GUIStyle("box"));
            {
                EditorGUILayout.LabelField("Selected Object", Selection.activeGameObject?.name);

                if (Selection.activeGameObject != null)
                {
                    var box_col = Selection.activeGameObject.GetComponent <BoxCollider>();
                    if (box_col != null && box_col.transform.parent.GetComponent <GrindSurface>())
                    {
                        if (GUILayout.Button("Flip Edge Collider Offset"))
                        {
                            var c = box_col.center;

                            c.x = c.x * -1f;

                            box_col.center = c;
                        }
                    }
                    else
                    {
                        var surface = Selection.activeGameObject.GetComponent <GrindSurface>() ?? Selection.activeGameObject.transform.GetComponentInParent <GrindSurface>();
                        if (surface == null)
                        {
                            EditorGUILayout.LabelField($"<i>No GrindSurface found</i>", new GUIStyle("label")
                            {
                                richText = true
                            });

                            if (GUILayout.Button("Generate Grind Surface"))
                            {
                                surface = Selection.activeGameObject.AddComponent <GrindSurface>();

                                surface.IsEdge = gsDefault_IsEdge;
                                surface.AutoDetectEdgeAlignment = gsDefault_AutoDetectEdgeAlignment;
                                surface.ColliderType            = gsDefault_ColliderType;

                                GrindSplineGenerator.Generate(surface);
                            }
                        }
                        else
                        {
                            EditorGUILayout.LabelField($"GrindSurface found!", new GUIStyle("label")
                            {
                                richText = true
                            });
                        }
                    }
                }
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndVertical();
    }