public void OnInspectorGUI()
        {
            GUILayout.BeginVertical("box");

            EditorGUILayout.LabelField("Spline settings", GUIStyles.BoxTitleStyle);

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.PropertyField(curveResolution, new GUIContent("Curve Resolution"));
            EditorGUILayout.PropertyField(loop, new GUIContent("Loop"));

            EditorGUILayout.PropertyField(separation, new GUIContent("Separation"));

            if (gizmo.splineSettings.separation == SplineSettings.Separation.Fixed)
            {
                EditorGUILayout.PropertyField(separationDistance, new GUIContent("  Distance"));
            }
            else if (gizmo.splineSettings.separation == SplineSettings.Separation.Range)
            {
                EditorGuiUtilities.MinMaxEditor("  Distance Min", ref separationDistanceMin, "  Distance Max", ref separationDistanceMax);
            }
            else if (gizmo.splineSettings.separation == SplineSettings.Separation.PrefabBounds)
            {
                EditorGuiUtilities.MinMaxEditor("  Distance Min", ref separationDistanceMin, "  Distance Max", ref separationDistanceMax);
            }

            EditorGUILayout.PropertyField(lanes, new GUIContent("Lanes"));

            if (lanes.intValue > 1)
            {
                EditorGUILayout.PropertyField(skipCenterLane, new GUIContent("Skip Center Lane"));
            }

            EditorGUILayout.PropertyField(laneDistance, new GUIContent("Lane Distance"));

            EditorGUILayout.PropertyField(instanceRotation, new GUIContent("Rotation"));

            // allow control point rotation only in spline rotation mode
            SplineSettings.Rotation selectedInstanceRotation = (SplineSettings.Rotation)System.Enum.GetValues(typeof(SplineSettings.Rotation)).GetValue(instanceRotation.enumValueIndex);

            if (selectedInstanceRotation == SplineSettings.Rotation.Spline)
            {
                EditorGUILayout.PropertyField(controlPointRotation, new GUIContent("Control Point Rotation"));
            }

            EditorGUILayout.PropertyField(attachMode, new GUIContent("Attach Mode"));

            EditorGUILayout.PropertyField(reusePrefabs, new GUIContent("Reuse Prefabs", "If active, then already created prefabs will be reused. Otherwise new prefabs are created whenever something changes ont he spline."));
            EditorGUILayout.PropertyField(snap, new GUIContent("Snap", "Snap to the closest vertical object / terrain. Best used for initial alignment."));

            EditorGUILayout.PropertyField(debug, new GUIContent("Debug"));

            bool changed = EditorGUI.EndChangeCheck();

            if (changed)
            {
                // at least 1 lane must be active
                if (lanes.intValue <= 1)
                {
                    skipCenterLane.boolValue = false;
                }

                // avoid endless loop by limiting min distance between objects to a value above 0
                if (separationDistance.floatValue <= 0)
                {
                    separationDistance.floatValue = minDistanceBetweenObjectsd;
                }


                // allow control point rotation only in spline rotation mode
                if (selectedInstanceRotation != SplineSettings.Rotation.Spline)
                {
                    controlPointRotation.boolValue = false;
                }
            }

            dirty.boolValue |= changed;

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("New"))
            {
                ClearSpline(false);
            }

            if (GUILayout.Button("Clear"))
            {
                ClearSpline(true);
            }

            if (GUILayout.Button("Update"))
            {
                UpdatePrefabs();
            }

            if (GUILayout.Button("Snap All"))
            {
                SnapAll();
            }


            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            PerformEditorAction();
        }
示例#2
0
        public void OnInspectorGUI()
        {
            GUILayout.BeginVertical("box");

            EditorGUILayout.LabelField("Spline settings", GUIStyles.BoxTitleStyle);

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.PropertyField(curveResolution, new GUIContent("Curve Resolution"));
            EditorGUILayout.PropertyField(loop, new GUIContent("Loop"));

            EditorGUILayout.PropertyField(separation, new GUIContent("Separation"));

            if (gizmo.splineSettings.separation == SplineSettings.Separation.Fixed)
            {
                EditorGUILayout.PropertyField(separationDistance, new GUIContent("  Distance"));
            }
            else if (gizmo.splineSettings.separation == SplineSettings.Separation.Range)
            {
                EditorGuiUtilities.MinMaxEditor("  Distance Min", ref separationDistanceMin, "  Distance Max", ref separationDistanceMax);
            }
            else if (gizmo.splineSettings.separation == SplineSettings.Separation.PrefabRadiusBounds)
            {
                EditorGuiUtilities.MinMaxEditor("  Distance Min", ref separationDistanceMin, "  Distance Max", ref separationDistanceMax);
            }
            else if (gizmo.splineSettings.separation == SplineSettings.Separation.PrefabForwardSize)
            {
                EditorGuiUtilities.MinMaxEditor("  Distance Min", ref separationDistanceMin, "  Distance Max", ref separationDistanceMax);
            }

            EditorGUILayout.PropertyField(lanes, new GUIContent("Lanes"));

            if (lanes.intValue > 1)
            {
                EditorGUILayout.PropertyField(skipCenterLane, new GUIContent("Skip Center Lane"));
            }

            EditorGUILayout.PropertyField(laneDistance, new GUIContent("Lane Distance"));

            EditorGUILayout.PropertyField(instanceRotation, new GUIContent("Rotation"));

            // allow control point rotation only in spline rotation mode
            SplineSettings.Rotation selectedInstanceRotation = (SplineSettings.Rotation)System.Enum.GetValues(typeof(SplineSettings.Rotation)).GetValue(instanceRotation.enumValueIndex);

            if (selectedInstanceRotation == SplineSettings.Rotation.Spline)
            {
                EditorGUILayout.PropertyField(controlPointRotation, new GUIContent("Control Point Rotation"));
            }

            EditorGUILayout.PropertyField(attachMode, new GUIContent("Attach Mode"));

            EditorGUILayout.PropertyField(reusePrefabs, new GUIContent("Reuse Prefabs", "If active, then already created prefabs will be reused. Otherwise new prefabs are created whenever something changes ont he spline."));
            EditorGUILayout.PropertyField(snap, new GUIContent("Snap", "Snap to the closest vertical object / terrain. Best used for initial alignment."));

            EditorGUILayout.PropertyField(debug, new GUIContent("Debug"));

            /* show a list of points
             * TODO:
             *   optimize instantiation
             *   reflection for position
             *   maybe move to dedicated debug tab
             *
             * ReorderableList list = new ReorderableList(editor.serializedObject, controlPoints, false, true, false, false);
             * list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) =>
             * {
             *  var element = list.serializedProperty.GetArrayElementAtIndex(index);
             *  rect.y += 2;
             *  EditorGUI.PropertyField(
             *      new Rect(rect.x, rect.y, 200, EditorGUIUtility.singleLineHeight),
             *      element.FindPropertyRelative("position"), GUIContent.none);
             * };
             * list.DoLayoutList();
             */

            bool changed = EditorGUI.EndChangeCheck();

            if (changed)
            {
                // at least 1 lane must be active
                if (lanes.intValue <= 1)
                {
                    skipCenterLane.boolValue = false;
                }

                // avoid endless loop by limiting min distance between objects to a value above 0
                if (separationDistance.floatValue <= 0)
                {
                    separationDistance.floatValue = minDistanceBetweenObjects;
                }


                // allow control point rotation only in spline rotation mode
                if (selectedInstanceRotation != SplineSettings.Rotation.Spline)
                {
                    controlPointRotation.boolValue = false;
                }
            }

            dirty.boolValue |= changed;

            GUILayout.BeginHorizontal();

            if (GUILayout.Button("New"))
            {
                ClearSpline(false);
            }

            if (GUILayout.Button("Clear"))
            {
                ClearSpline(true);
            }

            if (GUILayout.Button("Update"))
            {
                UpdatePrefabs();
            }

            if (GUILayout.Button("Snap All"))
            {
                SnapAll();
            }


            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            PerformEditorAction();
        }